<?php
/**
 * Digi Restaurant functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package Digi Restaurant
 */

function digi_restaurant_files_setup() {

    if ( ! defined( 'RESTAURANT_ZONE_CONTACT_SUPPORT' ) ) {
        define('RESTAURANT_ZONE_CONTACT_SUPPORT',__('https://wordpress.org/support/theme/digi-restaurant/','digi-restaurant'));
    }
    if ( ! defined( 'RESTAURANT_ZONE_REVIEW' ) ) {
        define('RESTAURANT_ZONE_REVIEW',__('https://wordpress.org/support/theme/digi-restaurant/reviews/','digi-restaurant'));
    }
    if ( ! defined( 'RESTAURANT_ZONE_LIVE_DEMO' ) ) {
        define('RESTAURANT_ZONE_LIVE_DEMO',__('https://demo.themagnifico.net/restaurant-zone/','digi-restaurant'));
    }
    if ( ! defined( 'RESTAURANT_ZONE_GET_PREMIUM_PRO' ) ) {
        define('RESTAURANT_ZONE_GET_PREMIUM_PRO',__('https://www.themagnifico.net/products/pet-wordpress-theme','digi-restaurant'));
    }
    if ( ! defined( 'RESTAURANT_ZONE_PRO_DOC' ) ) {
        define('RESTAURANT_ZONE_PRO_DOC',__('https://demo.themagnifico.net/eard/wathiqa/digi-restaurant-pro-doc/','digi-restaurant'));
    }
    if ( ! defined( 'RESTAURANT_ZONE_FREE_DOC' ) ) {
        define('RESTAURANT_ZONE_FREE_DOC',__('https://demo.themagnifico.net/eard/wathiqa/digi-restaurant-free-doc/','digi-restaurant'));
    }
    if ( ! defined( 'RESTAURANT_ZONE_URL' ) ) {
        define( 'RESTAURANT_ZONE_URL', esc_url( 'https://www.themagnifico.net/products/restaurant-wordpress-theme', 'digi-restaurant') );
    }
    if ( ! defined( 'RESTAURANT_ZONE_TEXT' ) ) {
        define( 'RESTAURANT_ZONE_TEXT', __( 'Digi Restaurant Pro','digi-restaurant' ));
    }
    if ( ! defined( 'RESTAURANT_ZONE_BUNDLE_LINK' ) ) {
        define('RESTAURANT_ZONE_BUNDLE_LINK',__('https://www.themagnifico.net/products/wordpress-theme-bundle','digi-restaurant'));
    }
}

add_action( 'after_setup_theme', 'digi_restaurant_files_setup' );

function digi_restaurant_enqueue_styles() {
    $digi_restaurant_parentcss = 'restaurant-zone-style';
    $digi_restaurant_theme = wp_get_theme(); wp_enqueue_style( $digi_restaurant_parentcss, get_template_directory_uri() . '/style.css', array(), $digi_restaurant_theme->parent()->get('Version'));
    wp_enqueue_style( 'digi-restaurant-style', get_stylesheet_uri(), array( $digi_restaurant_parentcss ), $digi_restaurant_theme->get('Version'));

    wp_enqueue_style( 'digi-restaurant-style', get_stylesheet_uri(), array( $digi_restaurant_parentcss ) );
        require get_theme_file_path( '/custom-option.php' );
        wp_add_inline_style( 'digi-restaurant-style',$restaurant_zone_theme_css );
        require get_parent_theme_file_path( '/custom-option.php' );
        wp_add_inline_style( 'restaurant-zone-basic-style',$restaurant_zone_theme_css );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}

add_action( 'wp_enqueue_scripts', 'digi_restaurant_enqueue_styles' );

function digi_restaurant_admin_scripts() {
    // demo CSS
    wp_enqueue_style( 'digi-restaurant-demo-css', get_theme_file_uri( 'assets/css/demo.css' ) );
}
add_action( 'admin_enqueue_scripts', 'digi_restaurant_admin_scripts' );

function digi_restaurant_string_limit_words($digi_restaurant_string, $digi_restaurant_word_limit) {
    $digi_restaurant_words = explode(' ', $digi_restaurant_string, ($digi_restaurant_word_limit + 1));
    if(count($digi_restaurant_words) > $digi_restaurant_word_limit)
    array_pop($digi_restaurant_words);
    return implode(' ', $digi_restaurant_words);
}

