<?php
/**
 * Block Editor Support and Patterns for Doctors Profile Theme
 *
 * @package Doctors Profile
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Register Custom Block Pattern Categories
 */
function doctors_profile_register_pattern_categories() {
	register_block_pattern_category(
		'doctors-profile-patterns',
		array(
			'label' => esc_html__('Doctors Profile', 'doctors-profile'),
		)
	);
}
add_action('init', 'doctors_profile_register_pattern_categories');

/**
 * Register Custom Block Patterns
 */
function doctors_profile_register_block_patterns() {
	// Medical Services Pattern
	register_block_pattern(
		'doctors-profile/medical-services',
		array(
			'title'       => esc_html__('Medical Services Section', 'doctors-profile'),
			'description' => esc_html__('A section showcasing medical services with icons and descriptions', 'doctors-profile'),
			'content'     => '<!-- wp:group {"style":{"spacing":{"padding":{"top":"60px","bottom":"60px"}}},"backgroundColor":"soft-gray","className":"medical-services-section"} -->
<div class="wp-block-group medical-services-section has-soft-gray-background-color has-background" style="padding-top:60px;padding-bottom:60px"><!-- wp:heading {"textAlign":"center","style":{"typography":{"fontSize":"36px","fontWeight":"700"}},"textColor":"dark-text"} -->
<h2 class="wp-block-heading has-text-align-center has-dark-text-color has-text-color" style="font-size:36px;font-weight:700">Our Medical Services</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"18px"}},"textColor":"dark-text"} -->
<p class="has-text-align-center has-dark-text-color has-text-color" style="font-size:18px">Comprehensive healthcare services delivered with compassion and expertise</p>
<!-- /wp:paragraph -->

<!-- wp:columns {"style":{"spacing":{"margin":{"top":"40px"}}}} -->
<div class="wp-block-columns" style="margin-top:40px"><!-- wp:column {"style":{"spacing":{"padding":{"all":"30px"}}}} -->
<div class="wp-block-column" style="padding:30px"><!-- wp:html -->
<div class="text-center">
<i class="fas fa-heart fa-3x" style="color: #28a745; margin-bottom: 20px;"></i>
</div>
<!-- /wp:html -->

<!-- wp:heading {"textAlign":"center","level":3,"style":{"typography":{"fontSize":"24px","fontWeight":"600"}},"textColor":"primary-blue"} -->
<h3 class="wp-block-heading has-text-align-center has-primary-blue-color has-text-color" style="font-size:24px;font-weight:600">Cardiology</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">Expert cardiac care with state-of-the-art diagnostic and treatment facilities</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"spacing":{"padding":{"all":"30px"}}}} -->
<div class="wp-block-column" style="padding:30px"><!-- wp:html -->
<div class="text-center">
<i class="fas fa-brain fa-3x" style="color: #28a745; margin-bottom: 20px;"></i>
</div>
<!-- /wp:html -->

<!-- wp:heading {"textAlign":"center","level":3,"style":{"typography":{"fontSize":"24px","fontWeight":"600"}},"textColor":"primary-blue"} -->
<h3 class="wp-block-heading has-text-align-center has-primary-blue-color has-text-color" style="font-size:24px;font-weight:600">Neurology</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">Advanced neurological care for brain and nervous system disorders</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"spacing":{"padding":{"all":"30px"}}}} -->
<div class="wp-block-column" style="padding:30px"><!-- wp:html -->
<div class="text-center">
<i class="fas fa-user-md fa-3x" style="color: #28a745; margin-bottom: 20px;"></i>
</div>
<!-- /wp:html -->

