<?php
if ( ! defined( 'ABSPATH' ) ) { exit; }

global $wpdb;

// -- Pagination & Search ---------------------------------------------------
$per_page = 30;
$page     = isset( $_GET['paged'] ) ? max( 1, intval( $_GET['paged'] ) ) : 1;
$offset   = ( $page - 1 ) * $per_page;
$search   = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '';
$orderby  = isset( $_GET['orderby'] ) ? sanitize_key( wp_unslash( $_GET['orderby'] ) ) : 'last_visit';
$order    = isset( $_GET['order'] ) && 'asc' === strtolower( sanitize_text_field( wp_unslash( $_GET['order'] ) ) ) ? 'asc' : 'desc';

$sortable_columns = array(
    'name'       => array( 'label' => 'Name',        'default_order' => 'asc' ),
    'visits'     => array( 'label' => 'Visits',      'default_order' => 'desc' ),
    'last_visit' => array( 'label' => 'Last Visit',  'default_order' => 'desc' ),
    'spent'      => array( 'label' => 'Total Spent', 'default_order' => 'desc' ),
    'loyalty'    => array( 'label' => 'Loyalty',     'default_order' => 'desc' ),
);
if ( ! isset( $sortable_columns[ $orderby ] ) ) {
    $orderby = 'last_visit';
}

$table    = $wpdb->prefix . 'yatoon_clients';
$bookings = $wpdb->prefix . 'yatoon_bookings';

// -- Build query -----------------------------------------------------------
$where = '';
$args  = array();
if ( $search ) {
    $like  = '%' . $wpdb->esc_like( $search ) . '%';
    $where = 'WHERE (c.customer_name LIKE %s OR c.customer_email LIKE %s OR c.customer_phone LIKE %s OR c.tags LIKE %s)';
    $args  = array( $like, $like, $like, $like );
}

