<?php

class Whizzie {

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

	public function init()
	{
	}

	public static function school_education_setup_widgets(){

	$school_education_options = get_theme_mod('theme_options', []);
        $school_education_options['school_education_header_top_text'] = 'Future ready skills on your schedule | Learn why Alumity is trusted by students and companies.';
        $school_education_options['school_education_header_top_button_text'] = 'Register Now';
		$school_education_options['school_education_header_top_button_link'] = '#';
    set_theme_mod('theme_options', $school_education_options);	

	$school_education_product_image_gallery = array();
	$school_education_product_ids = array();

	$school_education_product_category= array(
		'Computer Courses' => array(
			'2023 Web Development Bootcamp',
			'2024 Web Development Bootcamp',
			'2025 Web Development Bootcamp',
		),
	);

	foreach ( $school_education_product_category as $school_education_product_cats => $school_education_products_name ) {

		$school_education_parent_category = wp_insert_term(
			$school_education_product_cats,
			'product_cat',
			array(
				'description'=> 'This is sample product category',
				'slug' => sanitize_title( $school_education_product_cats )
			)
		);

		$school_education_n = 1;

		foreach ( $school_education_products_name as $school_education_product_title ) {

			$content = '
			<div class="main_content">
				<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
			</div>';

			$school_education_my_post = array(
				'post_title'   => wp_strip_all_tags( $school_education_product_title ),
				'post_content' => $content,
				'post_status'  => 'publish',
				'post_type'    => 'product',
			);

			$school_education_uqpost_id = wp_insert_post( $school_education_my_post );

			wp_set_object_terms(
				$school_education_uqpost_id,
				$school_education_parent_category['term_id'],
				'product_cat'
			);

			/* ========== PRICE FIX (IMPLEMENTED) ========== */

			$school_education_product_regular_price = array('93.57','93.57','93.57');
			$school_education_product_sale_price    = array('65.42','65.42','65.42');

			update_post_meta(
				$school_education_uqpost_id,
				'_regular_price',
				$school_education_product_regular_price[$school_education_n-1]
			);

			update_post_meta(
				$school_education_uqpost_id,
				'_sale_price',
				$school_education_product_sale_price[$school_education_n-1]
			);

			update_post_meta(
				$school_education_uqpost_id,
				'_price',
				$school_education_product_sale_price[$school_education_n-1]
			);

			/* ========== PRICE FIX END ========== */

			$school_education_product_ids[] = $school_education_uqpost_id;

			/* ========== IMAGE FIX (DIRECT /images/) ========== */

			$image_slug = sanitize_title( $school_education_product_title );

			$image_url  = get_template_directory_uri() . '/images/' . $image_slug . '.png';
			$image_name = $image_slug . '.png';

			$upload_dir = wp_upload_dir();
			$image_data = @file_get_contents( $image_url );

			if ( $image_data ) {

				$filename = wp_unique_filename( $upload_dir['path'], $image_name );
				$file     = $upload_dir['path'] . '/' . $filename;

				file_put_contents( $file, $image_data );

				$wp_filetype = wp_check_filetype( $filename, null );

				$attachment = array(
					'post_mime_type' => $wp_filetype['type'],
					'post_title'     => sanitize_file_name( $filename ),
					'post_status'    => 'inherit',
				);

				$attach_id = wp_insert_attachment( $attachment, $file, $school_education_uqpost_id );

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

				$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
				wp_update_attachment_metadata( $attach_id, $attach_data );

				set_post_thumbnail( $school_education_uqpost_id, $attach_id );

				if ( count( $school_education_product_image_gallery ) < 3 ) {
					$school_education_product_image_gallery[] = $attach_id;
				}
			}

			/* ========== IMAGE FIX END ========== */

			$school_education_n++;
		}
	}

	$school_education_product_image_gallery = implode( ',', $school_education_product_image_gallery );

	foreach ( $school_education_product_ids as $school_education_product_id ) {
		update_post_meta(
			$school_education_product_id,
			'school_education_product_image_gallery',
			$school_education_product_image_gallery
		);
	}

	/* Create Menu */
            $school_education_menuname  = 'Primary Menu';
            $school_education_location  = 'primary-menu';

            $school_education_menu = wp_get_nav_menu_object( $school_education_menuname );

            if ( ! $school_education_menu ) {
            $school_education_menu_id = wp_create_nav_menu( $school_education_menuname );

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

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

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

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

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

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

             // Create Shop Page
                $school_education_about_title = 'Shop';
                $school_education_about_content = 'Lorem ipsum dolor sit amet...';

                $shop_page = get_page_by_path('shop');
                if ( !$shop_page ) {
                    $school_education_about = array(
                        'post_type'   => 'page',
                        'post_title'  => $school_education_about_title,
                        'post_content'=> $school_education_about_content,
                        'post_status' => 'publish',
                        'post_author' => 1,
                        'post_name'   => 'shop' 
                        );
                        $school_education_about_id = wp_insert_post($school_education_about);
                    } else {
                        $school_education_about_id = $shop_page->ID;
                    }

                    wp_update_nav_menu_item($school_education_menu_id, 0, array(
                        'menu-item-title'   => __('Shop', 'school-education'),
                        'menu-item-classes' => 'shop',
                        'menu-item-object-id' => $school_education_about_id,
                        'menu-item-object'  => 'page',
                        'menu-item-type'    => 'post_type',
                        'menu-item-status'  => 'publish'
                    ));
          
			/* Assign Menu Location */
			$school_education_locations = get_theme_mod( 'nav_menu_locations', array() );
			$school_education_locations[ $school_education_location ] = $school_education_menu_id;
			set_theme_mod( 'nav_menu_locations', $school_education_locations );
		}
    }
}
