<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** HERO SLIDE FORM — Expects: $slide, $mode. */
$s = $slide;
?>
<div class="page-head">
	<div><h2><?= $mode === 'edit' ? 'Edit' : 'Add' ?> Hero Slide</h2></div>
	<a href="<?= base_url('admin/hero') ?>" class="btn btn-ghost">← Back to Slides</a>
</div>

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

	<div class="grid grid-2-1">
		<div>
			<!-- CONTENT -->
			<div class="card">
				<div class="card-head"><h3>Slide Content</h3></div>
				<div class="card-body">
					<div class="form-grid">
						<div class="fld">
							<label>Eyebrow Text</label>
							<input type="text" name="eyebrow" value="<?= html_escape($s['eyebrow']) ?>" placeholder="e.g. Creative Agency">
						</div>
						<div class="fld">
							<label>Heading <span class="req">*</span></label>
							<input type="text" name="heading" value="<?= html_escape($s['heading']) ?>" required placeholder="Main headline">
						</div>
						<div class="fld fld-full">
							<label>Subheading</label>
							<textarea name="subheading" placeholder="Supporting line of text"><?= html_escape($s['subheading']) ?></textarea>
						</div>
					</div>
				</div>
			</div>

			<!-- CALL TO ACTION -->
			<div class="card">
				<div class="card-head"><h3>Call-to-Action Buttons</h3></div>
				<div class="card-body">
					<div class="form-grid cols-2">
						<div class="fld">
							<label>Primary Button Label</label>
							<input type="text" name="cta1_label" value="<?= html_escape($s['cta1_label']) ?>" placeholder="Work With Us">
						</div>
						<div class="fld">
							<label>Primary Button URL</label>
							<input type="text" name="cta1_url" value="<?= html_escape($s['cta1_url']) ?>" placeholder="contact">
						</div>
						<div class="fld">
							<label>Secondary Button Label</label>
							<input type="text" name="cta2_label" value="<?= html_escape($s['cta2_label']) ?>" placeholder="View Portfolio">
						</div>
						<div class="fld">
							<label>Secondary Button URL</label>
							<input type="text" name="cta2_url" value="<?= html_escape($s['cta2_url']) ?>" placeholder="portfolio">
						</div>
					</div>
					<p class="hint" style="margin-top:10px;">URLs are relative to the site root, e.g. <code>portfolio</code> or <code>contact</code>.</p>
				</div>
			</div>
		</div>

		<!-- SIDEBAR: media + settings -->
		<div>
			<div class="card">
				<div class="card-head"><h3>Media</h3></div>
				<div class="card-body">
					<div class="fld">
						<label>Media Type <span class="req">*</span></label>
						<select name="media_type" id="mediaType">
							<?php foreach (array('image' => 'Background Image', 'video' => 'Video File', 'youtube' => 'YouTube Video') as $v => $l): ?>
								<option value="<?= $v ?>" <?= $s['media_type'] === $v ? 'selected' : '' ?>><?= $l ?></option>
							<?php endforeach; ?>
						</select>
					</div>

					<div class="fld">
						<label>Background / Poster Image</label>
						<?php if ($s['image']): ?>
							<img src="<?= upload_url($s['image']) ?>" class="thumb-lg" style="margin-bottom:8px;" id="imgPrev">
						<?php else: ?>
							<img src="" class="thumb-lg" style="margin-bottom:8px;display:none;" id="imgPrev">
						<?php endif; ?>
						<?php $this->load->view('admin/partials/_upload_field', array(
							'name'    => 'image',
							'accept'  => 'image/*',
							'icon'    => 'image',
							'label'   => 'Choose image',
							'preview' => '#imgPrev',
							'hint'    => 'Used for image slides and as the video poster.',
						)); ?>
					</div>

					<div class="fld">
						<label>Video File</label>
						<?php $this->load->view('admin/partials/_upload_field', array(
							'name'   => 'video_file',
							'accept' => 'video/mp4,video/webm',
							'icon'   => 'film',
							'label'  => 'Choose video',
							'hint'   => 'MP4/WebM, up to '.floor((setting('upload_max_video') ?: ($this->config->item('upload_max_video') ?: 51200)) / 1024).' MB. Used when media type is "Video File". For best performance keep hero videos short and compressed.',
						)); ?>
						<?php if ($s['video_file']): ?><p class="hint">Current: <?= html_escape(basename($s['video_file'])) ?></p><?php endif; ?>
					</div>

					<div class="fld">
						<label>YouTube URL or ID</label>
						<input type="text" name="youtube_id" value="<?= html_escape($s['youtube_id']) ?>" placeholder="https://youtube.com/watch?v=...">
					</div>
				</div>
			</div>

			<div class="card">
				<div class="card-head"><h3>Settings</h3></div>
				<div class="card-body">
					<div class="fld">
						<label>Sort Order</label>
						<input type="number" name="sort_order" value="<?= (int) $s['sort_order'] ?>">
					</div>
					<div class="fld">
						<label class="check"><input type="checkbox" name="overlay" value="1" <?= $s['overlay'] ? 'checked' : '' ?>><span>Dark overlay (improves text legibility)</span></label>
					</div>
					<div class="fld">
						<label class="check"><input type="checkbox" name="is_active" value="1" <?= $s['is_active'] ? 'checked' : '' ?>><span>Active (visible on site)</span></label>
					</div>
				</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 Slide</button>
			<a href="<?= base_url('admin/hero') ?>" class="btn btn-ghost">Cancel</a>
		</div>
	</div></div>
</form>