<!-- wp:heading {"textAlign":"center","level":3,"style":{"typography":{"fontSize":"24px","fontWeight":"600"}},"textColor":"primary-blue"} -->
<h3 class="wp-block-heading has-text-align-center has-primary-blue-color has-text-color" style="font-size:24px;font-weight:600">General Medicine</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center">Comprehensive primary care and preventive medicine services</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div>
<!-- /wp:group -->',
			'categories'  => array('doctors-profile-patterns'),
		)
	);

	// Doctor Profile Pattern
	register_block_pattern(
		'doctors-profile/doctor-profile',
		array(
			'title'       => esc_html__('Doctor Profile Card', 'doctors-profile'),
			'description' => esc_html__('A professional doctor profile card with image and details', 'doctors-profile'),
			'content'     => '<!-- wp:group {"style":{"spacing":{"padding":{"all":"30px"}},"border":{"radius":"10px"}},"backgroundColor":"white","className":"doctor-profile-card"} -->
<div class="wp-block-group doctor-profile-card has-white-background-color has-background" style="border-radius:10px;padding:30px"><!-- wp:columns {"verticalAlignment":"center"} -->
<div class="wp-block-columns are-vertically-aligned-center"><!-- wp:column {"verticalAlignment":"center","width":"200px"} -->
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:200px"><!-- wp:image {"id":123,"width":"150px","height":"150px","sizeSlug":"medium","linkDestination":"none","style":{"border":{"radius":"75px"}}} -->
<figure class="wp-block-image size-medium is-resized" style="border-radius:75px"><img src="' . get_template_directory_uri() . '/assets/img/doctor.png" alt="Doctor Profile" style="border-radius:75px;width:150px;height:150px"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->

<!-- wp:column {"verticalAlignment":"center"} -->
<div class="wp-block-column is-vertically-aligned-center"><!-- wp:heading {"level":3,"style":{"typography":{"fontSize":"28px","fontWeight":"700"}},"textColor":"primary-blue"} -->
<h3 class="wp-block-heading has-primary-blue-color has-text-color" style="font-size:28px;font-weight:700">Dr. Sarah Johnson</h3>
<!-- /wp:heading -->

<!-- wp:paragraph {"style":{"typography":{"fontSize":"18px","fontWeight":"500"}},"textColor":"medical-green"} -->
<p class="has-medical-green-color has-text-color" style="font-size:18px;font-weight:500">Cardiologist | MD, FACC</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>15+ years of experience in cardiovascular medicine. Specialized in interventional cardiology and heart disease prevention.</p>
<!-- /wp:paragraph -->

<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"backgroundColor":"primary-blue","style":{"border":{"radius":"25px"}}} -->
<div class="wp-block-button"><a class="wp-block-button__link has-primary-blue-background-color has-background wp-element-button" style="border-radius:25px">Book Appointment</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div>
<!-- /wp:group -->',
			'categories'  => array('doctors-profile-patterns'),
		)
	);

	// Testimonial Pattern
	register_block_pattern(
		'doctors-profile/patient-testimonial',
		array(
			'title'       => esc_html__('Patient Testimonial', 'doctors-profile'),
			'description' => esc_html__('A patient testimonial with quote and rating', 'doctors-profile'),
			'content'     => '<!-- wp:group {"style":{"spacing":{"padding":{"all":"40px"}},"border":{"radius":"15px"}},"backgroundColor":"trust-blue","textColor":"white","className":"testimonial-card"} -->
<div class="wp-block-group testimonial-card has-white-color has-trust-blue-background-color has-text-color has-background" style="border-radius:15px;padding:40px"><!-- wp:html -->
<div class="text-center" style="margin-bottom: 20px;">
<i class="fas fa-quote-left fa-2x" style="opacity: 0.7;"></i>
</div>
<!-- /wp:html -->

<!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"18px","lineHeight":"1.6"}}} -->
<p class="has-text-align-center" style="font-size:18px;line-height:1.6">Dr. Johnson provided exceptional care during my treatment. Her expertise and compassionate approach made all the difference in my recovery.</p>
<!-- /wp:paragraph -->

<!-- wp:html -->
<div class="text-center" style="margin: 20px 0;">
<span style="color: #ffd700;">★★★★★</span>
</div>
<!-- /wp:html -->

<!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"16px","fontWeight":"600"}}} -->
<p class="has-text-align-center" style="font-size:16px;font-weight:600">- Maria Rodriguez</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"14px"}}} -->
<p class="has-text-align-center" style="font-size:14px">Cardiac Surgery Patient</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->',
			'categories'  => array('doctors-profile-patterns'),
		)
	);

	// Appointment Booking Section
	register_block_pattern(
		'doctors-profile/appointment-booking',
		array(
			'title'       => esc_html__('Appointment Booking Section', 'doctors-profile'),
			'description' => esc_html__('A complete appointment booking section with form', 'doctors-profile'),
			'content'     => '<!-- wp:group {"style":{"spacing":{"padding":{"all":"60px"}}},"gradient":"medical-gradient","textColor":"white"} -->
<div class="wp-block-group has-white-color has-medical-gradient-background has-text-color has-background" style="padding:60px"><!-- wp:heading {"textAlign":"center","style":{"typography":{"fontSize":"42px","fontWeight":"700"}}} -->
<h2 class="wp-block-heading has-text-align-center" style="font-size:42px;font-weight:700">Book Your Appointment</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"20px"}}} -->
<p class="has-text-align-center" style="font-size:20px">Schedule your consultation with our experienced medical professionals</p>
<!-- /wp:paragraph -->

