<div class="theme-offer">
<?php

    function quantic_create_customizer_nav_menu() {
        // ------- Create Nav Menu --------
        $quantic_menuname = 'Primary';
        $quantic_menulocation = 'primary';
        $quantic_menu_exists = wp_get_nav_menu_object($quantic_menuname);

        if (!$quantic_menu_exists) {
            $quantic_menu_id = wp_create_nav_menu($quantic_menuname);

            wp_update_nav_menu_item($quantic_menu_id, 0, array(
                'menu-item-title' => __('Home', 'quantic'),
                'menu-item-url' => home_url('/'),
                'menu-item-status' => 'publish',
            ));

            wp_update_nav_menu_item($quantic_menu_id, 0, array(
                'menu-item-title' => __('About Us', 'quantic'),
                'menu-item-url' => home_url('/index.php/about-us/'),
                'menu-item-status' => 'publish',
            ));

            wp_update_nav_menu_item($quantic_menu_id, 0, array(
                'menu-item-title' => __('Services', 'quantic'),
                'menu-item-url' => home_url('/index.php/services/'),
                'menu-item-status' => 'publish',
            ));

            wp_update_nav_menu_item($quantic_menu_id, 0, array(
                'menu-item-title' => __('Pages', 'quantic'),
                'menu-item-url' => home_url('/index.php/pages/'),
                'menu-item-status' => 'publish',
            ));

            wp_update_nav_menu_item($quantic_menu_id, 0, array(
                'menu-item-title' => __('Blog', 'quantic'),
                'menu-item-url' => home_url('/index.php/blog/'),
                'menu-item-status' => 'publish',
            ));

            // Set menu to location
            $quantic_locations = get_theme_mod('nav_menu_locations');
            if (!is_array($quantic_locations)) {
                $quantic_locations = array();
            }
            $quantic_locations[$quantic_menulocation] = $quantic_menu_id;
            set_theme_mod('nav_menu_locations', $quantic_locations);
        }
    }

    // POST and update the customizer and other related data of Quantic
    if (isset($_POST['submit'])) {

        // -------- Plugin Installation and Activation (WooCommerce & Classic Widgets) -------- //
        include_once(ABSPATH . 'wp-admin/includes/plugin.php');
        include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
        include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
        include_once(ABSPATH . 'wp-admin/includes/file.php');
        include_once(ABSPATH . 'wp-admin/includes/misc.php');

        // Plugin list
        $quantic_plugins = array(
            array(
                'slug' => 'classic-widgets',
                'file' => 'classic-widgets/classic-widgets.php',
                'download_url' => 'https://downloads.wordpress.org/plugin/classic-widgets.zip'
            )
        );

        foreach ($quantic_plugins as $plugin) {
            $installed_plugins = get_plugins();

            // Install the plugin if it's not installed
            if (!isset($installed_plugins[$plugin['file']])) {
                $upgrader = new Plugin_Upgrader();
                $upgrader->install($plugin['download_url']);
            }

            // Activate the plugin if it's not active
            if (file_exists(WP_PLUGIN_DIR . '/' . $plugin['file']) && !is_plugin_active($plugin['file'])) {
                activate_plugin($plugin['file']);
            }
        }

        // ------- Create Menu --------
        quantic_create_customizer_nav_menu();

        // ------- Create Pages --------
        function create_demo_page($title, $content = '', $template = '') {
            $page_id = quantic_get_page_id_by_title($title);
        
            if (!$page_id) {
                $page_data = array(
                    'post_type'    => 'page',
                    'post_title'   => $title,
                    'post_content' => $content,
                    'post_status'  => 'publish',
                    'post_author'  => 1,
                );
        
                $page_id = wp_insert_post($page_data);
        
                if ($template && !is_wp_error($page_id)) {
                    update_post_meta($page_id, '_wp_page_template', $template);
                }
            }
        
            return $page_id;
        }
        

        $quantic_home_id = create_demo_page('Home', '', 'home/home.php');
        update_option('page_on_front', $quantic_home_id);
        update_option('show_on_front', 'page');

        create_demo_page('Pages', '<p>Lorem Ipsum ...</p>');
        create_demo_page('About Us', '<p>Lorem Ipsum ...</p>');
        create_demo_page('Services', '<p>Service description...</p>');

        // Create blog page and assign it to display posts
        $blog_page_id = create_demo_page('Blog');
        update_option('page_for_posts', $blog_page_id);

        // Create the nav menu
        quantic_create_customizer_nav_menu();

        // ------- Set Theme Mods --------

        set_theme_mod('quantic_header_calling_text', 'Have any Question');
        set_theme_mod('quantic_header_calling_number', '+12345678912');

        // ------- Banner Section --------

        set_theme_mod('quantic_social_media1_heading', 'www.facebook.com');
        set_theme_mod('quantic_social_media2_heading', 'www.instagram.com');
        set_theme_mod('quantic_social_media3_heading', 'www.twitter.com');
        set_theme_mod('quantic_social_media4_heading', 'www.youtube.com');        

        set_theme_mod("quantic_banner_image", get_template_directory_uri() . "/img/banner.png");        
        set_theme_mod("quantic_banner_small_heading", 'Growth Your Business');
        set_theme_mod("quantic_banner_heading", 'We Provide Reliable Business Consulting Help');
        set_theme_mod("quantic_banner_text", 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since');
        set_theme_mod("quantic_banner_button_link", '#');
        

        // ------- About Section --------
        
        set_theme_mod('quantic_about_experience_number', '15+');
        set_theme_mod('quantic_about_image_big', get_template_directory_uri() . '/img/abt-left.png');
        set_theme_mod('quantic_about_image_small', get_template_directory_uri() . '/img/abt-right.png');
        set_theme_mod('quantic_about_short_heading', 'Company About Us');
        set_theme_mod('quantic_about_heading', 'A New Way To Manage Your Business!');
        set_theme_mod('quantic_about_content', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since. Lorem Ipsum has been the industrys standard dummy text ever since.');
        set_theme_mod('quantic_about_achivement_number', 'Best Business Solution');
        set_theme_mod('quantic_about_achivement_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
        set_theme_mod('quantic_about_leading_text', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.');
        set_theme_mod('quantic_about_leading_heading', 'Best Business Experts');
        set_theme_mod('quantic_about_content2', 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since.');
        set_theme_mod('quantic_about_button_link', '#');
       

       
        echo '<div class="success">Demo Import Successful</div>';
    }
?>

<ul>
    <li>
        <hr>
        <?php if (!isset($_POST['submit'])) : ?>
            <?php echo esc_html__('Click on the below button to get demo content installed.', 'quantic'); ?>
            <br>
            <form id="demo-importer-form" action="" method="POST" onsubmit="return confirm('Do you really want to do this?');">
                <input class="run-btn" type="submit" name="submit" value="<?php echo esc_attr('Run Importer', 'quantic'); ?>">
            </form>
        <?php else: ?>
            <div class="visit">
                <a href="<?php echo esc_url(home_url()); ?>" class="button button-primary button-large run-btn" style="margin-top: 10px;" target="_blank">View Site</a>
            </div>
        <?php endif; ?>
        <hr>
    </li>
</ul>
</div>