<div class="invoice-modern">
<?php echo message_box('success'); ?>
<?php echo message_box('error'); ?>

<?php
$created = can_action('16', 'created');
$edited = can_action('16', 'edited');
$tax_rates_info = isset($tax_rates_info) ? $tax_rates_info : null;
$tax_rate_id = !empty($tax_rates_info->tax_rates_id) ? $tax_rates_info->tax_rates_id : null;
$tax_rate_name = !empty($tax_rates_info->tax_rate_name) ? $tax_rates_info->tax_rate_name : '';
$tax_rate_percent = !empty($tax_rates_info->tax_rate_percent) ? $tax_rates_info->tax_rate_percent : '';
$permissionL = !empty($tax_rates_info->permission) ? $tax_rates_info->permission : null;
?>

<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('tax_rates') ?></p>
				<h1 class="text-2xl font-semibold text-foreground">
					<?= !empty($tax_rate_id) ? lang('edit') . ' ' . lang('tax_rate') : lang('new_tax_rate') ?>
				</h1>
				<p class="text-sm text-muted-foreground"><?= lang('manage') . ' ' . lang('tax_rates') ?></p>
			</div>
			<div class="flex flex-wrap items-center gap-2">
				<a href="<?= base_url('admin/invoice/tax_rates') ?>" 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('tax_rates') ?>
				</a>
				<?php if (!empty($tax_rate_id)) { ?>
					<a href="<?= base_url('admin/invoice/createtax_rates') ?>" 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="plus" class="h-4 w-4"></i>
						<?= lang('new_tax_rate') ?>
					</a>
				<?php } ?>
			</div>
		</div>
	</div>

	<?php if (!empty($created) || !empty($edited)) { ?>
		<?= form_open(base_url('admin/invoice/save_tax_rate/' . $tax_rate_id), array('class' => 'space-y-6', 'data-parsley-validate' => '', 'novalidate' => '')); ?>
		<div class="grid grid-cols-1 xl:grid-cols-12 gap-6">
			<div class="xl:col-span-8 space-y-6">
				<div class="rounded-xl border border-border bg-card p-6 space-y-5">
					<div class="flex items-center gap-2 text-sm font-semibold text-foreground border-b border-border pb-3">
						<i data-lucide="percent" class="h-5 w-5"></i>
						<h2 class="text-base font-semibold text-foreground"><?= lang('tax_rate') . ' ' . lang('details') ?></h2>
					</div>
					<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
						<?= form_input_group('tax_rate_name', lang('tax_rate_name'), $tax_rate_name, 'text', true, array('placeholder' => lang('tax_rate_name'))); ?>
						<?= form_input_group(
							'tax_rate_percent',
							lang('tax_rate_percent'),
							$tax_rate_percent,
							'number',
							true,
							array(
								'step' => '0.01',
								'min' => '0',
								'data-parsley-type' => 'number',
								'placeholder' => '0.00',
							)
						); ?>
					</div>
				</div>
			</div>
			<aside class="xl:col-span-4 space-y-6">
				<div class="rounded-xl border border-border bg-card p-6 space-y-4">
					<div class="flex items-center gap-2 text-sm font-semibold text-foreground border-b border-border pb-2">
						<i data-lucide="shield" class="h-5 w-5"></i>
						<h2 class="text-base font-semibold text-foreground"><?= lang('permission') ?></h2>
					</div>
					<?= form_permission_modern($permission_user, $permissionL, lang('assined_to')); ?>
				</div>
			</aside>
		</div>

		<div class="flex flex-wrap justify-end gap-3">
			<a href="<?= base_url('admin/invoice/tax_rates') ?>" class="inline-flex items-center gap-2 rounded-lg border border-border bg-card px-4 py-2 text-sm font-semibold text-foreground hover:bg-muted">
				<i data-lucide="arrow-left" class="h-4 w-4"></i>
				<?= lang('back') ?>
			</a>
			<button type="submit" 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">
				<i data-lucide="check" class="h-4 w-4"></i>
				<?= !empty($tax_rate_id) ? lang('update') : lang('save') ?>
			</button>
			<button type="submit" name="save" value="2" class="inline-flex items-center gap-2 rounded-lg border border-amber-200 bg-amber-50 px-4 py-2 text-sm font-semibold text-amber-700 hover:bg-amber-100">
				<i data-lucide="plus-circle" class="h-4 w-4"></i>
				<?= !empty($tax_rate_id) ? lang('update') . ' & ' . lang('add_more') : lang('save') . ' & ' . lang('add_more') ?>
			</button>
		</div>
		<?= form_close(); ?>
	<?php } else { ?>
		<div class="rounded-2xl border border-border bg-card p-6 text-sm text-muted-foreground">
			<?= lang('you_dont_have_permission') ?>
		</div>
	<?php } ?>
</div>
</div>
