<?php

/**
 * Bricks & Beam Theme Info
 *
 * @package Brick_Beam
 * @since 1.0
 */

/**
 * Add theme page
 */
function brick_beam_menu() {
    add_theme_page(esc_html__('Bricks & Beam Theme', 'brick-beam'), esc_html__('Bricks & Beam Theme', 'brick-beam'), 'edit_theme_options', 'brick-beam-info', 'brick_beam_theme_page_display');
}
add_action('admin_menu', 'brick_beam_menu');

/**
 * Display About page
 */
function brick_beam_theme_page_display() {
    require get_parent_theme_file_path('/inc/about-admin/templates/theme-info.php');
}

function brick_beam_admin_plugin_notice() {
    if (! get_option('brick_beam_notice_dismissed_v2') || (time() - get_option('brick_beam_notice_dismissed_v2') > 1 * MINUTE_IN_SECONDS)) {
        require get_parent_theme_file_path('/inc/about-admin/templates/admin-plugin-notice.php');
    }
}
add_action('admin_notices', 'brick_beam_admin_plugin_notice');

/**
 * Enqueue admin scripts and styles.
 */
function brick_beam_admin_scripts() {

    wp_enqueue_style(
        'brick-beam-admin-message-style',
        get_template_directory_uri() . '/assets/css/admin-style.css',
        array(),
        brick_beam_file_version('/assets/css/admin-style.css')
    );
}
add_action('admin_enqueue_scripts', 'brick_beam_admin_scripts');

function brick_beam_admin_notice_script() {
?>
    <script>
        jQuery(document).ready(function($) {
            $(document).on('click', '#brick-beam-admin-notice .notice-dismiss', function() {
                $.ajax({
                    url: ajaxurl,
                    data: {
                        action: 'brick_beam_dismiss_custom_notice'
                    }
                });
            });
        });
    </script>
<?php
}
add_action('admin_footer', 'brick_beam_admin_notice_script');

function brick_beam_dismiss_custom_notice() {
    update_option('brick_beam_notice_dismissed_v2', time());
    wp_die();
}
add_action('wp_ajax_brick_beam_dismiss_custom_notice', 'brick_beam_dismiss_custom_notice');
