<?php

class Whizzie {

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

	public function init()
	{
	
	}

	public static function solar_panel_distributor_setup_widgets(){

        require_once ABSPATH . 'wp-admin/includes/media.php';
        require_once ABSPATH . 'wp-admin/includes/file.php';
        require_once ABSPATH . 'wp-admin/includes/image.php';

        $solar_panel_distributor_options = get_theme_mod('theme_options', []);
        $solar_panel_distributor_options['solar_panel_distributor_header_top_text'] = 'We provide best services for you solar energy system.';
        $solar_panel_distributor_options['solar_panel_distributor_header_top_location'] = '1870, New York, USA';
		$solar_panel_distributor_options['solar_panel_distributor_header_top_email'] = 'solarenergy@gmail.com';
		$solar_panel_distributor_options['solar_panel_distributor_header_top_button_text'] = 'ORDER NOW';
        $solar_panel_distributor_options['solar_panel_distributor_header_top_button_link'] = '#';
		$solar_panel_distributor_options['solar_panel_distributor_header_top_phone_text'] = 'Have a question?';
		$solar_panel_distributor_options['solar_panel_distributor_header_top_phone_number'] = '+00 123 4567';

		$solar_panel_distributor_options['solar_panel_distributor_header_social_facebook_link'] = '#';
		$solar_panel_distributor_options['solar_panel_distributor_header_social_twitter_link'] = '#';
		$solar_panel_distributor_options['solar_panel_distributor_header_social_instagram_link'] = '#';
        $solar_panel_distributor_options['solar_panel_distributor_header_social_youtube_link'] = '#';
		$solar_panel_distributor_options['solar_panel_distributor_header_social_pintrest_link'] = '#';
        set_theme_mod('theme_options', $solar_panel_distributor_options);

        $post_titles = array(
            "Solar panel Services",
            "Turbines Services",
            "Hydro power plants",
            "Fossil resources"
        );

        for ($i = 1; $i <= 4; $i++) {

            $title   = $post_titles[$i - 1];
            $content = "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.";

            $existing_post = get_page_by_title($title, OBJECT, 'post');
            if ($existing_post) {
                continue;
            }

            $post_id = wp_insert_post(array(
                'post_title'   => wp_strip_all_tags($title),
                'post_content' => $content,
                'post_status'  => 'publish',
                'post_type'    => 'post',
            ));

            if (is_wp_error($post_id)) {
                continue;
            }

            $image_url = get_template_directory_uri() . '/images/post/image' . $i . '.png';
            $attach_id = media_sideload_image($image_url, $post_id, null, 'id');

            if (!is_wp_error($attach_id)) {
                set_post_thumbnail($post_id, $attach_id);
            }
        }

		/* Create Menu */
            $solar_panel_distributor_menuname  = 'Primary Menu';
            $solar_panel_distributor_location  = 'primary-menu';

            $solar_panel_distributor_menu = wp_get_nav_menu_object( $solar_panel_distributor_menuname );

            if ( ! $solar_panel_distributor_menu ) {
            $solar_panel_distributor_menu_id = wp_create_nav_menu( $solar_panel_distributor_menuname );

           // Home Page 
			wp_update_nav_menu_item( $solar_panel_distributor_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'solar-panel-distributor' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

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

			// Pages Page 
			$solar_panel_distributor_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 ( $solar_panel_distributor_about_id ) {
			wp_update_nav_menu_item( $solar_panel_distributor_menu_id, 0, array(
			'menu-item-title'     => 'Pages',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $solar_panel_distributor_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

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

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

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

             // Create Shop Page
                $solar_panel_distributor_about_title = 'Shop';
                $solar_panel_distributor_about_content = 'Lorem ipsum dolor sit amet...';

                $shop_page = get_page_by_path('shop');
                if ( !$shop_page ) {
                    $solar_panel_distributor_about = array(
                        'post_type'   => 'page',
                        'post_title'  => $solar_panel_distributor_about_title,
                        'post_content'=> $solar_panel_distributor_about_content,
                        'post_status' => 'publish',
                        'post_author' => 1,
                        'post_name'   => 'shop' 
                        );
                        $solar_panel_distributor_about_id = wp_insert_post($solar_panel_distributor_about);
                    } else {
                        $solar_panel_distributor_about_id = $shop_page->ID;
                    }

                    wp_update_nav_menu_item($solar_panel_distributor_menu_id, 0, array(
                        'menu-item-title'   => __('Shop', 'solar-panel-distributor'),
                        'menu-item-classes' => 'shop',
                        'menu-item-object-id' => $solar_panel_distributor_about_id,
                        'menu-item-object'  => 'page',
                        'menu-item-type'    => 'post_type',
                        'menu-item-status'  => 'publish'
                    ));
          
			/* Assign Menu Location */
			$solar_panel_distributor_locations = get_theme_mod( 'nav_menu_locations', array() );
			$solar_panel_distributor_locations[ $solar_panel_distributor_location ] = $solar_panel_distributor_menu_id;
			set_theme_mod( 'nav_menu_locations', $solar_panel_distributor_locations );
		}
	}
}
 