<?php

class Whizzie {

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

	public function init()
	{
	
	}

	public static function unique_fun_center_setup_widgets(){

		$unique_fun_center_options = get_theme_mod('theme_options', []);
        $unique_fun_center_options['unique_fun_center_header_top_button'] = 'Get Started';
        $unique_fun_center_options['unique_fun_center_header_top_buttonlink'] = '#';
		$unique_fun_center_options['unique_fun_center_header_opening_time'] = 'Mon-Sat: 9:00am-7:00am';
		$unique_fun_center_options['unique_fun_center_header_location'] = 'My Street, New York';
        $unique_fun_center_options['unique_fun_center_header_email_address'] = 'uniquefun@gmail.com';

		$unique_fun_center_options['unique_fun_center_header_facebook_link'] = '#';
		$unique_fun_center_options['unique_fun_center_header_twitter_link'] = '#';
		$unique_fun_center_options['unique_fun_center_header_instagram_link'] = '#';
        $unique_fun_center_options['unique_fun_center_header_youtube_link'] = '#';
        set_theme_mod('theme_options', $unique_fun_center_options);

		$existing_form = get_page_by_title('Visitor Information form', OBJECT, 'wpcf7_contact_form');
		if ($existing_form) {
			return;
		}

		// Form title
		$contact_form_title = 'Visitor Information form';

		// Visitor Information form 7 form content (AS IT IS)
		$contact_form_content = <<<'EOT'
				<div class="form-row"> 
		<div class="form-group">
				<label>First Name</label> 
				[text* first-name] 
		</div> 
		<div class="form-group"> 
				<label>Last Name</label>
				[text* last-name]
		</div>
		</div>
		<div class="form-row">
		<div class="form-group">
				<label>Phone No</label>
				[tel* phone]
		</div>
		</div>
		<div class="form-row">
		<div class="form-group">
				<label for="kids">Kids:</label>
				<div class="inc-dec-sec">
					<button class="quantity-btn" type="button" onclick="unique_fun_center_decreaseValue('kids')">-</button>
					<input type="number" id="kids" class="quantity-input" name="kids" value="1" min="0">
					<button class="quantity-btn" type="button" onclick="unique_fun_center_increaseValue('kids')">+</button>
				</div>
		</div>
		<div class="form-group">
				<label for="adults">Adults:</label>
				<div class="inc-dec-sec">
					<button class="quantity-btn" type="button" onclick="unique_fun_center_decreaseValue('adults')">-</button>
					<input type="number" id="adults" class="quantity-input" name="adults" value="1" min="0">
					<button class="quantity-btn" type="button" onclick="unique_fun_center_increaseValue('adults')">+</button>
				</div> 
		</div> 
		</div> 
		<div class="form-row">
		<div class="form-group">
				<label>Visit Date</label>
				[date* visit-date]
			</div>
		</div>
		<div class="form-row"> 
		<div class="form-group">
				<label>Park Category</label>
				[checkbox* park-category "Water Park" "Amusement Park"]
		</div>
		</div>
		<div class="form-row">
		<div class="form-group">
				<label>Add-Ons</label>
				[checkbox add-ons "Food" "Rain Dance" "Train Ride"]
		</div>
		</div>
		<div class="form-row form-button">
		<div class="form-group">
				[submit "Submit"]
			</div>
		</div>
EOT;

		// Insert CF7 form
		$contact_post_id = wp_insert_post(array(
			'post_title'  => $contact_form_title,
			'post_type'   => 'wpcf7_contact_form',
			'post_status' => 'publish',
		));

		if ($contact_post_id && ! is_wp_error($contact_post_id)) {

			// Form fields
			update_post_meta($contact_post_id, '_form', $contact_form_content);

			// ADMIN MAIL (Appointment title ke according FIX)
			update_post_meta($contact_post_id, '_mail', array(
				'subject'   => 'New Visit Request',
				'sender'    => '[your-name] <[your-email]>',
				'recipient' => get_option('admin_email'),
				'body'      =>
					"New Visit Request:\n\n" .
					"Name: [your-name]\n" .
					"Phone: [phone]\n" .
					"Email: [your-email]\n" .
					"Concern: [your-concern]\n" .
					"Doctor: [doctor]\n",
				'use_html'  => false,
			));

			// USER AUTO-REPLY (Appointment title ke according FIX)
			update_post_meta($contact_post_id, '_mail_2', array(
				'active'    => true,
				'subject'   => 'Thank you for your Visit request',
				'sender'    => get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
				'recipient' => '[your-email]',
				'body'      =>
					"Hi [your-name],\n\n" .
					"Thank you for requesting an Visit with us.\n" .
					"Our team will contact you shortly.\n\n" .
					"Regards,\n" . get_bloginfo('name'),
				'use_html'  => false,
			));
		}

	// select Post Box
	$unique_fun_center_title_array = array("Project Name Goes Here 01", "Project Name Goes Here 02" , "Project Name Goes Here 03" , "Project Name Goes Here 04" );
	for ($unique_fun_center_i = 1; $unique_fun_center_i <= 3; $unique_fun_center_i++) {
		// Create post
		$unique_fun_center_title = $unique_fun_center_title_array[$unique_fun_center_i - 1];
		$unique_fun_center_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.';            
		$unique_fun_center_my_post = array(
				'post_title'   => wp_strip_all_tags($unique_fun_center_title),
				'post_content' => $unique_fun_center_content,
				'post_status'  => 'publish',
				'post_type'    => 'post',
		);
		$unique_fun_center_post_id = wp_insert_post($unique_fun_center_my_post);
		// Get image URL
		$unique_fun_center_image_url = get_template_directory_uri() . '/images/post/image' . $unique_fun_center_i . '.png';
		$unique_fun_center_image_data = wp_remote_get($unique_fun_center_image_url);
		if (!is_wp_error($unique_fun_center_image_data)) {
				$unique_fun_center_image_body = wp_remote_retrieve_body($unique_fun_center_image_data);
				$unique_fun_center_upload_dir = wp_upload_dir();
				$unique_fun_center_image_name = 'image' . $unique_fun_center_i . '.png';
				$uploaded_file = wp_upload_bits($unique_fun_center_image_name, null, $unique_fun_center_image_body);
				if (!$uploaded_file['error']) {
					// Set attachment data
					$attachment = array(
						'post_mime_type' => $uploaded_file['type'],
						'post_title'     => sanitize_file_name($unique_fun_center_image_name),
						'post_content'   => '',
						'post_status'    => 'inherit',
					);
					$unique_fun_center_attach_id = wp_insert_attachment($attachment, $uploaded_file['file'], $unique_fun_center_post_id);
					require_once(ABSPATH . 'wp-admin/includes/image.php');
					$unique_fun_center_attach_data = wp_generate_attachment_metadata($unique_fun_center_attach_id, $uploaded_file['file']);
					wp_update_attachment_metadata($unique_fun_center_attach_id, $unique_fun_center_attach_data);
					set_post_thumbnail($unique_fun_center_post_id, $unique_fun_center_attach_id);
				}
		}
	}

	/* Create Menu */
            $unique_fun_center_menuname  = 'Primary Menu';
            $unique_fun_center_location  = 'primary';

            $unique_fun_center_menu = wp_get_nav_menu_object( $unique_fun_center_menuname );

            if ( ! $unique_fun_center_menu ) {
            $unique_fun_center_menu_id = wp_create_nav_menu( $unique_fun_center_menuname );

           // Home Page 
			wp_update_nav_menu_item( $unique_fun_center_menu_id, 0, array(
				'menu-item-title'     => __( 'Home', 'unique-fun-center' ),
				'menu-item-url'       => home_url( '/' ),
				'menu-item-type'      => 'custom',
				'menu-item-status'    => 'publish',
			) );

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

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

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

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

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

                $unique_fun_center_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($unique_fun_center_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$unique_fun_center_blog_page_query->hae_posts()) {
                    $unique_fun_center_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $unique_fun_center_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $unique_fun_center_blog_page_id = wp_insert_post($unique_fun_center_blog_page);
                    update_option('page_for_posts', $unique_fun_center_blog_page_id);

                    wp_update_na_menu_item($unique_fun_center_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'unique-fun-center'),
                        'menu-item-url'        => get_permalink($unique_fun_center_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $unique_fun_center_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }

			/* Assign Menu Location */
			$unique_fun_center_locations = get_theme_mod( 'nav_menu_locations', array() );
			$unique_fun_center_locations[ $unique_fun_center_location ] = $unique_fun_center_menu_id;
			set_theme_mod( 'nav_menu_locations', $unique_fun_center_locations );
		}

}

}
 