<?= message_box('success'); ?>
<?= message_box('error');
$created = can_action('39', 'created');
$edited = can_action('39', 'edited');
$deleted = can_action('39', 'deleted');
?>
<div class="space-y-4">
	<div class="rounded-2xl border border-border bg-card shadow-sm">
		<div class="p-6">
			<div class="grid grid-cols-1 lg:grid-cols-12 gap-6">

				<?php if (!empty($edited) || !empty($deleted)) { ?>
					<div class="lg:col-span-4">
						<div class="rounded-2xl border border-dashed border-border bg-card p-4 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="user-x" class="h-4 w-4"></i>
								<span>
									<?= !empty($termination) ? lang('update') : lang('new') ?>
									<?= lang('termination_type') ?>
								</span>
							</div>

								<?php echo form_open(
									base_url('admin/termination/saved_termination_type/' . (!empty($termination) ? $termination->customer_group_id : '')),
									array('class' => 'space-y-3')
								); ?>

								<?= form_input_group(
									'customer_group',
									lang('termination_type'),
									!empty($termination) ? $termination->customer_group : '',
									'text',
									true,
									['placeholder' => lang('termination_type')]
								); ?>

								<?= form_input_group(
									'description',
									lang('description'),
									!empty($termination) ? $termination->description : '',
									'text',
									false,
									['placeholder' => lang('description')]
								); ?>

								<div class="flex items-center gap-2">
									<button type="submit"
										class="btn btn-sm btn-primary inline-flex items-center gap-2">
										<i data-lucide="check" class="h-4 w-4"></i>
										<?= !empty($termination) ? lang('update') : lang('add') ?>
									</button>

									<?php if (!empty($termination)) { ?>
										<a href="<?= base_url('admin/termination/termination_type/termination/') ?>"
											class="btn btn-danger btn-sm">
											<?= lang('cancel') ?>
										</a>
									<?php } ?>
								</div>
								<?php echo form_close(); ?>
						</div>
					</div>
				<?php } ?>

				<div class="lg:col-span-8">
					<div class="grid grid-cols-1 xl:grid-cols-2 2xl:grid-cols-3 gap-4">
						<?php
						$all_customer_group = get_order_by(
							'tbl_customer_group',
							['type' => 'termination'],
							true
						);

						if (!empty($all_customer_group)) {
							foreach ($all_customer_group as $customer_group) {
						?>
								<div id="termination_<?= $customer_group->customer_group_id ?>"
									class="rounded-xl border border-border bg-muted/30 p-4">

									<div class="flex items-start justify-between gap-2">
										<div>
											<h4 class="text-sm font-semibold text-foreground">
												<?= $customer_group->customer_group ?>
											</h4>

											<?php if (!empty($customer_group->description)) { ?>
												<p class="mt-2 text-xs text-muted-foreground">
													<?= $customer_group->description ?>
												</p>
											<?php } ?>
										</div>

										<div class="flex items-center gap-0">
											<?php if (!empty($edited)) { ?>
												<?= btn_edit(
													'admin/termination/termination_type/termination/' .
														$customer_group->customer_group_id
												) ?>
											<?php } ?>

											<?php if (!empty($deleted)) { ?>
												<?= ajax_anchor(
													base_url(
														"admin/termination/delete_termination_type/" .
															$customer_group->customer_group_id
													),
													'',
													[
														"class" => "",
														"title" => lang('delete'),
														"data-fade-out-on-success" =>
														"#termination_" .
															$customer_group->customer_group_id
													]
												); ?>
											<?php } ?>
										</div>
									</div>

								</div>
						<?php
							}
						}
						?>
					</div>
				</div>

			</div>
		</div>

	</div>
</div>
