<?php if (isset($daily_statistics) && !empty($daily_statistics)): ?>
	<?php
	$order_type_list =  $this->admin_m->get_users_order_types_by_shop_id($_ENV['ID']);
	?>

	<div class="col-12 mb-4 mt-15">
		<div class="modern-card statistics-card">
			<div class="card-header">
				<h3 class="card-title">
					<i class="fas fa-chart-line"></i>
					<?= lang('total_sell'); ?>
				</h3>
			</div>
			<div class="card-body">
				<div class="statistics-overview">
					<div class="stat-overview-item stat-overview-primary">
						<div class="stat-overview-icon">
							<i class="fas fa-dollar-sign"></i>
						</div>
						<div class="stat-overview-content">
							<h4><?= currency_position($daily_statistics->amount, $_ENV['ID']); ?></h4>
							<p><?= lang('total_sell'); ?> - <?= $daily_statistics->count; ?> <?= lang('orders'); ?></p>
						</div>
					</div>
					<?php foreach ($order_type_list as $key => $order): ?>
						<div class="stat-overview-item stat-overview-<?= $key + 1; ?>">
							<div class="stat-overview-icon">
								<i class="fas fa-receipt"></i>
							</div>
							<div class="stat-overview-content">
								<h4><?= currency_position($this->statistics_m->get_daily_statistics($_ENV['ID'], $order['order_type_id'])->amount, $_ENV['ID']); ?></h4>
								<p><?= $order['type_name']; ?> (<?= $this->statistics_m->get_daily_statistics($_ENV['ID'], $order['order_type_id'])->count; ?>)</p>
							</div>
						</div>
					<?php endforeach ?>
				</div>
				<div id="salescontainer" style="height: 300px; margin-top: 20px;"></div>
			</div>
		</div>
	</div>





	<script src="<?php echo asset_url() ?>assets/admin/plugins/chart/highchart.js"></script>
	<?php $theme = getLogo(auth('id'))['theme'] ?? 'theme-light'; ?>

	<script>
		var bgcolor = `<?= $theme == 'theme-light' ? "#fff" : "#343a40" ?>`;
		var borderColor = `<?= $theme == 'theme-light' ? "#eee" : "#333" ?>`;
		Highcharts.chart('salescontainer', {
			chart: {
				type: 'column',
				backgroundColor: bgcolor
			},
			title: {
				text: '',
				align: 'left'
			},
			subtitle: {
				text: '',
				align: 'left'
			},
			accessibility: {
				announceNewData: {
					enabled: true
				}
			},
			xAxis: {
				type: 'category',
				lineColor: borderColor,
				tickColor: borderColor,
				labels: {
					style: {
						color: '#ccc' // X-axis label color
					}
				}
			},
			yAxis: {
				title: {
					text: ''
				},
				gridLineColor: borderColor,
				lineColor: borderColor,
				tickColor: borderColor,
				labels: {
					style: {
						color: '#ccc'
					}
				}
			},
			legend: {
				enabled: false
			},
			plotOptions: {
				column: {
					borderColor: borderColor, // Dark border
					borderWidth: 1, // Width of the border
					color: '#4CAF50' // Solid fill color (if not using colorByPoint)
				},
				series: {
					borderWidth: 0,
					dataLabels: {
						enabled: true,
						formatter: function() {
							return '<?= currency_format("' + this.y.toFixed(1) + '", $_ENV["ID"]); ?>';
						}
					}
				}
			},
			tooltip: {
				headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
				pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}</b><br/>'
			},
			series: [{
				name: `<?= lang('orders'); ?>`,
				colorByPoint: true,
				data: [
					<?php
					$last = end($order_type_list);
					foreach ($order_type_list as $order_type):
						$amount = $this->statistics_m->get_daily_statistics($_ENV['ID'], $order_type['order_type_id'])->amount;
					?> {
							name: "<?= $order_type['type_name']; ?>",
							y: <?= $amount; ?>,
							drilldown: null
						}
						<?= $order_type !== $last ? ',' : '' ?>
					<?php endforeach; ?>
				]
			}],
			drilldown: {
				breadcrumbs: {
					position: {
						align: 'right'
					}
				},
				series: []
			}
		});
	</script>

<?php endif; ?>