<?php

class Whizzie {

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

	public function init() {
	}

	public static function medical_clinic_center_setup_widgets(){

		$medical_clinic_center_options = get_theme_mod('theme_options', []);
        $medical_clinic_center_options['medical_clinic_center_header_top_phone_text'] = 'Contact Info';
        $medical_clinic_center_options['medical_clinic_center_header_top_phone_number'] = '+1234567890';
		$medical_clinic_center_options['medical_clinic_center_header_top_hiring_head'] = 'We are always ready to help you.';
		$medical_clinic_center_options['medical_clinic_center_header_top_emergency_call'] = '+1234567890';
        $medical_clinic_center_options['medical_clinic_center_header_top_location_text'] = 'Address';
		$medical_clinic_center_options['medical_clinic_center_header_top_location'] = '34th Avenue, New York.';
		$medical_clinic_center_options['medical_clinic_center_header_top_timing_text'] = 'Operating Time';
        $medical_clinic_center_options['medical_clinic_center_header_top_timing'] = 'Mon-Fri: 8:00-20:00';
        $medical_clinic_center_options['medical_clinic_center_header_top_booknow_btn_text'] = 'Book An Appointment';
		$medical_clinic_center_options['medical_clinic_center_header_top_booknow_btn_link'] = '#';
		$medical_clinic_center_options['medical_clinic_center_social_media_facebook'] = '#';
		$medical_clinic_center_options['medical_clinic_center_social_media_twitter'] = '#';
		$medical_clinic_center_options['medical_clinic_center_social_media_instagram'] = '#';
        $medical_clinic_center_options['medical_clinic_center_social_media_linkdin'] = '#';
		$medical_clinic_center_options['medical_clinic_center_social_media_youtube'] = '#';
        set_theme_mod('theme_options', $medical_clinic_center_options);

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

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

		// Appointment Form 7 form content (AS IT IS)
		$contact_form_content = <<<'EOT'
		<div class="contact-box">
			[text* your-name placeholder "Enter Your Name*"]
			
			[number* phone placeholder "Enter Your Phone Number*"]
			
			[email* your-email placeholder "Enter Your Email*"]
		</div>

		<div class="contact-box">
			[text* your-concern placeholder "Enter Your Concern"]
			
			[select* doctor "Select Doctor" "Dr. Jane Doe" "Dr. Billy Maupin" "Dr. Debra Ridenour" "Dr. Kenneth Rodrigues"]
		</div>

		[submit "SUBMIT DETAILS"]
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 Appointment Request',
				'sender'    => '[your-name] <[your-email]>',
				'recipient' => get_option('admin_email'),
				'body'      =>
					"New Appointment 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 appointment request',
				'sender'    => get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
				'recipient' => '[your-email]',
				'body'      =>
					"Hi [your-name],\n\n" .
					"Thank you for requesting an appointment with us.\n" .
					"Our team will contact you shortly.\n\n" .
					"Regards,\n" . get_bloginfo('name'),
				'use_html'  => false,
			));
		}

		/* Create Menu */
            $medical_clinic_center_menuname  = 'Primary Menu';
            $medical_clinic_center_location  = 'primary-menu';

            $medical_clinic_center_menu = wp_get_nav_menu_object( $medical_clinic_center_menuname );

            if ( ! $medical_clinic_center_menu ) {
            $medical_clinic_center_menu_id = wp_create_nav_menu( $medical_clinic_center_menuname );

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

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

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

			// Case Studies Page 
			$medical_clinic_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'  => 'Case Studies',
			'post_status' => 'publish',
			) );

			if ( $medical_clinic_center_about_id ) {
			wp_update_nav_menu_item( $medical_clinic_center_menu_id, 0, array(
			'menu-item-title'     => 'Case Studies',
			'menu-item-object'    => 'page',
			'menu-item-object-id' => $medical_clinic_center_about_id,
			'menu-item-type'      => 'post_type',
			'menu-item-status'    => 'publish',
			) );
			}

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

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

                $medical_clinic_center_blog_page_query = new WP_Query(array(
                    'post_type'      => 'page',
                    'name'           => sanitize_title($medical_clinic_center_blog_page_title),
                    'post_status'    => 'publish',
                    'posts_per_page' => 1
                ));
                if (!$medical_clinic_center_blog_page_query->hae_posts()) {
                    $medical_clinic_center_blog_page = array(
                        'post_type'   => 'page',
                        'post_title'  => $medical_clinic_center_blog_page_title,
                        'post_status' => 'publish',
                        'post_author' => 1,
                    );
                    $medical_clinic_center_blog_page_id = wp_insert_post($medical_clinic_center_blog_page);
                    update_option('page_for_posts', $medical_clinic_center_blog_page_id);

                    wp_update_nav_menu_item($medical_clinic_center_menu_id, 0, array(
                        'menu-item-title'      => __('Blog', 'medical-clinic-center'),
                        'menu-item-url'        => get_permalink($medical_clinic_center_blog_page_id),
                        'menu-item-status'     => 'publish',
                        'menu-item-object-id'  => $medical_clinic_center_blog_page_id,
                        'menu-item-object'     => 'page',
                        'menu-item-type'       => 'post_type',
                    ));
                }
          
			/* Assign Menu Location */
			$medical_clinic_center_locations = get_theme_mod( 'nav_menu_locations', array() );
			$medical_clinic_center_locations[ $medical_clinic_center_location ] = $medical_clinic_center_menu_id;
			set_theme_mod( 'nav_menu_locations', $medical_clinic_center_locations );
		}
	}
}
