<?php
/**
 * Dakidarts Numerology Core - Admin Welcome Page
 *
 * Displays a beautiful HTML welcome page in the admin dashboard.
 *
 * @package Dakidarts_Numerology_Core
 */

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

if ( ! class_exists( 'Dakidarts_Admin_Welcome' ) ) {

    class Dakidarts_Admin_Welcome {

        /**
         * Constructor.
         */
        public function __construct() {
            add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
        }

        /**
         * Enqueue CSS/JS for the welcome page.
         */
        public function enqueue_assets( $hook ) {
            // Only enqueue on our plugin admin page
            if ( strpos( $hook, 'dakidarts-numerology-core' ) === false ) {
                return;
            }

            $css_file = DAKIDARTS_PLUGIN_URL . 'assets/css/admin.css';
            $js_file  = DAKIDARTS_PLUGIN_URL . 'assets/js/admin.js';

            wp_enqueue_style(
                'dakidarts-admin-welcome',
                $css_file,
                [],
                file_exists( $css_file ) ? filemtime( $css_file ) : null
            );

            wp_enqueue_script(
                'dakidarts-admin-welcome-js',
                $js_file,
                [ 'jquery' ],
                file_exists( $js_file ) ? filemtime( $js_file ) : null,
                true
            );
        }

        /**
         * Render the welcome HTML content.
         */
        /**
 * Render the welcome HTML content.
 */
public function render() {
    $icon_url = DAKIDARTS_PLUGIN_URL . 'assets/images/icon.jpg';
    $api_doc_link = 'https://docs.numerologyapi.com/';
    $gateway_key_link = 'https://dashboard.numerologyapi.com/login';
    $settings_link = esc_url( add_query_arg( 'page', 'dakidarts-numerology-settings', admin_url( 'admin.php' ) ) );
    ?>
    <div class="dakidarts-admin-page dakidarts-admin-welcome">
        <div class="dakidarts-hero">
            <div class="dakidarts-hero__content">
                <div class="dakidarts-hero__brand">
                    <img src="<?php echo esc_url( $icon_url ); ?>" alt="<?php esc_attr_e( 'Dakidarts Logo', 'dakidarts-numerology-core' ); ?>" class="dakidarts-logo" />
                    <span class="dakidarts-pill"><i class="fa-solid fa-sparkles"></i> <?php esc_html_e( 'Numerology Core', 'dakidarts-numerology-core' ); ?></span>
                </div>
                <h1><?php esc_html_e( 'Welcome to Dakidarts Numerology', 'dakidarts-numerology-core' ); ?></h1>
                <p><?php esc_html_e( 'Unlock enterprise-grade numerology in WordPress. Build forms with shortcodes and blocks, deliver real-time calculations, and now serve multi-language responses through the NumerologyAPI Gateway.', 'dakidarts-numerology-core' ); ?></p>
                <div class="dakidarts-hero__actions">
                    <a href="<?php echo esc_url( $settings_link ); ?>" class="dakidarts-btn dakidarts-btn--primary">
                        <i class="fa-solid fa-gear"></i> <?php esc_html_e( 'Open Settings', 'dakidarts-numerology-core' ); ?>
                    </a>
                    <a href="<?php echo esc_url( $api_doc_link ); ?>" target="_blank" rel="noopener" class="dakidarts-btn dakidarts-btn--ghost">
                        <i class="fa-solid fa-book"></i> <?php esc_html_e( 'API Docs', 'dakidarts-numerology-core' ); ?>
                    </a>
                    <a href="<?php echo esc_url( $gateway_key_link ); ?>" target="_blank" rel="noopener" class="dakidarts-btn dakidarts-btn--ghost">
                        <i class="fa-solid fa-key"></i> <?php esc_html_e( 'Get Gateway Key', 'dakidarts-numerology-core' ); ?>
                    </a>
                </div>
            </div>
            <div class="dakidarts-hero__meta">
                <div class="dakidarts-stat">
                    <span class="dakidarts-stat__label"><?php esc_html_e( 'Languages', 'dakidarts-numerology-core' ); ?></span>
                    <span class="dakidarts-stat__value">EN · FR · ES · DE · PT</span>
                </div>
                <div class="dakidarts-stat">
                    <span class="dakidarts-stat__label"><?php esc_html_e( 'Gateway', 'dakidarts-numerology-core' ); ?></span>
                    <span class="dakidarts-stat__value">api.numerologyapi.com</span>
                </div>
            </div>
        </div>

        <div class="dakidarts-feature-grid">
            <?php foreach ( $this->getFeatures() as $feature ) : ?>
                <a href="<?php echo esc_url( $feature['url'] ); ?>" target="_blank" rel="noopener" class="dakidarts-feature-card">
                    <img src="<?php echo esc_url( DAKIDARTS_PLUGIN_URL . 'assets/images/' . $feature['icon'] ); ?>" alt="<?php echo esc_attr( $feature['title'] ); ?>" />
                    <div class="dakidarts-feature-card__body">
                        <h3><?php echo esc_html( $feature['title'] ); ?></h3>
                        <p><?php echo esc_html( $feature['description'] ); ?></p>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>

        <div class="dakidarts-card dakidarts-card--wide">
            <div>
                <h2><?php esc_html_e( 'New: NumerologyAPI Gateway', 'dakidarts-numerology-core' ); ?></h2>
                <p><?php esc_html_e( 'Route requests directly through our infrastructure for improved performance, multi-language support, and a streamlined API key experience.', 'dakidarts-numerology-core' ); ?></p>
            </div>
            <div class="dakidarts-card__actions">
                <a href="<?php echo esc_url( $settings_link ); ?>" class="dakidarts-btn dakidarts-btn--primary">
                    <i class="fa-solid fa-rocket"></i> <?php esc_html_e( 'Switch to Gateway', 'dakidarts-numerology-core' ); ?>
                </a>
            </div>
        </div>
    </div>
    <?php
}

/**
 * Get the features for the welcome page.
 *
 * @return array Array of feature arrays.
 */
private function getFeatures() {
    return [
        [
            'title' => 'Shortcodes',
            'description' => 'Quickly insert numerology forms anywhere using simple shortcodes.',
            'icon' => 'shortcodes.jpg',
            'url'  => esc_url( add_query_arg( 'page', 'dakidarts-numerology-settings', admin_url( 'admin.php' ) ) ),
        ],
        [
            'title' => 'Gutenberg Blocks',
            'description' => 'Add interactive numerology blocks to your posts and pages with ease.',
            'icon' => 'blocks.jpg',
            'url'  => 'https://docs.numerologyapi.com/',
        ],
        [
            'title' => 'Fully Customizable',
            'description' => 'Change colors, sizes, padding, margins, buttons, and form styles directly from the admin panel.',
            'icon' => 'customizable.jpg',
            'url'  => esc_url( add_query_arg( 'page', 'dakidarts-numerology-style', admin_url( 'admin.php' ) ) ),
        ],
    ];
}

}
}
