<?php
$period = !empty($period) ? $period : null;
$status_options = array(
	'open' => lang('open'),
	'closed' => lang('closed'),
);
$is_edit = !empty($period);
?>

<div class="space-y-5">
	<div class="rounded-2xl border border-slate-200 bg-gradient-to-r from-slate-950 via-slate-900 to-slate-800 px-5 py-5 text-white shadow-sm dark:border-slate-700">
		<div class="flex items-start gap-4">
			<div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-white/10 ring-1 ring-white/10">
				<i data-lucide="calendar-range" class="h-6 w-6"></i>
			</div>
			<div class="min-w-0 flex-1">
				<p class="text-xs font-semibold uppercase tracking-[0.18em] text-white/60"><?= lang('accounting_period') ?></p>
				<h3 class="mt-1 text-xl font-semibold tracking-tight"><?= $is_edit ? lang('edit') : lang('new') ?> <?= lang('accounting_period') ?></h3>
				<p class="mt-2 text-sm leading-6 text-white/70"><?= lang('accounting_period_form_intro') ?></p>
			</div>
		</div>
	</div>

	<?php echo form_open(base_url('admin/accounting/save_accounting_period/' . (!empty($period->period_id) ? $period->period_id : '')), array('class' => 'space-y-5', 'data-parsley-validate' => '', 'data-modal-refresh-page' => '1', 'novalidate' => '', 'enctype' => 'multipart/form-data', 'role' => 'form')); ?>
		<div class="rounded-2xl border border-border bg-card p-5 shadow-sm">
			<div class="grid gap-4">
				<?= form_input_group('name', lang('name'), !empty($period->name) ? $period->name : '', 'text', true, array('placeholder' => lang('name'))); ?>
				<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
					<?= form_datepicker('start_date', lang('start_date'), !empty($period->start_date) ? $period->start_date : date('Y-m-d'), true, array('class' => 'w-full', 'data-max' => '#end_date', 'data-auto-close' => 'true')); ?>
					<?= form_datepicker('end_date', lang('end_date'), !empty($period->end_date) ? $period->end_date : date('Y-m-d'), true, array('class' => 'w-full', 'data-min' => '#start_date', 'data-auto-close' => 'true')); ?>
				</div>
				<?= form_select_group('status', lang('status'), $status_options, !empty($period->status) ? $period->status : 'open', true); ?>
				<?= form_textarea_group('notes', lang('notes'), !empty($period->notes) ? $period->notes : '', 4, false, array('placeholder' => lang('notes'))); ?>
			</div>
			<div class="mt-5 flex items-center justify-end gap-2 border-t border-border pt-4">
				<button type="button" class="inline-flex items-center gap-2 rounded-lg border border-border bg-card px-4 py-2 text-sm font-semibold text-foreground transition hover:bg-muted" data-dismiss="modal">
					<i data-lucide="x" class="h-4 w-4"></i>
					<?= lang('close') ?>
				</button>
				<button type="submit" class="inline-flex items-center gap-2 rounded-lg bg-slate-900 px-4 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-slate-800 dark:bg-slate-100 dark:text-slate-900 dark:hover:bg-white">
					<i data-lucide="check" class="h-4 w-4"></i>
					<?= lang('save') ?>
				</button>
			</div>
		</div>
	<?php echo form_close(); ?>
</div>
