<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** PARTNER FORM — Expects: $partner, $mode. */
$p = $partner;
?>
<div class="page-head">
	<div><h2><?= $mode === 'edit' ? 'Edit' : 'Add' ?> Partner</h2></div>
	<a href="<?= base_url('admin/partners') ?>" class="btn btn-ghost">← Back</a>
</div>

<form action="<?= base_url('admin/partners/save') ?>" method="post" enctype="multipart/form-data">
	<?= form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash()) ?>
	<input type="hidden" name="id" value="<?= (int) $p['id'] ?>">

	<div class="grid grid-2">
		<div class="card">
			<div class="card-head"><h3>Partner Details</h3></div>
			<div class="card-body">
				<div class="form-grid">
					<div class="fld"><label>Name <span class="req">*</span></label>
						<input type="text" name="name" value="<?= html_escape($p['name']) ?>" required></div>
					<div class="fld"><label>Website URL</label>
						<input type="url" name="website" value="<?= html_escape($p['website']) ?>" placeholder="https://"></div>
					<div class="fld"><label>Category</label>
						<select name="category">
							<?php foreach (array('client'=>'Client','partner'=>'Partner','media'=>'Media') as $v=>$l): ?>
								<option value="<?= $v ?>" <?= $p['category'] === $v ? 'selected' : '' ?>><?= $l ?></option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="fld"><label>Sort Order</label>
						<input type="number" name="sort_order" value="<?= (int) $p['sort_order'] ?>"></div>
				</div>
			</div>
		</div>

		<div class="card">
			<div class="card-head"><h3>Logo &amp; Display</h3></div>
			<div class="card-body">
				<div class="fld"><label>Logo</label>
					<?php if ($p['logo']): ?><img src="<?= upload_url($p['logo']) ?>" class="thumb-lg" id="imgPrev" style="object-fit:contain;background:#f4f1f5;margin-bottom:8px;"><?php else: ?><img src="" class="thumb-lg" id="imgPrev" style="display:none;margin-bottom:8px;"><?php endif; ?>
					<?php $this->load->view('admin/partials/_upload_field', array(
						'name' => 'logo',
						'accept' => 'image/*,.svg',
						'icon' => 'image',
						'label' => 'Choose logo',
						'preview' => '#imgPrev',
					)); ?>
					<p class="hint">PNG, SVG or WebP. Transparent background recommended.</p>
				</div>
				<div class="fld"><label class="check"><input type="checkbox" name="is_featured" value="1" <?= $p['is_featured'] ? 'checked' : '' ?>><span>Show in homepage logo strip</span></label></div>
				<div class="fld"><label class="check"><input type="checkbox" name="is_active" value="1" <?= $p['is_active'] ? 'checked' : '' ?>><span>Active</span></label></div>
			</div>
		</div>
	</div>

	<div class="card"><div class="card-body"><div class="form-actions">
		<button type="submit" class="btn btn-primary"><?= bloom_icon('check', 16) ?> Save Partner</button>
		<a href="<?= base_url('admin/partners') ?>" class="btn btn-ghost">Cancel</a>
	</div></div></div>
</form>
