<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** TEAM FORM — Expects: $member, $mode. */
$m = $member;
$socials = decode_json($m['socials']);
?>
<div class="page-head">
	<div><h2><?= $mode === 'edit' ? 'Edit' : 'Add' ?> Team Member</h2></div>
	<a href="<?= base_url('admin/team') ?>" class="btn btn-ghost">← Back</a>
</div>

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

	<div class="grid grid-2">
		<div class="card">
			<div class="card-head"><h3>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($m['name']) ?>" required></div>
					<div class="fld"><label>Role <span class="req">*</span></label>
						<input type="text" name="role" value="<?= html_escape($m['role']) ?>" required placeholder="e.g. Creative Director"></div>
					<div class="fld"><label>Bio</label>
						<textarea name="bio"><?= html_escape($m['bio']) ?></textarea></div>
					<div class="fld"><label>Instagram URL</label>
						<input type="text" name="social_instagram" value="<?= html_escape($socials['instagram'] ?? '') ?>"></div>
					<div class="fld"><label>LinkedIn URL</label>
						<input type="text" name="social_linkedin" value="<?= html_escape($socials['linkedin'] ?? '') ?>"></div>
				</div>
			</div>
		</div>

		<div class="card">
			<div class="card-head"><h3>Photo &amp; Settings</h3></div>
			<div class="card-body">
				<div class="fld"><label>Photo</label>
					<?php if ($m['photo']): ?><img src="<?= upload_url($m['photo']) ?>" class="thumb-lg" id="imgPrev" style="border-radius:50%;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' => 'photo',
						'accept' => 'image/*',
						'icon' => 'camera',
						'label' => 'Choose photo',
						'preview' => '#imgPrev',
					)); ?>
				</div>
				<div class="fld"><label>Sort Order</label><input type="number" name="sort_order" value="<?= (int) $m['sort_order'] ?>"></div>
				<div class="fld"><label class="check"><input type="checkbox" name="is_founder" value="1" <?= $m['is_founder'] ? 'checked' : '' ?>><span>Founder</span></label></div>
				<div class="fld"><label class="check"><input type="checkbox" name="is_active" value="1" <?= $m['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 Member</button>
		<a href="<?= base_url('admin/team') ?>" class="btn btn-ghost">Cancel</a>
	</div></div></div>
</form>
