<?php 
function howcan_admin_notice() {
    // Only show for administrators on Dashboard
    if (!current_user_can('manage_options')) {
        return;
    }

    // Only show if not dismissed
    $dismissed = get_user_meta(get_current_user_id(), 'howcan_notice_dismissed', true);
    if ($dismissed) {
        return;
        $customizer_url = admin_url('customize.php');

    }

    ?>
    <div class="notice notice-success is-dismissible howcan-admin-notice">
        <p><?php _e('Welcome to Howcan Theme! Customize your site from Appearance → Customize.', 'howcan'); ?></p>
    </div>
    <script>
    (function($){
        $('body').on('click', '.howcan-admin-notice .notice-dismiss', function(){
            $.post(ajaxurl, {
                action: 'howcan_dismiss_notice',
                user_id: '<?php echo get_current_user_id(); ?>',
                _ajax_nonce: '<?php echo wp_create_nonce("howcan_dismiss_nonce"); ?>'
            });
        });
    })(jQuery);
    </script>
    <?php
    
    
}
add_action('admin_notices', 'howcan_admin_notice');


function howcan_dismiss_notice() {
    check_ajax_referer('howcan_dismiss_nonce');

    $user_id = get_current_user_id();
    update_user_meta($user_id, 'howcan_notice_dismissed', true);

    wp_send_json_success();
}
add_action('wp_ajax_howcan_dismiss_notice', 'howcan_dismiss_notice');

// Show admin notice only in admin area
function howcan_pro_upgrade_notice() {
    // Check if Pro Addon not active and user is in admin area
    if ( ! class_exists( 'Howcan_Pro_Addon' ) && is_admin() ) {
        echo '<div class="notice notice-info">
        <p><strong>Howcan Pro:</strong> Unlock Layout, Color, Header Options. Install Howcan Pro Add-on First.
        <a href="https://www.dropbox.com/scl/fi/tdxp5hriadr84zdwqoa4s/howcan-pro-addons.zip" target="_blank">Download</a></p>
    </div>';
    }
}
add_action( 'admin_notices', 'howcan_pro_upgrade_notice' );

if ( ! class_exists( 'Howcan_Pro_Addon' ) && is_customize_preview() ) {
    echo '<div class="notice notice-info">
        <p><strong>Howcan Pro:</strong> Unlock Layout, Color, Header Options. Install Howcan Pro Add-on First.
        <a href="https://www.dropbox.com/scl/fi/tdxp5hriadr84zdwqoa4s/howcan-pro-addons.zip" target="_blank">Download</a></p>
    </div>';
}