function digi_restaurant_theme_color() {

    $theme_color_css = '';
    $restaurant_zone_theme_color = get_theme_mod('restaurant_zone_theme_color');
    $restaurant_zone_theme_color_2 = get_theme_mod('restaurant_zone_theme_color_2');
    $restaurant_zone_preloader_bg_color = get_theme_mod('restaurant_zone_preloader_bg_color');
    $restaurant_zone_preloader_dot_1_color = get_theme_mod('restaurant_zone_preloader_dot_1_color');
    $restaurant_zone_preloader_dot_2_color = get_theme_mod('restaurant_zone_preloader_dot_2_color');

    if(get_theme_mod('restaurant_zone_preloader_bg_color') == '') {
            $restaurant_zone_preloader_bg_color = '#000';
        }
        if(get_theme_mod('restaurant_zone_preloader_dot_1_color') == '') {
            $restaurant_zone_preloader_dot_1_color = '#fff';
        }
        if(get_theme_mod('restaurant_zone_preloader_dot_2_color') == '') {
            $restaurant_zone_preloader_dot_2_color = '#d26e2b';
        }

    $theme_color_css = '
        .sidebar input[type="submit"],.sidebar button[type="submit"],#button,.sticky .entry-title::before,.comment-respond input#submit,.main-navigation .menu > li > a:hover,.main-navigation .sub-menu,.btn-primary,.sidebar .tagcloud a:hover,.woocommerce ul.products li.product .onsale, .woocommerce span.onsale,.woocommerce .woocommerce-ordering select,.pro-button a, .woocommerce #respond input#submit, .woocommerce a.button, .woocommerce button.button, .woocommerce input.button, .woocommerce #respond input#submit.alt, .woocommerce a.button.alt, .woocommerce button.button.alt, .woocommerce input.button.alt,.woocommerce-account .woocommerce-MyAccount-navigation ul li,.reservation-btn a,.post-navigation .nav-previous a:hover, .post-navigation .nav-next a:hover, .posts-navigation .nav-previous a:hover, .posts-navigation .nav-next a:hover,.toggle-nav button,.top-inner-btn a:hover,a.added_to_cart.wc-forward{
            background: '.esc_attr($restaurant_zone_theme_color).';
         }
         p.price, .woocommerce ul.products li.product .price, .woocommerce div.product p.price, .woocommerce div.product span.price,.sidebar p a, .entry-content a, .entry-summary a, .comment-content a,.navbar-brand p,#colophon a:hover, #colophon a:focus,.sidebar a:hover,.woocommerce-message::before, .woocommerce-info::before,.top-info i,.widget a:hover, .widget a:focus,.top-inner h2,.welcome-box h2,.woocommerce .star-rating span::before,.top-info p, .social-link a{
            color: '.esc_attr($restaurant_zone_theme_color).';
         }
         h3.entry-title a:hover{
            color: '.esc_attr($restaurant_zone_theme_color).'!important;
         }
         .woocommerce-message, .woocommerce-info,.wp-block-quote, .wp-block-quote:not(.is-large):not(.is-style-large), .wp-block-pullquote,
            .post-navigation .nav-previous a:hover, .post-navigation .nav-next a:hover, .posts-navigation .nav-previous a:hover, .posts-navigation .nav-next a:hover{
            border-color: '.esc_attr($restaurant_zone_theme_color).'!important;
         }
        .socialmedia,.reservation-btn a:hover,.woocommerce-account .woocommerce-MyAccount-navigation ul li:hover {
            background: '.esc_attr($restaurant_zone_theme_color_2).';
         }
         .stick_header{
            background: '.esc_attr($restaurant_zone_theme_color_2).'!important;
         }
        .loading{
            background-color: '.esc_attr($restaurant_zone_preloader_bg_color).';
         }
         @keyframes loading {
          0%,
          100% {
            transform: translatey(-2.5rem);
            background-color: '.esc_attr($restaurant_zone_preloader_dot_1_color).';
          }
          50% {
            transform: translatey(2.5rem);
            background-color: '.esc_attr($restaurant_zone_preloader_dot_2_color).';
          }
        }
    ';
    wp_add_inline_style( 'digi-restaurant-style',$theme_color_css );

}
add_action( 'wp_enqueue_scripts', 'digi_restaurant_theme_color' );

