<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Templates use local variables supplied by the render context.
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');
/* translators: %s: Placeholder value. */
$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');
/* translators: %s: Placeholder value. */
$section_images_heading = sprintf(__('%s Images', 'nexdirectory'), $singular_label);
/* translators: %s: Placeholder value. */
$section_contact_heading = sprintf(__('%s Contact Information', 'nexdirectory'), $singular_label);
/* translators: %s: Placeholder value. */
$section_location_heading = sprintf(__('%s Location', 'nexdirectory'), $singular_label);
/* translators: %s: Placeholder value. */
$section_details_heading = sprintf(__('%s Details', 'nexdirectory'), $singular_label);
/* translators: %s: Placeholder value. */
$title_label = sprintf(__('Your %s name?', 'nexdirectory'), $singular_lower);
/* translators: %s: Placeholder value. */
$title_placeholder = sprintf(__('%s name...', 'nexdirectory'), $singular_label);
/* translators: %s: Placeholder value. */
$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');
/* translators: %s: Placeholder value. */
$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');
/* translators: %s: Placeholder value. */
$excerpt_placeholder = sprintf(__('One-line summary used on %s cards.', 'nexdirectory'), strtolower((string) ($ui_labels['plural'] ?? __('event', 'nexdirectory'))));
/* translators: %s: Placeholder value. */
$submit_primary_cta = sprintf(__('Submit %s', 'nexdirectory'), $singular_label);
/* translators: %s: Placeholder value. */
$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('nexdirectory_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('nexdirectory_enable_event_seo_fields', '1') === '1');
$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 : [
    /* translators: %s: Placeholder value. */
    'official' => sprintf(__('Official %s', 'nexdirectory'), $singular_label),
    /* translators: %s: Placeholder value. */
    '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['nexdirectory_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['nexdirectory_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['nexdirectory_video_urls'] ?? '') : '';
$prefill_stream_url_value = $show_stream_field ? (string) ($prefill['nexdirectory_event_stream_url'] ?? '') : '';
$prefill_start_raw = (string) ($prefill['nexdirectory_start_raw'] ?? '');
if ($prefill_start_raw === '') {
    $prefill_start_raw = str_replace('T', ' ', (string) ($prefill['nexdirectory_start_local'] ?? ''));
}
$prefill_end_raw = (string) ($prefill['nexdirectory_end_raw'] ?? '');
if ($prefill_end_raw === '') {
    $prefill_end_raw = str_replace('T', ' ', (string) ($prefill['nexdirectory_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] ?? '');
}
$email_tokens_help = $is_events_profile
    ? __('Override default platform emails for this event. Tokens: {event_title}, {event_date}, {event_url}, {status}, {moderator_note}.', 'nexdirectory')
    /* translators: %1$s: Placeholder value. */
    : 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['nexdirectory_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['nexdirectory_city'] ?? ''),
    'countryValue' => (string) ($prefill['nexdirectory_country'] ?? ''),
    'latValue' => (string) ($prefill['nexdirectory_lat'] ?? ''),
    'lngValue' => (string) ($prefill['nexdirectory_lng'] ?? ''),
    'streamUrl' => $prefill_stream_url_value,
    'metaTitleValue' => (string) ($prefill['nexdirectory_meta_title'] ?? ''),
    'metaDescriptionValue' => (string) ($prefill['nexdirectory_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['nexdirectory_event_mode_option'] ?? 'in-person'),
    'isRecurring' => (string) ($prefill['nexdirectory_is_recurring'] ?? '0') === '1' ? '1' : '0',
    'sessions' => is_array($prefill['sessions'] ?? null) ? array_values((array) $prefill['sessions']) : [],
    'recurrenceUntil' => (string) ($prefill['nexdirectory_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);
$plan_notice_class = 'nexdirectory-plan-status--pro';
$plan_notice_title = __('You can keep adding listings', 'nexdirectory');
$plan_notice_text = __('There is no built-in limit here. Submit as many listings as your site allows.', 'nexdirectory');
$plan_notice_badge = __('Unlimited', 'nexdirectory');
$plan_notice_tooltip = __('Your site can accept unlimited listings; admins can still moderate or reject submissions.', 'nexdirectory');
$plan_show_cta = false;
$page_kicker = sanitize_text_field((string) ($ui_labels['hero_kicker_default'] ?? $this->get_event_hero_kicker_text()));
echo wp_kses_post($this->render_notice());
$nexdirectory_breadcrumb_markup = NEXDIRECTORY_Escaping::prepare_markup_for_wp_kses((string) $this->render_platform_breadcrumbs($is_edit_mode ? $submit_edit_title : $submit_add_title));
echo wp_kses($nexdirectory_breadcrumb_markup, NEXDIRECTORY_Escaping::allowed_html($nexdirectory_breadcrumb_markup));
?>
<section class="nexdirectory-page-banner">
    <p class="nexdirectory-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 wp_kses((string) $this->render_account_tabs('submit', $profile_key), NEXDIRECTORY_Escaping::allowed_html()); ?>
<section class="nexdirectory-plan-status <?php echo esc_attr($plan_notice_class); ?>" title="<?php echo esc_attr($plan_notice_tooltip); ?>">
    <div>
        <strong><?php echo esc_html($plan_notice_title); ?></strong>
        <p><?php echo esc_html($plan_notice_text); ?></p>
    </div>
    <div class="nexdirectory-plan-status-actions">
        <span class="nexdirectory-plan-status-badge"><?php echo esc_html($plan_notice_badge); ?> <span aria-label="<?php echo esc_attr($plan_notice_tooltip); ?>">?</span></span>
        <?php if ($plan_show_cta) : ?>
            <span class="nexdirectory-btn nexdirectory-btn-sm" aria-hidden="true"></span>
        <?php endif; ?>
    </div>
</section>
<?php if ($is_edit_mode && !empty($event_completion_missing)) : ?>
    <div class="nexdirectory-notice nexdirectory-submit-completion-note">
        <?php /* translators: %s: Placeholder value. */ ?>
        <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="nexdirectory-account-shell">
<div class="nexdirectory-submit-wrap<?php echo $show_nav ? '' : ' nexdirectory-submit-no-nav'; ?>">
    <?php if ($show_nav) : ?>
    <aside class="nexdirectory-submit-nav" id="nexdirectory-submit-nav">
        <a class="nexdirectory-submit-nav-link" href="#nexdirectory-section-general"><?php echo esc_html($section_general_heading); ?></a>
        <a class="nexdirectory-submit-nav-link" href="#nexdirectory-section-images"><?php echo esc_html($section_images_heading); ?></a>
        <a class="nexdirectory-submit-nav-link" href="#nexdirectory-section-contact"><?php echo esc_html($section_contact_heading); ?></a>
        <a class="nexdirectory-submit-nav-link" href="#nexdirectory-section-location"><?php echo esc_html($section_location_heading); ?></a>
        <a class="nexdirectory-submit-nav-link" href="#nexdirectory-section-details"><?php echo esc_html($section_details_heading); ?></a>
        <?php if ($custom_fields_enabled && has_action('nexdirectory_render_extension_submission_custom_builder_nav')) : ?>
            <?php do_action('nexdirectory_render_extension_submission_custom_builder_nav'); ?>
        <?php endif; ?>
        <?php if ($show_video_embeds_section) : ?>
            <a class="nexdirectory-submit-nav-link" href="#nexdirectory-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="nexdirectory-submit-nav-link" href="#nexdirectory-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="nexdirectory-form nexdirectory-submit-form" id="nexdirectory-submit-form" x-data='nexdirectorySubmitForm(<?php echo esc_attr($alpine_prefill_json ? $alpine_prefill_json : '{}'); ?>)' data-nexdirectory-editing="<?php echo $is_edit_mode ? '1' : '0'; ?>" data-nexdirectory-initial-sessions="<?php echo esc_attr(wp_json_encode((array) ($prefill['sessions'] ?? []))); ?>" data-nexdirectory-recurrence-until="<?php echo esc_attr((string) ($prefill['nexdirectory_recurrence_until'] ?? '')); ?>">
        <input type="hidden" name="action" value="nexdirectory_submit_event">
        <input type="hidden" name="nexdirectory_edit_post_id" value="<?php echo esc_attr((string) ($prefill['edit_event_id'] ?? '0')); ?>">
        <?php wp_nonce_field('nexdirectory_submit_event_nonce', 'nexdirectory_nonce'); ?>
        <input type="hidden" name="nexdirectory_website" class="nexdirectory-honeypot" tabindex="-1" autocomplete="off" aria-hidden="true">
        <input type="hidden" name="nexdirectory_recaptcha_token" class="<?php echo $submit_recaptcha_required ? 'nexdirectory-recaptcha-token' : ''; ?>" value="">
        <input type="hidden" name="nexdirectory_sessions" :value="JSON.stringify(sessions)">
        <input type="hidden" name="nexdirectory_autosave_post_id" x-model="autosavePostId">
        <input type="hidden" name="nexdirectory_recurrence" :value="isRecurring === '1' ? 'custom' : 'none'">
            <input type="hidden" name="nexdirectory_recurrence_until" :value="recurrenceUntil">
            <input type="hidden" name="nexdirectory_lock_pin" value="0">
            <input type="hidden" name="nexdirectory_lat" id="nexdirectory-lat-input" x-model="latValue" x-init="latValue = $el.value || latValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_lat'] ?? '')); ?>">
            <input type="hidden" name="nexdirectory_lng" id="nexdirectory-lng-input" x-model="lngValue" x-init="lngValue = $el.value || lngValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_lng'] ?? '')); ?>">
        <input type="hidden" name="nexdirectory_country" x-model="countryValue" x-init="countryValue = $el.value || countryValue" value="<?php echo esc_attr((string) ($prefill['nexdirectory_country'] ?? '')); ?>">
            <input type="hidden" name="nexdirectory_youtube_video_id_1" :value="youtubeIdOne">
            <input type="hidden" name="nexdirectory_youtube_video_id_2" :value="youtubeIdTwo">
            <?php if (!$show_date_block) : ?>
                <input type="hidden" name="nexdirectory_start_date" value="<?php echo esc_attr($prefill_start_date !== '' ? $prefill_start_date : wp_date('Y-m-d')); ?>">
                <input type="hidden" name="nexdirectory_start_time" value="<?php echo esc_attr($prefill_start_time !== '' ? $prefill_start_time : '09:00'); ?>">
                <input type="hidden" name="nexdirectory_end_date" value="<?php echo esc_attr($prefill_end_date); ?>">
                <input type="hidden" name="nexdirectory_end_time" value="<?php echo esc_attr($prefill_end_time); ?>">
                <input type="hidden" name="nexdirectory_timezone" value="<?php echo esc_attr((string) ($prefill['nexdirectory_timezone'] ?? wp_timezone_string())); ?>">
                <input type="hidden" name="nexdirectory_is_recurring" value="0">
            <?php endif; ?>
            <textarea name="nexdirectory_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="file" name="nexdirectory_cover_file" x-ref="coverFileInput" accept="image/*" style="display:none;" @change="handleFileSelect($event, 'cover')">
        <input type="file" name="nexdirectory_gallery_files[]" x-ref="galleryFileInput" accept="image/*" multiple style="display:none;" @change="handleFileSelect($event, 'gallery')">

        <section id="nexdirectory-section-general" class="nexdirectory-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="nexdirectory-meta" x-text="titleCounterText()"></p>
            <p class="nexdirectory-validation-error" x-show="titleError" x-text="titleError"></p>

            <label><?php echo esc_html($description_label); ?></label>
            <span class="nexdirectory-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'] ?? ''), 'nexdirectory_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>
            <?php /* translators: %d: Placeholder value. */ ?>
            <span class="nexdirectory-help-text"><?php echo esc_html(sprintf(__('Maximum %d characters.', 'nexdirectory'), $excerpt_max_chars)); ?></span>
            <textarea class="nexdirectory-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="nexdirectory-meta" x-text="excerptCounterText()"></p>
            <p class="nexdirectory-validation-error" x-show="excerptError" x-text="excerptError"></p>

            <?php if ($organizer_event_seo_enabled) : ?>
                <div class="nexdirectory-seo-block" style="margin-top:16px;">
                    <h4 style="margin:0 0 8px;"><?php esc_html_e('SEO Snippet Preview', 'nexdirectory'); ?></h4>
                    <p class="nexdirectory-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="nexdirectory-btn nexdirectory-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="nexdirectory_meta_title" maxlength="60" x-model="metaTitleValue" @input="queueAutosave(220)" placeholder="<?php esc_attr_e('Best between 50 and 60 characters', 'nexdirectory'); ?>">
                    <p class="nexdirectory-meta"><span x-text="seoTitleCount()"></span> / 60 · <span x-text="seoTitleStatusText()"></span></p>

                    <label><?php esc_html_e('Meta Description', 'nexdirectory'); ?></label>
                    <textarea name="nexdirectory_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="nexdirectory-meta"><span x-text="seoDescriptionCount()"></span> / 158 · <span x-text="seoDescriptionStatusText()"></span></p>

                    <div class="nexdirectory-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="nexdirectory-section-images" class="nexdirectory-form-section">
            <h3><?php echo esc_html($section_images_heading); ?></h3>
            <label><?php echo esc_html($cover_image_label); ?></label>
            <?php /* translators: %d: Placeholder value. */ ?>
            <span class="nexdirectory-help-text"><?php echo esc_html(sprintf(__('Max file size: %d KB.', 'nexdirectory'), (int) $cover_max_kb)); ?></span>
            <div class="nexdirectory-dropzone" data-nexdirectory-upload-target="cover" @dragover.prevent @drop.prevent="handleDrop($event, 'cover')" @click="openMedia('cover')">
                <template x-if="coverImage">
                    <div class="nexdirectory-upload-preview-wrap">
                        <img class="nexdirectory-upload-preview" :src="coverImage" alt="Cover preview">
                        <button type="button" class="nexdirectory-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="nexdirectory_cover_image_url" x-model="coverImage" x-init="coverImage = $el.value || coverImage" value="<?php echo esc_attr((string) ($prefill['nexdirectory_cover_image_url'] ?? '')); ?>">

            <label><?php echo esc_html($gallery_images_label); ?></label>
            <?php /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */ ?>
            <span class="nexdirectory-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="nexdirectory-dropzone" data-nexdirectory-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="nexdirectory-gallery" x-show="galleryImages.length">
                <template x-for="(url, index) in galleryImages" :key="index">
                    <div class="nexdirectory-gallery-tile">
                        <img :src="url" alt="Gallery preview">
                        <button class="nexdirectory-upload-remove nexdirectory-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="nexdirectory_gallery_urls" x-model="galleryTextarea" x-init="galleryTextarea = $el.value || galleryTextarea" style="display:none;"><?php echo esc_textarea((string) ($prefill['nexdirectory_gallery_urls'] ?? '')); ?></textarea>
        </section>

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

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

            <label><?php echo esc_html($address_label); ?></label>
            <input type="text" name="nexdirectory_address" id="nexdirectory-address-input" list="nexdirectory-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['nexdirectory_address'] ?? '')); ?>">
            <datalist id="nexdirectory-address-suggestions"></datalist>
            <span class="nexdirectory-help-text"><?php echo esc_html($address_help); ?></span>

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

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

        <section id="nexdirectory-section-details" class="nexdirectory-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="nexdirectory-radio-group">
                    <input type="radio" id="nexdirectory-mode-in-person" name="nexdirectory_event_mode_option" value="in-person" x-model="modeOption" @change="if (modeOption !== 'video-stream') { streamUrl = ''; syncVideoUrls(); }" <?php checked((string) ($prefill['nexdirectory_event_mode_option'] ?? 'in-person'), 'in-person'); ?>>
                    <label for="nexdirectory-mode-in-person"><?php echo esc_html($mode_primary_label); ?></label>
                    <input type="radio" id="nexdirectory-mode-video-stream" name="nexdirectory_event_mode_option" value="video-stream" x-model="modeOption" <?php checked((string) ($prefill['nexdirectory_event_mode_option'] ?? 'in-person'), 'video-stream'); ?>>
                    <label for="nexdirectory-mode-video-stream"><?php echo esc_html($mode_secondary_label); ?></label>
                </div>
            <?php else : ?>
                <input type="hidden" name="nexdirectory_event_mode_option" value="<?php echo esc_attr((string) ($prefill['nexdirectory_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="nexdirectory-radio-group">
                    <input type="radio" id="nexdirectory-price-free" name="nexdirectory_price_simple" value="free" <?php checked((string) ($prefill['nexdirectory_price_simple'] ?? 'free'), 'free'); ?>>
                    <label for="nexdirectory-price-free"><?php echo esc_html($is_marketplace_profile ? __('Negotiable / Free', 'nexdirectory') : __('Free', 'nexdirectory')); ?></label>
                    <input type="radio" id="nexdirectory-price-paid" name="nexdirectory_price_simple" value="paid" <?php checked((string) ($prefill['nexdirectory_price_simple'] ?? 'free'), 'paid'); ?>>
                    <label for="nexdirectory-price-paid"><?php echo esc_html($is_marketplace_profile ? __('Fixed Price', 'nexdirectory') : __('Paid', 'nexdirectory')); ?></label>
                </div>
            <?php else : ?>
                <input type="hidden" name="nexdirectory_price_simple" value="paid">
            <?php endif; ?>

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

                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php echo esc_html($job_type_label); ?></label>
                        <select name="nexdirectory_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['nexdirectory_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="nexdirectory_job_contract_duration" placeholder="<?php esc_attr_e('12 months, Permanent, 6-week project...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_contract_duration'] ?? '')); ?>">
                    </div>
                </div>

                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Work Location Type', 'nexdirectory'); ?></label>
                        <select name="nexdirectory_job_work_mode" required>
                            <option value=""><?php esc_html_e('Select location type', 'nexdirectory'); ?></option>
                            <option value="on-site" <?php selected((string) ($prefill['nexdirectory_job_work_mode'] ?? ''), 'on-site'); ?>><?php esc_html_e('On-site', 'nexdirectory'); ?></option>
                            <option value="hybrid" <?php selected((string) ($prefill['nexdirectory_job_work_mode'] ?? ''), 'hybrid'); ?>><?php esc_html_e('Hybrid', 'nexdirectory'); ?></option>
                            <option value="remote" <?php selected((string) ($prefill['nexdirectory_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="nexdirectory_job_working_hours" placeholder="<?php esc_attr_e('Mon-Fri, 09:00-17:30', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_working_hours'] ?? '')); ?>">
                    </div>
                </div>

                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Department', 'nexdirectory'); ?></label>
                        <input type="text" name="nexdirectory_job_department" required placeholder="<?php esc_attr_e('Event, Marketing, Operations...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_department'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Experience Level', 'nexdirectory'); ?></label>
                        <select name="nexdirectory_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['nexdirectory_job_experience_level'] ?? ''), $experience_level_option); ?>><?php echo esc_html($experience_level_option); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>

                <h4 class="nexdirectory-subheading"><?php esc_html_e('Compensation & Benefits', 'nexdirectory'); ?></h4>
                <span class="nexdirectory-help-text"><?php esc_html_e('Set compensation details clearly so candidates can self-qualify quickly.', 'nexdirectory'); ?></span>
                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Compensation Type', 'nexdirectory'); ?></label>
                        <select name="nexdirectory_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['nexdirectory_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="nexdirectory_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['nexdirectory_job_salary'] ?? '')); ?>">
                    </div>
                </div>

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

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

                <h4 class="nexdirectory-subheading"><?php esc_html_e('Application Timeline', 'nexdirectory'); ?></h4>
                <span class="nexdirectory-help-text"><?php esc_html_e('Control when applications close and when the role is expected to start.', 'nexdirectory'); ?></span>
                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Application Deadline', 'nexdirectory'); ?></label>
                        <input type="date" name="nexdirectory_job_closing_date" required value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_closing_date'] ?? '')); ?>">
                        <span class="nexdirectory-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="nexdirectory_job_expected_start_date" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_expected_start_date'] ?? '')); ?>">
                    </div>
                </div>

                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Open Positions (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="nexdirectory_job_open_positions" min="0" step="1" placeholder="1" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_open_positions'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Remote Policy (Optional)', 'nexdirectory'); ?></label>
                        <?php $prefill_remote_policy = strtolower(trim((string) ($prefill['nexdirectory_job_remote_policy'] ?? ''))); ?>
                        <select name="nexdirectory_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="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Visa Sponsorship', 'nexdirectory'); ?></label>
                        <select name="nexdirectory_job_visa_sponsorship">
                            <option value="0" <?php selected((string) ($prefill['nexdirectory_job_visa_sponsorship'] ?? '0'), '0'); ?>><?php esc_html_e('No', 'nexdirectory'); ?></option>
                            <option value="1" <?php selected((string) ($prefill['nexdirectory_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="nexdirectory_job_industry" placeholder="<?php esc_attr_e('SaaS, Fintech, Manufacturing...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_industry'] ?? '')); ?>">
                    </div>
                </div>

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

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

                <h4 class="nexdirectory-subheading"><?php esc_html_e('Role Content', 'nexdirectory'); ?></h4>
                <span class="nexdirectory-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="nexdirectory_job_skills" placeholder="<?php esc_attr_e('PHP, React, Kubernetes, CRM...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_job_skills'] ?? '')); ?>">

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

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

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

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

                <label><?php esc_html_e('Recruitment Timeline (Optional)', 'nexdirectory'); ?></label>
                <textarea name="nexdirectory_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['nexdirectory_job_recruitment_timeline'] ?? '')); ?></textarea>
            <?php elseif ($is_directory_profile) : ?>
                <h4 class="nexdirectory-subheading"><?php esc_html_e('Business Profile', 'nexdirectory'); ?></h4>
                <span class="nexdirectory-help-text"><?php esc_html_e('Set the core business profile details shown on the public listing page.', 'nexdirectory'); ?></span>
                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php echo esc_html($company_label); ?></label>
                        <input type="text" name="nexdirectory_company_name" required placeholder="<?php esc_attr_e('Business / Organization name', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_company_name'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('Business Type', 'nexdirectory'); ?></label>
                        <?php $directory_business_type = sanitize_key((string) ($prefill['nexdirectory_directory_business_type'] ?? 'independent-business')); ?>
                        <select name="nexdirectory_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="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Listing Status', 'nexdirectory'); ?></label>
                        <?php $directory_listing_status = sanitize_key((string) ($prefill['nexdirectory_directory_listing_status'] ?? 'active')); ?>
                        <select name="nexdirectory_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="nexdirectory_directory_contact_person" placeholder="<?php esc_attr_e('Owner, manager, support lead...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_directory_contact_person'] ?? '')); ?>">
                    </div>
                </div>

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

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

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

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

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

                <label><?php esc_html_e('Certifications / Credentials (Optional)', 'nexdirectory'); ?></label>
                <textarea name="nexdirectory_directory_certifications" rows="3" placeholder="<?php esc_attr_e('ISO, licensed, insured, certified partner...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['nexdirectory_directory_certifications'] ?? '')); ?></textarea>
            <?php elseif ($is_marketplace_profile) : ?>
                <h4 class="nexdirectory-subheading"><?php esc_html_e('Listing Basics', 'nexdirectory'); ?></h4>
                <span class="nexdirectory-help-text"><?php esc_html_e('Set clear pricing and condition details so buyers can decide quickly.', 'nexdirectory'); ?></span>
                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php echo esc_html($condition_label); ?></label>
                        <select name="nexdirectory_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['nexdirectory_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['nexdirectory_market_price_type'] ?? 'fixed')); ?>
                        <select name="nexdirectory_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="nexdirectory-grid-3">
                    <div>
                        <label><?php echo esc_html($price_input_label); ?></label>
                        <input type="text" name="nexdirectory_price" placeholder="<?php echo esc_attr($price_input_placeholder); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_price'] ?? '')); ?>">
                        <span class="nexdirectory-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="nexdirectory_market_quantity" min="0" step="1" placeholder="1" value="<?php echo esc_attr((string) ($prefill['nexdirectory_market_quantity'] ?? '')); ?>">
                    </div>
                    <div>
                        <label><?php esc_html_e('SKU (Optional)', 'nexdirectory'); ?></label>
                        <input type="text" name="nexdirectory_market_sku" placeholder="<?php esc_attr_e('SKU-123', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_market_sku'] ?? '')); ?>">
                    </div>
                </div>

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

                <div class="nexdirectory-grid-3">
                    <div>
                        <label><?php esc_html_e('Seller Type', 'nexdirectory'); ?></label>
                        <?php $market_seller_type = sanitize_key((string) ($prefill['nexdirectory_market_seller_type'] ?? 'private')); ?>
                        <select name="nexdirectory_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['nexdirectory_market_listing_status'] ?? 'active')); ?>
                        <select name="nexdirectory_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="nexdirectory_market_expires_on" value="<?php echo esc_attr((string) ($prefill['nexdirectory_market_expires_on'] ?? '')); ?>">
                    </div>
                </div>

                <div class="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Accept Offers', 'nexdirectory'); ?></label>
                        <select name="nexdirectory_market_accept_offers">
                            <option value="1" <?php selected((string) ($prefill['nexdirectory_market_accept_offers'] ?? '1'), '1'); ?>><?php esc_html_e('Yes', 'nexdirectory'); ?></option>
                            <option value="0" <?php selected((string) ($prefill['nexdirectory_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="nexdirectory_market_payment_methods" placeholder="<?php esc_attr_e('Cash, Bank transfer, PayPal...', 'nexdirectory'); ?>" value="<?php echo esc_attr((string) ($prefill['nexdirectory_market_payment_methods'] ?? '')); ?>">
                    </div>
                </div>

                <h4 class="nexdirectory-subheading"><?php esc_html_e('Delivery & Returns', 'nexdirectory'); ?></h4>
                <span class="nexdirectory-help-text"><?php esc_html_e('Choose one or more delivery methods and set buyer expectations.', 'nexdirectory'); ?></span>
                <?php
                $delivery_prefill_raw = (string) ($prefill['nexdirectory_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="nexdirectory-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="nexdirectory-checkbox-chip">
                            <input type="checkbox" name="nexdirectory_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="nexdirectory-grid-2">
                    <div>
                        <label><?php esc_html_e('Returns Accepted', 'nexdirectory'); ?></label>
                        <select name="nexdirectory_market_returns_accepted">
                            <option value="0" <?php selected((string) ($prefill['nexdirectory_market_returns_accepted'] ?? '0'), '0'); ?>><?php esc_html_e('No', 'nexdirectory'); ?></option>
                            <option value="1" <?php selected((string) ($prefill['nexdirectory_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="nexdirectory_external_url" placeholder="https://www.example.com/listing" value="<?php echo esc_attr((string) ($prefill['nexdirectory_external_url'] ?? '')); ?>">
                    </div>
                </div>
                <label><?php esc_html_e('Condition Notes (Optional)', 'nexdirectory'); ?></label>
                <textarea name="nexdirectory_market_condition_notes" rows="3" placeholder="<?php esc_attr_e('State defects, wear, included accessories, warranty notes...', 'nexdirectory'); ?>"><?php echo esc_textarea((string) ($prefill['nexdirectory_market_condition_notes'] ?? '')); ?></textarea>
                <label><?php esc_html_e('Delivery / Collection Notes (Optional)', 'nexdirectory'); ?></label>
                <textarea name="nexdirectory_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['nexdirectory_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="nexdirectory_job_company_website" placeholder="https://www.example.com" value="<?php echo esc_attr((string) (($prefill['nexdirectory_job_company_website'] ?? '') !== '' ? $prefill['nexdirectory_job_company_website'] : ($prefill['nexdirectory_external_url'] ?? ''))); ?>">
                <input type="hidden" name="nexdirectory_external_url" value="<?php echo esc_attr((string) ($prefill['nexdirectory_external_url'] ?? '')); ?>">
            <?php elseif ($is_marketplace_profile) : ?>
                <input type="hidden" name="nexdirectory_event_stream_url" value="">
            <?php else : ?>
                <div class="nexdirectory-grid-2">
                    <div>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <label><?php echo esc_html(sprintf(__('%s Website (Optional)', 'nexdirectory'), $singular_label)); ?></label>
                        <input type="url" name="nexdirectory_external_url" placeholder="https://www.example.com" value="<?php echo esc_attr((string) ($prefill['nexdirectory_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="nexdirectory_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['nexdirectory_event_stream_url'] ?? '')); ?>">
                        </div>
                    <?php else : ?>
                        <input type="hidden" name="nexdirectory_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="nexdirectory-grid-3">
                    <div>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <label><?php echo esc_html(sprintf(__('%s Start Date (From)', 'nexdirectory'), $singular_label)); ?></label>
                        <input type="date" name="nexdirectory_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="nexdirectory_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>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <label><?php echo esc_html(sprintf(__('%s End Date (To)', 'nexdirectory'), $singular_label)); ?></label>
                        <input type="date" name="nexdirectory_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="nexdirectory_end_time" x-model="endTimeValue" x-init="endTimeValue = $el.value || endTimeValue" @input="validateDates" @change="validateDates" value="<?php echo esc_attr($prefill_end_time); ?>">
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <span class="nexdirectory-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 wp_kses((string) $this->render_timezone_dropdown('nexdirectory_timezone', (string) ($prefill['nexdirectory_timezone'] ?? '')), NEXDIRECTORY_Escaping::allowed_html()); ?>
                        <span class="nexdirectory-help-text"><?php esc_html_e('Automatically detected from your browser when empty.', 'nexdirectory'); ?></span>
                    </div>
                </div>
                <p class="nexdirectory-validation-error" x-show="dateError" x-text="dateError"></p>
                <p class="nexdirectory-validation-warning" x-show="dateWarning" x-text="dateWarning"></p>
                <p class="nexdirectory-validation-warning" x-show="timeWarning" x-text="timeWarning"></p>
                <p class="nexdirectory-meta" x-show="timezoneHint" x-text="timezoneHint"></p>
            <?php endif; ?>

            <div class="nexdirectory-grid-3">
                <?php if ($show_capacity_field) : ?>
                    <div>
                        <label><?php esc_html_e('Capacity (Optional)', 'nexdirectory'); ?></label>
                        <input type="number" name="nexdirectory_capacity" min="0" value="<?php echo esc_attr((string) ($prefill['nexdirectory_capacity'] ?? '')); ?>">
                    </div>
                <?php endif; ?>
                <?php if ($is_events_profile) : ?>
                    <div>
                        <label for="nexdirectory_attendee_visibility"><?php esc_html_e('Attendee privacy', 'nexdirectory'); ?></label>
                        <?php $attendee_visibility = sanitize_key((string) ($prefill['nexdirectory_attendee_visibility'] ?? 'counts')); ?>
                        <select id="nexdirectory_attendee_visibility" name="nexdirectory_attendee_visibility">
                            <option value="counts" <?php selected($attendee_visibility, 'counts'); ?>><?php esc_html_e('Show confirmed count only', 'nexdirectory'); ?></option>
                            <option value="members" <?php selected($attendee_visibility, 'members'); ?>><?php esc_html_e('Show opted-in names to members', 'nexdirectory'); ?></option>
                            <option value="public" <?php selected($attendee_visibility, 'public'); ?>><?php esc_html_e('Show explicitly public names', 'nexdirectory'); ?></option>
                            <option value="off" <?php selected($attendee_visibility, 'off'); ?>><?php esc_html_e('Hide attendance entirely', 'nexdirectory'); ?></option>
                        </select>
                        <span class="nexdirectory-help-text"><?php esc_html_e('Waitlist names are always private. Each attendee’s own visibility choice is respected.', 'nexdirectory'); ?></span>
                    </div>
                <?php endif; ?>
            </div>

            <?php if ($is_events_profile && function_exists('nexdirectory_is_pro_feature_enabled') && nexdirectory_is_pro_feature_enabled('ticketing')) : ?>
                <?php do_action('nexdirectory_render_extension_submit_ticket_fields', $this, $prefill, 'standalone'); ?>
            <?php endif; ?>

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

            <?php /* translators: %s: Placeholder value. */ ?>
            <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="nexdirectory-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="nexdirectory-tax-<?php echo esc_attr($taxonomy_slug); ?>"><?php echo esc_html($taxonomy_label); ?></label>
                <select id="nexdirectory-tax-<?php echo esc_attr($taxonomy_slug); ?>" name="nexdirectory_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="nexdirectory-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="nexdirectory-radio-group">
                    <input type="radio" id="nexdirectory-recurring-no" name="nexdirectory_is_recurring" value="0" <?php checked((string) ($prefill['nexdirectory_is_recurring'] ?? '0'), '0'); ?> x-model="isRecurring" @change="sessions = []; syncRecurrenceMeta();">
                    <label for="nexdirectory-recurring-no"><?php esc_html_e('No', 'nexdirectory'); ?></label>
                    <input type="radio" id="nexdirectory-recurring-yes" name="nexdirectory_is_recurring" value="1" <?php checked((string) ($prefill['nexdirectory_is_recurring'] ?? '0'), '1'); ?> x-model="isRecurring" @change="syncRecurrenceMeta">
                    <label for="nexdirectory-recurring-yes"><?php esc_html_e('Yes', 'nexdirectory'); ?></label>
                </div>

                <div class="nexdirectory-session-builder" x-show="isRecurring === '1'">
                    <h4><?php echo esc_html($session_heading); ?></h4>
                    <span class="nexdirectory-help-text"><?php echo esc_html($session_help); ?></span>
                    <template x-for="(session, index) in sessions" :key="index">
                        <div class="nexdirectory-inline-date-card">
                            <div class="nexdirectory-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="nexdirectory-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="nexdirectory-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="nexdirectory-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="nexdirectory-inline-actions" style="margin-top:8px; display:flex; flex-wrap:wrap; gap:8px;">
                                    <button type="button" class="nexdirectory-btn nexdirectory-btn-secondary" @click="triggerSessionAttachmentInput(index)">
                                        <?php esc_html_e('Upload File', 'nexdirectory'); ?>
                                    </button>
                                    <button type="button" class="nexdirectory-btn nexdirectory-btn-secondary" @click="openSessionAttachmentMediaPicker(index)">
                                        <?php esc_html_e('Media Library', 'nexdirectory'); ?>
                                    </button>
                                </div>
                                <input type="file" class="nexdirectory-session-attachment-upload" :id="'nexdirectory-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="nexdirectory-btn nexdirectory-btn-danger" @click="removeSession(index)"><?php echo esc_html($session_remove_label); ?></button>
                        </div>
                    </template>
                    <button type="button" class="nexdirectory-btn nexdirectory-btn-secondary" @click="addSession()"><?php echo esc_html($session_heading); ?></button>
                </div>
            <?php else : ?>
                <input type="hidden" name="nexdirectory_is_recurring" value="0">
            <?php endif; ?>
        </section>

        <?php if ($custom_fields_enabled && has_action('nexdirectory_render_extension_submission_custom_builder')) : ?>
            <?php do_action('nexdirectory_render_extension_submission_custom_builder', $this, [
                'custom_form_fields' => $custom_form_fields,
                'custom_values' => $custom_values,
                'singular_lower' => $singular_lower,
            ]); ?>
        <?php endif; ?>

            <?php if ($show_video_embeds_section) : ?>
            <section id="nexdirectory-section-videos" class="nexdirectory-form-section">
                <h3><?php echo esc_html(($is_marketplace_profile || $is_directory_profile) ? __('Videos', 'nexdirectory') : __('Video Embeds', 'nexdirectory')); ?></h3>
                <span class="nexdirectory-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="nexdirectory-video-repeater">
                    <template x-for="(video, index) in videoEmbeds" :key="index">
                        <div class="nexdirectory-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="nexdirectory-btn nexdirectory-btn-danger" @click="removeVideoEmbed(index)"><?php esc_html_e('Remove', 'nexdirectory'); ?></button>
                        </div>
                    </template>
                    <button type="button" class="nexdirectory-btn nexdirectory-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="nexdirectory-section-email-templates" class="nexdirectory-form-section">
                <?php /* translators: %s: Placeholder value. */ ?>
                <h3><?php echo esc_html(sprintf(__('Per-%s Email Templates (Optional)', 'nexdirectory'), $singular_label)); ?></h3>
                <span class="nexdirectory-help-text"><?php echo esc_html($email_tokens_help); ?></span>
                <div class="nexdirectory-email-template-notes">
                    <?php /* translators: %1$s: Placeholder value. */ ?>
                    <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; ?>
                    <?php /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */ ?>
                    <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>
                    <?php /* translators: 1: Placeholder value 1, 2: Placeholder value 2. */ ?>
                    <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="nexdirectory-email-template-grid">
                    <div class="nexdirectory-email-template-card">
                        <label><?php esc_html_e('Confirmation Subject', 'nexdirectory'); ?></label>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <span class="nexdirectory-help-text"><?php echo esc_html(sprintf(__('Trigger: submission/update to pending. Recipient: %s owner.', 'nexdirectory'), $singular_lower)); ?></span>
                        <input type="text" name="nexdirectory_email_subject_confirmation" value="<?php echo esc_attr((string) ($prefill['nexdirectory_email_subject_confirmation'] ?? '')); ?>">
                        <label><?php esc_html_e('Confirmation Body', 'nexdirectory'); ?></label>
                        <textarea name="nexdirectory_email_body_confirmation" rows="4"><?php echo esc_textarea((string) ($prefill['nexdirectory_email_body_confirmation'] ?? '')); ?></textarea>
                    </div>
                    <?php if ($is_events_profile) : ?>
                        <div class="nexdirectory-email-template-card">
                            <label><?php esc_html_e('Reminder Subject', 'nexdirectory'); ?></label>
                            <span class="nexdirectory-help-text"><?php esc_html_e('Trigger: reminder cron (~24h before start). Recipient: RSVP attendees.', 'nexdirectory'); ?></span>
                            <input type="text" name="nexdirectory_email_subject_reminder" value="<?php echo esc_attr((string) ($prefill['nexdirectory_email_subject_reminder'] ?? '')); ?>">
                            <label><?php esc_html_e('Reminder Body', 'nexdirectory'); ?></label>
                            <textarea name="nexdirectory_email_body_reminder" rows="4"><?php echo esc_textarea((string) ($prefill['nexdirectory_email_body_reminder'] ?? '')); ?></textarea>
                        </div>
                    <?php endif; ?>
                    <div class="nexdirectory-email-template-card">
                        <label><?php esc_html_e('Update Subject', 'nexdirectory'); ?></label>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <span class="nexdirectory-help-text"><?php echo esc_html(sprintf(__('Trigger: moderation publish/update. Recipient: %s owner.', 'nexdirectory'), $singular_lower)); ?></span>
                        <input type="text" name="nexdirectory_email_subject_update" value="<?php echo esc_attr((string) ($prefill['nexdirectory_email_subject_update'] ?? '')); ?>">
                        <label><?php esc_html_e('Update Body', 'nexdirectory'); ?></label>
                        <textarea name="nexdirectory_email_body_update" rows="4"><?php echo esc_textarea((string) ($prefill['nexdirectory_email_body_update'] ?? '')); ?></textarea>
                    </div>
                    <div class="nexdirectory-email-template-card">
                        <label><?php esc_html_e('Cancellation Subject', 'nexdirectory'); ?></label>
                        <?php /* translators: %s: Placeholder value. */ ?>
                        <span class="nexdirectory-help-text"><?php echo esc_html(sprintf(__('Trigger: moderation rejection/cancellation. Recipient: %s owner.', 'nexdirectory'), $singular_lower)); ?></span>
                        <input type="text" name="nexdirectory_email_subject_cancellation" value="<?php echo esc_attr((string) ($prefill['nexdirectory_email_subject_cancellation'] ?? '')); ?>">
                        <label><?php esc_html_e('Cancellation Body', 'nexdirectory'); ?></label>
                        <textarea name="nexdirectory_email_body_cancellation" rows="4"><?php echo esc_textarea((string) ($prefill['nexdirectory_email_body_cancellation'] ?? '')); ?></textarea>
                    </div>
                </div>
            </section>
        <?php endif; ?>

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