<?php
/**
 * Modern Dashboard View
 * 
 * @package Cloudi7_ID_Card_Generator
 */

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

// Group Event and Club counts
$cloudi7_icg_events_clubs_count = (isset($cloudi7_icg_org_counts['Event']) ? intval($cloudi7_icg_org_counts['Event']) : 0) + 
                      (isset($cloudi7_icg_org_counts['Club']) ? intval($cloudi7_icg_org_counts['Club']) : 0);
?>

<div class="cloudi7-icg-dashboard-wrap">
    
    <!-- Header -->
    <header class="cloudi7-icg-dashboard-header">
        <h1><?php esc_html_e( 'Universal ID Card Generator', 'cloudi7-id-card-generator' ); ?></h1>
        <p><?php esc_html_e( 'Quick overview of your ID cards and activity.', 'cloudi7-id-card-generator' ); ?></p>
    </header>

    <!-- Statistics Row -->
    <div class="cloudi7-icg-stats-row">
        
        <!-- Total Cards -->
        <div class="cloudi7-icg-stat-card blue">
            <div class="cloudi7-icg-stat-icon">
                <span class="dashicons dashicons-id"></span>
            </div>
            <div class="cloudi7-icg-stat-info">
                <span class="cloudi7-icg-stat-number"><?php echo intval( $cloudi7_icg_total_cards ); ?></span>
                <span class="cloudi7-icg-stat-label"><?php esc_html_e( 'Total ID Cards', 'cloudi7-id-card-generator' ); ?></span>
            </div>
        </div>

        <!-- School Cards -->
        <div class="cloudi7-icg-stat-card green">
            <div class="cloudi7-icg-stat-icon">
                <span class="dashicons dashicons-welcome-learn-more"></span>
            </div>
            <div class="cloudi7-icg-stat-info">
                <span class="cloudi7-icg-stat-number"><?php echo isset( $cloudi7_icg_org_counts['School'] ) ? intval( $cloudi7_icg_org_counts['School'] ) : 0; ?></span>
                <span class="cloudi7-icg-stat-label"><?php esc_html_e( 'School Cards', 'cloudi7-id-card-generator' ); ?></span>
            </div>
        </div>

        <!-- Corporate Cards -->
        <div class="cloudi7-icg-stat-card purple">
            <div class="cloudi7-icg-stat-icon">
                <span class="dashicons dashicons-building"></span>
            </div>
            <div class="cloudi7-icg-stat-info">
                <span class="cloudi7-icg-stat-number"><?php echo isset( $cloudi7_icg_org_counts['Corporate'] ) ? intval( $cloudi7_icg_org_counts['Corporate'] ) : 0; ?></span>
                <span class="cloudi7-icg-stat-label"><?php esc_html_e( 'Corporate Cards', 'cloudi7-id-card-generator' ); ?></span>
            </div>
        </div>

        <!-- Events / Clubs -->
        <div class="cloudi7-icg-stat-card orange">
            <div class="cloudi7-icg-stat-icon">
                <span class="dashicons dashicons-groups"></span>
            </div>
            <div class="cloudi7-icg-stat-info">
                <span class="cloudi7-icg-stat-number"><?php echo intval( $cloudi7_icg_events_clubs_count ); ?></span>
                <span class="cloudi7-icg-stat-label"><?php esc_html_e( 'Events / Clubs', 'cloudi7-id-card-generator' ); ?></span>
            </div>
        </div>

    </div>

    <!-- Quick Action Buttons -->
    <div class="cloudi7-icg-actions-row">
        <a href="<?php echo esc_url( admin_url( 'admin.php?page=cloudi7-icg-create-card' ) ); ?>" class="cloudi7-icg-action-card">
            <div class="cloudi7-icg-action-icon">
                <span class="dashicons dashicons-plus-alt"></span>
            </div>
            <div class="cloudi7-icg-action-content">
                <h3><?php esc_html_e( 'Create New ID Card', 'cloudi7-id-card-generator' ); ?></h3>
                <p><?php esc_html_e( 'Manually generate a new ID card for any organization.', 'cloudi7-id-card-generator' ); ?></p>
            </div>
        </a>

        <a href="<?php echo esc_url( admin_url( 'admin.php?page=cloudi7-icg-settings' ) ); ?>" class="cloudi7-icg-action-card">
            <div class="cloudi7-icg-action-icon">
                <span class="dashicons dashicons-admin-settings"></span>
            </div>
            <div class="cloudi7-icg-action-content">
                <h3><?php esc_html_e( 'Plugin Settings', 'cloudi7-id-card-generator' ); ?></h3>
                <p><?php esc_html_e( 'Configure your organization details and card orientation.', 'cloudi7-id-card-generator' ); ?></p>
            </div>
        </a>
    </div>

    <!-- Main Grid -->
    <div class="cloudi7-icg-main-grid">
        
        <!-- Recent Cards Table -->
        <div class="cloudi7-icg-content-box">
            <h2>
                <span class="dashicons dashicons-calendar"></span>
                <?php esc_html_e( 'Recent ID Cards', 'cloudi7-id-card-generator' ); ?>
            </h2>
            
            <?php if ( $cloudi7_icg_recent_cards ) : ?>
                <table class="cloudi7-icg-recent-table">
                    <thead>
                        <tr>
                            <th><?php esc_html_e( 'Photo', 'cloudi7-id-card-generator' ); ?></th>
                            <th><?php esc_html_e( 'Name', 'cloudi7-id-card-generator' ); ?></th>
                            <th><?php esc_html_e( 'ID Number', 'cloudi7-id-card-generator' ); ?></th>
                            <th><?php esc_html_e( 'Org Type', 'cloudi7-id-card-generator' ); ?></th>
                            <th><?php esc_html_e( 'Date', 'cloudi7-id-card-generator' ); ?></th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ( $cloudi7_icg_recent_cards as $cloudi7_icg_card_item ) : ?>
                            <tr>
                                <td>
                                    <?php if ( $cloudi7_icg_card_item->photo ) : ?>
                                        <img src="<?php echo esc_url( $cloudi7_icg_card_item->photo ); ?>" class="cloudi7-icg-recent-photo">
                                    <?php else : ?>
                                        <div class="cloudi7-icg-recent-photo" style="display:flex;align-items:center;justify-content:center;">
                                            <span class="dashicons dashicons-admin-users" style="color:#ccc;"></span>
                                        </div>
                                    <?php endif; ?>
                                </td>
                                <td><strong><?php echo esc_html( $cloudi7_icg_card_item->name ); ?></strong></td>
                                <td><code><?php echo esc_html( $cloudi7_icg_card_item->id_number ); ?></code></td>
                                <td><span class="cloudi7-icg-badge"><?php echo esc_html( $cloudi7_icg_card_item->organization_type ); ?></span></td>
                                <td><?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $cloudi7_icg_card_item->created_at ) ) ); ?></td>
                                <td align="right">
                                    <a href="<?php echo esc_url( admin_url( 'admin.php?page=cloudi7-icg-all-cards&action=view&id=' . $cloudi7_icg_card_item->id ) ); ?>" class="cloudi7-icg-btn-view">
                                        <?php esc_html_e( 'View Card', 'cloudi7-id-card-generator' ); ?>
                                    </a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else : ?>
                <p><?php esc_html_e( 'No ID cards created yet.', 'cloudi7-id-card-generator' ); ?></p>
            <?php endif; ?>
            
            <div style="margin-top: 20px;">
                <a href="<?php echo esc_url( admin_url( 'admin.php?page=cloudi7-icg-all-cards' ) ); ?>" class="button"><?php esc_html_e( 'See All Cards', 'cloudi7-id-card-generator' ); ?></a>
            </div>
        </div>

        <!-- System Information -->
        <div class="cloudi7-icg-content-box">
            <h2>
                <span class="dashicons dashicons-info"></span>
                <?php esc_html_e( 'System Information', 'cloudi7-id-card-generator' ); ?>
            </h2>
            <ul class="cloudi7-icg-info-list">
                <li>
                    <span class="cloudi7-icg-info-label"><?php esc_html_e( 'Plugin Version', 'cloudi7-id-card-generator' ); ?></span>
                    <span class="cloudi7-icg-info-value"><?php echo esc_html( Cloudi7_ICG_VERSION ); ?></span>
                </li>
                <li>
                    <span class="cloudi7-icg-info-label"><?php esc_html_e( 'PHP Version', 'cloudi7-id-card-generator' ); ?></span>
                    <span class="cloudi7-icg-info-value"><?php echo esc_html( PHP_VERSION ); ?></span>
                </li>
                <li>
                    <span class="cloudi7-icg-info-label"><?php esc_html_e( 'Database Status', 'cloudi7-id-card-generator' ); ?></span>
                    <span class="cloudi7-icg-info-value" style="color:var(--cloudi7-icg-green);">Online</span>
                </li>
                <li>
                    <span class="cloudi7-icg-info-label"><?php esc_html_e( 'Organization Set', 'cloudi7-id-card-generator' ); ?></span>
                    <span class="cloudi7-icg-info-value">
                        <?php echo esc_html( get_option('cloudi7_icg_org_name') ? 'Yes' : 'No' ); ?>
                    </span>
                </li>
            </ul>
        </div>

    </div>

</div>
