<?php
class Whizzie {

    public function __construct() {
        $this->init();
    }

    public function init() {
        // Initialize content and settings
        $this->unique_freelancer_portfolio_setup_widgets();
        $this->unique_freelancer_portfolio_setup_theme_mods();
    }

    public function unique_freelancer_portfolio_setup_widgets() {

        /* Create Menu */
            $unique_freelancer_portfolio_menuname  = 'Primary Menu';
            $unique_freelancer_portfolio_location  = 'primary';

            $unique_freelancer_portfolio_menu = wp_get_nav_menu_object( $unique_freelancer_portfolio_menuname );

            if ( ! $unique_freelancer_portfolio_menu ) {
            $unique_freelancer_portfolio_menu_id = wp_create_nav_menu( $unique_freelancer_portfolio_menuname );

           // Home Page 
			wp_update_nav_menu_item( $unique_freelancer_portfolio_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'unique-freelancer-portfolio' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

			// About Us Page 
			$unique_freelancer_portfolio_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'About Us',
			'post_status' => 'publish',
			) );

			if ( $unique_freelancer_portfolio_about_id ) {
			wp_update_nav_menu_item( $unique_freelancer_portfolio_menu_id, 0, array(
			'menu-item-title'     => 'About Us',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $unique_freelancer_portfolio_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

            // Projects Page 
			$unique_freelancer_portfolio_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Projects',
			'post_status' => 'publish',
			) );

			if ( $unique_freelancer_portfolio_about_id ) {
			wp_update_nav_menu_item( $unique_freelancer_portfolio_menu_id, 0, array(
			'menu-item-title'     => 'Projects',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $unique_freelancer_portfolio_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

            // Contact Us Page 
			$unique_freelancer_portfolio_about_id = wp_insert_post( array(
			'post_type'   => 'page',
			'post_content' => 'We are committed to providing reliable, professional, and result-oriented solutions tailored to meet individual needs. Our goal is to empower people with the right guidance, knowledge, and support to help them make informed decisions for a better future. <br><br> Our mission is to deliver high-quality services with honesty, transparency, and dedication. We focus on understanding client requirements and offering practical solutions that create long-term value. <br><br> With a client-centric approach, experienced professionals, and a commitment to excellence, we ensure every individual receives the attention and guidance they deserve. We believe in building trust through quality service and consistent results.',
			'post_title'  => 'Contact Us',
			'post_status' => 'publish',
			) );

			if ( $unique_freelancer_portfolio_about_id ) {
			wp_update_nav_menu_item( $unique_freelancer_portfolio_menu_id, 0, array(
			'menu-item-title'     => 'Contact Us',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $unique_freelancer_portfolio_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

            // Create Blog Page
                $unique_freelancer_portfolio_blog_page_title = 'Blog';

                $unique_freelancer_portfolio_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($unique_freelancer_portfolio_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$unique_freelancer_portfolio_blog_page_query->hae_posts()) {
                    $unique_freelancer_portfolio_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $unique_freelancer_portfolio_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $unique_freelancer_portfolio_blog_page_id = wp_insert_post($unique_freelancer_portfolio_blog_page);
                    update_option('page_for_posts', $unique_freelancer_portfolio_blog_page_id);

                    wp_update_nav_menu_item($unique_freelancer_portfolio_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'unique-freelancer-portfolio'),
                        'menu-item-url'        => get_permalink($unique_freelancer_portfolio_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $unique_freelancer_portfolio_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }

			/* Assign Menu Location */
			$unique_freelancer_portfolio_locations = get_theme_mod( 'nav_menu_locations', array() );
			$unique_freelancer_portfolio_locations[ $unique_freelancer_portfolio_location ] = $unique_freelancer_portfolio_menu_id;
			set_theme_mod( 'nav_menu_locations', $unique_freelancer_portfolio_locations );
		}
    }

    public function unique_freelancer_portfolio_setup_theme_mods() {
        $unique_freelancer_portfolio_options = get_theme_mod('theme_options', []);
        $unique_freelancer_portfolio_options['unique_freelancer_portfolio_quote_button_text'] = 'Get A Quote';
        $unique_freelancer_portfolio_options['unique_freelancer_portfolio_quote_button_link'] = '#';
        set_theme_mod('theme_options', $unique_freelancer_portfolio_options);


    }
}