<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php
global $wpdb;
$total_orders   = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}ros_orders WHERE status = 'closed'" );
$total_revenue  = $wpdb->get_var( "SELECT SUM(total) FROM {$wpdb->prefix}ros_orders WHERE status = 'closed'" );
$active_orders  = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}ros_orders WHERE status NOT IN ('closed')" );
$total_tables   = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}ros_tables" );
$settings       = ROS_DB::get_all_settings();
$currency       = $settings['currency_symbol'] ?? '$';
?>
<div class="ros-admin-wrap">
  <div class="ros-admin-header">
    <h1>🍽️ <?php echo esc_html( $settings['restaurant_name'] ?? 'Restaurant' ); ?> — Dashboard</h1>
  </div>

  <div class="ros-stat-grid">
    <div class="ros-stat-card ros-stat-green">
      <div class="ros-stat-icon">📋</div>
      <div class="ros-stat-number"><?php echo intval( $active_orders ); ?></div>
      <div class="ros-stat-label">Active Orders</div>
    </div>
    <div class="ros-stat-card ros-stat-blue">
      <div class="ros-stat-icon">✅</div>
      <div class="ros-stat-number"><?php echo intval( $total_orders ); ?></div>
      <div class="ros-stat-label">Closed Orders</div>
    </div>
    <div class="ros-stat-card ros-stat-gold">
      <div class="ros-stat-icon">💰</div>
      <div class="ros-stat-number"><?php echo $currency . number_format( floatval( $total_revenue ), 2 ); ?></div>
      <div class="ros-stat-label">Total Revenue</div>
    </div>
    <div class="ros-stat-card ros-stat-purple">
      <div class="ros-stat-icon">🪑</div>
      <div class="ros-stat-number"><?php echo intval( $total_tables ); ?></div>
      <div class="ros-stat-label">Tables</div>
    </div>
  </div>

  <div class="ros-admin-shortcuts">
    <h2>Quick Links</h2>
    <div class="ros-shortcut-grid">
      <a href="<?php echo admin_url( 'admin.php?page=ros-settings' ); ?>" class="ros-shortcut">⚙️ Settings</a>
      <a href="<?php echo admin_url( 'admin.php?page=ros-menu' ); ?>" class="ros-shortcut">📖 Manage Menu</a>
      <a href="<?php echo admin_url( 'admin.php?page=ros-tables' ); ?>" class="ros-shortcut">🪑 Manage Tables</a>
      <a href="<?php echo admin_url( 'admin.php?page=ros-orders' ); ?>" class="ros-shortcut">📋 View Orders</a>
      <a href="<?php echo admin_url( 'admin.php?page=ros-report' ); ?>" class="ros-shortcut">📊 Report</a>
    </div>
  </div>

  <div class="ros-admin-info">
    <h2>Shortcodes</h2>
    <p>Use these shortcodes on your pages:</p>
    <table class="widefat">
      <tr><td><code>[restaurant_customer]</code></td><td>Customer ordering page</td></tr>
      <tr><td><code>[restaurant_kitchen]</code></td><td>Kitchen display screen</td></tr>
    </table>
  </div>
</div>