<!-- wp:columns {"style":{"spacing":{"margin":{"top":"40px"}}}} -->
<div class="wp-block-columns" style="margin-top:40px"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:group {"style":{"spacing":{"padding":{"all":"30px"}},"border":{"radius":"15px"}},"backgroundColor":"white","textColor":"dark-text"} -->
<div class="wp-block-group has-dark-text-color has-white-background-color has-text-color has-background" style="border-radius:15px;padding:30px"><!-- wp:heading {"level":3,"style":{"typography":{"fontSize":"24px"}},"textColor":"primary-blue"} -->
<h3 class="wp-block-heading has-primary-blue-color has-text-color" style="font-size:24px">Quick Contact</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Phone:</strong> (555) 123-4567</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Email:</strong> appointments@medical.com</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><strong>Hours:</strong> Mon-Fri 8AM-6PM</p>
<!-- /wp:paragraph -->

<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"backgroundColor":"medical-green","style":{"border":{"radius":"25px"}}} -->
<div class="wp-block-button"><a class="wp-block-button__link has-medical-green-background-color has-background wp-element-button" style="border-radius:25px">Call Now</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons --></div>
<!-- /wp:group --></div>
<!-- /wp:column -->

<!-- wp:column -->
<div class="wp-block-column"><!-- wp:group {"style":{"spacing":{"padding":{"all":"30px"}},"border":{"radius":"15px"}},"backgroundColor":"white","textColor":"dark-text"} -->
<div class="wp-block-group has-dark-text-color has-white-background-color has-text-color has-background" style="border-radius:15px;padding:30px"><!-- wp:heading {"level":3,"style":{"typography":{"fontSize":"24px"}},"textColor":"primary-blue"} -->
<h3 class="wp-block-heading has-primary-blue-color has-text-color" style="font-size:24px">Online Booking</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Use our convenient online booking system to schedule your appointment at your preferred time.</p>
<!-- /wp:paragraph -->

<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"style":{"border":{"radius":"25px"}},"className":"is-style-medical-cta"} -->
<div class="wp-block-button is-style-medical-cta"><a class="wp-block-button__link wp-element-button" style="border-radius:25px">Book Online</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons --></div>
<!-- /wp:group --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div>
<!-- /wp:group -->',
			'categories'  => array('doctors-profile-patterns'),
		)
	);

	// FAQ Section Pattern
	register_block_pattern(
		'doctors-profile/medical-faq',
		array(
			'title'       => esc_html__('Medical FAQ Section', 'doctors-profile'),
			'description' => esc_html__('Frequently asked questions about medical services', 'doctors-profile'),
			'content'     => '<!-- wp:group {"style":{"spacing":{"padding":{"all":"60px"}}},"backgroundColor":"soft-gray"} -->
<div class="wp-block-group has-soft-gray-background-color has-background" style="padding:60px"><!-- wp:heading {"textAlign":"center","className":"is-style-medical-heading"} -->
<h2 class="wp-block-heading has-text-align-center is-style-medical-heading">Frequently Asked Questions</h2>
<!-- /wp:heading -->

<!-- wp:paragraph {"align":"center","style":{"typography":{"fontSize":"18px"}}} -->
<p class="has-text-align-center" style="font-size:18px">Common questions about our medical services and procedures</p>
<!-- /wp:paragraph -->

<!-- wp:group {"style":{"spacing":{"margin":{"top":"40px"}}},"className":"faq-container"} -->
<div class="wp-block-group faq-container" style="margin-top:40px"><!-- wp:details {"style":{"spacing":{"margin":{"bottom":"20px"}},"border":{"radius":"10px"}},"backgroundColor":"white"} -->
<details class="wp-block-details has-white-background-color has-background" style="border-radius:10px;margin-bottom:20px"><summary><strong>What should I bring to my first appointment?</strong></summary><!-- wp:paragraph {"style":{"spacing":{"padding":{"all":"20px"}}}} -->
<p style="padding:20px">Please bring a valid ID, insurance cards, list of current medications, and any relevant medical records from previous doctors.</p>
<!-- /wp:paragraph --></details>
<!-- /wp:details -->

<!-- wp:details {"style":{"spacing":{"margin":{"bottom":"20px"}},"border":{"radius":"10px"}},"backgroundColor":"white"} -->
<details class="wp-block-details has-white-background-color has-background" style="border-radius:10px;margin-bottom:20px"><summary><strong>Do you accept insurance?</strong></summary><!-- wp:paragraph {"style":{"spacing":{"padding":{"all":"20px"}}}} -->
<p style="padding:20px">Yes, we accept most major insurance plans. Please contact our office to verify your specific coverage.</p>
<!-- /wp:paragraph --></details>
<!-- /wp:details -->

<!-- wp:details {"style":{"spacing":{"margin":{"bottom":"20px"}},"border":{"radius":"10px"}},"backgroundColor":"white"} -->
<details class="wp-block-details has-white-background-color has-background" style="border-radius:10px;margin-bottom:20px"><summary><strong>How far in advance should I book an appointment?</strong></summary><!-- wp:paragraph {"style":{"spacing":{"padding":{"all":"20px"}}}} -->
<p style="padding:20px">For routine check-ups, we recommend booking 2-4 weeks in advance. For urgent matters, we offer same-day appointments when available.</p>
<!-- /wp:paragraph --></details>
<!-- /wp:details --></div>
<!-- /wp:group --></div>
<!-- /wp:group -->',
			'categories'  => array('doctors-profile-patterns'),
		)
	);
}
add_action('init', 'doctors_profile_register_block_patterns');

