<?php
$created = can_action('36', 'created');
$edited = can_action('36', 'edited');
$deleted = can_action('36', 'deleted');
$currency = $this->db->where('code', config_item('default_currency'))->get('tbl_currencies')->row();
$account_id = !empty($account_info) ? $account_info->account_id : null;
$permissionL = !empty($account_info) ? $account_info->permission : null;
?>

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

<?php if (!empty($created) || !empty($edited)) : ?>
	<div class="rounded-2xl border border-border bg-card shadow-sm">
		<div class="px-6 py-5 flex justify-between items-start border-b border-border">
			<div class="flex items-center">
				<div>
					<h3 class="text-xl font-bold text-foreground"><?= !empty($account_info) ? lang('edit') . ' ' . lang('account') : lang('new_account'); ?></h3>
				</div>
			</div>
			<div class="flex gap-2">
				<a href="<?= base_url('admin/account/manage_account'); ?>"
					class="inline-flex items-center gap-2 rounded-lg border border-border bg-card px-4 py-2 text-sm font-medium text-foreground shadow-sm hover:bg-muted transition">
					<i data-lucide="arrow-left" class="h-4 w-4"></i>
					<?= lang('back'); ?>
				</a>
				<a href="<?= base_url('admin/account/manage_account'); ?>"
					class="inline-flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white shadow hover:bg-primary/90 transition"><?= lang('all') . ' ' . lang('account'); ?></a>
			</div>
		</div>

		<?= form_open(base_url('admin/account/save_account/' . $account_id), array('class' => 'p-6 space-y-6', 'enctype' => 'multipart/form-data', 'data-parsley-validate' => '', 'role' => 'form')); ?>

		<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
			<div class="lg:col-span-2 space-y-5">
				<div class="bg-slate-50 p-4 rounded-xl border border-slate-200 dark:bg-slate-800 dark:border-slate-700">
					<h4 class="text-sm font-semibold text-foreground flex items-center gap-2 mb-3 border-b border-slate-200 pb-2 dark:text-slate-100 dark:border-slate-700">
						<i data-lucide="landmark" class="h-5 w-5"></i>
						<?= lang('general'); ?>
					</h4>

					<div class="grid grid-cols-1 md:grid-cols-2 gap-5 mb-4">
						<?= form_input_group('account_name', lang('account_name'), !empty($account_info) ? $account_info->account_name : '', 'text', true, array('placeholder' => lang('account_name'))); ?>
						<?= form_input_group('balance', lang('initial_balance'), !empty($account_info) ? $account_info->balance : '', 'number', true, array('step' => '0.01'), !empty($currency->symbol) ? $currency->symbol : default_currency()); ?>
						<?= form_input_group('account_number', lang('account_number'), !empty($account_info) ? $account_info->account_number : '', 'text', false, array('placeholder' => lang('account_number'))); ?>
						<?= form_input_group('contact_person', lang('contact_person'), !empty($account_info) ? $account_info->contact_person : '', 'text', false, array('placeholder' => lang('contact_person'))); ?>
						<?= form_input_group('contact_phone', lang('phone'), !empty($account_info) ? $account_info->contact_phone : '', 'text', false, array('placeholder' => lang('phone'))); ?>
					</div>

					<?= form_textarea('description', lang('description'), !empty($account_info) ? $account_info->description : '', 4, false, array(), 'stacked'); ?>

					<div class="mt-4">
						<?= form_textarea('bank_details', lang('bank_details'), !empty($account_info) ? $account_info->bank_details : '', 4, false, array(), 'stacked'); ?>
					</div>

					<div class="flex items-center gap-2 mt-6">
						<?= btn_update(!empty($account_info) ? lang('updates') : lang('create_acount'), 'md') ?>
						<?= btn_cancel('admin/account/manage_account', 'cancel', 'md', 'x', array('class' => 'mb-0 !h-9')); ?>
					</div>
				</div>
			</div>

			<div class="space-y-5">
				<?= form_permission_modern($permission_user, $permissionL, lang('assined_to')); ?>

				<div class="bg-slate-50 p-4 rounded-xl border border-slate-200 dark:bg-slate-800 dark:border-slate-700">
					<h4 class="text-sm font-semibold text-foreground flex items-center gap-2 mb-3 border-b border-slate-200 pb-2 dark:text-slate-100 dark:border-slate-700">
						<i data-lucide="list" class="h-5 w-5"></i>
						<?= lang('custom_field'); ?>
					</h4>
					<?= custom_form_Fields(21, $account_id); ?>
				</div>
			</div>
		</div>

		<?= form_close(); ?>
	</div>
<?php endif; ?>
