<?php
if (!defined('ABSPATH')) {
    exit;
}
$prefill = isset($prefill) && is_array($prefill) ? $prefill : [];
$is_edit_mode = !empty($prefill['is_edit']);
$ui_labels = isset($ui_labels) && is_array($ui_labels) ? $ui_labels : [];
$singular_label = sanitize_text_field((string) ($ui_labels['singular'] ?? __('Event', 'nexdirectory')));
$singular_lower = sanitize_text_field((string) ($ui_labels['singular_lower'] ?? strtolower($singular_label)));
$is_events_profile = (string) ($ui_labels['is_events_profile'] ?? '1') === '1';
$profile_key = sanitize_key((string) ($ui_labels['profile_key'] ?? 'events'));
$is_directory_profile = (string) ($ui_labels['is_directory_profile'] ?? '0') === '1';
$is_job_profile = (string) ($ui_labels['is_job_profile'] ?? '0') === '1';
$is_marketplace_profile = (string) ($ui_labels['is_marketplace_profile'] ?? '0') === '1';
$show_schedule_builder = $is_events_profile;
$show_event_mode_toggle = $is_events_profile;
$show_price_range_toggle = $is_events_profile;
$show_capacity_field = $is_events_profile;
$show_official_classification = $is_events_profile;
$show_date_block = $is_events_profile;
$show_video_embeds_section = $is_events_profile || $is_marketplace_profile || $is_directory_profile;
$show_stream_field = $is_events_profile;
$company_label = sanitize_text_field((string) ($ui_labels['submit_company_label'] ?? __('Company Name', 'nexdirectory')));
$job_type_label = sanitize_text_field((string) ($ui_labels['submit_job_type_label'] ?? __('Employment Type', 'nexdirectory')));
$salary_label = sanitize_text_field((string) ($ui_labels['submit_salary_label'] ?? __('Salary Range', 'nexdirectory')));
$apply_url_label = sanitize_text_field((string) ($ui_labels['submit_apply_url_label'] ?? __('Application URL', 'nexdirectory')));
$closing_date_label = sanitize_text_field((string) ($ui_labels['submit_closing_date_label'] ?? __('Closing Date', 'nexdirectory')));
$condition_label = sanitize_text_field((string) ($ui_labels['submit_market_condition_label'] ?? __('Condition', 'nexdirectory')));
$submit_add_title = sanitize_text_field((string) ($ui_labels['submit_add_title'] ?? __('Add Event', 'nexdirectory')));
$submit_edit_title = sanitize_text_field((string) ($ui_labels['submit_edit_title'] ?? __('Edit Event', 'nexdirectory')));
$submit_add_description = sanitize_text_field((string) ($ui_labels['submit_add_description'] ?? __('Submit your event for review and publication on the events map.', 'nexdirectory')));
$submit_edit_description = sanitize_text_field((string) ($ui_labels['submit_edit_description'] ?? __('Update your event details using the same submission workflow.', 'nexdirectory')));
$type_label = sanitize_text_field((string) ($ui_labels['taxonomy_type_singular'] ?? __('Event Type', 'nexdirectory')));
$mode_label = sanitize_text_field((string) ($ui_labels['taxonomy_mode_singular'] ?? __('Event Mode', 'nexdirectory')));
$tag_label = sanitize_text_field((string) ($ui_labels['taxonomy_tag_plural'] ?? __('Tags', 'nexdirectory')));
$stream_label = $is_events_profile ? __('Video Stream URL (Optional)', 'nexdirectory') : __('Video URL (Optional)', 'nexdirectory');
$stream_placeholder = $is_events_profile ? 'https://www.youtube.com/yourevent' : 'https://www.example.com/video';
$description_help_text = __('Short and concise description of what people can expect.', 'nexdirectory');
$description_placeholder = sprintf(__('Describe your %s details, audience, and outcomes...', 'nexdirectory'), $singular_lower);
$mode_primary_label = __('In-person', 'nexdirectory');
$mode_secondary_label = __('Video Stream', 'nexdirectory');
$price_input_label = __('Price (Optional)', 'nexdirectory');
$price_input_placeholder = 'Free / $99';
$section_general_heading = __('General Information', 'nexdirectory');
$section_images_heading = sprintf(__('%s Images', 'nexdirectory'), $singular_label);
$section_contact_heading = sprintf(__('%s Contact Information', 'nexdirectory'), $singular_label);
$section_location_heading = sprintf(__('%s Location', 'nexdirectory'), $singular_label);
$section_details_heading = sprintf(__('%s Details', 'nexdirectory'), $singular_label);
$title_label = sprintf(__('Your %s name?', 'nexdirectory'), $singular_lower);
$title_placeholder = sprintf(__('%s name...', 'nexdirectory'), $singular_label);
$description_label = sprintf(__('Please tell us about the %s.', 'nexdirectory'), $singular_lower);
$excerpt_label = __('Short Excerpt (optional)', 'nexdirectory');
$cover_image_label = __('Cover Image', 'nexdirectory');
$gallery_images_label = __('Gallery Images (Optional)', 'nexdirectory');
$phone_label = __('Phone Number (Optional)', 'nexdirectory');
$phone_placeholder = __('Your phone number', 'nexdirectory');
$contact_email_label = __('Contact Email (Optional)', 'nexdirectory');
$contact_email_placeholder = __('Your email address', 'nexdirectory');
$location_label = __('Location', 'nexdirectory');
$location_placeholder = __('Auto-filled from address', 'nexdirectory');
$address_label = __('Address', 'nexdirectory');
$address_placeholder = __('Start typing and select an address', 'nexdirectory');
$address_help = __('Address suggestions appear while typing. Selecting one auto-fills city/country and map pin.', 'nexdirectory');
$venue_label = __('Venue (Optional)', 'nexdirectory');
$venue_placeholder = __('Venue name', 'nexdirectory');
$map_preview_cta = __('Find Address On Map', 'nexdirectory');
$type_optional_label = sprintf(__('%s (Optional)', 'nexdirectory'), $type_label);
$tags_placeholder = __('AI, Sustainability, Robotics (comma separated)', 'nexdirectory');
$tags_help = __('Comma separated. Maximum 8 tags, 40 characters per tag.', 'nexdirectory');
$excerpt_placeholder = sprintf(__('One-line summary used on %s cards.', 'nexdirectory'), strtolower((string) ($ui_labels['plural'] ?? __('event', 'nexdirectory'))));
$submit_primary_cta = sprintf(__('Submit %s', 'nexdirectory'), $singular_label);
$update_primary_cta = sprintf(__('Update %s', 'nexdirectory'), $singular_label);
if ($is_job_profile) {
    $submit_add_title = __('Add Job', 'nexdirectory');
    $submit_edit_title = __('Edit Job', 'nexdirectory');
    $submit_add_description = __('Post a role for review with salary, workplace setup, and clear application instructions.', 'nexdirectory');
    $submit_edit_description = __('Update the role details, closing date, and application method.', 'nexdirectory');
    $description_help_text = __('Include role responsibilities, requirements, and key benefits.', 'nexdirectory');
    $description_placeholder = __('Describe the role, responsibilities, qualifications, and team context.', 'nexdirectory');
    $section_general_heading = __('Role Basics', 'nexdirectory');
    $section_images_heading = __('Company Assets (Optional)', 'nexdirectory');
    $section_contact_heading = __('Recruiter & Applicant Contact', 'nexdirectory');
    $section_location_heading = __('Workplace & Map', 'nexdirectory');
    $section_details_heading = __('Compensation, Hiring & Application', 'nexdirectory');
    $title_label = __('Job Title', 'nexdirectory');
    $title_placeholder = __('Job title...', 'nexdirectory');
    $description_label = __('Job Description', 'nexdirectory');
    $excerpt_label = __('Short Summary (Optional)', 'nexdirectory');
    $cover_image_label = __('Company Cover Image (Optional)', 'nexdirectory');
    $gallery_images_label = __('Workplace / Team Images (Optional)', 'nexdirectory');
    $phone_label = __('Recruiter Phone (Optional)', 'nexdirectory');
    $phone_placeholder = __('Recruiter phone number', 'nexdirectory');
    $contact_email_label = __('Recruiter Contact Email (Optional)', 'nexdirectory');
    $contact_email_placeholder = __('recruitment@example.com', 'nexdirectory');
    $location_label = __('City / Area', 'nexdirectory');
    $location_placeholder = __('Auto-filled from workplace address', 'nexdirectory');
    $address_label = __('Workplace Address', 'nexdirectory');
    $address_placeholder = __('Start typing company address', 'nexdirectory');
    $address_help = __('Type the office/workplace address and choose a suggestion to set map details automatically.', 'nexdirectory');
    $venue_label = __('Office / Site Name (Optional)', 'nexdirectory');
    $venue_placeholder = __('Office name', 'nexdirectory');
    $map_preview_cta = __('Preview Workplace Map', 'nexdirectory');
    $type_optional_label = __('Job Category (Optional)', 'nexdirectory');
    $tag_label = __('Skills / Keywords', 'nexdirectory');
    $tags_placeholder = __('AI, DevOps, Product, Sales (comma separated)', 'nexdirectory');
    $tags_help = __('Comma separated skills/keywords. Maximum 8 tags, 40 characters per tag.', 'nexdirectory');
    $excerpt_placeholder = __('One-line summary used on job cards.', 'nexdirectory');
    $submit_primary_cta = __('Submit Job', 'nexdirectory');
    $update_primary_cta = __('Update Job', 'nexdirectory');
} elseif ($is_directory_profile) {
    $submit_add_title = __('Add Listing', 'nexdirectory');
    $submit_edit_title = __('Edit Listing', 'nexdirectory');
    $submit_add_description = __('Create a directory listing with services, coverage area, and clear contact options.', 'nexdirectory');
    $submit_edit_description = __('Update your listing details, service area, and contact channels.', 'nexdirectory');
    $description_help_text = __('Describe services, operating hours, service area, and what makes this listing unique.', 'nexdirectory');
    $description_placeholder = __('Describe services offered, operating hours, and service coverage.', 'nexdirectory');
    $section_general_heading = __('Listing Basics', 'nexdirectory');
    $section_images_heading = __('Listing Media', 'nexdirectory');
    $section_contact_heading = __('Owner Contact', 'nexdirectory');
    $section_location_heading = __('Business Location', 'nexdirectory');
    $section_details_heading = __('Business Details', 'nexdirectory');
    $title_label = __('Listing Title', 'nexdirectory');
    $title_placeholder = __('Listing title...', 'nexdirectory');
    $description_label = __('Listing Description', 'nexdirectory');
    $excerpt_label = __('Short Listing Summary (Optional)', 'nexdirectory');
    $cover_image_label = __('Primary Listing Image (Optional)', 'nexdirectory');
    $gallery_images_label = __('Gallery (Optional)', 'nexdirectory');
    $phone_label = __('Owner Phone (Optional)', 'nexdirectory');
    $phone_placeholder = __('Owner phone number', 'nexdirectory');
    $contact_email_label = __('Owner Email (Optional)', 'nexdirectory');
    $contact_email_placeholder = __('owner@example.com', 'nexdirectory');
    $location_label = __('City / Area', 'nexdirectory');
    $location_placeholder = __('Auto-filled from business address', 'nexdirectory');
    $address_label = __('Business Address', 'nexdirectory');
    $address_placeholder = __('Start typing business address', 'nexdirectory');
    $address_help = __('Type your address and select a suggestion to auto-fill city/country and map pin.', 'nexdirectory');
    $venue_label = __('Business / Office Name (Optional)', 'nexdirectory');
    $venue_placeholder = __('Office, branch, storefront...', 'nexdirectory');
    $map_preview_cta = __('Preview Business Map', 'nexdirectory');
    $type_optional_label = __('Directory Category (Optional)', 'nexdirectory');
    $tag_label = __('Keywords', 'nexdirectory');
    $tags_placeholder = __('plumber, legal, emergency, family-law (comma separated)', 'nexdirectory');
    $tags_help = __('Comma separated. Maximum 8 tags, 40 characters per tag.', 'nexdirectory');
    $price_input_label = __('Price / Rate (Optional)', 'nexdirectory');
    $price_input_placeholder = __('From £50, Free consultation, Hourly rate...', 'nexdirectory');
    $excerpt_placeholder = __('One-line summary used on listing cards.', 'nexdirectory');
    $submit_primary_cta = __('Submit Listing', 'nexdirectory');
    $update_primary_cta = __('Update Listing', 'nexdirectory');
} elseif ($is_marketplace_profile) {
    $submit_add_title = __('Add Listing', 'nexdirectory');
    $submit_edit_title = __('Edit Listing', 'nexdirectory');
    $submit_add_description = __('Create a marketplace listing with pricing, condition, and seller details.', 'nexdirectory');
    $submit_edit_description = __('Update listing details, availability, and delivery options.', 'nexdirectory');
    $description_help_text = __('Describe condition, included items, delivery options, and buyer expectations.', 'nexdirectory');
    $description_placeholder = __('Describe item condition, what is included, and pickup/delivery details.', 'nexdirectory');
    $section_general_heading = __('Listing Basics', 'nexdirectory');
    $section_images_heading = __('Listing Media', 'nexdirectory');
    $section_contact_heading = __('Seller Contact', 'nexdirectory');
    $section_location_heading = __('Item Location', 'nexdirectory');
    $section_details_heading = __('Pricing, Condition & Delivery', 'nexdirectory');
    $title_label = __('Listing Title', 'nexdirectory');
    $title_placeholder = __('Listing title...', 'nexdirectory');
    $description_label = __('Listing Description', 'nexdirectory');
    $excerpt_label = __('Short Listing Summary (Optional)', 'nexdirectory');
    $cover_image_label = __('Primary Listing Image', 'nexdirectory');
    $gallery_images_label = __('Gallery (Optional)', 'nexdirectory');
    $phone_label = __('Seller Phone (Optional)', 'nexdirectory');
    $phone_placeholder = __('Seller phone number', 'nexdirectory');
    $contact_email_label = __('Seller Email (Optional)', 'nexdirectory');
    $contact_email_placeholder = __('seller@example.com', 'nexdirectory');
    $location_label = __('Area / City', 'nexdirectory');
    $location_placeholder = __('Auto-filled from pickup address', 'nexdirectory');
    $address_label = __('Address (Optional)', 'nexdirectory');
    $address_placeholder = __('Start typing pickup or item address', 'nexdirectory');
    $address_help = __('Use an address for local pickup and map visibility. Leave blank for non-location specific listings.', 'nexdirectory');
    $venue_label = __('Pickup Location Name (Optional)', 'nexdirectory');
    $venue_placeholder = __('Warehouse, shop, home area...', 'nexdirectory');
    $map_preview_cta = __('Preview Pickup Map', 'nexdirectory');
    $type_optional_label = __('Listing Category (Optional)', 'nexdirectory');
    $tag_label = __('Keywords', 'nexdirectory');
    $tags_placeholder = __('phone, furniture, vintage, bike (comma separated)', 'nexdirectory');
    $tags_help = __('Comma separated. Maximum 8 tags, 40 characters per tag.', 'nexdirectory');
    $price_input_label = __('Asking Price', 'nexdirectory');
    $price_input_placeholder = __('e.g. £120', 'nexdirectory');
    $submit_primary_cta = __('Submit Listing', 'nexdirectory');
    $update_primary_cta = __('Update Listing', 'nexdirectory');
}
$itinerary_toggle_label = $is_events_profile ? __('Has itinerary ?', 'nexdirectory') : __('Add schedule items?', 'nexdirectory');
$session_heading = $is_events_profile ? __('Add Session', 'nexdirectory') : __('Add Schedule Item', 'nexdirectory');
$session_help = $is_events_profile
    ? __('Build your itinerary. Add each session with title, time range, and optional location.', 'nexdirectory')
    : __('Add optional schedule items (hours, appointments, or availability windows).', 'nexdirectory');
