<?php
class Whizzie {

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

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

    public function property_broker_setup_theme_mods() {
        $property_broker_options = get_theme_mod('theme_options', []);
        $property_broker_options['property_broker_header_top_text'] = 'Your Trusted Partner in Smart Investments and Deals!';
        $property_broker_options['property_broker_header_top_location'] = 'Address :- 38 High Street, Troll mall ';
        $property_broker_options['property_broker_header_top_location_link'] = '#';
        $property_broker_options['property_broker_header_top_email'] = 'broker@example.com';
        $property_broker_options['property_broker_header_top_button_text'] = 'Call Us Now';
        $property_broker_options['property_broker_header_top_button_link'] = '#';
        set_theme_mod('theme_options', $property_broker_options);

        /* Create Menu */
            $property_broker_menuname  = 'Primary Menu';
            $property_broker_location  = 'primary';

            $property_broker_menu = wp_get_nav_menu_object( $property_broker_menuname );

            if ( ! $property_broker_menu ) {
            $property_broker_menu_id = wp_create_nav_menu( $property_broker_menuname );

           // Home Page 
			wp_update_nav_menu_item( $property_broker_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'property-broker' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

			// About Us Page 
			$property_broker_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 ( $property_broker_about_id ) {
			wp_update_nav_menu_item( $property_broker_menu_id, 0, array(
			'menu-item-title'     => 'About Us',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $property_broker_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

			// Pages Page 
			$property_broker_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'  => 'Pages',
			'post_status' => 'publish',
			) );

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

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

                $property_broker_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($property_broker_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ) );
                
                if (!$property_broker_blog_page_query->hae_posts()) {
                    $property_broker_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $property_broker_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $property_broker_blog_page_id = wp_insert_post($property_broker_blog_page);
                    update_option('page_for_posts', $property_broker_blog_page_id);

                    wp_update_na_menu_item($property_broker_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'property-broker'),
                        'menu-item-url'        => get_permalink($property_broker_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $property_broker_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ) );
                    }

            // Contact Us Page 
			$property_broker_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 ( $property_broker_about_id ) {
			wp_update_nav_menu_item( $property_broker_menu_id, 0, array(
			'menu-item-title'     => 'Contact Us',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $property_broker_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}
            
			/* Assign Menu Location */
			$property_broker_locations = get_theme_mod( 'nav_menu_locations', array() );
			$property_broker_locations[ $property_broker_location ] = $property_broker_menu_id;
			set_theme_mod( 'nav_menu_locations', $property_broker_locations );
		}
    }
}