<?php

class Whizzie {

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

	public function init()
	{
		
	}

	public static function zoo_safari_setup_widgets(){

		set_theme_mod( 'zoo_safari_header_button_text', 'Explore More' );
		set_theme_mod( 'zoo_safari_header_button_link', '#' );

		/* Create Menu */
            $zoo_safari_menuname  = 'Main Menus';
            $zoo_safari_location  = 'main-menu';

            $zoo_safari_menu = wp_get_nav_menu_object( $zoo_safari_menuname );

            if ( ! $zoo_safari_menu ) {
            $zoo_safari_menu_id = wp_create_nav_menu( $zoo_safari_menuname );

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

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

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

                $zoo_safari_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($zoo_safari_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$zoo_safari_blog_page_query->hae_posts()) {
                    $zoo_safari_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $zoo_safari_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $zoo_safari_blog_page_id = wp_insert_post($zoo_safari_blog_page);
                    update_option('page_for_posts', $zoo_safari_blog_page_id);

                    wp_update_na_menu_item($zoo_safari_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'zoo-safari'),
                        'menu-item-url'        => get_permalink($zoo_safari_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $zoo_safari_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }
            
			/* Assign Menu Location */
			$zoo_safari_locations = get_theme_mod( 'nav_menu_locations', array() );
			$zoo_safari_locations[ $zoo_safari_location ] = $zoo_safari_menu_id;
			set_theme_mod( 'nav_menu_locations', $zoo_safari_locations );
		}


			function insert_custom_contact_and_subscribe_forms()
			{
				$existing_form = get_page_by_title('Booking Form', OBJECT, 'wpcf7_contact_form');
				if ($existing_form) {
					return;
				}

				// Form title
				$contact_form_title = 'Booking Form';

				// Booking Form 7 form content
				$contact_form_content = <<<EOT
			<div class="row booking-form">
				<div class="col-md-6">
					<label>Name</label>
					[text* first-name placeholder "First Name"]
				</div>
				<div class="col-md-6">
					<label>Email</label>
					[email* email-address placeholder "Email Address"]
				</div>
				<div class="col-md-6">
					<label>Select Package</label>
					[select* select-package first_as_label "Wildlife Safari Adventure" "Luxury Desert Safari" "Sunrise Safari Tour" "Jeep Safari Expedition"]
				</div>
				<div class="col-md-6">
					<label>Date</label>
					[date* safari-date]
				</div>
				<div class="col-md-3">
					<label>Adults</label>
					[number* adult-number min:1 max:20 placeholder "0"]
				</div>
				<div class="col-md-3">
					<label>Children</label>
					[number child-number min:0 max:10 placeholder "0"]
				</div>
				<div class="col-md-6 text-end book-now-button">
					<span class="book-now-btn">
						<button type="submit" class="newsltr-btn wpcf7-submit">Book Now <i class="fa-solid fa-arrow-right"></i></button>
					</span>
				</div>
			</div>
			EOT;

				// Insert the new Booking Form post
				$contact_post_id = wp_insert_post(array(
					'post_title'  => $contact_form_title,
					'post_type'   => 'wpcf7_contact_form',
					'post_status' => 'publish',
				));

				// If post created successfully, update form and mail settings
				if ($contact_post_id && !is_wp_error($contact_post_id)) {
					// Form fields
					update_post_meta($contact_post_id, '_form', $contact_form_content);

					// Email settings (admin notification)
					update_post_meta($contact_post_id, '_mail', array(
						'subject'   => 'New Safari Booking from [first-name]',
						'sender'    => '[first-name] <[email-address]>',
						'body'      => "You have received a new booking request:\n\n" .
									"Name: [first-name]\n" .
									"Email: [email-address]\n" .
									"Package: [select-package]\n" .
									"Date: [safari-date]\n" .
									"Adults: [adult-number]\n" .
									"Children: [child-number]\n\n" ,
						'recipient' => get_option('admin_email'),
						'use_html'  => true,
					));

					// Auto-reply settings (user notification)
					update_post_meta($contact_post_id, '_mail_2', array(
						'active'    => true,
						'subject'   => 'Thank you for booking with us, [first-name]!',
						'sender'    => get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
						'body'      => "Hi [first-name],\n\nThank you for booking your safari adventure with us!\n\nHere are your booking details:\n" .
									"Package: [select-package]\nDate: [safari-date]\nAdults: [adult-number]\nChildren: [child-number]\n\n" .
									"We will contact you soon with confirmation details.\n\nBest regards,\n" . get_bloginfo('name'),
						'recipient' => '[email-address]',
						'use_html'  => true,
					));
				}
			}
			insert_custom_contact_and_subscribe_forms();

	}

}
 