$session_title_label = $is_events_profile ? __('Session Title', 'nexdirectory') : __('Item Title', 'nexdirectory');
$session_title_placeholder = $is_events_profile ? __('Opening keynote', 'nexdirectory') : __('Morning availability', 'nexdirectory');
$session_location_label = $is_events_profile ? __('Session Location (Optional)', 'nexdirectory') : __('Location (Optional)', 'nexdirectory');
$session_location_placeholder = $is_events_profile ? __('Main Hall A', 'nexdirectory') : __('Branch office / service area', 'nexdirectory');
$session_remove_label = $is_events_profile ? __('Remove Session', 'nexdirectory') : __('Remove Item', 'nexdirectory');
$event_completion_missing = isset($event_completion_missing) && is_array($event_completion_missing)
    ? array_values(array_filter(array_map('eep_sanitize_text', $event_completion_missing), static function ($item) {
        return trim((string) $item) !== '';
    }))
    : [];
$custom_form_fields = isset($custom_form_fields) && is_array($custom_form_fields) ? $custom_form_fields : [];
$custom_fields_enabled = isset($custom_fields_enabled) && (bool) $custom_fields_enabled;
$per_event_email_templates_enabled = isset($per_event_email_templates_enabled) && (bool) $per_event_email_templates_enabled;
$organizer_event_seo_enabled = isset($organizer_event_seo_enabled) ? (bool) $organizer_event_seo_enabled : ((string) get_option('eep_enable_event_seo_fields', '1') === '1');
$custom_field_types = isset($custom_field_types) && is_array($custom_field_types) ? $custom_field_types : [
    'text' => __('Text', 'nexdirectory'),
    'textarea' => __('Textarea', 'nexdirectory'),
    'wysiwyg' => __('Rich Text (WYSIWYG)', 'nexdirectory'),
    'url' => __('URL', 'nexdirectory'),
    'email' => __('Email', 'nexdirectory'),
    'number' => __('Number', 'nexdirectory'),
    'date' => __('Date', 'nexdirectory'),
    'datetime-local' => __('Date + Time', 'nexdirectory'),
    'select' => __('Select Dropdown', 'nexdirectory'),
    'checkbox' => __('Yes/No Toggle', 'nexdirectory'),
    'image' => __('Image URL', 'nexdirectory'),
    'gallery' => __('Gallery URLs', 'nexdirectory'),
    'file' => __('File URL', 'nexdirectory'),
];
$custom_taxonomy_fields = isset($custom_taxonomy_fields) && is_array($custom_taxonomy_fields) ? $custom_taxonomy_fields : [];
$classification_labels = isset($classification_labels) && is_array($classification_labels) ? $classification_labels : [
    'official' => sprintf(__('Official %s', 'nexdirectory'), $singular_label),
    'unofficial' => sprintf(__('Unofficial %s', 'nexdirectory'), $singular_label),
];
$official_pending_note = isset($official_pending_note) ? (string) $official_pending_note : __('Official classification is reviewed by admins before it appears publicly.', 'nexdirectory');
$custom_values = isset($prefill['custom_fields_values']) && is_array($prefill['custom_fields_values']) ? $prefill['custom_fields_values'] : [];
$upload_limits = isset($upload_limits) && is_array($upload_limits) ? $upload_limits : [];
$cover_max_kb = max(64, (int) ($upload_limits['cover_max_kb'] ?? 500));
$gallery_max_kb = max(64, (int) ($upload_limits['gallery_max_kb'] ?? 2000));
$gallery_max_files = max(1, (int) ($upload_limits['gallery_max_files'] ?? 10));
$excerpt_max_chars = max(80, (int) ($excerpt_max_chars ?? 220));
$submit_recaptcha_required = !empty($submit_recaptcha_required);
$prefill_gallery_rows = preg_split('/\r\n|\r|\n/', (string) ($prefill['eep_gallery_urls'] ?? ''));
if (!is_array($prefill_gallery_rows)) {
    $prefill_gallery_rows = [];
}
$prefill_gallery_rows = array_values(array_filter(array_map('trim', $prefill_gallery_rows), static function ($row) {
    return $row !== '';
}));
$prefill_video_rows = preg_split('/\r\n|\r|\n/', (string) ($prefill['eep_video_urls'] ?? ''));
if (!is_array($prefill_video_rows)) {
    $prefill_video_rows = [];
}
$prefill_video_rows = array_values(array_filter(array_map('trim', $prefill_video_rows), static function ($row) {
    return $row !== '';
}));
$prefill_video_urls_value = $show_video_embeds_section ? (string) ($prefill['eep_video_urls'] ?? '') : '';
$prefill_stream_url_value = $show_stream_field ? (string) ($prefill['eep_event_stream_url'] ?? '') : '';
$prefill_start_raw = (string) ($prefill['eep_start_raw'] ?? '');
if ($prefill_start_raw === '') {
    $prefill_start_raw = str_replace('T', ' ', (string) ($prefill['eep_start_local'] ?? ''));
}
$prefill_end_raw = (string) ($prefill['eep_end_raw'] ?? '');
if ($prefill_end_raw === '') {
    $prefill_end_raw = str_replace('T', ' ', (string) ($prefill['eep_end_local'] ?? ''));
}
$prefill_start_date = '';
$prefill_start_time = '';
$prefill_end_date = '';
$prefill_end_time = '';
if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $prefill_start_raw, $start_date_match)) {
    $prefill_start_date = (string) ($start_date_match[1] ?? '');
}
if (preg_match('/\b(\d{2}:\d{2})\b/', $prefill_start_raw, $start_time_match)) {
    $prefill_start_time = (string) ($start_time_match[1] ?? '');
}
if (preg_match('/^(\d{4}-\d{2}-\d{2})/', $prefill_end_raw, $end_date_match)) {
    $prefill_end_date = (string) ($end_date_match[1] ?? '');
}
if (preg_match('/\b(\d{2}:\d{2})\b/', $prefill_end_raw, $end_time_match)) {
    $prefill_end_time = (string) ($end_time_match[1] ?? '');
}
$custom_builder_rows = [];
foreach ($custom_form_fields as $field_index => $field) {
    $field = is_array($field) ? $field : [];
    $field_id = sanitize_key((string) ($field['id'] ?? ''));
    if ($field_id === '') {
        $field_id = 'custom_field_' . (string) ((int) $field_index + 1);
    }
    $custom_builder_rows[] = [
        'id' => $field_id,
        'label' => sanitize_text_field((string) ($field['label'] ?? '')),
        'type' => sanitize_key((string) ($field['type'] ?? 'text')),
        'placeholder' => sanitize_text_field((string) ($field['placeholder'] ?? '')),
        'help' => sanitize_text_field((string) ($field['help'] ?? '')),
        'required' => (string) ($field['required'] ?? '0') === '1' ? '1' : '0',
        'show_in_event' => (string) ($field['show_in_event'] ?? '1') === '0' ? '0' : '1',
        'options' => eep_sanitize_textarea((string) ($field['options'] ?? '')),
        'value' => isset($custom_values[$field_id]) ? (string) $custom_values[$field_id] : '',
    ];
}
$custom_builder_rows_json = wp_json_encode($custom_builder_rows, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
$custom_field_types_json = wp_json_encode($custom_field_types, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
$email_tokens_help = $is_events_profile
    ? __('Override default platform emails for this event. Tokens: {event_title}, {event_date}, {event_url}, {status}, {moderator_note}.', 'nexdirectory')
    : sprintf(__('Override default platform emails for this %1$s. Tokens: {listing_title}, {listing_date}, {listing_url}, {status}, {moderator_note}.', 'nexdirectory'), $singular_lower);
$alpine_prefill = [
    'titleValue' => (string) ($prefill['post_title'] ?? ''),
    'excerptValue' => (string) ($prefill['post_excerpt'] ?? ''),
    'coverImage' => (string) ($prefill['eep_cover_image_url'] ?? ''),
    'galleryImages' => $prefill_gallery_rows,
    'videoUrlsTextarea' => $prefill_video_urls_value,
    'videoEmbeds' => $show_video_embeds_section ? (!empty($prefill_video_rows) ? $prefill_video_rows : ['']) : [],
    'startValue' => $prefill_start_date,
    'startTimeValue' => $prefill_start_time,
    'endValue' => $prefill_end_date,
    'endTimeValue' => $prefill_end_time,
    'cityValue' => (string) ($prefill['eep_city'] ?? ''),
    'countryValue' => (string) ($prefill['eep_country'] ?? ''),
    'latValue' => (string) ($prefill['eep_lat'] ?? ''),
    'lngValue' => (string) ($prefill['eep_lng'] ?? ''),
    'streamUrl' => $prefill_stream_url_value,
    'metaTitleValue' => (string) ($prefill['eep_meta_title'] ?? ''),
    'metaDescriptionValue' => (string) ($prefill['eep_meta_description'] ?? ''),
    'serpUrl' => !empty($prefill['edit_event_id']) ? esc_url_raw((string) get_permalink((int) $prefill['edit_event_id'])) : esc_url_raw((string) home_url('/events/')),
    'modeOption' => (string) ($prefill['eep_event_mode_option'] ?? 'in-person'),
    'isRecurring' => (string) ($prefill['eep_is_recurring'] ?? '0') === '1' ? '1' : '0',
    'sessions' => is_array($prefill['sessions'] ?? null) ? array_values((array) $prefill['sessions']) : [],
    'recurrenceUntil' => (string) ($prefill['eep_recurrence_until'] ?? ''),
];
$alpine_json_flags = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT;
if (defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
    $alpine_json_flags |= JSON_INVALID_UTF8_SUBSTITUTE;
}
$alpine_prefill_json = wp_json_encode($alpine_prefill, $alpine_json_flags);
$page_kicker = sanitize_text_field((string) ($ui_labels['hero_kicker_default'] ?? $this->get_event_hero_kicker_text()));
echo $this->render_notice();
echo $this->render_platform_breadcrumbs($is_edit_mode ? $submit_edit_title : $submit_add_title); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<section class="eep-page-banner">
    <p class="eep-page-kicker"><?php echo esc_html($page_kicker); ?></p>
    <h1><?php echo esc_html($is_edit_mode ? $submit_edit_title : $submit_add_title); ?></h1>
    <p><?php echo esc_html($is_edit_mode ? $submit_edit_description : $submit_add_description); ?></p>
</section>
<?php echo $this->render_account_tabs('submit', $profile_key); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ($is_edit_mode && !empty($event_completion_missing)) : ?>
    <div class="eep-notice eep-submit-completion-note">
        <strong><?php echo esc_html(sprintf(__('Recommended improvements for this %s', 'nexdirectory'), $singular_lower)); ?></strong>
        <p><?php esc_html_e('These optional sections are currently missing:', 'nexdirectory'); ?></p>
        <ul>
            <?php foreach ($event_completion_missing as $missing_item) : ?>
                <li><?php echo esc_html($missing_item); ?></li>
            <?php endforeach; ?>
        </ul>
    </div>
<?php endif; ?>
<div class="eep-account-shell">
<div class="eep-submit-wrap<?php echo $show_nav ? '' : ' eep-submit-no-nav'; ?>">
    <?php if ($show_nav) : ?>
    <aside class="eep-submit-nav" id="eep-submit-nav">
        <a class="eep-submit-nav-link" href="#eep-section-general"><?php echo esc_html($section_general_heading); ?></a>
        <a class="eep-submit-nav-link" href="#eep-section-images"><?php echo esc_html($section_images_heading); ?></a>
        <a class="eep-submit-nav-link" href="#eep-section-contact"><?php echo esc_html($section_contact_heading); ?></a>
        <a class="eep-submit-nav-link" href="#eep-section-location"><?php echo esc_html($section_location_heading); ?></a>
        <a class="eep-submit-nav-link" href="#eep-section-details"><?php echo esc_html($section_details_heading); ?></a>
        <?php if ($custom_fields_enabled) : ?>
            <a class="eep-submit-nav-link" href="#eep-section-custom-fields"><?php esc_html_e('Custom Fields', 'nexdirectory'); ?></a>
        <?php endif; ?>
        <?php if ($show_video_embeds_section) : ?>
            <a class="eep-submit-nav-link" href="#eep-section-videos"><?php echo esc_html(($is_marketplace_profile || $is_directory_profile) ? __('Videos', 'nexdirectory') : __('Video Embeds', 'nexdirectory')); ?></a>
        <?php endif; ?>
        <?php if ($per_event_email_templates_enabled) : ?>
            <a class="eep-submit-nav-link" href="#eep-section-email-templates"><?php esc_html_e('Email Templates', 'nexdirectory'); ?></a>
        <?php endif; ?>
    </aside>
    <?php endif; ?>

    <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" enctype="multipart/form-data" class="eep-form eep-submit-form" id="eep-submit-form" x-data='eepSubmitForm(<?php echo $alpine_prefill_json ? $alpine_prefill_json : '{}'; ?>)' data-eep-editing="<?php echo $is_edit_mode ? '1' : '0'; ?>" data-eep-initial-sessions="<?php echo esc_attr(wp_json_encode((array) ($prefill['sessions'] ?? []))); ?>" data-eep-recurrence-until="<?php echo esc_attr((string) ($prefill['eep_recurrence_until'] ?? '')); ?>">
        <input type="hidden" name="action" value="eep_submit_event">
        <input type="hidden" name="eep_edit_post_id" value="<?php echo esc_attr((string) ($prefill['edit_event_id'] ?? '0')); ?>">
        <?php wp_nonce_field('eep_submit_event_nonce', 'eep_nonce'); ?>
        <input type="hidden" name="eep_website" class="eep-honeypot" tabindex="-1" autocomplete="off" aria-hidden="true">
        <input type="hidden" name="eep_recaptcha_token" class="<?php echo $submit_recaptcha_required ? 'eep-recaptcha-token' : ''; ?>" value="">
        <input type="hidden" name="eep_sessions" :value="JSON.stringify(sessions)">
        <input type="hidden" name="eep_autosave_post_id" x-model="autosavePostId">
        <input type="hidden" name="eep_recurrence" :value="isRecurring === '1' ? 'custom' : 'none'">
            <input type="hidden" name="eep_recurrence_until" :value="recurrenceUntil">
            <input type="hidden" name="eep_lock_pin" value="0">
            <input type="hidden" name="eep_lat" id="eep-lat-input" x-model="latValue" x-init="latValue = $el.value || latValue" value="<?php echo esc_attr((string) ($prefill['eep_lat'] ?? '')); ?>">
            <input type="hidden" name="eep_lng" id="eep-lng-input" x-model="lngValue" x-init="lngValue = $el.value || lngValue" value="<?php echo esc_attr((string) ($prefill['eep_lng'] ?? '')); ?>">
        <input type="hidden" name="eep_country" x-model="countryValue" x-init="countryValue = $el.value || countryValue" value="<?php echo esc_attr((string) ($prefill['eep_country'] ?? '')); ?>">
            <input type="hidden" name="eep_youtube_video_id_1" :value="youtubeIdOne">
            <input type="hidden" name="eep_youtube_video_id_2" :value="youtubeIdTwo">
            <?php if (!$show_date_block) : ?>
                <input type="hidden" name="eep_start_date" value="<?php echo esc_attr($prefill_start_date !== '' ? $prefill_start_date : wp_date('Y-m-d')); ?>">
                <input type="hidden" name="eep_start_time" value="<?php echo esc_attr($prefill_start_time !== '' ? $prefill_start_time : '09:00'); ?>">
                <input type="hidden" name="eep_end_date" value="<?php echo esc_attr($prefill_end_date); ?>">
                <input type="hidden" name="eep_end_time" value="<?php echo esc_attr($prefill_end_time); ?>">
                <input type="hidden" name="eep_timezone" value="<?php echo esc_attr((string) ($prefill['eep_timezone'] ?? wp_timezone_string())); ?>">
                <input type="hidden" name="eep_is_recurring" value="0">
            <?php endif; ?>
            <textarea name="eep_video_urls" x-model="videoUrlsTextarea" x-init="videoUrlsTextarea = $el.value || videoUrlsTextarea" style="display:none;"><?php echo esc_textarea($prefill_video_urls_value); ?></textarea>
            <input type="hidden" name="eep_custom_fields_builder_json" id="eep-custom-builder-json" value="<?php echo esc_attr($custom_builder_rows_json ?: '[]'); ?>">
            <input type="hidden" id="eep-custom-field-types-json" value="<?php echo esc_attr($custom_field_types_json ?: '{}'); ?>">
        <input type="file" name="eep_cover_file" x-ref="coverFileInput" accept="image/*" style="display:none;" @change="handleFileSelect($event, 'cover')">
        <input type="file" name="eep_gallery_files[]" x-ref="galleryFileInput" accept="image/*" multiple style="display:none;" @change="handleFileSelect($event, 'gallery')">

        <section id="eep-section-general" class="eep-form-section">
            <h3><?php echo esc_html($section_general_heading); ?></h3>
            <label><?php echo esc_html($title_label); ?></label>
            <input type="text" name="post_title" required x-model="titleValue" x-init="titleValue = $el.value || titleValue" @input.debounce.150ms="validateTitle" placeholder="<?php echo esc_attr($title_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['post_title'] ?? '')); ?>">
            <p class="eep-meta" x-text="titleCounterText()"></p>
            <p class="eep-validation-error" x-show="titleError" x-text="titleError"></p>

            <label><?php echo esc_html($description_label); ?></label>
            <span class="eep-help-text"><?php echo esc_html($description_help_text); ?></span>
            <?php if ($use_rich_editor && function_exists('wp_editor')) : ?>
                <?php
                wp_editor((string) ($prefill['post_content'] ?? ''), 'eep_post_content_editor', [
                    'textarea_name' => 'post_content',
                    'textarea_rows' => 8,
                    'media_buttons' => false,
                    'teeny' => true,
                    'quicktags' => false,
                    'tinymce' => [
                        'wpautop' => true,
                    ],
                ]);
                ?>
            <?php else : ?>
                <textarea name="post_content" rows="6" required placeholder="<?php echo esc_attr($description_placeholder); ?>"><?php echo esc_textarea((string) ($prefill['post_content'] ?? '')); ?></textarea>
            <?php endif; ?>

            <label><?php echo esc_html($excerpt_label); ?></label>
            <span class="eep-help-text"><?php echo esc_html(sprintf(__('Maximum %d characters.', 'nexdirectory'), $excerpt_max_chars)); ?></span>
            <textarea class="eep-excerpt-input" name="post_excerpt" rows="2" maxlength="<?php echo esc_attr((string) $excerpt_max_chars); ?>" x-model="excerptValue" x-init="excerptValue = $el.value || excerptValue" @input="validateExcerpt" placeholder="<?php echo esc_attr($excerpt_placeholder); ?>"><?php echo esc_textarea((string) ($prefill['post_excerpt'] ?? '')); ?></textarea>
            <p class="eep-meta" x-text="excerptCounterText()"></p>
            <p class="eep-validation-error" x-show="excerptError" x-text="excerptError"></p>

            <?php if ($organizer_event_seo_enabled) : ?>
                <div class="eep-seo-block" style="margin-top:16px;">
                    <h4 style="margin:0 0 8px;"><?php esc_html_e('SEO Snippet Preview', 'nexdirectory'); ?></h4>
                    <p class="eep-help-text"><?php esc_html_e('Meta title max 60 characters (recommended 50-60). Meta description max 158 characters (recommended 120-158).', 'nexdirectory'); ?></p>
                    <button type="button" class="eep-btn eep-btn-secondary" style="margin-bottom:12px;" @click="fillSeoFromContent()"><?php esc_html_e('Use Title + Summary', 'nexdirectory'); ?></button>

                    <label><?php esc_html_e('Meta Title', 'nexdirectory'); ?></label>
                    <input type="text" name="eep_meta_title" maxlength="60" x-model="metaTitleValue" @input="queueAutosave(220)" placeholder="<?php esc_attr_e('Best between 50 and 60 characters', 'nexdirectory'); ?>">
                    <p class="eep-meta"><span x-text="seoTitleCount()"></span> / 60 · <span x-text="seoTitleStatusText()"></span></p>

                    <label><?php esc_html_e('Meta Description', 'nexdirectory'); ?></label>
                    <textarea name="eep_meta_description" rows="3" maxlength="158" x-model="metaDescriptionValue" @input="queueAutosave(220)" placeholder="<?php esc_attr_e('Best between 120 and 158 characters', 'nexdirectory'); ?>"></textarea>
                    <p class="eep-meta"><span x-text="seoDescriptionCount()"></span> / 158 · <span x-text="seoDescriptionStatusText()"></span></p>

                    <div class="eep-seo-serp-preview" style="margin-top:12px;padding:12px;border:1px solid #e5e7eb;border-radius:12px;background:#fff;">
                        <p style="margin:0 0 4px;font-size:12px;color:#15803d;" x-text="serpUrlPreview()"></p>
                        <p style="margin:0 0 4px;font-size:22px;line-height:1.2;color:#1a0dab;" x-text="serpTitlePreview()"></p>
                        <p style="margin:0;color:#4d5156;font-size:14px;line-height:1.45;" x-text="serpDescriptionPreview()"></p>
                    </div>
                </div>
            <?php endif; ?>
        </section>

        <section id="eep-section-images" class="eep-form-section">
            <h3><?php echo esc_html($section_images_heading); ?></h3>
            <label><?php echo esc_html($cover_image_label); ?></label>
            <span class="eep-help-text"><?php echo esc_html(sprintf(__('Max file size: %d KB.', 'nexdirectory'), (int) $cover_max_kb)); ?></span>
            <div class="eep-dropzone" data-eep-upload-target="cover" @dragover.prevent @drop.prevent="handleDrop($event, 'cover')" @click="openMedia('cover')">
                <template x-if="coverImage">
                    <div class="eep-upload-preview-wrap">
                        <img class="eep-upload-preview" :src="coverImage" alt="Cover preview">
                        <button type="button" class="eep-upload-remove" @click.stop="removeCover()" aria-label="<?php esc_attr_e('Remove cover image', 'nexdirectory'); ?>">&times;</button>
                    </div>
                </template>
                <template x-if="!coverImage">
                    <p><?php esc_html_e('Drag and drop image here, or click to upload from your device.', 'nexdirectory'); ?></p>
                </template>
            </div>
            <input type="hidden" name="eep_cover_image_url" x-model="coverImage" x-init="coverImage = $el.value || coverImage" value="<?php echo esc_attr((string) ($prefill['eep_cover_image_url'] ?? '')); ?>">

            <label><?php echo esc_html($gallery_images_label); ?></label>
            <span class="eep-help-text"><?php echo esc_html(sprintf(__('Up to %1$d files, max %2$d KB per file.', 'nexdirectory'), (int) $gallery_max_files, (int) $gallery_max_kb)); ?></span>
            <div class="eep-dropzone" data-eep-upload-target="gallery" @dragover.prevent @drop.prevent="handleDrop($event, 'gallery')" @click="openMedia('gallery')">
                <p><?php esc_html_e('Drop multiple images or click to select.', 'nexdirectory'); ?></p>
            </div>
            <div class="eep-gallery" x-show="galleryImages.length">
                <template x-for="(url, index) in galleryImages" :key="index">
                    <div class="eep-gallery-tile">
                        <img :src="url" alt="Gallery preview">
                        <button class="eep-upload-remove eep-upload-remove-sm" type="button" @click="removeGallery(index)" aria-label="<?php esc_attr_e('Remove gallery image', 'nexdirectory'); ?>">&times;</button>
                    </div>
                </template>
            </div>
            <textarea name="eep_gallery_urls" x-model="galleryTextarea" x-init="galleryTextarea = $el.value || galleryTextarea" style="display:none;"><?php echo esc_textarea((string) ($prefill['eep_gallery_urls'] ?? '')); ?></textarea>
        </section>

        <section id="eep-section-contact" class="eep-form-section">
            <h3><?php echo esc_html($section_contact_heading); ?></h3>
            <div class="eep-grid-2">
                <div>
                    <label><?php echo esc_html($phone_label); ?></label>
                    <input type="text" name="eep_contact_phone" placeholder="<?php echo esc_attr($phone_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_contact_phone'] ?? '')); ?>">
                </div>
                <div>
                    <label><?php echo esc_html($contact_email_label); ?></label>
                    <input type="email" name="eep_contact_email" placeholder="<?php echo esc_attr($contact_email_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_contact_email'] ?? '')); ?>">
                </div>
            </div>
        </section>

        <section id="eep-section-location" class="eep-form-section">
            <h3><?php echo esc_html($section_location_heading); ?></h3>
            <label><?php echo esc_html($location_label); ?></label>
            <input type="text" name="eep_city" x-model="cityValue" x-init="cityValue = $el.value || cityValue" placeholder="<?php echo esc_attr($location_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_city'] ?? '')); ?>">

            <label><?php echo esc_html($address_label); ?></label>
            <input type="text" name="eep_address" id="eep-address-input" list="eep-address-suggestions" <?php echo ($is_events_profile || $is_directory_profile) ? 'required' : ''; ?> placeholder="<?php echo esc_attr($address_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_address'] ?? '')); ?>">
            <datalist id="eep-address-suggestions"></datalist>
            <span class="eep-help-text"><?php echo esc_html($address_help); ?></span>

            <label><?php echo esc_html($venue_label); ?></label>
            <input type="text" name="eep_venue" placeholder="<?php echo esc_attr($venue_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_venue'] ?? '')); ?>">

            <button type="button" class="eep-btn eep-btn-secondary" id="eep-geocode-btn"><?php echo esc_html($map_preview_cta); ?></button>
            <?php if ($is_job_profile) : ?>
                <span class="eep-help-text"><?php esc_html_e('Optional for remote-first roles.', 'nexdirectory'); ?></span>
            <?php elseif ($is_marketplace_profile) : ?>
                <span class="eep-help-text"><?php esc_html_e('Optional for listings that are shipped or delivered digitally.', 'nexdirectory'); ?></span>
            <?php endif; ?>
            <div id="eep-location-preview" class="eep-mini-map"></div>
        </section>

        <section id="eep-section-details" class="eep-form-section">
            <h3><?php echo esc_html($section_details_heading); ?></h3>
            <?php if ($show_event_mode_toggle) : ?>
                <label><?php echo esc_html($mode_label); ?></label>
                <div class="eep-radio-group">
                    <input type="radio" id="eep-mode-in-person" name="eep_event_mode_option" value="in-person" x-model="modeOption" @change="if (modeOption !== 'video-stream') { streamUrl = ''; syncVideoUrls(); }" <?php checked((string) ($prefill['eep_event_mode_option'] ?? 'in-person'), 'in-person'); ?>>
                    <label for="eep-mode-in-person"><?php echo esc_html($mode_primary_label); ?></label>
                    <input type="radio" id="eep-mode-video-stream" name="eep_event_mode_option" value="video-stream" x-model="modeOption" <?php checked((string) ($prefill['eep_event_mode_option'] ?? 'in-person'), 'video-stream'); ?>>
                    <label for="eep-mode-video-stream"><?php echo esc_html($mode_secondary_label); ?></label>
                </div>
            <?php else : ?>
                <input type="hidden" name="eep_event_mode_option" value="<?php echo esc_attr((string) ($prefill['eep_event_mode_option'] ?? 'in-person')); ?>">
            <?php endif; ?>

            <?php if ($show_price_range_toggle) : ?>
                <label><?php echo esc_html($is_marketplace_profile ? __('Price Type', 'nexdirectory') : __('Price Range', 'nexdirectory')); ?></label>
                <div class="eep-radio-group">
                    <input type="radio" id="eep-price-free" name="eep_price_simple" value="free" <?php checked((string) ($prefill['eep_price_simple'] ?? 'free'), 'free'); ?>>
                    <label for="eep-price-free"><?php echo esc_html($is_marketplace_profile ? __('Negotiable / Free', 'nexdirectory') : __('Free', 'nexdirectory')); ?></label>
                    <input type="radio" id="eep-price-paid" name="eep_price_simple" value="paid" <?php checked((string) ($prefill['eep_price_simple'] ?? 'free'), 'paid'); ?>>
                    <label for="eep-price-paid"><?php echo esc_html($is_marketplace_profile ? __('Fixed Price', 'nexdirectory') : __('Paid', 'nexdirectory')); ?></label>
                </div>
            <?php else : ?>
                <input type="hidden" name="eep_price_simple" value="paid">
            <?php endif; ?>

            <?php if ($is_job_profile) : ?>
                <h4 class="eep-subheading"><?php esc_html_e('Role & Workplace', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Define the role details, reporting line, and where this job is delivered.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php echo esc_html($company_label); ?></label>
                        <input type="text" name="eep_company_name" required placeholder="<?php esc_attr_e('Company / Employer name', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_company_name'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Posted Date', 'nexdirectory'); ?></label>
                        <input type="date" name="eep_job_posted_date" value="<?php echo esc_attr((string) ($prefill['eep_job_posted_date'] ?? ($prefill_start_date !== '' ? $prefill_start_date : wp_date('Y-m-d')))); ?>">
                        <span class="eep-help-text"><?php esc_html_e('Used as listing publication date. Leave empty to use today.', 'nexdirectory'); ?></span>
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php echo esc_html($job_type_label); ?></label>
                        <select name="eep_job_type" required>
                            <option value=""><?php esc_html_e('Select employment type', 'nexdirectory'); ?></option>
                            <?php foreach (['Full-time', 'Part-time', 'Contract', 'Internship', 'Temporary', 'Freelance'] as $job_type_option) : ?>
                                <option value="<?php echo esc_attr($job_type_option); ?>" <?php selected((string) ($prefill['eep_job_type'] ?? ''), $job_type_option); ?>><?php echo esc_html($job_type_option); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Contract Duration (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_contract_duration" placeholder="<?php esc_attr_e('12 months, Permanent, 6-week project...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_contract_duration'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Work Location Type', 'nexdirectory'); ?></label>
                        <select name="eep_job_work_mode" required>
                            <option value=""><?php esc_html_e('Select location type', 'nexdirectory'); ?></option>
                            <option value="on-site" <?php selected((string) ($prefill['eep_job_work_mode'] ?? ''), 'on-site'); ?>><?php esc_html_e('On-site', 'nexdirectory'); ?></option>
                            <option value="hybrid" <?php selected((string) ($prefill['eep_job_work_mode'] ?? ''), 'hybrid'); ?>><?php esc_html_e('Hybrid', 'nexdirectory'); ?></option>
                            <option value="remote" <?php selected((string) ($prefill['eep_job_work_mode'] ?? ''), 'remote'); ?>><?php esc_html_e('Remote', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Working Hours (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_working_hours" placeholder="<?php esc_attr_e('Mon-Fri, 09:00-17:30', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_working_hours'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Department', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_department" required placeholder="<?php esc_attr_e('Event, Marketing, Operations...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_department'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Experience Level', 'nexdirectory'); ?></label>
                        <select name="eep_job_experience_level">
                            <option value=""><?php esc_html_e('Select experience level', 'nexdirectory'); ?></option>
                            <?php foreach (['Entry Level', 'Junior', 'Mid Level', 'Senior', 'Lead', 'Manager', 'Director'] as $experience_level_option) : ?>
                                <option value="<?php echo esc_attr($experience_level_option); ?>" <?php selected((string) ($prefill['eep_job_experience_level'] ?? ''), $experience_level_option); ?>><?php echo esc_html($experience_level_option); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>

                <h4 class="eep-subheading"><?php esc_html_e('Compensation & Benefits', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Set compensation details clearly so candidates can self-qualify quickly.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Compensation Type', 'nexdirectory'); ?></label>
                        <select name="eep_job_compensation_type" required>
                            <option value=""><?php esc_html_e('Select compensation type', 'nexdirectory'); ?></option>
                            <?php foreach (['Salary', 'Hourly', 'Contract / Day Rate', 'Commission', 'Volunteer'] as $compensation_option) : ?>
                                <option value="<?php echo esc_attr($compensation_option); ?>" <?php selected((string) ($prefill['eep_job_compensation_type'] ?? ''), $compensation_option); ?>><?php echo esc_html($compensation_option); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div>
                        <label><?php echo esc_html($salary_label); ?></label>
                        <input type="text" name="eep_job_salary" required placeholder="<?php esc_attr_e('e.g. £55,000 - £72,000 or £45/hour', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_salary'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Equity (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_equity" placeholder="<?php esc_attr_e('e.g. 0.2% - 0.5%', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_equity'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Bonus Structure (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_bonus" placeholder="<?php esc_attr_e('e.g. Annual performance bonus', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_bonus'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Reporting To (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_reporting_to" placeholder="<?php esc_attr_e('Head of Event', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_reporting_to'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Company Size (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_company_size" placeholder="<?php esc_attr_e('51-200 employees', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_company_size'] ?? '')); ?>">
                    </div>
                </div>

                <h4 class="eep-subheading"><?php esc_html_e('Application Timeline', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Control when applications close and when the role is expected to start.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Application Deadline', 'nexdirectory'); ?></label>
                        <input type="date" name="eep_job_closing_date" required value="<?php echo esc_attr((string) ($prefill['eep_job_closing_date'] ?? '')); ?>">
                        <span class="eep-help-text"><?php esc_html_e('Last date candidates can apply.', 'nexdirectory'); ?></span>
                    </div>
                    <div>
                        <label><?php esc_html_e('Expected Start Date (Optional)', 'nexdirectory'); ?></label>
                        <input type="date" name="eep_job_expected_start_date" value="<?php echo esc_attr((string) ($prefill['eep_job_expected_start_date'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Open Positions (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="eep_job_open_positions" min="0" step="1" placeholder="1" value="<?php echo esc_attr((string) ($prefill['eep_job_open_positions'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Remote Policy (Optional)', 'nexdirectory'); ?></label>
                        <?php $prefill_remote_policy = strtolower(trim((string) ($prefill['eep_job_remote_policy'] ?? ''))); ?>
                        <select name="eep_job_remote_policy">
                            <option value=""><?php esc_html_e('Select remote policy', 'nexdirectory'); ?></option>
                            <option value="On-site" <?php selected($prefill_remote_policy, 'on-site'); ?>><?php esc_html_e('On-site', 'nexdirectory'); ?></option>
                            <option value="Remote" <?php selected($prefill_remote_policy, 'remote'); ?>><?php esc_html_e('Remote', 'nexdirectory'); ?></option>
                            <option value="Hybrid" <?php selected($prefill_remote_policy, 'hybrid'); ?>><?php esc_html_e('Hybrid', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Visa Sponsorship', 'nexdirectory'); ?></label>
                        <select name="eep_job_visa_sponsorship">
                            <option value="0" <?php selected((string) ($prefill['eep_job_visa_sponsorship'] ?? '0'), '0'); ?>><?php esc_html_e('No', 'nexdirectory'); ?></option>
                            <option value="1" <?php selected((string) ($prefill['eep_job_visa_sponsorship'] ?? '0'), '1'); ?>><?php esc_html_e('Yes', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Industry (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_job_industry" placeholder="<?php esc_attr_e('SaaS, Fintech, Manufacturing...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_industry'] ?? '')); ?>">
                    </div>
                </div>

                <h4 class="eep-subheading"><?php esc_html_e('Apply & Company Links', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Provide one or more application channels plus your company website.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php echo esc_html($apply_url_label); ?></label>
                        <input type="url" name="eep_job_apply_url" placeholder="https://company.com/jobs/apply" value="<?php echo esc_attr((string) ($prefill['eep_job_apply_url'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Application Email (Optional)', 'nexdirectory'); ?></label>
                        <input type="email" name="eep_job_application_email" placeholder="<?php esc_attr_e('jobs@example.com', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_application_email'] ?? '')); ?>">
                    </div>
                </div>
                <span class="eep-help-text"><?php esc_html_e('At least one application method is required (URL or email).', 'nexdirectory'); ?></span>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Company Intro Video (Optional)', 'nexdirectory'); ?></label>
                        <input type="url" name="eep_job_company_intro_video" placeholder="https://www.youtube.com/watch?v=..." value="<?php echo esc_attr((string) ($prefill['eep_job_company_intro_video'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Role Overview Video (Optional)', 'nexdirectory'); ?></label>
                        <input type="url" name="eep_job_role_overview_video" placeholder="https://www.youtube.com/watch?v=..." value="<?php echo esc_attr((string) ($prefill['eep_job_role_overview_video'] ?? '')); ?>">
                    </div>
                </div>

                <h4 class="eep-subheading"><?php esc_html_e('Role Content', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Use these fields to present the role clearly to applicants.', 'nexdirectory'); ?></span>
                <label><?php esc_html_e('Skills / Keywords (Optional)', 'nexdirectory'); ?></label>
                <input type="text" name="eep_job_skills" placeholder="<?php esc_attr_e('PHP, React, Kubernetes, CRM...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_job_skills'] ?? '')); ?>">

                <label><?php esc_html_e('Responsibilities (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_job_responsibilities" rows="4" placeholder="<?php esc_attr_e('List the key responsibilities for this role.', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_job_responsibilities'] ?? '')); ?></textarea>

                <label><?php esc_html_e('Requirements (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_job_requirements" rows="4" placeholder="<?php esc_attr_e('Describe required experience, qualifications, and skills.', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_job_requirements'] ?? '')); ?></textarea>

                <label><?php esc_html_e('Benefits (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_job_benefits" rows="3" placeholder="<?php esc_attr_e('Health insurance, pension, bonus, flexible hours...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_job_benefits'] ?? '')); ?></textarea>

                <label><?php esc_html_e('Interview Process (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_job_interview_process" rows="3" placeholder="<?php esc_attr_e('Screening call, technical interview, final panel...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_job_interview_process'] ?? '')); ?></textarea>

                <label><?php esc_html_e('Recruitment Timeline (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_job_recruitment_timeline" rows="3" placeholder="<?php esc_attr_e('Week 1: screening, Week 2: interviews, Week 3: decision.', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_job_recruitment_timeline'] ?? '')); ?></textarea>
            <?php elseif ($is_directory_profile) : ?>
                <h4 class="eep-subheading"><?php esc_html_e('Business Profile', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Set the core business profile details shown on the public listing page.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php echo esc_html($company_label); ?></label>
                        <input type="text" name="eep_company_name" required placeholder="<?php esc_attr_e('Business / Organization name', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_company_name'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Business Type', 'nexdirectory'); ?></label>
                        <?php $directory_business_type = sanitize_key((string) ($prefill['eep_directory_business_type'] ?? 'independent-business')); ?>
                        <select name="eep_directory_business_type">
                            <option value="independent-business" <?php selected($directory_business_type, 'independent-business'); ?>><?php esc_html_e('Independent Business', 'nexdirectory'); ?></option>
                            <option value="agency" <?php selected($directory_business_type, 'agency'); ?>><?php esc_html_e('Agency', 'nexdirectory'); ?></option>
                            <option value="private-owner" <?php selected($directory_business_type, 'private-owner'); ?>><?php esc_html_e('Private Owner', 'nexdirectory'); ?></option>
                            <option value="nonprofit" <?php selected($directory_business_type, 'nonprofit'); ?>><?php esc_html_e('Nonprofit / Community', 'nexdirectory'); ?></option>
                            <option value="multi-location" <?php selected($directory_business_type, 'multi-location'); ?>><?php esc_html_e('Multi-location Brand', 'nexdirectory'); ?></option>
                            <option value="franchise" <?php selected($directory_business_type, 'franchise'); ?>><?php esc_html_e('Franchise', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Listing Status', 'nexdirectory'); ?></label>
                        <?php $directory_listing_status = sanitize_key((string) ($prefill['eep_directory_listing_status'] ?? 'active')); ?>
                        <select name="eep_directory_listing_status">
                            <option value="active" <?php selected($directory_listing_status, 'active'); ?>><?php esc_html_e('Active', 'nexdirectory'); ?></option>
                            <option value="temporarily-closed" <?php selected($directory_listing_status, 'temporarily-closed'); ?>><?php esc_html_e('Temporarily Closed', 'nexdirectory'); ?></option>
                            <option value="permanently-closed" <?php selected($directory_listing_status, 'permanently-closed'); ?>><?php esc_html_e('Permanently Closed', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Contact Person (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_directory_contact_person" placeholder="<?php esc_attr_e('Owner, manager, support lead...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_directory_contact_person'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Service Area (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_directory_service_area" placeholder="<?php esc_attr_e('London + 25 miles, Nationwide, Global...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_directory_service_area'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Operating Hours (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_directory_operating_hours" placeholder="<?php esc_attr_e('Mon-Fri 09:00-18:00', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_directory_operating_hours'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-3">
                    <div>
                        <label><?php esc_html_e('Typical Response Time (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_directory_response_time" placeholder="<?php esc_attr_e('Within 2 hours', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_directory_response_time'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Established Year (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="eep_directory_established_year" min="1800" step="1" placeholder="<?php echo esc_attr((string) wp_date('Y')); ?>" value="<?php echo esc_attr((string) ($prefill['eep_directory_established_year'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Pricing Summary (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_directory_pricing_summary" placeholder="<?php esc_attr_e('Free quote, From £70/hr, Custom pricing...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_directory_pricing_summary'] ?? '')); ?>">
                    </div>
                </div>

                <h4 class="eep-subheading"><?php esc_html_e('Links & Services', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Add direct contact/action links and service details for better conversion.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Appointment / Booking URL (Optional)', 'nexdirectory'); ?></label>
                        <input type="url" name="eep_directory_appointment_url" placeholder="https://www.example.com/book" value="<?php echo esc_attr((string) ($prefill['eep_directory_appointment_url'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('WhatsApp URL (Optional)', 'nexdirectory'); ?></label>
                        <input type="url" name="eep_directory_whatsapp_url" placeholder="https://wa.me/44123456789" value="<?php echo esc_attr((string) ($prefill['eep_directory_whatsapp_url'] ?? '')); ?>">
                    </div>
                </div>

                <label><?php esc_html_e('Services Offered (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_directory_services" rows="3" placeholder="<?php esc_attr_e('List your primary services or offerings.', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_directory_services'] ?? '')); ?></textarea>

                <label><?php esc_html_e('Highlights (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_directory_highlights" rows="3" placeholder="<?php esc_attr_e('What makes this listing stand out?', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_directory_highlights'] ?? '')); ?></textarea>

                <label><?php esc_html_e('Certifications / Credentials (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_directory_certifications" rows="3" placeholder="<?php esc_attr_e('ISO, licensed, insured, certified partner...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_directory_certifications'] ?? '')); ?></textarea>
            <?php elseif ($is_marketplace_profile) : ?>
                <h4 class="eep-subheading"><?php esc_html_e('Listing Basics', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Set clear pricing and condition details so buyers can decide quickly.', 'nexdirectory'); ?></span>
                <div class="eep-grid-2">
                    <div>
                        <label><?php echo esc_html($condition_label); ?></label>
                        <select name="eep_market_condition" required>
                            <option value=""><?php esc_html_e('Select condition', 'nexdirectory'); ?></option>
                            <?php foreach (['New', 'Like New', 'Used', 'Refurbished', 'For Parts'] as $condition_option) : ?>
                                <option value="<?php echo esc_attr($condition_option); ?>" <?php selected((string) ($prefill['eep_market_condition'] ?? ''), $condition_option); ?>><?php echo esc_html($condition_option); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Price Type', 'nexdirectory'); ?></label>
                        <?php $market_price_type_prefill = sanitize_key((string) ($prefill['eep_market_price_type'] ?? 'fixed')); ?>
                        <select name="eep_market_price_type" required>
                            <option value="fixed" <?php selected($market_price_type_prefill, 'fixed'); ?>><?php esc_html_e('Fixed', 'nexdirectory'); ?></option>
                            <option value="negotiable" <?php selected($market_price_type_prefill, 'negotiable'); ?>><?php esc_html_e('Negotiable', 'nexdirectory'); ?></option>
                            <option value="auction" <?php selected($market_price_type_prefill, 'auction'); ?>><?php esc_html_e('Auction', 'nexdirectory'); ?></option>
                            <option value="free" <?php selected($market_price_type_prefill, 'free'); ?>><?php esc_html_e('Free', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                </div>

                <div class="eep-grid-3">
                    <div>
                        <label><?php echo esc_html($price_input_label); ?></label>
                        <input type="text" name="eep_price" placeholder="<?php echo esc_attr($price_input_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_price'] ?? '')); ?>">
                        <span class="eep-help-text"><?php esc_html_e('Required unless Price Type is Free.', 'nexdirectory'); ?></span>
                    </div>
                    <div>
                        <label><?php esc_html_e('Quantity (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="eep_market_quantity" min="0" step="1" placeholder="1" value="<?php echo esc_attr((string) ($prefill['eep_market_quantity'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('SKU (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_market_sku" placeholder="<?php esc_attr_e('SKU-123', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_market_sku'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-3">
                    <div>
                        <label><?php esc_html_e('Brand (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_market_brand" placeholder="<?php esc_attr_e('Apple, Sony, IKEA...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_market_brand'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Model (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_market_model" placeholder="<?php esc_attr_e('Model number / variant', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_market_model'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Year (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="eep_market_year" min="1900" step="1" placeholder="<?php echo esc_attr((string) wp_date('Y')); ?>" value="<?php echo esc_attr((string) ($prefill['eep_market_year'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-3">
                    <div>
                        <label><?php esc_html_e('Seller Type', 'nexdirectory'); ?></label>
                        <?php $market_seller_type = sanitize_key((string) ($prefill['eep_market_seller_type'] ?? 'private')); ?>
                        <select name="eep_market_seller_type">
                            <option value="private" <?php selected($market_seller_type, 'private'); ?>><?php esc_html_e('Private Seller', 'nexdirectory'); ?></option>
                            <option value="business" <?php selected($market_seller_type, 'business'); ?>><?php esc_html_e('Business Seller', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Listing Status', 'nexdirectory'); ?></label>
                        <?php $market_listing_status = sanitize_key((string) ($prefill['eep_market_listing_status'] ?? 'active')); ?>
                        <select name="eep_market_listing_status">
                            <option value="active" <?php selected($market_listing_status, 'active'); ?>><?php esc_html_e('Active', 'nexdirectory'); ?></option>
                            <option value="reserved" <?php selected($market_listing_status, 'reserved'); ?>><?php esc_html_e('Reserved', 'nexdirectory'); ?></option>
                            <option value="sold" <?php selected($market_listing_status, 'sold'); ?>><?php esc_html_e('Sold', 'nexdirectory'); ?></option>
                            <option value="expired" <?php selected($market_listing_status, 'expired'); ?>><?php esc_html_e('Expired', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Expiry Date (Optional)', 'nexdirectory'); ?></label>
                        <input type="date" name="eep_market_expires_on" value="<?php echo esc_attr((string) ($prefill['eep_market_expires_on'] ?? '')); ?>">
                    </div>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Accept Offers', 'nexdirectory'); ?></label>
                        <select name="eep_market_accept_offers">
                            <option value="1" <?php selected((string) ($prefill['eep_market_accept_offers'] ?? '1'), '1'); ?>><?php esc_html_e('Yes', 'nexdirectory'); ?></option>
                            <option value="0" <?php selected((string) ($prefill['eep_market_accept_offers'] ?? '1'), '0'); ?>><?php esc_html_e('No', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('Payment Methods Accepted (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="eep_market_payment_methods" placeholder="<?php esc_attr_e('Cash, Bank transfer, PayPal...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_market_payment_methods'] ?? '')); ?>">
                    </div>
                </div>

                <h4 class="eep-subheading"><?php esc_html_e('Delivery & Returns', 'nexdirectory'); ?></h4>
                <span class="eep-help-text"><?php esc_html_e('Choose one or more delivery methods and set buyer expectations.', 'nexdirectory'); ?></span>
                <?php
                $delivery_prefill_raw = (string) ($prefill['eep_market_delivery_methods'] ?? '');
                $delivery_prefill_parts = preg_split('/[\s,]+/', $delivery_prefill_raw);
                $delivery_prefill = [];
                if (is_array($delivery_prefill_parts)) {
                    $delivery_prefill = array_values(array_unique(array_filter(array_map('sanitize_key', $delivery_prefill_parts))));
                }
                ?>
                <div class="eep-checkbox-grid">
                    <?php
                    $delivery_options = [
                        'pickup' => __('Pickup', 'nexdirectory'),
                        'shipping' => __('Shipping', 'nexdirectory'),
                        'local-delivery' => __('Local Delivery', 'nexdirectory'),
                        'digital' => __('Digital Delivery', 'nexdirectory'),
                    ];
                    foreach ($delivery_options as $delivery_key => $delivery_label) :
                    ?>
                        <label class="eep-checkbox-chip">
                            <input type="checkbox" name="eep_market_delivery_methods[]" value="<?php echo esc_attr($delivery_key); ?>" <?php checked(in_array($delivery_key, $delivery_prefill, true)); ?>>
                            <span><?php echo esc_html($delivery_label); ?></span>
                        </label>
                    <?php endforeach; ?>
                </div>

                <div class="eep-grid-2">
                    <div>
                        <label><?php esc_html_e('Returns Accepted', 'nexdirectory'); ?></label>
                        <select name="eep_market_returns_accepted">
                            <option value="0" <?php selected((string) ($prefill['eep_market_returns_accepted'] ?? '0'), '0'); ?>><?php esc_html_e('No', 'nexdirectory'); ?></option>
                            <option value="1" <?php selected((string) ($prefill['eep_market_returns_accepted'] ?? '0'), '1'); ?>><?php esc_html_e('Yes', 'nexdirectory'); ?></option>
                        </select>
                    </div>
                    <div>
                        <label><?php esc_html_e('External Listing URL (Optional)', 'nexdirectory'); ?></label>
                        <input type="url" name="eep_external_url" placeholder="https://www.example.com/listing" value="<?php echo esc_attr((string) ($prefill['eep_external_url'] ?? '')); ?>">
                    </div>
                </div>
                <label><?php esc_html_e('Condition Notes (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_market_condition_notes" rows="3" placeholder="<?php esc_attr_e('State defects, wear, included accessories, warranty notes...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_market_condition_notes'] ?? '')); ?></textarea>
                <label><?php esc_html_e('Delivery / Collection Notes (Optional)', 'nexdirectory'); ?></label>
                <textarea name="eep_market_shipping_notes" rows="3" placeholder="<?php esc_attr_e('Collection window, shipping zones, delivery fees, returns policy...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['eep_market_shipping_notes'] ?? '')); ?></textarea>
            <?php endif; ?>

            <?php if ($is_job_profile) : ?>
                <label><?php esc_html_e('Company Website (Optional)', 'nexdirectory'); ?></label>
                <input type="url" name="eep_job_company_website" placeholder="https://www.example.com" value="<?php echo esc_attr((string) (($prefill['eep_job_company_website'] ?? '') !== '' ? $prefill['eep_job_company_website'] : ($prefill['eep_external_url'] ?? ''))); ?>">
                <input type="hidden" name="eep_external_url" value="<?php echo esc_attr((string) ($prefill['eep_external_url'] ?? '')); ?>">
            <?php elseif ($is_marketplace_profile) : ?>
                <input type="hidden" name="eep_event_stream_url" value="">
            <?php else : ?>
                <div class="eep-grid-2">
                    <div>
                        <label><?php echo esc_html(sprintf(__('%s Website (Optional)', 'nexdirectory'), $singular_label)); ?></label>
                        <input type="url" name="eep_external_url" placeholder="https://www.example.com" value="<?php echo esc_attr((string) ($prefill['eep_external_url'] ?? '')); ?>">
                    </div>
                    <?php if ($show_stream_field) : ?>
                        <div x-show="modeOption === 'video-stream'">
                            <label><?php echo esc_html($stream_label); ?></label>
                            <input type="url" name="eep_event_stream_url" x-model="streamUrl" x-init="streamUrl = $el.value || streamUrl" @input="syncVideoUrls" placeholder="<?php echo esc_attr($stream_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['eep_event_stream_url'] ?? '')); ?>">
                        </div>
                    <?php else : ?>
                        <input type="hidden" name="eep_event_stream_url" value="">
                    <?php endif; ?>
                </div>
            <?php endif; ?>

            <label><?php echo esc_html($type_optional_label); ?></label>
            <?php
            wp_dropdown_categories([
                'taxonomy' => $this::TAX_TYPE,
                'name' => 'event_type',
                'show_option_none' => $is_job_profile
                    ? __('Select Job Category', 'nexdirectory')
                    : ($is_marketplace_profile ? __('Select Listing Category', 'nexdirectory') : __('Select Category', 'nexdirectory')),
                'hide_empty' => false,
                'selected' => (int) ($prefill['event_type_term_id'] ?? 0),
            ]);
            ?>

            <?php if ($show_date_block) : ?>
                <div class="eep-grid-3">
                    <div>
                        <label><?php echo esc_html(sprintf(__('%s Start Date (From)', 'nexdirectory'), $singular_label)); ?></label>
                        <input type="date" name="eep_start_date" required x-model="startValue" x-init="startValue = $el.value || startValue" @input="validateDates" @change="validateDates" value="<?php echo esc_attr($prefill_start_date); ?>">
                        <label><?php esc_html_e('Start Time (Optional)', 'nexdirectory'); ?></label>
                        <input type="time" name="eep_start_time" x-model="startTimeValue" x-init="startTimeValue = $el.value || startTimeValue" @input="validateDates" @change="validateDates" value="<?php echo esc_attr($prefill_start_time); ?>">
                    </div>
                    <div>
                        <label><?php echo esc_html(sprintf(__('%s End Date (To)', 'nexdirectory'), $singular_label)); ?></label>
                        <input type="date" name="eep_end_date" x-model="endValue" x-init="endValue = $el.value || endValue" @input="validateDates" @change="validateDates" value="<?php echo esc_attr($prefill_end_date); ?>">
                        <label><?php esc_html_e('End Time (Optional)', 'nexdirectory'); ?></label>
                        <input type="time" name="eep_end_time" x-model="endTimeValue" x-init="endTimeValue = $el.value || endTimeValue" @input="validateDates" @change="validateDates" value="<?php echo esc_attr($prefill_end_time); ?>">
                        <span class="eep-help-text"><?php echo esc_html(sprintf(__('If To date is empty, we treat it as a one-day %s.', 'nexdirectory'), $singular_lower)); ?></span>
                    </div>
                    <div>
                        <label><?php esc_html_e('Timezone', 'nexdirectory'); ?></label>
                        <?php echo $this->render_timezone_dropdown('eep_timezone', (string) ($prefill['eep_timezone'] ?? '')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
                        <span class="eep-help-text"><?php esc_html_e('Automatically detected from your browser when empty.', 'nexdirectory'); ?></span>
                    </div>
                </div>
                <p class="eep-validation-error" x-show="dateError" x-text="dateError"></p>
                <p class="eep-validation-warning" x-show="dateWarning" x-text="dateWarning"></p>
                <p class="eep-validation-warning" x-show="timeWarning" x-text="timeWarning"></p>
                <p class="eep-meta" x-show="timezoneHint" x-text="timezoneHint"></p>
            <?php endif; ?>

            <div class="eep-grid-3">
                <?php if ($show_capacity_field) : ?>
                    <div>
                        <label><?php esc_html_e('Capacity (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="eep_capacity" min="0" value="<?php echo esc_attr((string) ($prefill['eep_capacity'] ?? '')); ?>">
                    </div>
                <?php endif; ?>
            </div>

            <?php if ($is_events_profile) : ?>
                <div class="eep-ticket-settings" x-data="{ ticketEnabled: <?php echo ((string) ($prefill['eep_ticket_sales_enabled'] ?? '0') === '1') ? 'true' : 'false'; ?> }">
                    <input type="hidden" name="eep_ticket_sales_enabled" :value="ticketEnabled ? '1' : '0'">
                    <label class="eep-inline-check">
                        <input type="checkbox" x-model="ticketEnabled">
                        <span><?php esc_html_e('Enable ticket sales for this event', 'nexdirectory'); ?></span>
                    </label>
                    <span class="eep-help-text"><?php esc_html_e('Set ticket price to 0 for free ticket reservations.', 'nexdirectory'); ?></span>
                    <div class="eep-grid-2" x-show="ticketEnabled" x-cloak>
                        <div>
                            <label><?php esc_html_e('Ticket Price', 'nexdirectory'); ?></label>
                            <input type="number" name="eep_ticket_price" min="0" step="0.01" placeholder="0.00" value="<?php echo esc_attr((string) ($prefill['eep_ticket_price'] ?? '')); ?>">
                        </div>
                        <div>
                            <label><?php esc_html_e('Ticket Button Label (Optional)', 'nexdirectory'); ?></label>
                            <input type="text" name="eep_ticket_button_label" maxlength="80" placeholder="<?php esc_attr_e('Buy Tickets', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['eep_ticket_button_label'] ?? '')); ?>">
                        </div>
                    </div>
                </div>
            <?php endif; ?>

            <?php if ($show_official_classification) : ?>
                <label><?php echo esc_html(sprintf(__('Official %s?', 'nexdirectory'), $singular_label)); ?></label>
                <select name="eep_official_event">
                    <option value="0" <?php selected((string) ($prefill['eep_official_event'] ?? '0'), '0'); ?>><?php echo esc_html((string) ($classification_labels['unofficial'] ?? __('Unofficial Event', 'nexdirectory'))); ?></option>
                    <option value="1" <?php selected((string) ($prefill['eep_official_event'] ?? '0'), '1'); ?>><?php echo esc_html((string) ($classification_labels['official'] ?? __('Official Event', 'nexdirectory'))); ?></option>
                </select>
                <span class="eep-help-text"><?php echo esc_html($official_pending_note); ?></span>
            <?php else : ?>
                <input type="hidden" name="eep_official_event" value="0">
            <?php endif; ?>

            <label><?php echo esc_html(sprintf(__('%s (Optional)', 'nexdirectory'), $tag_label)); ?></label>
            <input type="text" name="event_tags" maxlength="360" placeholder="<?php echo esc_attr($tags_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['event_tags'] ?? '')); ?>">
            <span class="eep-help-text"><?php echo esc_html($tags_help); ?></span>

            <?php foreach ($custom_taxonomy_fields as $taxonomy_field) : ?>
                <?php
                $taxonomy_slug = sanitize_key((string) ($taxonomy_field['slug'] ?? ''));
                $taxonomy_label = sanitize_text_field((string) ($taxonomy_field['label'] ?? $taxonomy_slug));
                $taxonomy_terms = isset($taxonomy_field['terms']) && is_array($taxonomy_field['terms']) ? $taxonomy_field['terms'] : [];
                $selected_ids = array_values(array_filter(array_map('absint', (array) ($taxonomy_field['selected_ids'] ?? []))));
                if ($taxonomy_slug === '' || empty($taxonomy_terms)) {
                    continue;
                }
                ?>
                <label for="eep-tax-<?php echo esc_attr($taxonomy_slug); ?>"><?php echo esc_html($taxonomy_label); ?></label>
                <select id="eep-tax-<?php echo esc_attr($taxonomy_slug); ?>" name="eep_tax_<?php echo esc_attr($taxonomy_slug); ?>[]" multiple size="<?php echo esc_attr((string) min(max(count($taxonomy_terms), 3), 8)); ?>">
                    <?php foreach ($taxonomy_terms as $term_obj) : ?>
                        <?php if (!$term_obj instanceof WP_Term) { continue; } ?>
                        <option value="<?php echo esc_attr((string) $term_obj->term_id); ?>" <?php selected(in_array((int) $term_obj->term_id, $selected_ids, true)); ?>>
                            <?php echo esc_html((string) $term_obj->name); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <span class="eep-help-text"><?php esc_html_e('Hold Ctrl/Cmd to select multiple options.', 'nexdirectory'); ?></span>
            <?php endforeach; ?>

            <?php if ($show_schedule_builder) : ?>
                <label><?php echo esc_html($itinerary_toggle_label); ?></label>
                <div class="eep-radio-group">
                    <input type="radio" id="eep-recurring-no" name="eep_is_recurring" value="0" <?php checked((string) ($prefill['eep_is_recurring'] ?? '0'), '0'); ?> x-model="isRecurring" @change="sessions = []; syncRecurrenceMeta();">
                    <label for="eep-recurring-no"><?php esc_html_e('No', 'nexdirectory'); ?></label>
                    <input type="radio" id="eep-recurring-yes" name="eep_is_recurring" value="1" <?php checked((string) ($prefill['eep_is_recurring'] ?? '0'), '1'); ?> x-model="isRecurring" @change="syncRecurrenceMeta">
                    <label for="eep-recurring-yes"><?php esc_html_e('Yes', 'nexdirectory'); ?></label>
                </div>

                <div class="eep-session-builder" x-show="isRecurring === '1'">
                    <h4><?php echo esc_html($session_heading); ?></h4>
                    <span class="eep-help-text"><?php echo esc_html($session_help); ?></span>
                    <template x-for="(session, index) in sessions" :key="index">
                        <div class="eep-inline-date-card">
                            <div class="eep-grid-2">
                                <div>
                                    <label><?php echo esc_html($session_title_label); ?></label>
                                    <input type="text" x-model="session.title" @input="syncRecurrenceMeta" placeholder="<?php echo esc_attr($session_title_placeholder); ?>">
                                </div>
                                <div>
                                    <label><?php echo esc_html($session_location_label); ?></label>
                                    <input type="text" x-model="session.location" @input="syncRecurrenceMeta" placeholder="<?php echo esc_attr($session_location_placeholder); ?>">
                                </div>
                            </div>
                            <div class="eep-grid-2">
                                <div>
                                    <label><?php esc_html_e('Speaker', 'nexdirectory'); ?></label>
                                    <input type="text" x-model="session.speaker" @input="syncRecurrenceMeta" placeholder="<?php esc_attr_e('Speaker Name', 'nexdirectory'); ?>">
                                </div>
                                <div>
                                    <label><?php esc_html_e('Day Label (Optional)', 'nexdirectory'); ?></label>
                                    <input type="text" x-model="session.day" @input="syncRecurrenceMeta" placeholder="<?php esc_attr_e('Day 1 or Jun 9, 2026', 'nexdirectory'); ?>">
                                </div>
                            </div>
                            <div class="eep-grid-2">
                                <div>
                                    <label><?php esc_html_e('From', 'nexdirectory'); ?></label>
                                    <input type="datetime-local" x-model="session.start" @input="syncRecurrenceMeta">
                                </div>
                                <div>
                                    <label><?php esc_html_e('To', 'nexdirectory'); ?></label>
                                    <input type="datetime-local" x-model="session.end" @input="syncRecurrenceMeta">
                                </div>
                            </div>
                            <div>
                                <label><?php esc_html_e('Notes (Optional)', 'nexdirectory'); ?></label>
                                <textarea x-model="session.notes" @input="syncRecurrenceMeta" rows="3" placeholder="<?php esc_attr_e('Add session notes, reminders, or key points.', 'nexdirectory'); ?>"></textarea>
                            </div>
                            <div>
                                <label><?php esc_html_e('Attachment URLs (Optional)', 'nexdirectory'); ?></label>
                                <textarea x-model="session.attachments" @input="syncRecurrenceMeta" rows="3" placeholder="<?php esc_attr_e('One URL per line (file URL, image URL, or YouTube URL)', 'nexdirectory'); ?>"></textarea>
                                <div class="eep-help-text" style="margin-top:8px;">
                                    <?php esc_html_e('You can upload files, pick existing media, or paste direct URLs and YouTube links.', 'nexdirectory'); ?>
                                </div>
                                <div class="eep-inline-actions" style="margin-top:8px; display:flex; flex-wrap:wrap; gap:8px;">
                                    <button type="button" class="eep-btn eep-btn-secondary" @click="triggerSessionAttachmentInput(index)">
                                        <?php esc_html_e('Upload File', 'nexdirectory'); ?>
                                    </button>
                                    <button type="button" class="eep-btn eep-btn-secondary" @click="openSessionAttachmentMediaPicker(index)">
                                        <?php esc_html_e('Media Library', 'nexdirectory'); ?>
                                    </button>
                                </div>
                                <input type="file" class="eep-session-attachment-upload" :id="'eep-session-attachment-upload-' + index" @change="handleSessionAttachmentUpload($event, index)" multiple accept="image/*,video/*,.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.zip,.csv,.json,.rtf,.odt,.ods,.odp,.mp4,.mov,.webm,.m4v,.avi,.mkv" style="display:none;">
                            </div>
                            <button type="button" class="eep-btn eep-btn-danger" @click="removeSession(index)"><?php echo esc_html($session_remove_label); ?></button>
                        </div>
                    </template>
                    <button type="button" class="eep-btn eep-btn-secondary" @click="addSession()"><?php echo esc_html($session_heading); ?></button>
                </div>
            <?php else : ?>
                <input type="hidden" name="eep_is_recurring" value="0">
            <?php endif; ?>
        </section>

        <?php if ($custom_fields_enabled) : ?>
            <section id="eep-section-custom-fields" class="eep-form-section" data-eep-custom-builder>
                <h3><?php esc_html_e('Additional Submission Fields', 'nexdirectory'); ?></h3>
                <span class="eep-help-text"><?php echo esc_html(sprintf(__('Add any extra fields this %s needs. These fields and values render automatically on the details page.', 'nexdirectory'), $singular_lower)); ?></span>
                <div class="eep-custom-fields-wrap eep-custom-fields-wrap-submit">
                    <table class="eep-custom-fields-table">
                        <thead>
                            <tr>
                                <th style="width: 10%;"><?php esc_html_e('Field Key', 'nexdirectory'); ?></th>
                                <th style="width: 13%;"><?php esc_html_e('Label', 'nexdirectory'); ?></th>
                                <th style="width: 11%;"><?php esc_html_e('Type', 'nexdirectory'); ?></th>
                                <th style="width: 21%;"><?php esc_html_e('Value', 'nexdirectory'); ?></th>
                                <th style="width: 10%;"><?php esc_html_e('Placeholder', 'nexdirectory'); ?></th>
                                <th style="width: 12%;"><?php esc_html_e('Help Text', 'nexdirectory'); ?></th>
                                <th style="width: 13%;"><?php esc_html_e('Select Options', 'nexdirectory'); ?></th>
                                <th style="width: 6%;"><?php esc_html_e('Flags', 'nexdirectory'); ?></th>
                                <th style="width: 4%;"><?php esc_html_e('Action', 'nexdirectory'); ?></th>
                            </tr>
                        </thead>
                        <tbody id="eep-custom-builder-body">
                            <?php if (empty($custom_builder_rows)) : ?>
                                <tr class="eep-custom-fields-empty-row">
                                    <td colspan="9" class="eep-custom-fields-empty"><?php esc_html_e('No additional fields yet. Click Add Field to create one.', 'nexdirectory'); ?></td>
                                </tr>
                            <?php else : ?>
                                <?php foreach ($custom_builder_rows as $row) : ?>
                                    <?php
                                    $row_id = sanitize_key((string) ($row['id'] ?? ''));
                                    $row_type = sanitize_key((string) ($row['type'] ?? 'text'));
                                    if (!isset($custom_field_types[$row_type])) {
                                        $row_type = 'text';
                                    }
                                    $row_value = (string) ($row['value'] ?? '');
                                    $row_placeholder = sanitize_text_field((string) ($row['placeholder'] ?? ''));
                                    ?>
                                    <tr class="eep-custom-field-row eep-custom-builder-row">
                                        <td><input type="text" class="eep-cbf-id" value="<?php echo esc_attr($row_id); ?>" placeholder="<?php esc_attr_e('field_key', 'nexdirectory'); ?>"></td>
                                        <td><input type="text" class="eep-cbf-label" value="<?php echo esc_attr((string) ($row['label'] ?? '')); ?>" placeholder="<?php esc_attr_e('Field Label', 'nexdirectory'); ?>"></td>
                                        <td>
                                            <select class="eep-cbf-type">
                                                <?php foreach ($custom_field_types as $type_key => $type_label) : ?>
                                                    <option value="<?php echo esc_attr((string) $type_key); ?>" <?php selected((string) $row_type, (string) $type_key); ?>><?php echo esc_html((string) $type_label); ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </td>
                                        <td class="eep-cbf-value-wrap">
                                            <?php if ($row_type === 'textarea' || $row_type === 'wysiwyg' || $row_type === 'gallery') : ?>
                                                <textarea class="eep-cbf-value" rows="3" placeholder="<?php esc_attr_e('Value', 'nexdirectory'); ?>"><?php echo esc_textarea($row_value); ?></textarea>
                                            <?php elseif ($row_type === 'checkbox') : ?>
                                                <select class="eep-cbf-value">
                                                    <option value="0" <?php selected((string) $row_value, '0'); ?>><?php esc_html_e('No', 'nexdirectory'); ?></option>
                                                    <option value="1" <?php selected((string) $row_value, '1'); ?>><?php esc_html_e('Yes', 'nexdirectory'); ?></option>
                                                </select>
                                            <?php else : ?>
                                                <?php
                                                $value_input_type = in_array($row_type, ['url', 'email', 'number', 'date', 'datetime-local'], true) ? $row_type : 'text';
                                                $display_value = $row_value;
                                                if ($value_input_type === 'datetime-local' && strpos((string) $display_value, ' ') !== false) {
                                                    $display_value = str_replace(' ', 'T', substr((string) $display_value, 0, 16));
                                                }
                                                ?>
                                                <input type="<?php echo esc_attr($value_input_type); ?>" class="eep-cbf-value" value="<?php echo esc_attr($display_value); ?>" placeholder="<?php echo esc_attr($row_placeholder !== '' ? $row_placeholder : __('Value', 'nexdirectory')); ?>">
                                            <?php endif; ?>
                                        </td>
                                        <td><input type="text" class="eep-cbf-placeholder" value="<?php echo esc_attr($row_placeholder); ?>" placeholder="<?php esc_attr_e('Optional placeholder', 'nexdirectory'); ?>"></td>
                                        <td><input type="text" class="eep-cbf-help" value="<?php echo esc_attr((string) ($row['help'] ?? '')); ?>" placeholder="<?php esc_attr_e('Short instruction', 'nexdirectory'); ?>"></td>
                                        <td><textarea class="eep-cbf-options" rows="2" placeholder="<?php esc_attr_e('One option per line', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($row['options'] ?? '')); ?></textarea></td>
                                        <td>
                                            <label style="display:block;"><input type="checkbox" class="eep-cbf-required" value="1" <?php checked((string) ($row['required'] ?? '0'), '1'); ?>> <?php esc_html_e('Req', 'nexdirectory'); ?></label>
                                            <label style="display:block;"><input type="checkbox" class="eep-cbf-show" value="1" <?php checked((string) ($row['show_in_event'] ?? '1'), '1'); ?>> <?php esc_html_e('Show', 'nexdirectory'); ?></label>
                                        </td>
                                        <td><button type="button" class="button button-link-delete eep-cbf-remove"><?php esc_html_e('Remove', 'nexdirectory'); ?></button></td>
                                    </tr>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
                <div class="eep-custom-fields-controls">
                    <button type="button" class="eep-btn eep-btn-secondary" id="eep-custom-builder-add"><?php esc_html_e('Add Field', 'nexdirectory'); ?></button>
                    <span class="eep-help-text"><?php esc_html_e('Supports text, textarea, rich text, URL/email, select, checkbox, and media URL based fields.', 'nexdirectory'); ?></span>
                </div>
            </section>
        <?php endif; ?>

            <?php if ($show_video_embeds_section) : ?>
            <section id="eep-section-videos" class="eep-form-section">
                <h3><?php echo esc_html(($is_marketplace_profile || $is_directory_profile) ? __('Videos', 'nexdirectory') : __('Video Embeds', 'nexdirectory')); ?></h3>
                <span class="eep-help-text"><?php echo esc_html($is_marketplace_profile ? __('Add optional product demo or walkthrough videos (YouTube URLs or IDs).', 'nexdirectory') : __('Add unlimited video URLs or YouTube IDs.', 'nexdirectory')); ?></span>
                <div class="eep-video-repeater">
                    <template x-for="(video, index) in videoEmbeds" :key="index">
                        <div class="eep-video-row">
                            <input type="text" x-model="videoEmbeds[index]" @input="syncVideoUrls" placeholder="<?php esc_attr_e('https://youtube.com/watch?v=... or YouTube ID', 'nexdirectory'); ?>">
                            <button type="button" class="eep-btn eep-btn-danger" @click="removeVideoEmbed(index)"><?php esc_html_e('Remove', 'nexdirectory'); ?></button>
                        </div>
                    </template>
                    <button type="button" class="eep-btn eep-btn-secondary" @click="addVideoEmbed()"><?php esc_html_e('Add Video', 'nexdirectory'); ?></button>
                </div>
            </section>
        <?php endif; ?>

        <?php if ($per_event_email_templates_enabled) : ?>
            <section id="eep-section-email-templates" class="eep-form-section">
                <h3><?php echo esc_html(sprintf(__('Per-%s Email Templates (Optional)', 'nexdirectory'), $singular_label)); ?></h3>
                <span class="eep-help-text"><?php echo esc_html($email_tokens_help); ?></span>
                <div class="eep-email-template-notes">
                    <p><strong><?php esc_html_e('Confirmation', 'nexdirectory'); ?>:</strong> <?php echo esc_html(sprintf(__('Sent to the %1$s owner after submission/update when status becomes Pending review.', 'nexdirectory'), $singular_lower)); ?></p>
                    <?php if ($is_events_profile) : ?>
                        <p><strong><?php esc_html_e('Reminder', 'nexdirectory'); ?>:</strong> <?php esc_html_e('Sent to attendees who RSVPed Yes about 24 hours before event start.', 'nexdirectory'); ?></p>
                    <?php else : ?>
                        <p><strong><?php esc_html_e('Reminder', 'nexdirectory'); ?>:</strong> <?php esc_html_e('Not used in this mode.', 'nexdirectory'); ?></p>
                    <?php endif; ?>
                    <p><strong><?php esc_html_e('Update', 'nexdirectory'); ?>:</strong> <?php echo esc_html(sprintf(__('Sent to the %1$s owner when moderation changes %2$s status to Published.', 'nexdirectory'), $singular_lower, $singular_lower)); ?></p>
                    <p><strong><?php esc_html_e('Cancellation', 'nexdirectory'); ?>:</strong> <?php echo esc_html(sprintf(__('Sent to the %1$s owner when moderation rejects/cancels the %2$s.', 'nexdirectory'), $singular_lower, $singular_lower)); ?></p>
                </div>

                <div class="eep-email-template-grid">
                    <div class="eep-email-template-card">
                        <label><?php esc_html_e('Confirmation Subject', 'nexdirectory'); ?></label>
                        <span class="eep-help-text"><?php echo esc_html(sprintf(__('Trigger: submission/update to pending. Recipient: %s owner.', 'nexdirectory'), $singular_lower)); ?></span>
                        <input type="text" name="eep_email_subject_confirmation" value="<?php echo esc_attr((string) ($prefill['eep_email_subject_confirmation'] ?? '')); ?>">
                        <label><?php esc_html_e('Confirmation Body', 'nexdirectory'); ?></label>
                        <textarea name="eep_email_body_confirmation" rows="4"><?php echo esc_textarea((string) ($prefill['eep_email_body_confirmation'] ?? '')); ?></textarea>
                    </div>
                    <?php if ($is_events_profile) : ?>
                        <div class="eep-email-template-card">
                            <label><?php esc_html_e('Reminder Subject', 'nexdirectory'); ?></label>
                            <span class="eep-help-text"><?php esc_html_e('Trigger: reminder cron (~24h before start). Recipient: RSVP attendees.', 'nexdirectory'); ?></span>
                            <input type="text" name="eep_email_subject_reminder" value="<?php echo esc_attr((string) ($prefill['eep_email_subject_reminder'] ?? '')); ?>">
                            <label><?php esc_html_e('Reminder Body', 'nexdirectory'); ?></label>
                            <textarea name="eep_email_body_reminder" rows="4"><?php echo esc_textarea((string) ($prefill['eep_email_body_reminder'] ?? '')); ?></textarea>
                        </div>
                    <?php endif; ?>
                    <div class="eep-email-template-card">
                        <label><?php esc_html_e('Update Subject', 'nexdirectory'); ?></label>
                        <span class="eep-help-text"><?php echo esc_html(sprintf(__('Trigger: moderation publish/update. Recipient: %s owner.', 'nexdirectory'), $singular_lower)); ?></span>
                        <input type="text" name="eep_email_subject_update" value="<?php echo esc_attr((string) ($prefill['eep_email_subject_update'] ?? '')); ?>">
                        <label><?php esc_html_e('Update Body', 'nexdirectory'); ?></label>
                        <textarea name="eep_email_body_update" rows="4"><?php echo esc_textarea((string) ($prefill['eep_email_body_update'] ?? '')); ?></textarea>
                    </div>
                    <div class="eep-email-template-card">
                        <label><?php esc_html_e('Cancellation Subject', 'nexdirectory'); ?></label>
                        <span class="eep-help-text"><?php echo esc_html(sprintf(__('Trigger: moderation rejection/cancellation. Recipient: %s owner.', 'nexdirectory'), $singular_lower)); ?></span>
                        <input type="text" name="eep_email_subject_cancellation" value="<?php echo esc_attr((string) ($prefill['eep_email_subject_cancellation'] ?? '')); ?>">
                        <label><?php esc_html_e('Cancellation Body', 'nexdirectory'); ?></label>
                        <textarea name="eep_email_body_cancellation" rows="4"><?php echo esc_textarea((string) ($prefill['eep_email_body_cancellation'] ?? '')); ?></textarea>
                    </div>
                </div>
            </section>
        <?php endif; ?>

        <div class="eep-submit-actions">
            <button type="submit" name="eep_intent" value="pending" class="eep-btn eep-force-accent-action" :disabled="hasBlockingErrors()" :class="{ 'eep-btn-disabled': hasBlockingErrors() }"><?php echo esc_html($is_edit_mode ? $update_primary_cta : $submit_primary_cta); ?></button>
            <button type="submit" name="eep_intent" value="preview" class="eep-btn eep-btn-secondary"><?php esc_html_e('Preview', 'nexdirectory'); ?></button>
            <button type="submit" name="eep_intent" value="draft" class="eep-btn eep-btn-secondary"><?php esc_html_e('Save Draft', 'nexdirectory'); ?></button>
        </div>
        <p class="eep-meta" x-text="autosaveMessage"></p>
    </form>
</div>
</div>
