<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** PAGE FORM — Expects: $page, $blocks. */
$pg = $page;
$b = $blocks;
$values = isset($b['values']) && is_array($b['values']) ? $b['values'] : array();
?>
<div class="page-head">
	<div><h2>Edit Page — <?= html_escape($pg['title']) ?></h2></div>
	<a href="<?= base_url('admin/pages') ?>" class="btn btn-ghost">← Back</a>
</div>

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

	<div class="card">
		<div class="card-head"><h3>Page Content Blocks</h3></div>
		<div class="card-body">
			<div class="form-grid">
				<div class="fld"><label>Page Title</label>
					<input type="text" name="title" value="<?= html_escape($pg['title']) ?>"></div>
				<div class="fld"><label>Our Origin Story</label>
					<textarea name="origin"><?= html_escape($b['origin'] ?? '') ?></textarea></div>
				<div class="fld"><label>Our Vision</label>
					<textarea name="vision"><?= html_escape($b['vision'] ?? '') ?></textarea></div>
				<div class="fld"><label>Our Mission</label>
					<textarea name="mission"><?= html_escape($b['mission'] ?? '') ?></textarea></div>
				<div class="fld"><label>Our Philosophy</label>
					<textarea name="philosophy"><?= html_escape($b['philosophy'] ?? '') ?></textarea></div>
				<div class="fld"><label>What Makes Us Different</label>
					<textarea name="difference"><?= html_escape($b['difference'] ?? '') ?></textarea></div>
			</div>
		</div>
	</div>

	<div class="card" data-repeater>
		<div class="card-head">
			<h3>Core Values</h3>
			<button type="button" class="btn btn-ghost btn-sm" data-repeater-add><?= bloom_icon('plus', 14) ?> Add Value</button>
		</div>
		<div class="card-body">
			<div data-repeater-list>
				<?php foreach ($values as $v): ?>
					<div data-repeater-row style="display:flex;gap:8px;margin-bottom:10px;">
						<input type="text" name="values[]" value="<?= html_escape($v) ?>" style="flex:1;padding:11px 13px;border-radius:9px;border:1.5px solid var(--line);">
						<button type="button" class="icon-btn danger" data-repeater-remove><?= bloom_icon('trash', 16) ?></button>
					</div>
				<?php endforeach; ?>
			</div>
			<template data-repeater-template>
				<div data-repeater-row style="display:flex;gap:8px;margin-bottom:10px;">
					<input type="text" name="values[]" style="flex:1;padding:11px 13px;border-radius:9px;border:1.5px solid var(--line);">
					<button type="button" class="icon-btn danger" data-repeater-remove><?= bloom_icon('trash', 16) ?></button>
				</div>
			</template>
		</div>
	</div>

	<div class="card">
		<div class="card-head"><h3>SEO</h3></div>
		<div class="card-body">
			<div class="form-grid cols-2">
				<div class="fld"><label>Meta Title</label><input type="text" name="meta_title" value="<?= html_escape($pg['meta_title']) ?>"></div>
				<div class="fld"><label>Meta Description</label><input type="text" name="meta_desc" value="<?= html_escape($pg['meta_desc']) ?>"></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 Page</button>
		<a href="<?= base_url('admin/pages') ?>" class="btn btn-ghost">Cancel</a>
	</div></div></div>
</form>
