<?php
/**
 * Admin Notice - Dismissible Welcome Notice
 *
 * @package Paws_And_Care
 * @since 0.0.1
 */

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

/**
 * Display admin notice on theme activation
 */
function paws_and_care_admin_notice() {
    // Check if already dismissed
    $user_id = get_current_user_id();
    if (get_user_meta($user_id, 'paws_and_care_notice_dismissed', true)) {
        return;
    }
    
    // Only show on dashboard and themes pages (not on Theme Info page)
    $screen = get_current_screen();
    if (!in_array($screen->id, array('dashboard', 'themes'))) {
        return;
    }
    
    ?>
    <div class="notice notice-get-started-class is-dismissible paws-welcome-notice">
        <div class="paws-getting-started-notice clearfix">
            <div class="paws-theme-screenshot">
                <img src="<?php echo esc_url( get_stylesheet_directory_uri() ); ?>/screenshot.png" class="screenshot" alt="<?php esc_attr_e( 'Theme Screenshot', 'paws-and-care' ); ?>" />
            </div><!-- /.paws-theme-screenshot -->
            <div class="paws-theme-notice-content">
                <h2 class="paws-notice-h2">
                    <?php
                    printf(
                        /* translators: %s: theme name */
                        esc_html__( 'Welcome! Thank you for choosing %s!', 'paws-and-care' ),
                        '<strong>' . esc_html( wp_get_theme()->get('Name') ) . '</strong>'
                    );
                    ?>
                </h2>

                <p class="paws-notice-text">
                    <?php esc_html_e( 'To begin customizing your theme, exploring features, or importing demo data, simply click the Get Started button below.', 'paws-and-care' ); ?>
                </p>

                <div class="paws-notice-actions">
                    <a href="<?php echo esc_url(admin_url('themes.php?page=paws-and-care-info')); ?>" class="button button-primary button-hero paws-btn-get-started">
                        <?php
                        printf(
                            /* translators: %s: theme name */
                            esc_html__( 'Get started with %s', 'paws-and-care' ),
                            '<strong>' . esc_html( wp_get_theme()->get('Name') ) . '</strong>'
                        );
                        ?>
                    </a>
                </div>
            </div><!-- /.paws-theme-notice-content -->
        </div>
    </div>
    <?php
}
add_action('admin_notices', 'paws_and_care_admin_notice');

/**
 * AJAX handler to dismiss notice
 */
function paws_and_care_dismiss_notice() {
    // Verify nonce
    if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'paws_dismiss_notice')) {
        wp_die();
    }
    
    $user_id = get_current_user_id();
    update_user_meta($user_id, 'paws_and_care_notice_dismissed', true);
    
    wp_die();
}
add_action('wp_ajax_paws_and_care_dismiss_notice', 'paws_and_care_dismiss_notice');
