<?php
if (!defined('ABSPATH')) {
    exit;
}
$ui_labels = isset($ui_labels) && is_array($ui_labels) ? $ui_labels : [];
$profile_key = sanitize_key((string) ($ui_labels['profile_key'] ?? ''));
$my_items_title = sanitize_text_field((string) ($ui_labels['my_items_title'] ?? __('My Listings', 'nexdirectory')));
$my_items_description = sanitize_text_field((string) ($ui_labels['my_items_description'] ?? __('Manage submissions, update details, and monitor moderation status.', 'nexdirectory')));
$plural_label = sanitize_text_field((string) ($ui_labels['plural'] ?? __('Listings', 'nexdirectory')));
$singular_label = sanitize_text_field((string) ($ui_labels['singular'] ?? __('Listing', 'nexdirectory')));
$is_events_profile = (string) ($ui_labels['is_events_profile'] ?? '1') === '1';
$page_kicker = sanitize_text_field((string) $this->get_event_hero_kicker_text());
$delete_prompt = $is_events_profile
    ? __('Delete this event?', 'nexdirectory')
    : sprintf(__('Delete this %s?', 'nexdirectory'), strtolower((string) $singular_label));
$attendees_heading = $is_events_profile ? __('Attendees', 'nexdirectory') : __('Followers', 'nexdirectory');
$confirmed_label = $is_events_profile ? __('Confirmed', 'nexdirectory') : __('Saved', 'nexdirectory');
$waitlist_label = $is_events_profile ? __('Waitlist', 'nexdirectory') : __('Queue', 'nexdirectory');
$boosts_enabled = method_exists($this, 'is_boost_enabled') ? (bool) $this->is_boost_enabled() : false;
$boost_test_free_mode = $boosts_enabled && method_exists($this, 'boost_test_free_mode_enabled') ? (bool) $this->boost_test_free_mode_enabled() : false;
$boost_checkout_available = $boosts_enabled && ($boost_test_free_mode || (string) get_option('eep_boost_stripe_enabled', '0') === '1' || (string) get_option('eep_boost_paypal_enabled', '0') === '1');
$boost_auto_renew_module = !$boost_test_free_mode && method_exists($this, 'boost_auto_renew_enabled') ? (bool) $this->boost_auto_renew_enabled() : false;
$boost_duration_pricing = $boosts_enabled && method_exists($this, 'get_boost_duration_pricing') ? (array) $this->get_boost_duration_pricing() : [];
$boost_gateway_stripe_enabled = $boosts_enabled && (string) get_option('eep_boost_stripe_enabled', '0') === '1';
$boost_gateway_paypal_enabled = $boosts_enabled && (string) get_option('eep_boost_paypal_enabled', '0') === '1';
$boost_currency = sanitize_text_field((string) get_option('eep_boost_currency', 'USD'));
$boost_badge_label = sanitize_text_field((string) get_option('eep_boost_featured_badge_text', __('Featured', 'nexdirectory')));
$edit_action_label = sanitize_text_field((string) ($ui_labels['single_edit_cta'] ?? __('Edit Event', 'nexdirectory')));
echo $this->render_notice();
echo $this->render_platform_breadcrumbs($my_items_title); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
<section class="eep-page-banner">
    <p class="eep-page-kicker"><?php echo esc_html($page_kicker); ?></p>
    <h1><?php echo esc_html($my_items_title); ?></h1>
    <p><?php echo esc_html($my_items_description); ?></p>
