<?php

 /**
 * =============================================================================
 * @package         Blue Raven (Free Version)
 * @Plugin URI      https://enterrahost.com/plugins/blue-raven
 * 
 * @Author          EnterraHost
 * @Author URI      https://enterrahost.com
 * @License         GPL-2.0-or-later
 *  
 * @Copyright       (c) 2025 EnterraHost
 * @Contents        Plugin Tools > Main Schema
 *
 * =============================================================================
 * 
 * || INDEX:
 * ||   - BLUE RAVEN ADMIN TOOL MAIN SCHEMA
 * || 
 * =============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) exit; 

/*
============================================================
    BLUE RAVEN ADMIN TOOL MAIN SCHEMA
============================================================
*/
 
/**
 * Class Blue_Raven_Admin_Tools_Main_Schema
 *
 * This class is responsible for rendering the main schema settings page within the
 * Blue Raven Admin Tools section. It handles loading existing schema data,
 * managing the form for schema input (e.g., JSON-LD), and enqueuing
 * any necessary JavaScript for its functionality.
 */ 
class Blue_Raven_Admin_Tools_Main_Schema {

    /**
     * Renders the main schema settings page.
     */
    public function render() {
        self::load_tools_main_schema_template();
    }
    
    /**
     * Loads the template for the main schema settings.
     *
     * This private static method fetches existing schema data from the database,
     * determines the appropriate button text ('Update' or 'Save'), and
     * prepares the data for display in the HTML form.
     *
     * @access private
     */
    private static function load_tools_main_schema_template() {
        
        $buttonName = 'Update ';
        
        global $wpdb; 
        
        $schema = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}BlueRavenValues WHERE setting LIKE %s",'%schema-json%'), ARRAY_A  );
        $schema_setting = [];
        
        if (!empty($schema) && isset($schema[0]['value'])) {  $schema_setting = json_decode($schema[0]['value'], true); } else { $buttonName = 'Save ';}
        $name = $schema_setting['name']; 
        