$total_sql = "SELECT COUNT(*) FROM $table c $where";
$total     = $args ? $wpdb->get_var( $wpdb->prepare( $total_sql, $args ) ) : $wpdb->get_var( $total_sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
$pages     = ceil( $total / $per_page );

// 4.6.1 V2 -- this list was empty on every install, for everyone.
//
// MySQL and MariaDB let you ORDER BY the *bare* alias of an aggregate, but not
// by an expression built around it. Three of the five sort options did exactly
// that and every one of them failed at the database:
//
//   ORDER BY last_visit IS NULL ASC   -> Reference 'last_visit' not supported
//   ORDER BY COALESCE(total_spent, 0) -> Reference 'total_spent' not supported
//   ORDER BY c.loyalty_points         -> Unknown column (added by a later migration)
//
// last_visit is the DEFAULT sort, so the query failed on first page load,
// $wpdb->get_results() returned an empty array, and the page rendered
// "No clients yet" directly underneath a heading that said "262 total".
// Repeating the aggregate expression is what MySQL actually supports.
$last_visit_expr  = 'MAX(CASE WHEN b.start_time < NOW() THEN b.start_time ELSE NULL END)';
$total_spent_expr = 'SUM(b.total_price)';

// loyalty_points arrives via yatoon_clients_loyalty_points_migration(); a site
// that has not run it yet must not be handed a query naming a missing column.
$has_loyalty_column = (bool) $wpdb->get_var( $wpdb->prepare( "SHOW COLUMNS FROM `{$table}` LIKE %s", 'loyalty_points' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
if ( 'loyalty' === $orderby && ! $has_loyalty_column ) {
    $orderby = 'last_visit';
}

$order_expressions = array(
    'name'       => "SUBSTRING_INDEX(TRIM(c.customer_name), ' ', 1)",
    'visits'     => 'COUNT(b.id)',
    'last_visit' => $last_visit_expr,
    'spent'      => 'COALESCE(' . $total_spent_expr . ', 0)',
    'loyalty'    => 'COALESCE(c.loyalty_points, 0)',
);
$order_direction = 'asc' === $order ? 'ASC' : 'DESC';
$order_sql       = $order_expressions[ $orderby ] . ' ' . $order_direction;
if ( 'last_visit' === $orderby ) {
    // Customers who have never visited belong at the end whichever way the
    // column is sorted, so this cannot rely on MySQL's NULL ordering.
    $order_sql = $last_visit_expr . ' IS NULL ASC, ' . $order_sql;
}
$order_sql .= ', c.customer_name ASC, c.id ASC';

$select_sql = "SELECT c.*,
    COUNT(b.id)      AS visit_count,
    MAX(CASE WHEN b.start_time < NOW() THEN b.start_time ELSE NULL END) AS last_visit,
    SUM(b.total_price) AS total_spent,
    SUM(CASE WHEN b.status IN ('no_show','NO_SHOW') THEN 1 ELSE 0 END) AS no_show_count,
    SUM(CASE WHEN b.payment_status IS NULL OR b.payment_status = 'unpaid' THEN 1 ELSE 0 END) AS unpaid_count,
    SUM(CASE WHEN b.start_time >= NOW() AND b.status NOT IN ('cancelled','CANCELLED_BY_CUSTOMER','CANCELLED_BY_SELLER','DECLINED','no_show','NO_SHOW') THEN 1 ELSE 0 END) AS upcoming_count
FROM $table c
LEFT JOIN $bookings b ON (b.customer_phone = c.customer_phone OR b.customer_email = c.customer_email)
    AND b.status NOT IN ('cancelled','CANCELLED_BY_CUSTOMER','CANCELLED_BY_SELLER','DECLINED')
$where
GROUP BY c.id
ORDER BY $order_sql
LIMIT %d OFFSET %d";

$query_args = $args ? array_merge( $args, array( $per_page, $offset ) ) : array( $per_page, $offset );
$clients    = $wpdb->get_results( $wpdb->prepare( $select_sql, $query_args ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching

// A failed query and a salon with no customers both produce an empty array.
// Telling them apart matters: one is a normal empty state, the other is a bug
// the owner should be able to report instead of quietly distrusting the page.
$clients_query_error = $wpdb->last_error;
if ( $clients_query_error && $total > 0 ) {
    $clients = array();
}

$nonce = wp_create_nonce( 'yatoon_client_nonce' );
// Handed to assets/js/admin-clients.js rather than printed into the page.
// The screen script is enqueued in the footer, so localizing from the view
// still lands ahead of it.
wp_localize_script( 'yatoon-admin-clients', 'yatoonClientsData', array(
	'nonce' => $nonce,
) );
$sort_url = static function ( $column ) use ( $orderby, $order, $search, $sortable_columns ) {
    $next_order = $sortable_columns[ $column ]['default_order'];
    if ( $orderby === $column ) {
        $next_order = 'asc' === $order ? 'desc' : 'asc';
    }
    $query_args = array(
        'page'    => 'yatoon-clients',
        'orderby' => $column,
        'order'   => $next_order,
    );
    if ( '' !== $search ) {
        $query_args['s'] = $search;
    }
    return add_query_arg( $query_args, admin_url( 'admin.php' ) );
};
?>

<div class="wrap" id="yatoon-clients-wrap">
<h1 style="display:flex;align-items:center;gap:10px;margin-bottom:4px;">
    <span style="font-size:24px;">👤</span> <?php esc_html_e( 'Clients', 'yatoon-booking-system' ); ?>
    <span style="font-size:14px;color:#888;font-weight:400;margin-left:4px;"><?php echo intval($total); ?> total</span>
</h1>
<p style="color:#666;margin-top:0;"><?php esc_html_e( 'Client profiles are automatically created when a booking is made. Add notes, allergies, and preferences here.', 'yatoon-booking-system' ); ?></p>


<!-- Search bar -->
<form method="get" class="yc-search-bar">
    <input type="hidden" name="page" value="yatoon-clients">
    <input type="hidden" name="orderby" value="<?php echo esc_attr( $orderby ); ?>">
    <input type="hidden" name="order" value="<?php echo esc_attr( $order ); ?>">
    <input type="text" name="s" value="<?php echo esc_attr($search); ?>" placeholder="<?php echo esc_attr__( 'Search name, email, phone, tag...', 'yatoon-booking-system' ); ?>">
    <button type="submit" class="button"><?php esc_html_e( 'Search', 'yatoon-booking-system' ); ?></button>
    <?php if ($search) : ?><a href="?page=yatoon-clients" class="button"><?php esc_html_e( 'Clear', 'yatoon-booking-system' ); ?></a><?php endif; ?>
</form>

<!-- Clients table -->
<?php if ( ! empty( $clients_query_error ) && $total > 0 ) : ?>
    <div class="notice notice-error" style="margin:16px 0;padding:12px 14px;">
        <p><strong><?php esc_html_e( 'This list could not be loaded.', 'yatoon-booking-system' ); ?></strong>
        <?php
        printf(
            /* translators: %d: number of customer records that exist. */
            esc_html__( 'Your %d customer records are safe — the database rejected the query used to display them. Try a different sort column, and send this message to support:', 'yatoon-booking-system' ),
            (int) $total
        );
        ?></p>
        <p><code><?php echo esc_html( $clients_query_error ); ?></code></p>
    </div>
<?php elseif ( empty($clients) ) : ?>
    <div style="background:#fff;border:1px solid #ddd;border-radius:8px;padding:40px;text-align:center;color:#888;">
                    <?php echo esc_html( $search ? __( 'No clients found matching your search.', 'yatoon-booking-system' ) : __( 'No clients yet - they will appear automatically after bookings are made.', 'yatoon-booking-system' ) ); ?>
    </div>
<?php else : ?>
<div style="margin-bottom:10px;display:flex;align-items:center;gap:10px;">
    <button type="button" id="yc-delete-selected" class="button" disabled><?php esc_html_e( 'Delete Selected', 'yatoon-booking-system' ); ?></button>
    <span id="yc-selected-summary" style="color:#666;font-size:13px;"></span>
</div>
<div class="yc-table-wrap">
<table>
    <thead>
        <tr>
            <th class="yc-col-check"><input type="checkbox" id="yc-select-all" aria-label="<?php echo esc_attr__( 'Select all clients', 'yatoon-booking-system' ); ?>"></th>
            <?php foreach ( array( 'name' ) as $sort_column ) :
                $is_active = $orderby === $sort_column;
                $aria_sort = $is_active ? ( 'asc' === $order ? 'ascending' : 'descending' ) : 'none';
            ?>
            <th aria-sort="<?php echo esc_attr( $aria_sort ); ?>">
                <a class="yc-sort-link<?php echo $is_active ? ' is-active' : ''; ?>" href="<?php echo esc_url( $sort_url( $sort_column ) ); ?>">
                    <?php echo esc_html( $sortable_columns[ $sort_column ]['label'] ); ?>
                    <span class="yc-sort-icon" aria-hidden="true"><?php echo $is_active ? ( 'asc' === $order ? '&#9650;' : '&#9660;' ) : '&#8645;'; ?></span>
                </a>
            </th>
            <?php endforeach; ?>
            <th><?php esc_html_e( 'Phone', 'yatoon-booking-system' ); ?></th>
            <th><?php esc_html_e( 'Email', 'yatoon-booking-system' ); ?></th>
            <?php foreach ( array( 'visits', 'last_visit', 'spent', 'loyalty' ) as $sort_column ) :
                $is_active = $orderby === $sort_column;
                $aria_sort = $is_active ? ( 'asc' === $order ? 'ascending' : 'descending' ) : 'none';
            ?>
            <th aria-sort="<?php echo esc_attr( $aria_sort ); ?>">
                <a class="yc-sort-link<?php echo $is_active ? ' is-active' : ''; ?>" href="<?php echo esc_url( $sort_url( $sort_column ) ); ?>">
                    <?php echo esc_html( $sortable_columns[ $sort_column ]['label'] ); ?>
                    <span class="yc-sort-icon" aria-hidden="true"><?php echo $is_active ? ( 'asc' === $order ? '&#9650;' : '&#9660;' ) : '&#8645;'; ?></span>
                </a>
            </th>
            <?php endforeach; ?>
            <th><?php esc_html_e( 'Notes / Tags', 'yatoon-booking-system' ); ?></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ( $clients as $c ) :
        $tags = array_filter( array_map( 'trim', explode( ',', $c->tags ?? '' ) ) );
        $allergy_short = $c->allergies ? mb_substr( $c->allergies, 0, 40 ) . ( mb_strlen($c->allergies) > 40 ? '...' : '' ) : '';
        $visit_count = (int) ( $c->visit_count ?? 0 );
        $no_show_count = (int) ( $c->no_show_count ?? 0 );
        $unpaid_count = (int) ( $c->unpaid_count ?? 0 );
        $upcoming_count = (int) ( $c->upcoming_count ?? 0 );
        $total_spent = (float) ( $c->total_spent ?? 0 );
        $client_level = $total_spent >= 500 ? 'VIP' : ( $visit_count >= 5 ? 'Regular' : '' );
    ?>
        <tr data-client-id="<?php echo intval($c->id); ?>">
            <td class="yc-col-check">
                <input type="checkbox" class="yc-client-checkbox" value="<?php echo intval($c->id); ?>" aria-label="Select <?php echo esc_attr( $c->customer_name ?: 'client' ); ?>">
            </td>
            <td class="yc-client-name-cell">
                <strong><?php echo esc_html( $c->customer_name ?: '-' ); ?></strong>
                <?php if ( $client_level ) : ?><small><?php echo esc_html($client_level); ?> client</small><?php endif; ?>
            </td>
            <td><?php echo esc_html( $c->customer_phone ?: '-' ); ?></td>
            <td style="font-size:13px;color:#555;"><?php echo esc_html( $c->customer_email ?: '-' ); ?></td>
            <td style="text-align:center;">
                <button type="button" class="yc-visits-btn yc-open-modal" data-id="<?php echo intval($c->id); ?>" title="<?php echo esc_attr__( 'View visit history', 'yatoon-booking-system' ); ?>"><?php echo esc_html( $visit_count ); ?></button>
                <div>
                    <?php if ( $client_level === 'VIP' ) : ?><span class="yc-signal vip">VIP</span><?php endif; ?>
                    <?php if ( $upcoming_count > 0 ) : ?><span class="yc-signal next"><?php echo esc_html( $upcoming_count ); ?> upcoming</span><?php endif; ?>
                    <?php if ( $no_show_count > 0 ) : ?><span class="yc-signal warn"><?php echo esc_html( $no_show_count ); ?> no-show</span><?php endif; ?>
                    <?php if ( $unpaid_count > 0 ) : ?><span class="yc-signal money"><?php echo esc_html( $unpaid_count ); ?> unpaid</span><?php endif; ?>
                </div>
            </td>
            <td style="font-size:13px;"><?php echo $c->last_visit ? esc_html( yatoon_format_local('M j, Y', $c->last_visit) ) : '-'; ?></td>
            <td>$<?php echo number_format( $total_spent, 0 ); ?></td>
            <td><?php echo intval( $c->loyalty_points ?? 0 ); ?></td>
            <td class="yc-client-meta-cell">
                <?php if ( $allergy_short ) : ?>
                    <span class="yc-tag allergy">Warning: <?php echo esc_html($allergy_short); ?></span><br>
                <?php endif; ?>
                <?php if ( ! empty( $c->preferences ) ) : ?>
                    <span class="yc-tag"><?php esc_html_e( 'Prefs saved', 'yatoon-booking-system' ); ?></span>
                <?php endif; ?>
                <?php foreach ( $tags as $tag ) : ?>
                    <span class="yc-tag"><?php echo esc_html($tag); ?></span>
                <?php endforeach; ?>
                <?php if ( $c->notes ) : ?>
                    <div class="yc-note-preview"><?php echo esc_html($c->notes); ?></div>
                <?php endif; ?>
            </td>
            <td>
                <button class="btn-edit yc-open-modal"
                    data-id="<?php echo intval($c->id); ?>"><?php esc_html_e( '✏️ Edit', 'yatoon-booking-system' ); ?></button>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
</div>

<!-- Pagination -->
<?php if ( $pages > 1 ) : ?>
<div style="margin-top:16px;display:flex;gap:6px;align-items:center;">
    <?php for ( $i = 1; $i <= $pages; $i++ ) : ?>
        <a href="<?php echo esc_url( add_query_arg( array_filter( array( 'page' => 'yatoon-clients', 'paged' => $i, 's' => $search, 'orderby' => $orderby, 'order' => $order ) ), admin_url( 'admin.php' ) ) ); ?>"
           style="padding:5px 12px;border:1px solid <?php echo $i===$page ? '#0073aa' : '#ddd'; ?>;border-radius:4px;background:<?php echo $i===$page ? '#0073aa' : '#fff'; ?>;color:<?php echo $i===$page ? '#fff' : '#333'; ?>;text-decoration:none;font-size:13px;">
            <?php echo esc_html( $i ); ?>
        </a>
    <?php endfor; ?>
</div>
<?php endif; ?>
<?php endif; ?>

<!-- -- Edit Client Modal ------------------------------------------------ -->
<div id="yc-modal-overlay">
    <div id="yc-modal">
        <div id="yc-modal-header">
            <h2 id="yc-modal-title"><?php esc_html_e( 'Client Profile', 'yatoon-booking-system' ); ?></h2>
            <button id="yc-modal-close">✕</button>
        </div>
        <div id="yc-modal-body">
            <div id="yc-modal-loading" style="text-align:center;padding:40px;color:#888;"><?php esc_html_e( 'Loading...', 'yatoon-booking-system' ); ?></div>
            <div id="yc-modal-content" style="display:none;">

                <div class="yc-stats-grid">
                    <div class="yc-stat"><strong id="yc-stats-total">0</strong><span><?php esc_html_e( 'Bookings', 'yatoon-booking-system' ); ?></span></div>
                    <div class="yc-stat"><strong id="yc-stats-spent">$0</strong><span><?php esc_html_e( 'Lifetime', 'yatoon-booking-system' ); ?></span></div>
                    <div class="yc-stat"><strong id="yc-stats-noshow">0</strong><span><?php esc_html_e( 'No Shows', 'yatoon-booking-system' ); ?></span></div>
                    <div class="yc-stat"><strong id="yc-stats-unpaid">0</strong><span><?php esc_html_e( 'Unpaid', 'yatoon-booking-system' ); ?></span></div>
                </div>

                <!-- Look history -->
                <div class="yc-looks-section">
                    <div class="yc-looks-head">
                        <h3><?php esc_html_e( 'ð Look History', 'yatoon-booking-system' ); ?></h3>
                        <button type="button" class="button button-small" id="yc-add-look-btn"><?php esc_html_e( '+ Log this visit', 'yatoon-booking-system' ); ?></button>
                    </div>
                    <p class="description" style="margin:2px 0 10px;"><?php esc_html_e( 'What this client asked for, and what you actually did -- so next time nobody has to guess.', 'yatoon-booking-system' ); ?></p>

                    <div id="yc-look-form" class="yc-look-form" style="display:none;">
                        <input type="hidden" id="yc-look-id" value="">
                        <div class="yc-look-form-row">
                            <div class="yc-form-row" style="margin:0;">
                                <label><?php esc_html_e( 'Linked booking (optional)', 'yatoon-booking-system' ); ?></label>
                                <select id="yc-look-booking"><option value=""><?php esc_html_e( 'Not tied to a specific booking', 'yatoon-booking-system' ); ?></option></select>
                            </div>
                            <div class="yc-form-row" style="margin:0;">
                                <label><?php esc_html_e( 'Date', 'yatoon-booking-system' ); ?></label>
                                <input type="date" id="yc-look-date">
                            </div>
                        </div>
                        <div class="yc-form-row">
                            <label><?php esc_html_e( 'Color / style notes', 'yatoon-booking-system' ); ?></label>
                            <textarea id="yc-look-notes" rows="2" placeholder="<?php echo esc_attr__( 'e.g. OPI Bubble Bath, coffin shape, chrome accent nail...', 'yatoon-booking-system' ); ?>"></textarea>
                        </div>
                        <div class="yc-form-row">
                            <label><?php esc_html_e( 'Result photo', 'yatoon-booking-system' ); ?></label>
                            <div class="yc-look-photo-picker">
                                <input type="hidden" id="yc-look-photo-url" value="">
                                <img id="yc-look-photo-preview" style="display:none;">
                                <button type="button" class="button" id="yc-look-photo-btn"><?php esc_html_e( 'Choose Photo', 'yatoon-booking-system' ); ?></button>
                                <button type="button" class="button" id="yc-look-photo-remove" style="display:none;"><?php esc_html_e( 'Remove', 'yatoon-booking-system' ); ?></button>
                            </div>
                        </div>
                        <div class="yc-look-form-actions">
                            <button type="button" class="button button-primary button-small" id="yc-look-save"><?php esc_html_e( 'Save', 'yatoon-booking-system' ); ?></button>
                            <button type="button" class="button button-small" id="yc-look-cancel"><?php esc_html_e( 'Cancel', 'yatoon-booking-system' ); ?></button>
                            <span id="yc-look-status" style="font-size:13px;"></span>
                        </div>
                    </div>

                    <div id="yc-looks-grid" class="yc-looks-grid"></div>
                </div>

                <div style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:16px;">
                    <div class="yc-form-row" style="margin:0;">
                        <label><?php esc_html_e( 'Name', 'yatoon-booking-system' ); ?></label>
                        <input type="text" id="yc-client-name">
                    </div>
                    <div class="yc-form-row" style="margin:0;">
                        <label><?php esc_html_e( 'Phone', 'yatoon-booking-system' ); ?></label>
                        <input type="text" id="yc-client-phone" disabled style="background:#f9f9f9;color:#888;">
                    </div>
                    <div class="yc-form-row" style="margin:0;grid-column:1/-1;">
                        <label><?php esc_html_e( 'Email', 'yatoon-booking-system' ); ?></label>
                        <input type="text" id="yc-client-email" disabled style="background:#f9f9f9;color:#888;">
                    </div>
                </div>

                <div class="yc-form-row">
                    <label><?php esc_html_e( 'Warning: Allergies / Sensitivities', 'yatoon-booking-system' ); ?></label>
                    <textarea id="yc-client-allergies" rows="2" placeholder="<?php echo esc_attr__( 'e.g. Allergic to acrylic, sensitive to gel remover...', 'yatoon-booking-system' ); ?>"></textarea>
                </div>

                <div class="yc-form-row">
                    <label><?php esc_html_e( '👩 Preferred Staff', 'yatoon-booking-system' ); ?></label>
                    <select id="yc-client-staff">
                        <option value=""><?php esc_html_e( 'No preference', 'yatoon-booking-system' ); ?></option>
                    </select>
                </div>

                <div class="yc-form-row">
                    <label><?php esc_html_e( '* Client Preferences', 'yatoon-booking-system' ); ?></label>
                    <textarea id="yc-client-preferences" rows="3" placeholder="<?php echo esc_attr__( 'Favorite colors, usual shape, likes/dislikes, drink preference, service notes...', 'yatoon-booking-system' ); ?>"></textarea>
                </div>

                <div class="yc-form-row">
                    <label><?php esc_html_e( '🏷️ Tags', 'yatoon-booking-system' ); ?> <span style="font-weight:400;color:#888;"><?php esc_html_e( '(comma separated, e.g. VIP, Regular, Nail Art)', 'yatoon-booking-system' ); ?></span></label>
                    <input type="text" id="yc-client-tags" placeholder="<?php echo esc_attr__( 'VIP, Regular, Gel only...', 'yatoon-booking-system' ); ?>">
                </div>

                <div class="yc-form-row">
                    <label><?php esc_html_e( '📝 Admin Notes', 'yatoon-booking-system' ); ?></label>
                    <textarea id="yc-client-notes" rows="4" placeholder="<?php echo esc_attr__( 'Internal notes for preferences, cautions, special requests, or service reminders...', 'yatoon-booking-system' ); ?>"></textarea>
                </div>

                <div style="display:flex;gap:10px;align-items:center;margin-bottom:20px;">
                    <button id="yc-save-btn" class="button button-primary" style="padding:8px 24px;"><?php esc_html_e( '💾 Save Profile', 'yatoon-booking-system' ); ?></button>
                    <span id="yc-save-msg" style="font-size:13px;"></span>
                </div>

                <!-- Booking history -->
                <h3 style="margin:0 0 10px;font-size:15px;border-top:1px solid #eee;padding-top:16px;"><?php esc_html_e( '📅 Booking History', 'yatoon-booking-system' ); ?></h3>
                <div id="yc-history-wrap"></div>

            </div><!-- /yc-modal-content -->
        </div><!-- /yc-modal-body -->
    </div><!-- /yc-modal -->
</div><!-- /yc-modal-overlay -->

<input type="hidden" id="yc-current-client-id" value="">

</div>
