<?php

declare(strict_types=1);

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$total_ingredients = RC_Ingredient_Repository::count();
$total_recipes     = RC_Recipe_Repository::count( '', true );
$total_suppliers   = RC_Supplier_Repository::count();
$total_inventories = RC_Inventory_Repository::count();
$total_areas       = count( RC_Area_Repository::get_all() );
$user_counts       = count_users();
$total_rc_users    = ( $user_counts['avail_roles'][ RC_Roles::ROLE_USER ] ?? 0 ) + ( $user_counts['avail_roles'][ RC_Roles::ROLE_MANAGER ] ?? 0 );
$total_menu_types  = count( RC_Menu_Type_Repository::get_all() );
?>
<div class="wrap">
	<h1><?php esc_html_e( 'Restaurant Costing - Dashboard', 'restaurant-costing' ); ?></h1>
	<div class="rc-version">v<?php echo esc_html( RC_VERSION ); ?></div>
	<div id="rc-dash-tagline-wrap" style="background:#ed7a21;padding:20px 24px;margin-bottom:20px;border-radius:8px;border:1px solid #000;">
		<h2 id="rc-dash-tagline" style="text-align:center;color:#000;font-size:28px;font-weight:900;font-family:'Vujahday Script',cursive;margin:0;padding:0;"><?php esc_html_e( 'Salamander Restaurant Costing — Your Money Saving Journey Starts Here', 'restaurant-costing' ); ?></h2>
	</div>

	<h2 class="rc-dashboard-section-title"><?php esc_html_e( 'Modules', 'restaurant-costing' ); ?></h2>
	<div class="rc-dashboard-cards">
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-ingredients' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/ingredients.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Ingredients', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_ingredients; ?></p>
			</div>
		</a>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-recipes' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/recipes.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Recipes', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_recipes; ?></p>
			</div>
		</a>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-inventory' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/inventory.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Inventory', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_inventories; ?></p>
			</div>
		</a>
	</div>

	<h2 class="rc-dashboard-section-title"><?php esc_html_e( 'Tools', 'restaurant-costing' ); ?></h2>
	<div class="rc-dashboard-cards">
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-suppliers' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/suppliers.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Suppliers', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_suppliers; ?></p>
			</div>
		</a>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-areas' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/areas.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Areas', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_areas; ?></p>
			</div>
		</a>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-users' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/users.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Users', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_rc_users; ?></p>
			</div>
		</a>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=restaurant-costing-settings' ) ); ?>" class="postbox rc-stat-card rc-dash-btn rc-dash-module">
			<div class="rc-dash-icon"><?php echo file_get_contents( RC_PLUGIN_DIR . 'admin/assets/icons/menu-types.svg' ); ?></div>
			<div class="rc-dash-info">
				<h3><?php esc_html_e( 'Menu Types', 'restaurant-costing' ); ?></h3>
				<p class="rc-stat-number"><?php echo (int) $total_menu_types; ?></p>
			</div>
		</a>
	</div>
</div>