</section>
<?php echo $this->render_account_tabs('my-events', $profile_key); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="eep-account-shell">
<div class="eep-my-events">
    <?php
    $my_events_url = isset($my_events_url) ? (string) $my_events_url : $this->get_platform_page_url(
        'eep_page_my_events_url',
        $this->get_profile_route_slugs('my_items'),
        $this->get_profile_route_default_url('my_items')
    );
    $attendees_panel = isset($attendees_panel) && is_array($attendees_panel) ? $attendees_panel : null;
    ?>
    <h3><?php echo esc_html($my_items_title); ?></h3>
    <?php if ($query->have_posts()) : ?>
        <div class="eep-table-wrap">
        <table class="eep-admin-table eep-responsive-table eep-my-events-table">
            <thead>
                <tr>
                    <th><?php esc_html_e('Title', 'nexdirectory'); ?></th>
                    <th><?php esc_html_e('Date', 'nexdirectory'); ?></th>
                    <th><?php esc_html_e('Status', 'nexdirectory'); ?></th>
                    <th><?php esc_html_e('Actions', 'nexdirectory'); ?></th>
                </tr>
            </thead>
            <tbody>
            <?php while ($query->have_posts()) : $query->the_post(); ?>
                <?php $event_status = (string) get_post_status(get_the_ID()); ?>
                <?php
                $edit_target_id = (int) get_the_ID();
                $edit_event_url = eep_add_query_arg([
                    'eep_tab' => 'submit',
                    'edit_event_id' => $edit_target_id,
                ], (string) $submit_event_url) . '#submit';
                $can_edit_target = $this->user_can_edit_event($edit_target_id);
                $is_demo_locked_target = is_callable([$this, 'is_demo_event_edit_locked']) ? (bool) $this->is_demo_event_edit_locked($edit_target_id, (int) get_current_user_id()) : false;
                $duplicate_event_url = wp_nonce_url(
                    eep_add_query_arg([
                        'action' => 'eep_duplicate_event',
                        'post' => (int) $edit_target_id,
                    ], admin_url('admin.php')),
                    'eep_duplicate_event_' . (int) $edit_target_id
                );
                $view_event_url = (string) get_permalink(get_the_ID());
                $view_event_label = __('View', 'nexdirectory');
                if ($event_status !== 'publish' && $can_edit_target) {
                    $preview_url = get_preview_post_link($edit_target_id);
                    if ((!is_string($preview_url) || $preview_url === '') && $edit_target_id > 0) {
                        $preview_url = eep_add_query_arg([
                            'p' => $edit_target_id,
                            'post_type' => $this::POST_TYPE,
                            'preview' => 'true',
                        ], home_url('/'));
                    }
                    if (is_string($preview_url) && $preview_url !== '') {
                        $view_event_url = $preview_url;
                    } elseif (is_string($edit_event_url) && $edit_event_url !== '') {
                        $view_event_url = $edit_event_url;
                    }
                    $view_event_label = __('Preview', 'nexdirectory');
                }
                $boost_state = $boosts_enabled && method_exists($this, 'get_listing_boost_state') ? (array) $this->get_listing_boost_state(get_the_ID()) : [];
                $boost_active = !empty($boost_state['active']);
                $boost_expires_label = sanitize_text_field((string) ($boost_state['expires_label'] ?? ''));
                $boost_auto_renew = !empty($boost_state['auto_renew']);
                $boost_selected_duration = absint((int) ($boost_state['duration_days'] ?? 0));
                if ($boost_selected_duration <= 0) {
                    $boost_selected_duration = method_exists($this, 'get_default_boost_duration_days') ? (int) $this->get_default_boost_duration_days() : 30;
                }
                $boost_selected_gateway = sanitize_key((string) ($boost_state['gateway'] ?? 'stripe'));
                if (!in_array($boost_selected_gateway, ['stripe', 'paypal'], true)) {
                    $boost_selected_gateway = $boost_gateway_stripe_enabled ? 'stripe' : ($boost_gateway_paypal_enabled ? 'paypal' : 'stripe');
                }
                $can_toggle_live_draft = $this->can_manage_event_team($edit_target_id, get_current_user_id()) || $this->user_can_moderate_events(get_current_user_id());
                $toggle_redirect_url = $my_events_url !== '' ? $my_events_url : (wp_get_referer() ?: home_url('/'));
                $toggle_redirect_url = eep_add_query_arg('eep_tab', 'listings', $toggle_redirect_url) . '#listings';

                $ticket_status_display = '';
                if ($is_events_profile) {
                    $ticket_sales_enabled = (string) get_post_meta(get_the_ID(), 'eep_ticket_sales_enabled', true) === '1';
                    $ticket_price_raw = trim((string) get_post_meta(get_the_ID(), 'eep_ticket_price', true));
                    $ticket_price_amount = 0.0;
                    if ($ticket_price_raw !== '') {
                        $normalized_ticket_price = str_replace(',', '.', $ticket_price_raw);
                        if (is_numeric($normalized_ticket_price)) {
                            $ticket_price_amount = max(0.0, (float) $normalized_ticket_price);
                        } elseif (preg_match('/\d+(?:\.\d{1,2})?/', $normalized_ticket_price, $ticket_price_match)) {
                            $ticket_price_amount = max(0.0, (float) ($ticket_price_match[0] ?? 0));
                        }
                    }

                    if ($ticket_sales_enabled) {
                        if ($ticket_price_amount > 0) {
                            $ticket_currency = strtoupper(sanitize_text_field((string) get_option('eep_ticket_currency', 'USD')));
                            $ticket_status_display = sprintf('%1$s %2$s', $ticket_currency, number_format_i18n($ticket_price_amount, 2));
                        } else {
                            $ticket_status_display = __('Free', 'nexdirectory');
                        }
                    } else {
                        $ticket_status_display = __('Not enabled', 'nexdirectory');
                    }
                }
                ?>
                <tr>
                    <td class="eep-my-event-title" data-label="<?php esc_attr_e('Title', 'nexdirectory'); ?>"><?php the_title(); ?></td>
                    <td data-label="<?php esc_attr_e('Date', 'nexdirectory'); ?>">
                        <?php echo esc_html($this->format_event_date(get_the_ID())); ?>
                        <?php if ($is_events_profile) : ?>
                            <br><small><?php echo esc_html(sprintf(__('Ticket: %s', 'nexdirectory'), $ticket_status_display)); ?></small>
                        <?php endif; ?>
                    </td>
                    <td data-label="<?php esc_attr_e('Status', 'nexdirectory'); ?>">
                        <span class="eep-status-pill eep-status-<?php echo esc_attr($event_status); ?>">
                            <?php echo esc_html($this->event_status_badge($event_status)); ?>
                        </span>
                        <?php $moderation_note = get_post_meta(get_the_ID(), 'eep_moderation_note', true); ?>
                        <?php if ($moderation_note) : ?><br><small><?php echo esc_html($moderation_note); ?></small><?php endif; ?>
                        <?php if ($boosts_enabled) : ?>
                            <div class="eep-my-events-boost-status">
                                <?php if ($boost_active) : ?>
                                    <span class="eep-status-pill eep-status-publish"><?php echo esc_html($boost_badge_label); ?></span>
                                    <?php if ($boost_expires_label !== '') : ?>
                                        <small><?php echo esc_html(sprintf(__('Expires %s', 'nexdirectory'), $boost_expires_label)); ?></small>
                                    <?php endif; ?>
                                <?php else : ?>
                                    <small><?php esc_html_e('Not boosted', 'nexdirectory'); ?></small>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                    </td>
                    <td class="eep-actions eep-my-events-actions" data-label="<?php esc_attr_e('Actions', 'nexdirectory'); ?>">
                        <?php if ($can_toggle_live_draft) : ?>
                            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="eep-inline-form eep-live-toggle-form">
                                <input type="hidden" name="action" value="eep_toggle_event_live_draft">
                                <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                                <input type="hidden" name="redirect_to" value="<?php echo esc_attr($toggle_redirect_url); ?>">
                                <input type="hidden" name="desired_state" value="draft">
                                <?php wp_nonce_field('eep_toggle_event_live_draft_' . get_the_ID(), 'eep_toggle_event_live_draft_nonce'); ?>
                                <label class="eep-live-toggle" title="<?php esc_attr_e('Toggle between Live and Draft status', 'nexdirectory'); ?>">
                                    <input type="checkbox" name="desired_state" value="live" <?php checked($event_status, 'publish'); ?> data-eep-live-toggle-input="1" onchange="if(this.form){if(this.form.requestSubmit){this.form.requestSubmit();}else{this.form.submit();}}">
                                    <span class="eep-live-toggle-track" aria-hidden="true"></span>
                                    <span class="eep-live-toggle-label eep-live-toggle-label-live"><?php esc_html_e('Live', 'nexdirectory'); ?></span>
                                    <span class="eep-live-toggle-label eep-live-toggle-label-draft"><?php esc_html_e('Draft', 'nexdirectory'); ?></span>
                                </label>
                                <?php if ($event_status === 'pending') : ?>
                                    <small class="eep-live-toggle-meta"><?php esc_html_e('Pending moderation', 'nexdirectory'); ?></small>
                                <?php endif; ?>
                            </form>
                        <?php endif; ?>
                        <a class="eep-btn eep-btn-secondary eep-btn-sm" href="<?php echo esc_url($view_event_url); ?>"><?php echo esc_html($view_event_label); ?></a>
                        <?php if ($can_edit_target) : ?>
                            <a class="eep-btn eep-btn-sm" href="<?php echo esc_url($edit_event_url); ?>"><?php echo esc_html($edit_action_label); ?></a>
                        <?php elseif ($is_demo_locked_target) : ?>
                            <?php $demo_locked_edit_tip = __('Demo listing locked. Duplicate to use 1 free event credit, or upgrade.', 'nexdirectory'); ?>
                            <span class="eep-btn eep-btn-sm" role="button" aria-disabled="true" title="<?php echo esc_attr($demo_locked_edit_tip); ?>" style="opacity:.6;cursor:not-allowed;"><?php echo esc_html($edit_action_label); ?></span>
                            <a class="eep-btn eep-btn-sm" href="<?php echo esc_url($duplicate_event_url); ?>" title="<?php echo esc_attr($demo_locked_edit_tip); ?>"><?php esc_html_e('Use Free Credit', 'nexdirectory'); ?></a>
                        <?php endif; ?>
                        <a class="eep-btn eep-btn-secondary eep-btn-sm" href="<?php echo esc_url(eep_add_query_arg('attendees_event', (string) get_the_ID(), $my_events_url)); ?>"><?php echo esc_html($attendees_heading); ?></a>
                        <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="eep-inline-form" onsubmit="return confirm('<?php echo esc_js($delete_prompt); ?>');">
                            <input type="hidden" name="action" value="eep_delete_event">
                            <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                            <?php wp_nonce_field('eep_delete_event_' . get_the_ID(), 'eep_delete_nonce'); ?>
                            <button class="eep-btn eep-btn-danger eep-btn-sm" type="submit"><?php esc_html_e('Delete', 'nexdirectory'); ?></button>
                        </form>
                        <?php if ($boost_checkout_available) : ?>
                            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="eep-inline-form eep-my-events-boost-form">
                                <input type="hidden" name="action" value="eep_boost_checkout">
                                <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                                <?php wp_nonce_field('eep_boost_checkout_' . get_the_ID(), 'eep_boost_checkout_nonce'); ?>
                                <div class="eep-my-events-boost-inline">
                                    <select name="duration_days" aria-label="<?php esc_attr_e('Boost duration', 'nexdirectory'); ?>">
                                        <?php foreach ((array) $boost_duration_pricing as $boost_days => $boost_price) : ?>
                                            <?php $boost_days = absint((int) $boost_days); ?>
                                            <?php $boost_price = is_numeric($boost_price) ? (float) $boost_price : 0.0; ?>
                                            <?php if ($boost_days <= 0 || $boost_price <= 0) {
                                                continue;
                                            } ?>
                                            <option value="<?php echo esc_attr((string) $boost_days); ?>" <?php selected($boost_selected_duration, $boost_days); ?>>
                                                <?php
                                                echo esc_html($boost_test_free_mode
                                                    ? sprintf(__('%1$d days (Free test mode)', 'nexdirectory'), $boost_days)
                                                    : sprintf(__('%1$d days (%2$s %3$s)', 'nexdirectory'), $boost_days, $boost_currency, number_format($boost_price, 2)));
                                                ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                    <?php if ($boost_test_free_mode) : ?>
                                        <input type="hidden" name="gateway" value="test_free">
                                        <small><?php esc_html_e('Free test mode is enabled. No checkout required.', 'nexdirectory'); ?></small>
                                    <?php else : ?>
                                        <select name="gateway" aria-label="<?php esc_attr_e('Payment gateway', 'nexdirectory'); ?>">
                                            <?php if ($boost_gateway_stripe_enabled) : ?>
                                                <option value="stripe" <?php selected($boost_selected_gateway, 'stripe'); ?>><?php esc_html_e('Stripe', 'nexdirectory'); ?></option>
                                            <?php endif; ?>
                                            <?php if ($boost_gateway_paypal_enabled) : ?>
                                                <option value="paypal" <?php selected($boost_selected_gateway, 'paypal'); ?>><?php esc_html_e('PayPal', 'nexdirectory'); ?></option>
                                            <?php endif; ?>
                                        </select>
                                    <?php endif; ?>
                                    <?php if ($boost_auto_renew_module) : ?>
                                        <label class="eep-my-events-boost-renew">
                                            <input type="checkbox" name="auto_renew" value="1" <?php checked($boost_auto_renew, true); ?>>
                                            <span><?php esc_html_e('Auto-renew', 'nexdirectory'); ?></span>
                                        </label>
                                    <?php endif; ?>
                                </div>
                                <button class="eep-btn eep-btn-secondary eep-btn-sm" type="submit"><?php echo esc_html($boost_active ? __('Re-Boost', 'nexdirectory') : __('Boost', 'nexdirectory')); ?></button>
                            </form>
                        <?php endif; ?>
                        <?php if ($boosts_enabled && $boost_active && !$boost_test_free_mode) : ?>
                            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="eep-inline-form">
                                <input type="hidden" name="action" value="eep_boost_toggle_autorenew">
                                <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                                <input type="hidden" name="auto_renew" value="<?php echo esc_attr($boost_auto_renew ? '0' : '1'); ?>">
                                <?php wp_nonce_field('eep_boost_toggle_' . get_the_ID(), 'eep_boost_toggle_nonce'); ?>
                                <button class="eep-btn eep-btn-secondary eep-btn-sm" type="submit">
                                    <?php echo esc_html($boost_auto_renew ? __('Disable Auto-Renew', 'nexdirectory') : __('Enable Auto-Renew', 'nexdirectory')); ?>
                                </button>
                            </form>
                            <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" class="eep-inline-form">
                                <input type="hidden" name="action" value="eep_boost_cancel_subscription">
                                <input type="hidden" name="post_id" value="<?php echo esc_attr(get_the_ID()); ?>">
                                <?php wp_nonce_field('eep_boost_cancel_' . get_the_ID(), 'eep_boost_cancel_nonce'); ?>
                                <button class="eep-btn eep-btn-secondary eep-btn-sm" type="submit"><?php esc_html_e('Cancel Subscription', 'nexdirectory'); ?></button>
                            </form>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endwhile; ?>
            </tbody>
        </table>
        </div>
    <?php else : ?>
        <p><?php echo esc_html(sprintf(__('You have not submitted any %s yet.', 'nexdirectory'), strtolower((string) $plural_label))); ?></p>
    <?php endif; ?>

    <?php if (!empty($attendees_panel)) : ?>
        <?php
        $communication_allowed_count = absint((int) ($attendees_panel['communication_allowed_count'] ?? 0));
        $communication_blocked_count = absint((int) ($attendees_panel['communication_blocked_count'] ?? 0));
        ?>
        <div class="eep-attendees-modal eep-lightbox" id="eep-attendees-modal" data-open="1" data-base-url="<?php echo esc_attr($my_events_url); ?>">
            <div class="eep-attendees-modal-dialog">
                <button type="button" class="eep-attendees-modal-close" id="eep-attendees-modal-close" aria-label="<?php esc_attr_e('Close', 'nexdirectory'); ?>">&times;</button>
                <section class="eep-attendees-panel">
                    <div class="eep-attendees-panel-head">
                        <div>
                            <h3><?php echo esc_html($attendees_heading); ?>: <?php echo esc_html((string) ($attendees_panel['event_title'] ?? '')); ?></h3>
                            <p class="eep-meta">
                                <?php
                                echo esc_html(sprintf(
                                    __('%1$s: %2$d · %3$s: %4$d', 'nexdirectory'),
                                    $confirmed_label,
                                    (int) ($attendees_panel['yes_count'] ?? 0),
                                    $waitlist_label,
                                    (int) ($attendees_panel['waitlist_count'] ?? 0)
                                ));
                                ?>
                            </p>
                            <p class="eep-meta">
                                <?php
                                echo esc_html(sprintf(
                                    __('Communication enabled: %1$d · Opted out: %2$d', 'nexdirectory'),
                                    $communication_allowed_count,
                                    $communication_blocked_count
                                ));
                                ?>
                            </p>
                        </div>
                        <form method="post" action="<?php echo esc_url((string) ($attendees_panel['export_action'] ?? admin_url('admin-post.php'))); ?>" class="eep-inline-form">
                            <input type="hidden" name="action" value="eep_export_event_attendees">
                            <input type="hidden" name="event_id" value="<?php echo esc_attr((string) ($attendees_panel['event_id'] ?? '0')); ?>">
                            <input type="hidden" name="eep_export_attendees_nonce" value="<?php echo esc_attr((string) ($attendees_panel['export_nonce'] ?? '')); ?>">
                            <button type="submit" class="eep-btn eep-btn-secondary eep-btn-sm"><?php esc_html_e('Download CSV', 'nexdirectory'); ?></button>
                        </form>
                    </div>
                    <div class="eep-attendees-communication-box">
                        <h4><?php esc_html_e('Message Attendees', 'nexdirectory'); ?></h4>
                        <p class="eep-meta"><?php esc_html_e('Only attendees who opted in via GDPR communication settings will receive these inbox messages and email notifications.', 'nexdirectory'); ?></p>
                        <form method="post" action="<?php echo esc_url((string) ($attendees_panel['email_action'] ?? admin_url('admin-post.php'))); ?>" class="eep-form eep-attendees-email-form">
                            <input type="hidden" name="action" value="eep_email_event_attendees">
                            <input type="hidden" name="event_id" value="<?php echo esc_attr((string) ($attendees_panel['event_id'] ?? '0')); ?>">
                            <input type="hidden" name="eep_email_attendees_nonce" value="<?php echo esc_attr((string) ($attendees_panel['email_nonce'] ?? '')); ?>">
                            <div class="eep-attendees-email-grid">
                                <div>
                                    <label for="eep-attendee-audience"><?php esc_html_e('Audience', 'nexdirectory'); ?></label>
                                    <select id="eep-attendee-audience" name="audience">
                                        <option value="confirmed"><?php esc_html_e('Confirmed only', 'nexdirectory'); ?></option>
                                        <option value="waitlist"><?php esc_html_e('Waitlist only', 'nexdirectory'); ?></option>
                                        <option value="all"><?php esc_html_e('Confirmed + Waitlist', 'nexdirectory'); ?></option>
                                    </select>
                                </div>
                                <div>
                                    <label for="eep-attendee-subject"><?php esc_html_e('Subject', 'nexdirectory'); ?></label>
                                    <input type="text" id="eep-attendee-subject" name="subject" maxlength="160" required placeholder="<?php esc_attr_e('Update for {event_title}', 'nexdirectory'); ?>">
                                </div>
                            </div>
                            <label for="eep-attendee-message"><?php esc_html_e('Message', 'nexdirectory'); ?></label>
                            <textarea id="eep-attendee-message" name="message" rows="5" maxlength="6000" required placeholder="<?php esc_attr_e('Hi {attendee_name}, here is an update for {event_title}.', 'nexdirectory'); ?>"></textarea>
                            <p class="eep-help-text"><?php esc_html_e('Available tokens: {event_title}, {event_url}, {attendee_name}, {recipient_name}, {organizer_name}, {site_name}', 'nexdirectory'); ?></p>
                            <label class="eep-auth-consent-item">
                                <input type="checkbox" name="send_copy" value="1">
                                <span><?php esc_html_e('Send a copy to my inbox (and account email)', 'nexdirectory'); ?></span>
                            </label>
                            <button type="submit" class="eep-btn eep-btn-sm" style="background:var(--eep-primary,#FF5E14) !important; border-color:var(--eep-primary,#FF5E14) !important; color:#ffffff !important;"><?php esc_html_e('Send Inbox Update', 'nexdirectory'); ?></button>
                        </form>
                    </div>
                    <?php if (!empty($attendees_panel['rows']) && is_array($attendees_panel['rows'])) : ?>
                        <div class="eep-table-wrap">
                            <table class="eep-admin-table eep-responsive-table">
                                <thead>
                                    <tr>
                                        <th><?php esc_html_e('Name', 'nexdirectory'); ?></th>
                                        <th><?php esc_html_e('Email', 'nexdirectory'); ?></th>
                                        <th><?php esc_html_e('Status', 'nexdirectory'); ?></th>
                                        <th><?php esc_html_e('Communication', 'nexdirectory'); ?></th>
                                        <th><?php esc_html_e('Updated', 'nexdirectory'); ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ((array) $attendees_panel['rows'] as $row) : ?>
                                        <tr>
                                            <td data-label="<?php esc_attr_e('Name', 'nexdirectory'); ?>"><?php echo esc_html((string) ($row['name'] ?? '')); ?></td>
                                            <td data-label="<?php esc_attr_e('Email', 'nexdirectory'); ?>">
                                                <?php if (!empty($row['email']) && is_email((string) $row['email'])) : ?>
                                                    <a href="mailto:<?php echo esc_attr(sanitize_email((string) $row['email'])); ?>"><?php echo esc_html((string) $row['email']); ?></a>
                                                <?php else : ?>
                                                    <?php echo esc_html((string) ($row['email'] ?? '')); ?>
                                                <?php endif; ?>
                                            </td>
                                            <td data-label="<?php esc_attr_e('Status', 'nexdirectory'); ?>"><?php echo esc_html((string) ($row['status_label'] ?? '')); ?></td>
                                            <td data-label="<?php esc_attr_e('Communication', 'nexdirectory'); ?>">
                                                <span class="eep-status-pill <?php echo (string) ($row['communication_opt_in'] ?? '0') === '1' ? 'eep-status-publish' : 'eep-status-draft'; ?>">
                                                    <?php echo esc_html((string) ($row['communication_label'] ?? '')); ?>
                                                </span>
                                            </td>
                                            <td data-label="<?php esc_attr_e('Updated', 'nexdirectory'); ?>"><?php echo esc_html((string) ($row['updated_label'] ?? '')); ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    <?php else : ?>
                        <p><?php echo esc_html(sprintf(__('No %1$s yet for this %2$s.', 'nexdirectory'), strtolower((string) $attendees_heading), strtolower((string) $singular_label))); ?></p>
                    <?php endif; ?>
                </section>
            </div>
        </div>
    <?php endif; ?>
</div>
</div>
