<?= message_box('success'); ?>
<?= message_box('error'); ?>

<?php
$form_id = !empty($quotationforms_info) ? $quotationforms_info->quotationforms_id : null;
$form_title = !empty($quotationforms_info) ? $quotationforms_info->quotationforms_title : '';
$form_status = !empty($quotationforms_info) ? $quotationforms_info->quotationforms_status : 'enabled';
$status_options = array(
	'enabled' => lang('enabled'),
	'disabled' => lang('disabled'),
);
$builder_fields = !empty($formbuilder_data) && is_array($formbuilder_data) ? array_values($formbuilder_data) : array();
$forms_code = !empty($quotationforms_code) ? $quotationforms_code : '';
?>

<div class="space-y-6">
	<div class="rounded-2xl border border-border bg-card p-6 shadow-sm">
		<div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
			<div>
				<p class="text-xs font-semibold uppercase tracking-wide text-muted-foreground"><?= lang('quotations_form') ?></p>
				<h1 class="text-2xl font-semibold text-foreground"><?= lang('edit') . ' ' . lang('quotations_form') ?></h1>
				<p class="text-sm text-muted-foreground"><?= lang('manage') . ' ' . lang('quotations_form') ?></p>
			</div>
			<div class="flex flex-wrap items-center gap-2">
				<a href="<?= base_url('admin/quotations/quotations_form') ?>" class="inline-flex items-center gap-2 rounded-lg border border-border bg-card px-3 py-2 text-sm font-medium text-foreground hover:bg-muted">
					<i data-lucide="list" class="h-4 w-4"></i>
					<?= lang('quotations_form') ?>
				</a>
				<a href="<?= base_url('admin/quotations/new_quotations_form') ?>" class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-3 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-500">
					<i data-lucide="plus" class="h-4 w-4"></i>
					<?= lang('new_quotations_form') ?>
				</a>
			</div>
		</div>
	</div>

	<form action="<?= base_url('admin/quotations/add_form/' . $form_id) ?>" method="post" id="addQuotationForm" class="space-y-6">
		<div class="rounded-xl border border-border bg-card p-6">
			<div class="mb-4 flex items-center gap-2 border-b border-border pb-3 text-sm font-semibold text-foreground">
				<i data-lucide="file-pen-line" class="h-5 w-5"></i>
				<h2 class="text-base font-semibold"><?= lang('form') . ' ' . lang('details') ?></h2>
			</div>
			<div class="grid grid-cols-1 gap-5 md:grid-cols-2">
				<?= form_input_group('quotationforms_title', lang('form_title'), $form_title, 'text', true, array('placeholder' => lang('form_title'))); ?>
				<?= form_select_group('quotationforms_status', lang('status'), $status_options, $form_status, false); ?>
			</div>
		</div>

		<input type="hidden" name="quotationforms_code" id="quotationforms_code" value="<?= html_escape($forms_code) ?>">
		<?php
		$builder_id = 'quotation-form-builder-edit';
		$hidden_input_id = 'quotationforms_code';
		$this->load->view('admin/quotations/_quotation_form_builder', array(
			'builder_id' => $builder_id,
			'hidden_input_id' => $hidden_input_id,
			'builder_fields' => $builder_fields,
		));
		?>

		<div class="flex items-center justify-end">
			<button class="inline-flex items-center gap-2 rounded-lg bg-indigo-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500" type="submit">
				<i data-lucide="save" class="h-4 w-4"></i>
				<?= lang('save') ?>
			</button>
		</div>
	</form>
</div>
