<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php
$created = can_action('56', 'created');
$edited = can_action('56', 'edited');
$deleted = can_action('56', 'deleted');
?>

<div class="space-y-4">
	<?= message_box('success'); ?>
	<?= message_box('error'); ?>

	<div class="rounded-2xl border border-border bg-card shadow-sm">
		<div class="table-responsive p-4">
			<table class="table table-striped DataTables" id="DataTables" cellspacing="0" width="100%">
				<thead>
					<tr>
						<th><?= lang('opportunity_name') ?></th>
						<th><?= lang('stages') ?></th>
						<th><?= lang('state') ?></th>
						<th><?= lang('expected_revenue') ?></th>
						<th><?= lang('next_action') ?></th>
						<th><?= lang('next_action_date') ?></th>
						<?php $show_custom_fields = custom_form_table(8, null);
						if (!empty($show_custom_fields)) {
							foreach ($show_custom_fields as $c_label => $v_fields) {
								if (!empty($c_label)) { ?>
									<th><?= $c_label ?> </th>
							<?php }
							}
						}
						?>
						<?php if (!empty($edited) || !empty($deleted)) { ?>
							<th class="col-options no-sort text-right"><?= lang('action') ?></th>
						<?php } ?>
					</tr>
				</thead>
				<tbody></tbody>
			</table>
		</div>
	</div>
</div>

<script>
	$(document).ready(function() {
		list = base_url + "admin/opportunities/opportunitiesList";
		window.erpDatatablePreload = window.erpDatatablePreload || {};
		window.erpDatatablePreload.DataTables = window.erpDatatablePreload.DataTables || {};
		<?php if (!empty($datatable_preload)) { ?>
		window.erpDatatablePreload.DataTables["list"] = <?= json_encode($datatable_preload, JSON_UNESCAPED_SLASHES) ?>;
		<?php } ?>
	});
</script>
