<?php

class Whizzie {

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

	public function init()
	{
	
	}

	public static function renewable_energy_lite_setup_widgets(){

	set_theme_mod( 'renewable_energy_lite_header_phone_number', '+1234567890' );
	set_theme_mod( 'renewable_energy_lite_header_email', 'sunvoltenergy@example.com' );
	set_theme_mod( 'renewable_energy_lite_header_adver_text', 'Now offering solar consultations – book your today!.' );
	set_theme_mod( 'renewable_energy_lite_header_button_text', 'Get A Free Quote' );
	set_theme_mod( 'renewable_energy_lite_header_button_link', '#' );

	set_theme_mod('renewable_energy_lite_social_links_settings', array(
		array(
			"link_text" => "fab fa-instagram",
			"link_url" => "www.instagram.com"
		),
		array(
			"link_text" => "fab fa-twitter",
			"link_url" => "www.twitter.com"
		),
		array(
			"link_text" => "fab fa-youtube",
			"link_url" => "www.youtube.com"
		),
		array(
			"link_text" => "fab fa-linkedin-in",
			"link_url" => "www.linkedin.com"
		)
	));

    /* Create Menu */
            $renewable_energy_lite_menuname  = 'Main Menus';
            $renewable_energy_lite_location  = 'primary';

            $renewable_energy_lite_menu = wp_get_nav_menu_object( $renewable_energy_lite_menuname );

            if ( ! $renewable_energy_lite_menu ) {
            $renewable_energy_lite_menu_id = wp_create_nav_menu( $renewable_energy_lite_menuname );

           // Home Page 
			wp_update_nav_menu_item( $renewable_energy_lite_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'renewable-energy-lite' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

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

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

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

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

             $renewable_energy_lite_blog_page_query = new WP_Query(array(
            'post_type'      => 'page',
            'name'           => sanitize_title($renewable_energy_lite_blog_page_title),
            'post_status'    => 'publish',
            'posts_per_page' => 1
            ));
            if (!$renewable_energy_lite_blog_page_query->have_posts()) {
            $renewable_energy_lite_blog_page = array(
            'post_type'   => 'page',
            'post_title'  => $renewable_energy_lite_blog_page_title,
            'post_status' => 'publish',
            'post_author' => 1,
            );
            $renewable_energy_lite_blog_page_id = wp_insert_post($renewable_energy_lite_blog_page);
            update_option('page_for_posts', $renewable_energy_lite_blog_page_id);

            wp_update_nav_menu_item($renewable_energy_lite_menu_id, 0, array(
            'menu-item-title'      => __('Blog', 'renewable-energy-lite'),
            'menu-item-url'        => get_permalink($renewable_energy_lite_blog_page_id),
            'menu-item-status'     => 'publish',
            'menu-item-object-id'  => $renewable_energy_lite_blog_page_id,
            'menu-item-object'     => 'page',
            'menu-item-type'       => 'post_type',
            ));
            }
            
			/* Assign Menu Location */
			$renewable_energy_lite_locations = get_theme_mod( 'nav_menu_locations', array() );
			$renewable_energy_lite_locations[ $renewable_energy_lite_location ] = $renewable_energy_lite_menu_id;
			set_theme_mod( 'nav_menu_locations', $renewable_energy_lite_locations );
		}

        // select Post Box
        $renewable_energy_lite_title_array = array("Residential Rooftop Installations", "Corporate Solar Parks", "Solar-Power Schools");

        // Ensure the category exists
        $renewable_energy_lite_category_name = 'Solar';
        $renewable_energy_lite_category_id = get_cat_ID($renewable_energy_lite_category_name);

        if ($renewable_energy_lite_category_id == 0) {
            $renewable_energy_lite_category_id = wp_create_category($renewable_energy_lite_category_name);
        }

        // loop 1 to 3 (because array me 3 names hain)
        for ($renewable_energy_lite_i = 1; $renewable_energy_lite_i <= 3; $renewable_energy_lite_i++) {

            $renewable_energy_lite_title = $renewable_energy_lite_title_array[$renewable_energy_lite_i - 1];
            $renewable_energy_lite_content = 'High energy beats to keep the dance floor alive all night long';

            $renewable_energy_lite_my_post = array(
                'post_title'    => wp_strip_all_tags($renewable_energy_lite_title),
                'post_content'  => $renewable_energy_lite_content,
                'post_status'   => 'publish',
                'post_type'     => 'post',
                'post_category' => array($renewable_energy_lite_category_id),
            );

            $renewable_energy_lite_post_id = wp_insert_post($renewable_energy_lite_my_post);

            // Correct image path
            $renewable_energy_lite_image_url = get_template_directory_uri() . '/assets/images/solar-post-' . $renewable_energy_lite_i . '.png';

            $renewable_energy_lite_image_data = wp_remote_get($renewable_energy_lite_image_url);

            if (!is_wp_error($renewable_energy_lite_image_data)) {

                $renewable_energy_lite_image_body = wp_remote_retrieve_body($renewable_energy_lite_image_data);
                $renewable_energy_lite_upload_dir = wp_upload_dir();
                $renewable_energy_lite_image_name = 'solar-post-' . $renewable_energy_lite_i . '.png';

                $uploaded_file = wp_upload_bits($renewable_energy_lite_image_name, null, $renewable_energy_lite_image_body);

                if (!$uploaded_file['error']) {

                    $attachment = array(
                        'post_mime_type' => $uploaded_file['type'],
                        'post_title'     => sanitize_file_name($renewable_energy_lite_image_name),
                        'post_content'   => '',
                        'post_status'    => 'inherit',
                    );

                    $renewable_energy_lite_attach_id = wp_insert_attachment($attachment, $uploaded_file['file'], $renewable_energy_lite_post_id);
                    require_once(ABSPATH . 'wp-admin/includes/image.php');

                    $renewable_energy_lite_attach_data = wp_generate_attachment_metadata($renewable_energy_lite_attach_id, $uploaded_file['file']);
                    wp_update_attachment_metadata($renewable_energy_lite_attach_id, $renewable_energy_lite_attach_data);

                    set_post_thumbnail($renewable_energy_lite_post_id, $renewable_energy_lite_attach_id);
                }
            }
        }
	}
}
 