<?php

class Whizzie {

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

	public function init()
	{
	
	}

	public static function event_organizer_elemento_setup_widgets(){

        set_theme_mod( 'event_organizer_elemento_header_button_text', 'Get A quote' );
		set_theme_mod( 'event_organizer_elemento_header_button_url', '#' );
		set_theme_mod( 'event_organizer_elemento_header_email', 'info@exaple.com' );
		set_theme_mod( 'event_organizer_elemento_header_phone_number', '+1234567890' );
		set_theme_mod( 'event_organizer_elemento_header_location', '1234 Alassford street new York' );
		set_theme_mod('event_organizer_elemento_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"
            )
        ));

		$event_organizer_elemento_category_names =  array('servicecategory1');
		$event_organizer_elemento_title_array = array(
			array("Engagement party for adani family", "Kids birthday party for bowni", "Diwali festival party for friends")
		);
		foreach ($event_organizer_elemento_category_names as $event_organizer_elemento_index => $event_organizer_elemento_category_name) {
			// Create or retrieve the post category term ID
			$event_organizer_elemento_term = term_exists($event_organizer_elemento_category_name, 'category');
			if ($event_organizer_elemento_term === 0 || $event_organizer_elemento_term === null) {
				// If the term does not exist, create it
				$event_organizer_elemento_term = wp_insert_term($event_organizer_elemento_category_name, 'category');
			}
			if (is_wp_error($event_organizer_elemento_term)) {
				error_log('Error creating category: ' . $event_organizer_elemento_term->get_error_message());
				continue; // Skip to the next iteration if category creation fails
			}
			for ($event_organizer_elemento_i = 1; $event_organizer_elemento_i < 3; $event_organizer_elemento_i++) {
				// Create post content
				$event_organizer_elemento_title = $event_organizer_elemento_title_array[$event_organizer_elemento_index][$event_organizer_elemento_i];
				$event_organizer_elemento_content = 'Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s.';
				// Create post post object
				$event_organizer_elemento_my_post = array(
					'post_title'    => wp_strip_all_tags($event_organizer_elemento_title),
					'post_content'  => $event_organizer_elemento_content,
					'post_status'   => 'publish',
					'post_type'     => 'post', // Post type set to 'post'
				);
				// Insert the post into the database
				$event_organizer_elemento_post_id = wp_insert_post($event_organizer_elemento_my_post);
				if (is_wp_error($event_organizer_elemento_post_id)) {
					error_log('Error creating post: ' . $event_organizer_elemento_post_id->get_error_message());
					continue; // Skip to the next post if creation fails
				}
				// Assign the category to the post
				wp_set_post_categories($event_organizer_elemento_post_id, array((int)$event_organizer_elemento_term['term_id']));
				// Handle the featured image using media_sideload_image
				$event_organizer_elemento_image_url = get_template_directory_uri() . '/assets/images/blog/blog' . ($event_organizer_elemento_i + 1) . '.png';
				$event_organizer_elemento_image_id = media_sideload_image($event_organizer_elemento_image_url, $event_organizer_elemento_post_id, null, 'id');
				if (is_wp_error($event_organizer_elemento_image_id)) {
					error_log('Error downloading image: ' . $event_organizer_elemento_image_id->get_error_message());
					continue; // Skip to the next post if image download fails
				}
				// Assign featured image to post
				set_post_thumbnail($event_organizer_elemento_post_id, $event_organizer_elemento_image_id);
			}
		}

        /* Create Menu */
            $event_organizer_elemento_menuname  = 'Main Menus';
            $event_organizer_elemento_location  = 'main-menu';

            $event_organizer_elemento_menu = wp_get_nav_menu_object( $event_organizer_elemento_menuname );

            if ( ! $event_organizer_elemento_menu ) {
            $event_organizer_elemento_menu_id = wp_create_nav_menu( $event_organizer_elemento_menuname );

           // Home Page 
			wp_update_nav_menu_item( $event_organizer_elemento_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'event-organizer-elemento' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
				'menu-item-position'  => 1,
			) );

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

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

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

			if ( $event_organizer_elemento_about_id ) {
			wp_update_nav_menu_item( $event_organizer_elemento_menu_id, 0, array(
			'menu-item-title'     => 'Portfolio',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $event_organizer_elemento_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
            'menu-item-position'  => 4,
			) );
			}

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

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

                $event_organizer_elemento_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($event_organizer_elemento_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$event_organizer_elemento_blog_page_query->hae_posts()) {
                    $event_organizer_elemento_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $event_organizer_elemento_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $event_organizer_elemento_blog_page_id = wp_insert_post($event_organizer_elemento_blog_page);
                    update_option('page_for_posts', $event_organizer_elemento_blog_page_id);

                    wp_update_na_menu_item($event_organizer_elemento_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'event-organizer-elemento'),
                        'menu-item-url'        => get_permalink($event_organizer_elemento_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $event_organizer_elemento_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }
            
			/* ---------- Assign Menu Location ---------- */
			$event_organizer_elemento_locations = get_theme_mod( 'nav_menu_locations', array() );
			$event_organizer_elemento_locations[ $event_organizer_elemento_location ] = $event_organizer_elemento_menu_id;
			set_theme_mod( 'nav_menu_locations', $event_organizer_elemento_locations );
		}

	}
}
 