        $schemaEnable = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}BlueRavenValues WHERE setting LIKE %s",'%schema-enable%'));
        
    ## =========== Dropdown Data =========== ##
    
        $topLevel = [
            'Organization' =>['value' => 'Organization',],
            'Airline' => ['value' => 'Airline',],
            'Consortium' => ['value' => 'Consortium',],
            'Cooperative' => ['value' => 'Cooperative',],
            'Corporation' => ['value' => 'Corporation',],
            'Educational Organization' => ['value' => 'EducationalOrganization','children' => [
                
                'College Or University' => [ 'value' => 'CollegeOrUniversity',],
                'Elementary School' => ['value' => 'ElementarySchool',],
                'High School' => ['value' => 'HighSchool',],
                'Middle School' => ['value' => 'MiddleSchool', ],    
                'School' => ['value' => 'School',],
                'Preschool' => ['value' => 'PreSchool',]
                ],
            ],    
            'Funding Scheme' => ['value' => 'FundingScheme',],
            'Government Organization' => ['value' => 'GovernmentOrganization',],
            'Library System' => ['value' => 'LibrarySystem',],  
            'Local Business' => ['value' => 'LocalBusiness','children' => 
                [
                    'Animal Shelter' => [ 'value' => 'AnimalShelter',],
                    'Archive Organization' => ['value' => 'ArchiveOrganization',],
                    'Automotive Business' => ['value' => 'AutomotiveBusiness','children' => 
                        [
                            'AutoBody Shop' => ['value' => 'AutoBodyShop', ],
                            'Auto Dealer' => ['value' => 'AutoDealer',],
                            'AutoParts Store' => ['value' => 'AutoPartsStore',],    
                            'AutoRental' => ['value' => 'AutoRental',],
                            'AutoRepair' => ['value' => 'AutoRepair',],    
                            'AutoWash' => ['value' => 'AutoWash',],    
                            'Gas Station' => ['value' => 'GasStation',],
                            'MotorcycleDealer' => ['value' => 'MotorcycleDealer',],    
                            'MotorcycleRepair' => ['value' => 'MotorcycleRepair',],
                        ],
                    ],
                    'Child Care' => ['value' => 'ChildCare',],    
                    'Dentist' => ['value' => 'Dentist',],
                    'Dry Cleaning Or Laundry' => ['value' => 'DryCleaningOrLaundry',],
                    'Emergency Service' => ['value' => 'EmergencyService','children' => 
                        [          
                            'Fire Station' => ['value' => 'FireStation',],
                            'Hospital' => ['value' => 'Hospital',],
                            'Police Station' => ['value' => 'PoliceStation',], 
                        ],
                    ],
                    'Employment Agency' => ['value' => 'EmploymentAgency',],
                    'Entertainment Business' => ['value' => 'EntertainmentBusiness','children' => 
                        [          
                            'Adult Entertainment' => ['value' => 'AdultEntertainment',],
                            'Amusement Park' => ['value' => 'AmusementPark',],
                            'Art Gallery' => ['value' => 'ArtGallery',], 
                            'Casino' => ['value' => 'Casino',],
                            'Comedy Club' => ['value' => 'ComedyClub',],
                            'Movie Theater' => ['value' => 'MovieTheater',], 
                            'Night Club' => ['value' => 'NightClub',], 
                        ],
                    ],
                    'Financial Service' => ['value' => 'FinancialService ','children' => 
                        [          
                            'Accounting Service' => ['value' => 'AccountingService',],
                            'Automated Teller' => ['value' => 'AutomatedTeller',],
                            'Bank Or Credit Union' => ['value' => 'BankOrCreditUnion',], 
                            'Insurance Agency' => ['value' => 'InsuranceAgency',],
                        ],
                    ],
                    'Food Establishment' => ['value' => 'FoodEstablishment ','children' => 
                        [          
                            'Bakery' => ['value' => 'Bakery',],
                            'Bar Or Pub' => ['value' => 'BarOrPub',],
                            'Brewery' => ['value' => 'Brewery',], 
                            'Cafe Or Coffee Shop' => ['value' => 'CafeOrCoffeeShop',],
                            'Distillery' => ['value' => 'Distillery',],
                            'Fast Food Restaurant' => ['value' => 'FastFoodRestaurant',],
                            'Ice Cream Shop' => ['value' => 'IceCreamShop',], 
                            'Restaurant' => ['value' => 'Restaurant',],
                            'Winery' => ['value' => 'Winery',],
                        ],
                    ],
                    'Government Office' => ['value' => 'GovernmentOffice ','children' => 
                        [          
                            'PostOffice' => ['value' => 'PostOffice',],
                        ],
                    ],
                    'Health And Beauty Business' => ['value' => 'HealthAndBeautyBusiness ','children' => 
                        [          
                            'Beauty Salon' => ['value' => 'BeautySalon',],
                            'Day Spa' => ['value' => 'DaySpa',],
                            'Hair Salon' => ['value' => 'HairSalon',],
                            'Health Club' => ['value' => 'HealthClub',],
                            'Nail Salon' => ['value' => 'NailSalon',],
                            'Tattoo Parlor' => ['value' => 'TattooParlor',],
                        ],
                    ],
                    'Home And Construction Business' => ['value' => 'HomeAndConstructionBusiness ','children' => 
                        [          
                            'Electrician' => ['value' => 'Electrician',],
                            'General Contractor' => ['value' => 'GeneralContractor',],
                            'HVAC Business' => ['value' => 'HVACBusiness',],
                            'House Painter' => ['value' => 'HousePainter',],
                            'Locksmith' => ['value' => 'Locksmith',],
                            'Moving Company' => ['value' => 'MovingCompany',],
                            'Plumber' => ['value' => 'Plumber',],
                            'Roofing Contractor' => ['value' => 'RoofingContractor',],
                        ],
                    ],
                    'Internet Cafe' => ['value' => 'InternetCafe',],
                    'LegalService' => ['value' => 'LegalService','children' => 
                        [          
                            'Attorney' => ['value' => 'Attorney',],
                            'Notary' => ['value' => 'Notary',],
                        ],
                    ],
                    'Library' => ['value' => 'Library',],
                    'Lodging Business' => ['value' => 'LodgingBusiness','children' => 
                        [          
                            'Bed And Breakfast' => ['value' => 'BedAndBreakfast',],
                            'Campground' => ['value' => 'Campground',],
                            'Hostel' => ['value' => 'Hostel',],
                            'Hotel' => ['value' => 'Hotel',],
                            'Motel' => ['value' => 'Motel',],
                            'Ski Resort' => ['value' => 'SkiResort',],
                            'Vacation Rental' => ['value' => 'VacationRental',],
                        ],
                    ],
                    'Medical Business' => ['value' => 'MedicalBusiness','children' => 
                        [          
                            'Community Health' => ['value' => 'CommunityHealth'],
                            'Dentist' => ['value' => 'Dentist'],
                            'Dermatology' => ['value' => 'Dermatology'],
                            'Diet Nutrition' => ['value' => 'DietNutrition'],
                            'Emergency' => ['value' => 'Emergency'],
                            'Geriatric' => ['value' => 'Geriatric'],
                            'Gynecologic' => ['value' => 'Gynecologic'],
                            'Medical Clinic' => ['value' => 'MedicalClinic'],
                            'Midwifery' => ['value' => 'Midwifery'],
                            'Nursing' => ['value' => 'Nursing'],
                            'Obstetric' => ['value' => 'Obstetric'],
                            'Oncologic' => ['value' => 'Oncologic'],
                            'Optician' => ['value' => 'Optician'],
                            'Optometric' => ['value' => 'Optometric'],
                            'Otolaryngologic' => ['value' => 'Otolaryngologic'],
                            'Pediatric' => ['value' => 'Pediatric'],
                            'Pharmacy' => ['value' => 'Pharmacy'],
                            'Individual Physician' => ['value' => 'IndividualPhysician'],
                            'Physicians Office' => ['value' => 'PhysiciansOffice'],
                            'Physiotherapy' => ['value' => 'Physiotherapy'],
                            'Plastic Surgery' => ['value' => 'PlasticSurgery'],
                            'Podiatric' => ['value' => 'Podiatric'],
                            'Primary Care' => ['value' => 'PrimaryCare'],
                            'Psychiatric' => ['value' => 'Psychiatric'],
                            'Public Health' => ['value' => 'PublicHealth'],
                        ],
                    ],
                    'Professional Service' => ['value' => 'ProfessionalService',],
                    'Radio Station' => ['value' => 'RadioStation',],
                    'RealEstate Agent' => ['value' => 'RealEstateAgent',],
                    'Recycling Center' => ['value' => 'RecyclingCenter',],
                    'Self Storage' => ['value' => 'SelfStorage',],
                    'Shopping Center' => ['value' => 'ShoppingCenter',],
                    'Sports Activity Location' => ['value' => 'SportsActivityLocation','children' => 
                        [          
                            'Bowling Alley' => ['value' => 'BowlingAlley'],
                            'Exercise Gym' => ['value' => 'ExerciseGym'],
                            'Golf Course' => ['value' => 'GolfCourse'],
                            'Health Club' => ['value' => 'HealthClub'],
                            'Public Swimming Pool' => ['value' => 'PublicSwimmingPool'],
                            'Sports Club' => ['value' => 'SportsClub'],
                            'Stadium Or Arena' => ['value' => 'StadiumOrArena'],
                            'Tennis Complex' => ['value' => 'TennisComplex'],
                        ],
                    ],
                    'Store' => ['value' => 'Store','children' => 
                        [          
                            'AutoParts Store' => ['value' => 'AutoPartsStore'],
                            'Bike Store' => ['value' => 'BikeStore'],
                            'Book Store' => ['value' => 'BookStore'],
                            'Clothing Store' => ['value' => 'ClothingStore'],
                            'Computer Store' => ['value' => 'ComputerStore'],
                            'Convenience Store' => ['value' => 'ConvenienceStore'],
                            'Department Store' => ['value' => 'DepartmentStore'],
                            'Electronics Store' => ['value' => 'ElectronicsStore'],
                            'Florist' => ['value' => 'Florist'],
                            'Furniture Store' => ['value' => 'FurnitureStore'],
                            'Garden Store' => ['value' => 'GardenStore'],
                            'Grocery Store' => ['value' => 'GroceryStore'],
                            'Hardware Store' => ['value' => 'HardwareStore'],
                            'Hobby Shop' => ['value' => 'HobbyShop'],
                            'Home Goods Store' => ['value' => 'HomeGoodsStore'],
                            'Jewelry Store' => ['value' => 'JewelryStore'],
                            'Liquor Store' => ['value' => 'LiquorStore'],
                            'Mens Clothing Store' => ['value' => 'MensClothingStore'],
                            'Mobile Phone Store' => ['value' => 'MobilePhoneStore'],
                            'Movie Rental Store' => ['value' => 'MovieRentalStore'],
                            'Music Store' => ['value' => 'MusicStore'],
                            'Office Equipment Store' => ['value' => 'OfficeEquipmentStore'],
                            'Outlet Store' => ['value' => 'OutletStore'],
                            'Pawn Shop' => ['value' => 'PawnShop'],
                            'Pet Store' => ['value' => 'PetStore'],
                            'Shoe Store' => ['value' => 'ShoeStore'],
                            'Sporting Goods Store' => ['value' => 'SportingGoodsStore'],
                            'Tire Shop' => ['value' => 'TireShop'],
                            'Toy Store' => ['value' => 'ToyStore'],
                            'Wholesale Store' => ['value' => 'WholesaleStore'],
                        ],
                    ],
                    'Television Station' => ['value' => 'TelevisionStation',],
                    'Tourist Information Center' => ['value' => 'TouristInformationCenter',],
                    'Travel Agency' => ['value' => 'TravelAgency',],
                ],  
            ],
            'Medical Organization' => ['value' => 'MedicalOrganization','children' =>[
                    'Dentist' => ['value' => 'Dentist'],
                    'Diagnostic Lab' => ['value' => 'DiagnosticLab'],
                    'Hospital' => ['value' => 'Hospital'],
                    'Medical Clinic' => ['value' => 'MedicalClinic'],
                    'Pharmacy' => ['value' => 'Pharmacy'],
                    'Physician' => ['value' => 'Physician'],
                    'Veterinary Care' => ['value' => 'VeterinaryCare'],
                ],  
            ],
            'NGO' => ['value' => 'NGO',],
            'NewsMedia Organization' => ['value' => 'NewsMediaOrganization',],
            'Online Store' => ['value' => 'OnlineStore',],
            'Performing Group' => ['value' => 'PerformingGroup','children' =>[
                    'Dance Group' => ['value' => 'DanceGroup'],
                    'Music Group' => ['value' => 'MusicGroup'],
                    'Theater Group' => ['value' => 'TheaterGroup'],
                ],  
            ],
            'Political Party' => ['value' => 'PoliticalParty',],
            'Project' => ['value' => 'Project','children' =>[
                    'Funding Agency' => ['value' => 'FundingAgency'],
                    'Research Project' => ['value' => 'ResearchProject'],
                ],  
            ],
            'Research Organization' => ['value' => 'ResearchOrganization',],
            'Search Rescue Organization' => ['value' => 'SearchRescueOrganization',],
            'Sports Team' => ['value' => 'SportsTeam',],
            'Workers Union' => ['value' => 'WorkersUnion',],
            
        ];

        ?>
            <div class='flex-sb'>
                <h3><?php esc_html_e('Main Schema', 'blue-raven'); ?></h3>
                <h4>
                    <?php esc_html_e('Need Help', 'blue-raven'); ?>
                    <a href="<?php echo esc_url('https://portal.enterrahost.com/knowledgebase/7/'); ?>" target="_blank" rel="noopener noreferrer" style="margin-left: 8px;" title="<?php esc_attr_e('Learn more', 'blue-raven'); ?>"><i class="fas fa-question-circle"></i></a>
                </h4>
            </div>
            
            <p class='enterra-highlight indent-one'><?php esc_html_e('Schema markup is structured data added to your website that helps search engines better understand your content, improving how your pages appear in search results with rich snippets and enhanced listings.', 'blue-raven'); ?> </p>
            
            <section>
                <div style="margin: 20px 0;" class='border-bottom-white flex-right'>
                    <h4 class='no-margin-padding spacing-right text-center'>
                        <?php esc_html_e('Switch On Site Schema', 'blue-raven'); ?>
                    </h4>
                    <label class="switch">
                        <input type="checkbox" id="enable-site-schema"
                            <?php if (!empty($schemaEnable) && isset($schemaEnable[0]->enabled) && $schemaEnable[0]->enabled) echo 'checked'; ?>>
                        <span class="slider"></span>
                    </label>
                </div>
            </section>
            
            <section style='padding-bottom: 4rem;'>
                <form id='schema-form' style='width: 100%;'>
                    <h4><?php esc_html_e('About your site', 'blue-raven'); ?></h4>
                    <div class='flex-sb spacing-bottom-large spacing-left-small'>
                        <div style="width: 48%">
                            <label>
                                <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Business Name', 'blue-raven'); ?></strong></p>
                                <input type="text" name="name" placeholder="<?php esc_attr_e('Business Limited', 'blue-raven'); ?>" class="br-input" style="width:100%;" id="schema-name" value="<?php echo isset($schema_setting['name']) ? esc_attr($schema_setting['name']) : ''; ?>">
                            </label>
                        </div>
                    </div>
                    
                    <h4><?php esc_html_e('About your Business', 'blue-raven'); ?></h4>
                    
                    <div class='flex-sb spacing-bottom spacing-left-small'>
                        <div style="width: 48%">
                            <label>
                                <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Business Founding Date', 'blue-raven'); ?></strong></p>
                                <input type="text" name="founding-date" placeholder="<?php esc_attr_e('2025', 'blue-raven'); ?>" class="br-input" style="width:100%;" id="schema-founding-date" value="<?php echo isset($schema_setting['foundingDate']) ? esc_attr($schema_setting['foundingDate']) : ''; ?>">
                            </label>
                        </div>
                    </div>
                    
                    <div class='flex-sb spacing-bottom spacing-left-small'>
                        <div style="width: 100%">
                            <label>
                                <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Business Slogan', 'blue-raven'); ?></strong></p>
                                <textarea class="br-text-area-light" name="business-slogan" id="slogan-text-area" style="width: 100%; min-height: 5rem; max-height: 10rem;" maxlength="130"><?php echo isset($schema_setting['businessSlogan']) ? esc_textarea($schema_setting['businessSlogan']) : ''; ?></textarea>
                            </label>
                        </div>
                    </div>
                    
                    <div class='flex-sb spacing-bottom-large spacing-left-small'>
                        <div style="width: 100%">
                            <label>
                                <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Business Description', 'blue-raven'); ?></strong></p>
                                <textarea class="br-text-area-light" name="business-description" id="slogan-description-area" style="width: 100%; min-height: 15rem; max-height: 25rem;" maxlength="500"><?php echo isset($schema_setting['businessDescription']) ? esc_textarea($schema_setting['businessDescription']) : ''; ?></textarea>
                            </label>
                        </div>
                    </div>
                    
                    <h4><?php esc_html_e('Business Type', 'blue-raven'); ?></h4>
                    
                    <div class='flex-sb spacing-bottom spacing-left-small'>
                        <?php
                            $selected1 = isset($schema_setting['businessType1']) ? sanitize_text_field($schema_setting['businessType1']) : '';
                            $selected2 = isset($schema_setting['businessType2']) ? sanitize_text_field($schema_setting['businessType2']) : '';
                            $selected3 = isset($schema_setting['businessType3']) ? sanitize_text_field($schema_setting['businessType3']) : '';
                        ?>
                        
                        <!-- Top Level Dropdown -->
                        <div style="width: 32%">
                            <label>
                                <select id="top-level-organization-dropdown" name="business-type-1" class="br-dropdown" style="width: 100%; padding: 0.5rem; margin-bottom: 2rem; " data-selected="<?php echo esc_attr($selected1); ?>">
                                <?php foreach ($topLevel as $topLevelLabel => $topLevelItem): ?>
                                    <?php
                                        $hasChildren = isset($topLevelItem['children']);
                                        $value = $topLevelItem['value'];
                                        $label = $topLevelLabel;
                                        $selectedAttr = ($value === $selected1) ? ' selected' : '';
                                        $classAttr = $hasChildren ? ' class="subset"' : '';
                                        $dataAttr = $hasChildren ? ' data-children=\'' . esc_attr(wp_json_encode($topLevelItem['children'])) . '\'' : '';
                                    ?>
                                    <option 
										value="<?php echo esc_attr($value); ?>"
										<?php echo ($classAttr) . ' ' . ($dataAttr) . ' ' . ($selectedAttr); // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped?>>
										<?php echo esc_html($label); ?>
									</option>
                                <?php endforeach; ?>
                                </select>
                            </label>
                        </div>
                    
                        <!-- Middle Level -->
                        <div style="width: 32%">
                            <label>
                                <select id="middle-level-organization-dropdown" name="business-type-2" class="br-dropdown hidden" style="width: 100%; padding: 0.5rem; margin-bottom: 2rem;" data-selected="<?php echo esc_attr($selected2); ?>"></select>
                            </label>
                        </div>
                    
                        <!-- Bottom Level -->
                        <div style="width: 32%">
                            <label>
                                <select id="bottom-level-organization-dropdown" name="business-type-3" class="br-dropdown hidden" style="width: 100%; padding: 0.5rem; margin-bottom: 2rem;" data-selected="<?php echo esc_attr($selected3); ?>"></select>
                            </label>
                        </div>
                    </div>
                    
                    <h4><?php esc_html_e('Social', 'blue-raven'); ?></h4>

                    <div class="flex-left spacing-bottom-large spacing-left-small">
                        <div style="width: 48%">
                            <div id="link-fields">
                                <p style="margin-bottom: 16px;"><strong><?php esc_html_e('Social Media links', 'blue-raven'); ?></strong></p>
                                <?php
                                $socials = isset($schema_setting['socials']) && is_array($schema_setting['socials']) ? $schema_setting['socials'] : [];
                    
                                if (!empty($socials)) :
                                    foreach ($socials as $index => $link) :
                                        if (!empty($link)) :
                                            ?>
                                            <label style="display: block; margin-top: 0.5rem;">
                                                <input type="text" name="socials[]" data-link-id="<?php echo esc_attr($index + 1); ?>" placeholder="https://..." class="br-input" style="width: 100%;" value="<?php echo esc_attr($link); ?>">
                                            </label>
                                            <?php
                                        endif;
                                    endforeach;
                                else :
                                    ?>
                                    <label style="display: block; margin-top: 0.5rem;">
                                        <input type="text" name="socials[]" data-link-id="1" placeholder="https://..." class="br-input" style="width: 100%;" >
                                    </label>
                                <?php endif; ?>
                            </div>
                        </div>
                    
                        <div style="width: 48%; position: relative;">
                            <div style="text-align: left; position: absolute; bottom: 4px; margin-left: 1.5rem;">
                                <a class="enterra-button" data-tool="add-new-link" id="add-new-link">+</a>
                            </div>
                        </div>
                    </div>
                    
                    <h4><?php esc_html_e('Contact Points', 'blue-raven'); ?></h4>

                    <div class='spacing-bottom-large'>
                        <div class='spacing-left-small'>
                            
                            <div style='text-align: right;'>
                                <?php esc_html_e('Add a new Contact Point.', 'blue-raven'); ?>
                                <a class='enterra-button' data-tool='add-new-contact' id='add-new-contact' style='margin-left: 2rem;'>+</a>
                            </div>
                            
                            <div id='contact-points'>
                                <?php
                                    $contacts = isset($schema_setting['contact']) && is_array($schema_setting['contact']) ? $schema_setting['contact'] : [];
                                    $count = isset($contacts['type']) ? count($contacts['type']) : 0;
                                ?>
                    
                                <?php if ($count > 0): ?>
                                    <?php for ($i = 0; $i < $count; $i++): ?>
                                        <div class='contact-block' style='margin: 16px auto;' data-contact-id='<?php echo esc_attr($i + 1); ?>'>
                                            <div class='flex-sb' style='margin-bottom: 8px;'>
                                                <div style="width: 48%">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Contact Type', 'blue-raven'); ?></strong></p>
                                                        <input type="text" name="contact-type[]" placeholder="<?php esc_attr_e('Sales or Support etc...', 'blue-raven'); ?>" class="br-input" style="width:100%;" value="<?php echo esc_attr($contacts['type'][$i] ?? ''); ?>">
                                                    </label>
                                                </div>
                                            </div>
                                            <div class='flex-sb' style='margin-bottom: 8px;'>
                                                <div style="width: 48%;">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Contact Email', 'blue-raven'); ?></strong></p>
                                                        <input type="text" name="contact-email[]" placeholder="<?php esc_attr_e('sales@', 'blue-raven'); ?>" class="br-input" style="width:100%;" value="<?php echo esc_attr($contacts['email'][$i] ?? ''); ?>">
                                                    </label>
                                                </div>
                                                <div style="width: 48%">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Contact Number', 'blue-raven'); ?></strong></p>
                                                        <input type="text" name="contact-number[]" placeholder="<?php esc_attr_e('+1-555-035-2502', 'blue-raven'); ?>" class="br-input" style="width:100%;" value="<?php echo esc_attr($contacts['number'][$i] ?? ''); ?>">
                                                    </label>
                                                </div>
                                            </div>
                                            <div class='flex-sb' style='margin-bottom: 8px;'>
                                                <div style="width: 48%">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('URL', 'blue-raven'); ?></strong></p>
                                                        <input type="text" name="url[]" placeholder="<?php esc_attr_e('https://...', 'blue-raven'); ?>" class="br-input" style="width:100%;" value="<?php echo esc_url($contacts['url'][$i] ?? ''); ?>">
                                                    </label>
                                                </div>
                                                <div style="width: 48%">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Languages', 'blue-raven'); ?></strong></p>
                                                        <input type="text" name="languages[]" placeholder="<?php esc_attr_e('English, Spanish, French', 'blue-raven'); ?>" class="br-input" style="width:100%;" value="<?php echo esc_attr($contacts['languages'][$i] ?? ''); ?>">
                                                    </label>
                                                </div>
                                            </div>
                                            <div style='text-align: right; margin-top: 16px;'>
                                                <?php esc_html_e('Remove this Contact Point.', 'blue-raven'); ?>
                                                <a class='enterra-button open-botton remove-contact' data-tool='remove-contact-<?php echo esc_attr($i + 1); ?>' style='margin-left: 2rem;'>❌️</a>
                                            </div>
                                        </div>
                                    <?php endfor; ?>
                                <?php else: ?>
                                    <div class='contact-block' style='margin: 16px auto;' data-contact-id='1'>
                                        <div class='flex-sb' style='margin-bottom: 8px;'>
                                            <div style="width: 48%">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Contact Type', 'blue-raven'); ?></strong></p>
                                                    <input type="text" name="contact-type[]" placeholder="<?php esc_attr_e('Sales or Support etc...', 'blue-raven'); ?>" class="br-input" style="width:100%;">
                                                </label>
                                            </div>
                                        </div>
                                        <div class='flex-sb' style='margin-bottom: 8px;'>
                                            <div style="width: 48%;">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Contact Email', 'blue-raven'); ?></strong></p>
                                                    <input type="text" name="contact-email[]" placeholder="<?php esc_attr_e('sales@', 'blue-raven'); ?>" class="br-input" style="width:100%;">
                                                </label>
                                            </div>
                                            <div style="width: 48%">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Contact Number', 'blue-raven'); ?></strong></p>
                                                    <input type="text" name="contact-number[]" placeholder="<?php esc_attr_e('+1-555-035-2502', 'blue-raven'); ?>" class="br-input" style="width:100%;">
                                                </label>
                                            </div>
                                        </div>
                                        <div class='flex-sb' style='margin-bottom: 8px;'>
                                            <div style="width: 48%">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('URL', 'blue-raven'); ?></strong></p>
                                                    <input type="text" name="url[]" placeholder="<?php esc_attr_e('https://...', 'blue-raven'); ?>" class="br-input" style="width:100%;">
                                                </label>
                                            </div>
                                            <div style="width: 48%">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Languages', 'blue-raven'); ?></strong></p>
                                                    <input type="text" name="languages[]" placeholder="<?php esc_attr_e('English, Spanish, French', 'blue-raven'); ?>" class="br-input" style="width:100%;">
                                                </label>
                                            </div>
                                        </div>
                                        <div style='text-align: right; margin-top: 16px;'>
                                            <?php esc_html_e('Remove this Contact Point.', 'blue-raven'); ?>
                                            <a class='enterra-button open-botton remove-contact' data-tool='remove-contact-1' style='margin-left: 2rem;'>❌️</a>
                                        </div>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    
                    <h4><?php esc_html_e('Areas Served', 'blue-raven'); ?></h4>

                    <div class='spacing-bottom-large'>
                        <div class='spacing-left-small'>
                            
                            <div style='text-align: right;'>
                                <?php esc_html_e('Add a new Area.', 'blue-raven'); ?>
                                <a class='enterra-button' data-tool='add-new-area' id='add-new-area' style='margin-left: 2rem;'>+</a>
                            </div>
                            
                            <div id='areas-served'>
                                <?php
                                    $areas = isset($schema_setting['area']) && is_array($schema_setting['area']) ? $schema_setting['area'] : [];
                                    $areaCount = isset($areas['type']) ? count($areas['type']) : 0;
                                ?>
                                
                                <?php if ($areaCount > 0): ?>
                                    <?php for ($i = 0; $i < $areaCount; $i++): ?>
                                        <div class='flex-sb area-block' style='margin: 16px auto;' data-area-serviced-id='<?php echo esc_attr($i + 1); ?>'>
                                            <div class='flex-sb' style='margin-bottom: 8px; width: 90%;'>
                                                <div style="width: 48%;">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Type', 'blue-raven'); ?></strong></p>
                                                        <select name='area-type[]' class="br-dropdown" style="width: 100%; padding: 0.5rem;">
                                                            <option value="" disabled <?php selected(empty($areas['type'][$i]), true); ?>><?php esc_html_e('Select a type', 'blue-raven'); ?></option>
                                                            <option value="AdministrativeArea" <?php selected($areas['type'][$i], 'AdministrativeArea'); ?>><?php esc_html_e('AdministrativeArea (e.g., country, state, province)', 'blue-raven'); ?></option>
                                                            <option value="GeoShape" <?php selected($areas['type'][$i], 'GeoShape'); ?>><?php esc_html_e('GeoShape (custom geographic shape)', 'blue-raven'); ?></option>
                                                            <option value="Place" <?php selected($areas['type'][$i], 'Place'); ?>><?php esc_html_e('Place (e.g., city, building, park)', 'blue-raven'); ?></option>
                                                            <option value="Text" <?php selected($areas['type'][$i], 'Text'); ?>><?php esc_html_e('Text (e.g., "Global", "Europe")', 'blue-raven'); ?></option>
                                                        </select>
                                                    </label>
                                                </div>
                                                <div style="width: 48%;">
                                                    <label>
                                                        <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Name', 'blue-raven'); ?></strong></p>
                                                        <input type="text" name="area-name[]" placeholder="<?php esc_attr_e('Europe', 'blue-raven'); ?>" class="br-input" style="width:100%;" value="<?php echo esc_attr($areas['name'][$i] ?? ''); ?>">
                                                    </label>
                                                </div>
                                            </div>
                                            <div style='text-align: right; margin-top: 16px; width: 5rem;'>
                                                <a class='enterra-button open-botton remove-area' data-tool='remove-area-<?php echo esc_attr($i + 1); ?>' style='margin-left: 1rem; margin-top:1rem;'>❌️</a>
                                            </div>
                                        </div>
                                    <?php endfor; ?>
                                <?php else: ?>
                                    <div class='flex-sb area-block' style='margin: 16px auto;' data-area-serviced-id='1'>
                                        <div class='flex-sb' style='margin-bottom: 8px; width: 90%;'>
                                            <div style="width: 48%;">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Type', 'blue-raven'); ?></strong></p>
                                                    <select name='area-type[]' class="br-dropdown" style="width: 100%; padding: 0.5rem;">
                                                        <option value="" disabled selected><?php esc_html_e('Select a type', 'blue-raven'); ?></option>
                                                        <option value="AdministrativeArea"><?php esc_html_e('AdministrativeArea (e.g., country, state, province)', 'blue-raven'); ?></option>
                                                        <option value="GeoShape"><?php esc_html_e('GeoShape (custom geographic shape)', 'blue-raven'); ?></option>
                                                        <option value="Place"><?php esc_html_e('Place (e.g., city, building, park)', 'blue-raven'); ?></option>
                                                        <option value="Text"><?php esc_html_e('Text (e.g., "Global", "Europe")', 'blue-raven'); ?></option>
                                                    </select>
                                                </label>
                                            </div>
                                            <div style="width: 48%;">
                                                <label>
                                                    <p style="margin-bottom: 8px;"><strong><?php esc_html_e('Name', 'blue-raven'); ?></strong></p>
                                                    <input type="text" name="area-name[]" placeholder="<?php esc_attr_e('Europe', 'blue-raven'); ?>" class="br-input" style="width:100%;">
                                                </label>
                                            </div>
                                        </div>
                                        <div style='text-align: right; margin-top: 16px; width: 5rem;'>
                                            <a class='enterra-button open-botton remove-area' data-tool='remove-area-1' style='margin-left: 1rem; margin-top:1rem;'>❌️</a>
                                        </div>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    
                    <div style='text-align: right;'>
                        <button class='enterra-button' data-tool='schema' id='save-schema'>
                            <?php echo esc_html($buttonName); ?> <?php esc_html_e('Your Schema', 'blue-raven'); ?>
                        </button>
                    </div>
                </form>    
            </section>    
        <?php
    }
}