/**
 * Add Custom Block Styles
 */
function doctors_profile_register_block_styles() {
	// Add custom styles for core blocks
	register_block_style(
		'core/button',
		array(
			'name'  => 'medical-cta',
			'label' => esc_html__('Medical CTA', 'doctors-profile'),
		)
	);

	register_block_style(
		'core/group',
		array(
			'name'  => 'medical-card',
			'label' => esc_html__('Medical Card', 'doctors-profile'),
		)
	);

	register_block_style(
		'core/heading',
		array(
			'name'  => 'medical-heading',
			'label' => esc_html__('Medical Heading', 'doctors-profile'),
		)
	);

	register_block_style(
		'core/quote',
		array(
			'name'  => 'testimonial-style',
			'label' => esc_html__('Patient Testimonial', 'doctors-profile'),
		)
	);
}
add_action('init', 'doctors_profile_register_block_styles');

/**
 * Note: Custom Post Types for Medical Services, Doctor Profiles, and Testimonials
 * should be implemented in a separate plugin, not in the theme.
 * 
 * This follows WordPress theme review guidelines which require that 
 * register_post_type() be used in plugins rather than themes.
 * 
 * Create a companion plugin for this theme to handle:
 * - Medical Services CPT
 * - Doctor Profiles CPT  
 * - Testimonials CPT
 */

/**
 * Enqueue Block Editor Assets
 */
function doctors_profile_block_editor_assets() {
	// Add custom CSS for block editor
	wp_enqueue_style(
		'doctors-profile-block-editor-styles',
		get_template_directory_uri() . '/assets/css/editor-style.css',
		array(),
		DOCTORS_PROFILE_VERSION
	);
}
add_action('enqueue_block_editor_assets', 'doctors_profile_block_editor_assets');

/**
 * Add Block Editor Settings and Features
 */
function doctors_profile_block_editor_settings($editor_settings, $context) {
	// Add custom spacing sizes
	$editor_settings['spacingSizes'] = array(
		array(
			'name' => esc_html__('Small', 'doctors-profile'),
			'size' => '20px',
			'slug' => 'small'
		),
		array(
			'name' => esc_html__('Medium', 'doctors-profile'),
			'size' => '40px',
			'slug' => 'medium'
		),
		array(
			'name' => esc_html__('Large', 'doctors-profile'),
			'size' => '60px',
			'slug' => 'large'
		),
		array(
			'name' => esc_html__('Extra Large', 'doctors-profile'),
			'size' => '80px',
			'slug' => 'extra-large'
		),
	);

	return $editor_settings;
}
add_filter('block_editor_settings_all', 'doctors_profile_block_editor_settings', 10, 2);

/**
 * Enqueue Frontend Block Styles
 */
function doctors_profile_enqueue_block_styles() {
	// Load block styles on frontend
	wp_enqueue_style(
		'doctors-profile-block-styles',
		get_template_directory_uri() . '/assets/css/block-styles.css',
		array(),
		DOCTORS_PROFILE_VERSION
	);
}
add_action('wp_enqueue_scripts', 'doctors_profile_enqueue_block_styles');
add_action('enqueue_block_assets', 'doctors_profile_enqueue_block_styles');
