<?php
/**
 * Dashboard page - Simple version
 */

// If this file is called directly, abort.
if (!defined('ABSPATH')) {
    exit;
}

// Check user capabilities
if (!current_user_can('manage_options')) {
    wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'text-to-speech-tts'));
}

// Get API status
$api_key = get_option('mementor_tts_api_key', '');
$is_api_connected = !empty($api_key);

?>

<div class="wrap">
    <h1>
        <img src="<?php echo esc_url(MEMENTOR_TTS_PLUGIN_URL . 'admin/images/Mementor-Logo-Header.png'); ?>" alt="Logo" style="height: 30px; vertical-align: middle; margin-right: 10px;">
        <?php esc_html_e('Text to Speech Dashboard', 'text-to-speech-tts'); ?>
    </h1>

    <?php include(MEMENTOR_TTS_PLUGIN_DIR . 'admin/partials/navigation.php'); ?>

    <div class="mementor-tts-wrap two-column">
        <!-- Main Content -->
        <div class="mementor-tts-main">
            <!-- Main Content -->
            <div class="tts-main">
                <!-- Welcome Card -->
                <div class="mementor-tts-section" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">
                    <div class="mementor-tts-section-content" style="text-align: center; padding: 40px;">
                        <h2 style="color: white; margin: 0 0 15px 0; font-size: 32px;"><?php esc_html_e('Welcome to Text to Speech', 'text-to-speech-tts'); ?></h2>
                        <p style="color: rgba(255,255,255,0.9); font-size: 18px; margin: 0 0 30px 0;"><?php esc_html_e('Transform your content into natural-sounding audio with AI-powered voices.', 'text-to-speech-tts'); ?></p>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-generator')); ?>" class="button" style="background: white; color: #667eea; border: none; font-size: 16px; padding: 12px 30px;">
                            <span class="dashicons dashicons-microphone" style="margin-right: 8px;"></span>
                            <?php esc_html_e('Generate Your First Audio', 'text-to-speech-tts'); ?>
                        </a>
                    </div>
                </div>

                <!-- API Settings -->
                <div class="mementor-tts-section">
                    <div class="mementor-tts-section-header">
                        <h2><?php esc_html_e('API Configuration', 'text-to-speech-tts'); ?></h2>
                    </div>
                    <div class="mementor-tts-section-content">
                        <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 20px;">
                            <strong>ElevenLabs</strong>
                            <span class="mementor-tts-api-status <?php echo $is_api_connected ? 'connected' : 'not-connected'; ?>">
                                <?php if ($is_api_connected): ?>
                                    <span class="dashicons dashicons-yes-alt"></span>
                                <?php else: ?>
                                    <span class="dashicons dashicons-no-alt"></span>
                                <?php endif; ?>
                                <?php echo $is_api_connected ? esc_html__('Connected', 'text-to-speech-tts') : esc_html__('Not Connected', 'text-to-speech-tts'); ?>
                            </span>
                        </div>
                        <?php if (!$is_api_connected): ?>
                            <p style="color: #666;">
                                <?php esc_html_e('Connect your ElevenLabs API key to start generating audio.', 'text-to-speech-tts'); ?>
                            </p>
                        <?php endif; ?>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-settings-page')); ?>" class="button button-secondary">
                            <?php esc_html_e('Configure Settings', 'text-to-speech-tts'); ?>
                        </a>
                    </div>
                </div>
            </div>

            <!-- Sidebar -->
            <div class="mementor-tts-sidebar">
                <!-- Stats -->
                <div class="mementor-tts-stats-card">
                    <h3><?php esc_html_e('Quick Stats', 'text-to-speech-tts'); ?></h3>
                    <div class="mementor-tts-stats-grid">
                        <div class="mementor-tts-stat-item">
                            <div class="mementor-tts-stat-value"><?php echo number_format($total_characters); ?></div>
                            <div class="mementor-tts-stat-label"><?php esc_html_e('Characters', 'text-to-speech-tts'); ?></div>
                        </div>
                        <div class="mementor-tts-stat-item">
                            <div class="mementor-tts-stat-value"><?php echo esc_html($usage_percentage); ?>%</div>
                            <div class="mementor-tts-stat-label"><?php esc_html_e('Usage', 'text-to-speech-tts'); ?></div>
                        </div>
                        <div class="mementor-tts-stat-item">
                            <div class="mementor-tts-stat-value">23</div>
                            <div class="mementor-tts-stat-label"><?php esc_html_e('Audio Files', 'text-to-speech-tts'); ?></div>
                        </div>
                        <div class="mementor-tts-stat-item">
                            <div class="mementor-tts-stat-value">5</div>
                            <div class="mementor-tts-stat-label"><?php esc_html_e('Voices', 'text-to-speech-tts'); ?></div>
                        </div>
                    </div>
                </div>

                <!-- Upgrade Box -->
                <div class="mementor-tts-sidebar-box">
                    <h3><?php esc_html_e('Upgrade to PRO', 'text-to-speech-tts'); ?></h3>
                    <p><?php esc_html_e('Unlock premium voices, unlimited character usage, and advanced features.', 'text-to-speech-tts'); ?></p>
                    <a href="<?php echo esc_url(admin_url('admin.php?page=text-to-speech-tts-account#upgrade')); ?>" class="button">
                        <?php esc_html_e('Get PRO Now', 'text-to-speech-tts'); ?>
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>