<?= 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="alert-triangle" class="h-4 w-4"></i>
								<span>
									<?= !empty($warning) ? lang('update') : lang('new') ?>
									<?= lang('warning_type') ?>
								</span>
							</div>

							<form method="post"
								action="<?= base_url('admin/warning/saved_warning_type/' . (!empty($warning) ? $warning->customer_group_id : '')) ?>"
								class="space-y-3">

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

								<?= form_input_group(
									'description',
									lang('description'),
									!empty($warning) ? $warning->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($warning) ? lang('update') : lang('add') ?>
									</button>

									<?php if (!empty($warning)) { ?>
										<a href="<?= base_url('admin/warning/warning_type/warning/') ?>"
											class="btn btn-danger btn-sm">
											<?= lang('cancel') ?>
										</a>
									<?php } ?>
								</div>
							</form>
						</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' => 'warning'],
							true
						);

						if (!empty($all_customer_group)) {
							foreach ($all_customer_group as $customer_group) {
						?>
								<div id="warning_<?= $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/warning/warning_type/warning/' .
														$customer_group->customer_group_id
												) ?>
											<?php } ?>

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

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

			</div>
		</div>
	</div>
</div>