function digi_restaurant_customize_register($wp_customize){

     // Pro Version
    class Digi_Restaurant_Customize_Pro_Version extends WP_Customize_Control {
        public $type = 'pro_options';

        public function render_content() {
            echo '<span>For More <strong>'. esc_html( $this->label ) .'</strong>?</span>';
            echo '<a href="'. esc_url($this->description) .'" target="_blank">';
                echo '<span class="dashicons dashicons-info"></span>';
                echo '<strong> '. esc_html( RESTAURANT_ZONE_BUY_TEXT,'digi-restaurant' ) .'<strong></a>';
            echo '</a>';
        }
    }

    $wp_customize->add_setting('digi_restaurant_cart_setting', array(
        'default' => false,
        'sanitize_callback' => 'restaurant_zone_sanitize_checkbox'
    ));
    $wp_customize->add_control( new WP_Customize_Control($wp_customize,'digi_restaurant_cart_setting',array(
        'label'          => __( 'Enable Disable Cart Icon', 'digi-restaurant' ),
        'section'        => 'restaurant_zone_top_header',
        'settings'       => 'digi_restaurant_cart_setting',
        'type'           => 'checkbox',
    )));

    // Banner Section
    $wp_customize->add_section( 'digi_restaurant_top_image_section' , array(
        'title'      => __( 'Banner Settings', 'digi-restaurant' ),
        'priority'   => null
    ) );

    $wp_customize->add_setting('digi_restaurant_banner_setting', array(
        'default' => false,
        'sanitize_callback' => 'restaurant_zone_sanitize_checkbox'
    ));
    $wp_customize->add_control( new WP_Customize_Control($wp_customize,'digi_restaurant_banner_setting',array(
        'label'          => __( 'Enable Disable Banner', 'digi-restaurant' ),
        'section'        => 'digi_restaurant_top_image_section',
        'settings'       => 'digi_restaurant_banner_setting',
        'type'           => 'checkbox',
    )));

    $wp_customize->add_setting('digi_restaurant_top_section_heading',array(
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('digi_restaurant_top_section_heading',array(
        'label' => esc_html__('Section Title','digi-restaurant'),
        'section' => 'digi_restaurant_top_image_section',
        'setting' => 'digi_restaurant_top_section_heading',
        'type'  => 'text'
    ));

    $wp_customize->add_setting('digi_restaurant_top_section_content',array(
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('digi_restaurant_top_section_content',array(
        'label' => esc_html__('Section Content','digi-restaurant'),
        'section' => 'digi_restaurant_top_image_section',
        'setting' => 'digi_restaurant_top_section_content',
        'type'  => 'text'
    ));

    $wp_customize->add_setting('digi_restaurant_top_section_text',array(
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('digi_restaurant_top_section_text',array(
        'label' => esc_html__('Button Text','digi-restaurant'),
        'section' => 'digi_restaurant_top_image_section',
        'setting' => 'digi_restaurant_top_section_text',
        'type'  => 'text'
    ));

    $wp_customize->add_setting('digi_restaurant_top_section_url',array(
        'default' => '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('digi_restaurant_top_section_url',array(
        'label' => esc_html__('Button URL','digi-restaurant'),
        'section' => 'digi_restaurant_top_image_section',
        'setting' => 'digi_restaurant_top_section_url',
        'type'  => 'url'
    ));

    $wp_customize->add_setting('digi_restaurant_image_one', array(
        'transport'         => 'refresh',
        'height'         => 325,
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'digi_restaurant_image_one', array(
        'label'             => esc_html__('Image #1', 'digi-restaurant'),
        'section'           => 'digi_restaurant_top_image_section',
        'settings'          => 'digi_restaurant_image_one',
    )));

    $wp_customize->add_setting('digi_restaurant_image_two', array(
        'transport'         => 'refresh',
        'height'         => 325,
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'digi_restaurant_image_two', array(
        'label'             => esc_html__('Image #2', 'digi-restaurant'),
        'section'           => 'digi_restaurant_top_image_section',
        'settings'          => 'digi_restaurant_image_two',
    )));

    $wp_customize->add_setting('digi_restaurant_image_three', array(
        'transport'         => 'refresh',
        'height'         => 325,
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'digi_restaurant_image_three', array(
        'label'             => esc_html__('Image #3', 'digi-restaurant'),
        'section'           => 'digi_restaurant_top_image_section',
        'settings'          => 'digi_restaurant_image_three',
    )));

    $wp_customize->add_setting('digi_restaurant_image_four', array(
        'transport'         => 'refresh',
        'height'         => 325,
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'digi_restaurant_image_four', array(
        'label'             => esc_html__('Image #4', 'digi-restaurant'),
        'section'           => 'digi_restaurant_top_image_section',
        'settings'          => 'digi_restaurant_image_four',
    )));

    // Pro Version
    $wp_customize->add_setting( 'pro_version_image_setting', array(
        'sanitize_callback' => 'Restaurant_Zone_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Digi_Restaurant_Customize_Pro_Version ( $wp_customize,'pro_version_image_setting', array(
        'section'     => 'digi_restaurant_top_image_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Customizer Options', 'digi-restaurant' ),
        'description' => esc_url( RESTAURANT_ZONE_URL ),
        'priority'    => 100
    )));

    // Welcome Section
    $wp_customize->add_section( 'digi_restaurant_welcome_section' , array(
        'title'      => esc_html__( 'Welcome Section Settings', 'digi-restaurant' ),
        'priority'   => null
    ) );

    $wp_customize->add_setting('digi_restaurant_welcome_setting', array(
        'default' => true,
        'sanitize_callback' => 'restaurant_zone_sanitize_checkbox'
    ));
    $wp_customize->add_control( new WP_Customize_Control($wp_customize,'digi_restaurant_welcome_setting',array(
        'label'          => __( 'Enable Disable Banner', 'digi-restaurant' ),
        'section'        => 'digi_restaurant_welcome_section',
        'settings'       => 'digi_restaurant_welcome_setting',
        'type'           => 'checkbox',
    )));

    $wp_customize->add_setting('digi_restaurant_welcome_section_heading',array(
        'default' => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('digi_restaurant_welcome_section_heading',array(
        'label' => esc_html__('Section Heading','digi-restaurant'),
        'section' => 'digi_restaurant_welcome_section',
        'setting' => 'digi_restaurant_welcome_section_heading',
        'type'  => 'text'
    ));

    $wp_customize->add_setting( 'digi_restaurant_welcome_page', array(
        'default'           => '',
        'sanitize_callback' => 'restaurant_zone_sanitize_dropdown_pages'
    ) );
    $wp_customize->add_control( 'digi_restaurant_welcome_page', array(
        'label'    => esc_html__( 'Select Page', 'digi-restaurant' ),
        'section'  => 'digi_restaurant_welcome_section',
        'type'     => 'dropdown-pages'
    ) );

    // Pro Version
    $wp_customize->add_setting( 'pro_version_welcome_setting', array(
        'sanitize_callback' => 'Restaurant_Zone_sanitize_custom_control'
    ));
    $wp_customize->add_control( new Digi_Restaurant_Customize_Pro_Version ( $wp_customize,'pro_version_welcome_setting', array(
        'section'     => 'digi_restaurant_welcome_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Customizer Options', 'digi-restaurant' ),
        'description' => esc_url( RESTAURANT_ZONE_URL ),
        'priority'    => 100
    )));

}
add_action('customize_register', 'digi_restaurant_customize_register');

if ( ! function_exists( 'digi_restaurant_setup' ) ) :
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which
     * runs before the init hook. The init hook is too late for some features, such
     * as indicating support for post thumbnails.
     */
    function digi_restaurant_setup() {

        add_theme_support( 'responsive-embeds' );

        // Add default posts and comments RSS feed links to head.
        add_theme_support( 'automatic-feed-links' );

        /*
         * Let WordPress manage the document title.
         * By adding theme support, we declare that this theme does not use a
         * hard-coded <title> tag in the document head, and expect WordPress to
         * provide it for us.
         */
        add_theme_support( 'title-tag' );

        /*
         * Enable support for Post Thumbnails on posts and pages.
         *
         * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
         */
        add_theme_support( 'post-thumbnails' );

        add_image_size('digi-restaurant-featured-header-image', 2000, 660, true);

        /*
         * Switch default core markup for search form, comment form, and comments
         * to output valid HTML5.
         * to output valid HTML5.
         */
        add_theme_support( 'html5', array(
            'search-form',
            'comment-form',
            'comment-list',
            'gallery',
            'caption',
        ) );

        // Set up the WordPress core custom background feature.
        add_theme_support( 'custom-background', apply_filters( 'restaurant_zone_custom_background_args', array(
            'default-color' => '',
            'default-image' => '',
        ) ) );

        /**
         * Add support for core custom logo.
         *
         * @link https://codex.wordpress.org/Theme_Logo
         */
        add_theme_support( 'custom-logo', array(
            'height'      => 50,
            'width'       => 50,
            'flex-width'  => true,
        ) );

        add_editor_style( array( '/editor-style.css' ) );

        add_theme_support( 'align-wide' );

        add_theme_support( 'wp-block-styles' );
    }
endif;
add_action( 'after_setup_theme', 'digi_restaurant_setup' );

function digi_restaurant_font_url(){
    $font_url = '';
    $lobster = _x('on','Berkshire Swash:on or off','digi-restaurant');

    if('off' !== $lobster ){
        $font_family = array();
        if('off' !== $lobster){
            $font_family[] = 'Berkshire Swash';
        }
        $query_args = array(
            'family'    => urlencode(implode('|',$font_family)),
        );
        $font_url = add_query_arg($query_args,'//fonts.googleapis.com/css');
    }
    return $font_url;
}

function digi_restaurant_remove_customize_register() {
    global $wp_customize;
    $wp_customize->remove_section( 'restaurant_zone_top_slider' );
    $wp_customize->remove_section( 'restaurant_zone_menu_items_section' );
}

add_action( 'customize_register', 'digi_restaurant_remove_customize_register', 11 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function digi_restaurant_widgets_init() {
    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar', 'digi-restaurant' ),
        'id'            => 'sidebar-1',
        'description'   => esc_html__( 'Add widgets here.', 'digi-restaurant' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h5 class="widget-title">',
        'after_title'   => '</h5>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer Column 1', 'digi-restaurant' ),
        'id'            => 'restaurant-zone-footer1',
        'description'   => '',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h5 class="footer-column-widget-title">',
        'after_title'   => '</h5>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer Column 2', 'digi-restaurant' ),
        'id'            => 'restaurant-zone-footer2',
        'description'   => '',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h5 class="footer-column-widget-title">',
        'after_title'   => '</h5>',
    ) );

    register_sidebar( array(
        'name'          => esc_html__( 'Footer Column 3', 'digi-restaurant' ),
        'id'            => 'restaurant-zone-footer3',
        'description'   => '',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h5 class="footer-column-widget-title">',
        'after_title'   => '</h5>',
    ) );
}
add_action( 'widgets_init', 'digi_restaurant_widgets_init' );

function digi_restaurant_remove_my_action() {
    remove_action( 'remove_menu_page','restaurant-zone-info' );
    remove_action( 'admin_menu','demo_importer_admin_page' );
    remove_action( 'admin_enqueue_scripts', 'restaurant_zone_getpage_css' );
    remove_action( 'admin_notices', 'restaurant_zone_deprecated_hook_admin_notice' );
    remove_action( 'remove_menu_page','restaurant-zone-info' );
    remove_action( 'admin_menu','restaurant_zone_demo_importer_admin_page' );
    remove_action( 'admin_notices','restaurant_zone_deprecated_hook_admin_notice' );
}
add_action( 'after_setup_theme', 'digi_restaurant_remove_my_action');

function digi_restaurant_remove_parent_theme_hooks() {
    remove_action('init', 'digi_restaurant_remove_my_action');
}
add_action('after_setup_theme', 'digi_restaurant_remove_parent_theme_hooks', 20);


add_action('admin_menu', 'digi_restaurant_remove_my_theme_page', 999);
function digi_restaurant_remove_my_theme_page() {
    remove_submenu_page('themes.php','restaurant-zone-info');
}

/**
 * Get CSS
 */

function digi_restaurant_getpage_css($hook) {
    wp_register_script( 'admin-notice-script', get_stylesheet_directory_uri() . '/inc/admin/js/admin-notice-script.js', array( 'jquery' ) );
    wp_localize_script('admin-notice-script','digi_restaurant',
        array('admin_ajax'  =>  admin_url('admin-ajax.php'),'wpnonce'  =>   wp_create_nonce('digi_restaurant_dismissed_notice_nonce')
        )
    );
    wp_enqueue_script('admin-notice-script');

    wp_localize_script( 'admin-notice-script', 'digi_restaurant_ajax_object',
        array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )
    );
    if ( 'appearance_page_digi-restaurant-info' != $hook ) {
        return;
    }
}
add_action( 'admin_enqueue_scripts', 'digi_restaurant_getpage_css' );

//Admin Notice For Getstart
function digi_restaurant_ajax_notice_handler() {
    if ( isset( $_POST['type'] ) ) {
        $type = sanitize_text_field( wp_unslash( $_POST['type'] ) );
        update_option( 'dismissed-' . $type, TRUE );
    }
}

function digi_restaurant_deprecated_hook_admin_notice() {

     // Check if the notice has been dismissed by the user
    $dismissed = get_user_meta(get_current_user_id(), 'digi_restaurant_dismissable_notice', true);

    // Exclude the notice from being shown on the "Theme Importer" page
    $current_screen = get_current_screen();
    if ($current_screen && $current_screen->id === 'appearance_page_theme-importer') {
        return; // Don't show the notice on this page
    }

    if (!$dismissed) {  
        ?>
        <div class="updated notice notice-success is-dismissible notice-get-started-class" data-notice="get_started" style="background: #f7f9f9; padding: 20px 10px; display: flex;">
            <div class="tm-admin-image">
                <img style="width: 100%;max-width: 320px;line-height: 40px;display: inline-block;vertical-align: top;border: 2px solid #ddd;border-radius: 4px;" src="<?php echo esc_url(get_stylesheet_directory_uri()) .'/screenshot.png'; ?>" />
            </div>
            <div class="tm-admin-content" style="padding-left: 30px; align-self: center">
                <h2 style="font-weight: 600;line-height: 1.3; margin: 0px;"><?php esc_html_e('Thank You For Choosing ', 'digi-restaurant'); ?><?php echo esc_html( wp_get_theme() ); ?></h2>
                <p style="color: #3c434a; font-weight: 400; margin-bottom: 30px;"><?php esc_html_e('Get Started With Theme By Clicking On Getting Started.', 'digi-restaurant'); ?></p>
                <a class="admin-notice-btn button button-primary button-hero" href="<?php echo esc_url( admin_url( 'themes.php?page=digi-restaurant-info.php' )); ?>"><?php esc_html_e( 'Get started', 'digi-restaurant' ) ?></a>
                <a class="admin-notice-btn button button-primary button-hero" target="_blank" href="<?php echo esc_url( RESTAURANT_ZONE_GET_PREMIUM_PRO ); ?>"><?php esc_html_e( 'Get Premium ', 'digi-restaurant' ) ?></a>
                <a class="admin-notice-btn button button-primary button-hero" target="_blank" href="<?php echo esc_url( RESTAURANT_ZONE_BUNDLE_LINK ); ?>"><?php esc_html_e( 'Buy All Themes - 130+ Templates', 'digi-restaurant' ) ?></a>
                <a class="admin-notice-btn button button-primary button-hero"  target="_blank" href="<?php echo esc_url( RESTAURANT_ZONE_LIVE_DEMO ); ?>">
                    <span class="dashicons dashicons-admin-links"></span>
                    <?php esc_html_e( 'View Demo', 'digi-restaurant' ) ?>
                </a>
            </div>
        </div>
    <?php }
}

add_action( 'admin_notices', 'digi_restaurant_deprecated_hook_admin_notice' );

function digi_restaurant_switch_theme() {
    delete_user_meta(get_current_user_id(), 'digi_restaurant_dismissable_notice');
}
add_action('after_switch_theme', 'digi_restaurant_switch_theme');
function digi_restaurant_dismissable_notice() {
    check_ajax_referer( 'digi_restaurant_dismissed_notice_nonce', 'wpnonce' );
    update_user_meta(get_current_user_id(), 'digi_restaurant_dismissable_notice', true);
    wp_die();
}

// Demo Content Code

// Ensure WordPress is loaded
if (!defined('ABSPATH')) {
    exit;
}

// Add the AJAX action to trigger theme mods import
add_action('wp_ajax_import_theme_mods', 'digi_restaurant_demo_importer_ajax_handler');

// Handle the AJAX request
function digi_restaurant_demo_importer_ajax_handler() {
    check_ajax_referer( 'theme_importer_nonce' );

    if ( ! current_user_can( 'edit_theme_options' ) ) {
        wp_send_json_error( 'Permission denied.' );
        return;
    }

    // Sample data to import
    $theme_mods_data = array(
        'header_textcolor' => '000000',  // Example: change header text color
        'background_color' => 'ffffff',  // Example: change background color
        'custom_logo'      => 123,       // Example: set a custom logo by attachment ID
        'footer_text'      => 'Custom Footer Text', // Example: custom footer text
    );

    // Call the function to import theme mods
    if (digi_restaurant_demo_theme_importer($theme_mods_data)) {
        // After importing theme mods, create the menu
        digi_restaurant_create_demo_menu();
        wp_send_json_success(array(
            'msg' => 'Theme mods imported successfully.',
            'redirect' => home_url()
        ));
    } else {
        wp_send_json_error('Failed to import theme mods.');
    }

    wp_die();
}

// Function to set theme mods
function digi_restaurant_demo_theme_importer($import_data) {
    if (is_array($import_data)) {
        foreach ($import_data as $mod_name => $mod_value) {
            set_theme_mod($mod_name, $mod_value);
        }
        return true;
    } else {
        return false;
    }
}

// Function to create demo menu
function digi_restaurant_create_demo_menu() {
    // Page import process
    $pages_to_create = array(
        array(
            'title'    => 'Home',
            'slug'     => 'home',
            'template' => 'page-template/custom-front-page.php',
        ),
        array(
            'title'    => 'Popular',
            'slug'     => 'popular',
            'template' => '',
        ),
        array(
            'title'    => 'Category',
            'slug'     => 'category',
            'template' => '',
        ),
        array(
            'title'    => 'About us',
            'slug'     => 'about',
            'template' => '',
        ),
        array(
            'title'    => 'Book Now',
            'slug'     => 'book',
            'template' => '',
        ),
        array(
            'title'    => 'Chef',
            'slug'     => 'chef',
            'template' => '',
        ),
        array(
            'title'    => 'Testimonial',
            'slug'     => 'testimonial',
            'template' => '',
        ),
        array(
            'title'    => 'Blog',
            'slug'     => 'blog',
            'template' => '',
        ),
        array(
            'title'    => 'Contact Us',
            'slug'     => 'contact',
            'template' => '',
        ),
    );

    // Loop through each page data to create pages
    foreach ($pages_to_create as $page_data) {
        $existing_pages = get_posts( array( 'post_type' => 'page', 'title' => $page_data['title'], 'post_status' => 'publish', 'numberposts' => 1 ) );
        $page_check = ! empty( $existing_pages ) ? $existing_pages[0] : null;
        
        // Check if the page doesn't exist already
        if (!$page_check) {
            $page = array(
                'post_type'    => 'page',
                'post_title'   => $page_data['title'],
                'post_status'  => 'publish',
                'post_author'  => 1,
                'post_name'    => $page_data['slug'],
            );
            
            // Insert the page and get the inserted page ID
            $page_id = wp_insert_post($page);
            
            // Set the page template
            if ($page_id && !empty($page_data['template'])) {
                add_post_meta($page_id, '_wp_page_template', $page_data['template']);
            }
        }
    }

    // Set 'Home' as the front page
    $home_pages = get_posts( array( 'post_type' => 'page', 'title' => 'Home', 'post_status' => 'publish', 'numberposts' => 1 ) );
    $home_page = ! empty( $home_pages ) ? $home_pages[0] : null;
    if ($home_page) {
        update_option('page_on_front', $home_page->ID);
        update_option('show_on_front', 'page');
    }

    // Set 'Blog' as the posts page
    $blog_pages = get_posts( array( 'post_type' => 'page', 'title' => 'Blog', 'post_status' => 'publish', 'numberposts' => 1 ) );
    $blog_page = ! empty( $blog_pages ) ? $blog_pages[0] : null;
    if ($blog_page) {
        update_option('page_for_posts', $blog_page->ID);
    }

    // ------- Create Primary Menu --------
    $menuname = 'Primary Menu';
    $bpmenulocation = 'primary';
    $menu_exists = wp_get_nav_menu_object($menuname);

    if (!$menu_exists) {
        $menu_id = wp_create_nav_menu($menuname);
        
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Home', 'digi-restaurant'),
            'menu-item-classes' => 'home',
            'menu-item-url' => home_url('/'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Popular', 'digi-restaurant'),
            'menu-item-classes' => 'popular',
            'menu-item-url' => home_url('/popular'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Category', 'digi-restaurant'),
            'menu-item-classes' => 'category',
            'menu-item-url' => home_url('/category'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('About Us ', 'digi-restaurant'),
            'menu-item-classes' => 'about',
            'menu-item-url' => home_url('/about'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Book Now', 'digi-restaurant'),
            'menu-item-classes' => 'book',
            'menu-item-url' => home_url('/book'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Chef', 'digi-restaurant'),
            'menu-item-classes' => 'chef',
            'menu-item-url' => home_url('/chef'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Testimonial', 'digi-restaurant'),
            'menu-item-classes' => 'testimonial',
            'menu-item-url' => home_url('/testimonial'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('Blog', 'digi-restaurant'),
            'menu-item-classes' => 'blog',
            'menu-item-url' => home_url('/blog'),
            'menu-item-status' => 'publish'
        ));
        wp_update_nav_menu_item($menu_id, 0, array(
            'menu-item-title' => __('About Us', 'digi-restaurant'),
            'menu-item-classes' => 'about',
            'menu-item-url' => home_url('/about'),
            'menu-item-status' => 'publish'
        ));
        

        // Assign the menu to the location
        if (!has_nav_menu($bpmenulocation)) {
            $locations = get_theme_mod('nav_menu_locations');
            $locations[$bpmenulocation] = $menu_id;
            set_theme_mod('nav_menu_locations', $locations);
        }
    }

    //Top Header

    set_theme_mod( 'restaurant_zone_phone_number_info', '1324567890' );
    set_theme_mod( 'restaurant_zone_email_info', 'email@exapmle.com' );

    set_theme_mod( 'restaurant_zone_facebook_icon', 'fab fa-facebook-f' );
    set_theme_mod( 'restaurant_zone_facebook_url', '#' );
    set_theme_mod( 'restaurant_zone_twitter_icon', 'fab fa-twitter' );
    set_theme_mod( 'restaurant_zone_twitter_url', '#' );
    set_theme_mod( 'restaurant_zone_intagram_icon', 'fab fa-instagram' );
    set_theme_mod( 'restaurant_zone_intagram_url', '#' );
    set_theme_mod( 'restaurant_zone_linkedin_icon', 'fab fa-linkedin-in' );
    set_theme_mod( 'restaurant_zone_linkedin_url', '#' );
    set_theme_mod( 'restaurant_zone_pintrest_icon', 'fab fa-pinterest-p' );
    set_theme_mod( 'restaurant_zone_pintrest_url', '#' );

    set_theme_mod( 'restaurant_zone_reservation_button', '#' );

    //Slider
    set_theme_mod( 'digi_restaurant_banner_setting', 'true' );

    set_theme_mod( 'digi_restaurant_image_one', get_stylesheet_directory_uri().'/assets/img/post1.png' );
    set_theme_mod( 'digi_restaurant_image_two', get_stylesheet_directory_uri().'/assets/img/post2.png' );
 
    set_theme_mod( 'digi_restaurant_top_section_heading', 'The Unique Restaurant' );
    set_theme_mod( 'digi_restaurant_top_section_content', 'Give your cat safe strolls and playful adventures. Our walking service keeps them happy, healthy, and active. Book a walk today!' );

    set_theme_mod( 'digi_restaurant_top_section_text', 'View More' );
    set_theme_mod( 'digi_restaurant_top_section_url', '#' );

    set_theme_mod( 'digi_restaurant_image_three', get_stylesheet_directory_uri().'/assets/img/post3.png' );
    set_theme_mod( 'digi_restaurant_image_four', get_stylesheet_directory_uri().'/assets/img/post4.png' );


    //About Us

    set_theme_mod( 'digi_restaurant_welcome_setting', 'true' );

    set_theme_mod( 'digi_restaurant_welcome_section_heading', 'Welcome To' );

    for($i=1;$i<=3;$i++){
        $title = 'Lorem Ipsum has been the industrys standard dummy text ever since ';
        $content = 'Lorem Ipsum has been the industrys standard dummy text ever since the 1500 when an unknown printer took a galley of type and scrambled it to make a type specimen book when an unknown printer took a galley of type and scrambled it to make a type specimen book.
            Lorem Ipsum has been the industrys standard dummy text ever since the 1500 when an unknown printer took a galley of type and scrambled it to make a type specimen book when an unknown printer took a galley of type and scrambled it to make a type specimen book.';
            // Create post object
            $my_post = array(
            'post_title'    => wp_strip_all_tags( $title ),
            'post_content'  => $content,
            'post_status'   => 'publish',
            'post_type'     => 'page',
            );

        // Insert the post into the database
        $post_id = wp_insert_post( $my_post );

        if ($post_id) {
        // Keep compatibility with old and current key names used by the template.
        set_theme_mod('digi_restaurant_welcome_page', $post_id);
        set_theme_mod('digi_restaurant_welcome_page' . $i, $post_id);

        $image_url = get_stylesheet_directory_uri().'/assets/img/banner.png';

        $image_id = media_sideload_image($image_url, $post_id, null, 'id');

            if (!is_wp_error($image_id)) {
                // Set the downloaded image as the post's featured image
                set_post_thumbnail($post_id, $image_id);
            }
        }
    }

}
// Enqueue necessary scripts
add_action('admin_enqueue_scripts', 'digi_restaurant_demo_importer_enqueue_scripts');

function digi_restaurant_demo_importer_enqueue_scripts() {
    wp_enqueue_script(
        'demo-theme-importer',
        get_theme_file_uri( '/assets/js/theme-importer.js' ),
        array('jquery'),
        null,
        true
    );

    wp_enqueue_style('demo-importer-style', get_theme_file_uri( '/assets/css/importer.css' ), array(), '');

    // Localize script to pass AJAX URL to JS
    wp_localize_script(
        'demo-theme-importer',
        'demoImporter',
        array(
            'ajax_url' => admin_url('admin-ajax.php'),
            'nonce'    => wp_create_nonce('theme_importer_nonce'),
            'security' => wp_create_nonce('tm_theme_info_nonce')
        )
    );
}