<?php

/**
 * Mediora Theme Info
 *
 * @package mediora
 * @since 1.0
 */

/**
 * Add theme page
 */
function mediora_menu()
{
    add_theme_page(esc_html__('Mediora Theme', 'mediora'), esc_html__('Mediora Theme', 'mediora'), 'edit_theme_options', 'mediora-info', 'mediora_theme_page_display');
}
add_action('admin_menu', 'mediora_menu');

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

function mediora_admin_plugin_notice()
{
    if (!get_option('mediora_notice_dismissed_v2') || (time() - get_option('mediora_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', 'mediora_admin_plugin_notice');

/**
 * Enqueue admin scripts and styles.
 */
function mediora_admin_scripts()
{
    wp_enqueue_style(
        'mediora-admin-message-style',
        get_template_directory_uri() . '/assets/css/admin-style.css',
        array(),
        mediora_file_version('/assets/css/admin-style.css')
    );
}
add_action('admin_enqueue_scripts', 'mediora_admin_scripts');

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

function mediora_dismiss_custom_notice()
{
    update_option('mediora_notice_dismissed_v2', time());
    wp_die();
}
add_action('wp_ajax_mediora_dismiss_custom_notice', 'mediora_dismiss_custom_notice');
