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

<form action="<?= base_url('admin/testimonials/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) $t['id'] ?>">

	<div class="grid grid-2">
		<div class="card">
			<div class="card-head"><h3>Testimonial</h3></div>
			<div class="card-body">
				<div class="form-grid">
					<div class="fld"><label>Quote <span class="req">*</span></label>
						<textarea name="quote" style="min-height:140px;" required><?= html_escape($t['quote']) ?></textarea></div>
					<div class="fld"><label>Author Name <span class="req">*</span></label>
						<input type="text" name="author_name" value="<?= html_escape($t['author_name']) ?>" required></div>
					<div class="fld"><label>Author Role / Company</label>
						<input type="text" name="author_role" value="<?= html_escape($t['author_role']) ?>" placeholder="e.g. Brand Manager, Aurora Cosmetics"></div>
				</div>
			</div>
		</div>

		<div class="card">
			<div class="card-head"><h3>Details</h3></div>
			<div class="card-body">
				<div class="fld"><label>Author Photo</label>
					<?php if ($t['photo']): ?><img src="<?= upload_url($t['photo']) ?>" class="thumb-lg" id="imgPrev" style="margin-bottom:8px;border-radius:50%;"><?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' => 'photo',
						'accept' => 'image/*',
						'icon' => 'camera',
						'label' => 'Choose photo',
						'preview' => '#imgPrev',
					)); ?>
				</div>
				<div class="fld"><label>Source Type</label>
					<select name="source_type">
						<?php foreach (array('brand'=>'Brand / Client','talent'=>'Talent','partner'=>'Partner') as $v=>$l): ?>
							<option value="<?= $v ?>" <?= $t['source_type'] === $v ? 'selected' : '' ?>><?= $l ?></option>
						<?php endforeach; ?>
					</select>
				</div>
				<div class="fld"><label>Rating</label>
					<select name="rating">
						<?php for ($i=5;$i>=1;$i--): ?>
							<option value="<?= $i ?>" <?= (int) $t['rating'] === $i ? 'selected' : '' ?>><?= str_repeat('★', $i) ?> (<?= $i ?>)</option>
						<?php endfor; ?>
					</select>
				</div>
				<div class="fld"><label>Sort Order</label><input type="number" name="sort_order" value="<?= (int) $t['sort_order'] ?>"></div>
				<div class="fld"><label class="check"><input type="checkbox" name="is_featured" value="1" <?= $t['is_featured'] ? 'checked' : '' ?>><span>Featured</span></label></div>
				<div class="fld"><label class="check"><input type="checkbox" name="is_active" value="1" <?= $t['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 Testimonial</button>
		<a href="<?= base_url('admin/testimonials') ?>" class="btn btn-ghost">Cancel</a>
	</div></div></div>
</form>
