<?php
/**
 * Dashboard List Template
 *
 * @var string            $email       User email.
 * @var NemtlyBooking\Models\Booking[] $bookings    List of bookings.
 * @var string            $current_url Current URL for pagination/actions.
 * @package Nemtly_Booking
 */

defined( 'ABSPATH' ) || exit;
?>
<div class="nemtly-customer-dashboard">
    <div class="nb-dashboard-header">
        <h2>
            <?php
            // Translators: %s is the user email
            printf( esc_html__( 'Bookings for %s', 'nemtly-booking' ), esc_html( $email ) );
            ?>
        </h2>
        <?php /* Logout is effectively just clearing cookies, for now we don't have a direct logout link without a handler, but we can add one later. */ ?>
        <a href="<?php echo esc_url( add_query_arg( [ 'nemtly_action' => 'logout' ], $current_url ) ); ?>"
            class="nb-btn nb-btn-small nb-btn-outline"><?php esc_html_e( 'Logout', 'nemtly-booking' ); ?></a>
    </div>

    <?php if ( isset( $_GET['booking_cancelled'] ) ) : ?>
        <div class="nb-alert nb-alert-success">
            <?php esc_html_e( 'Booking cancelled successfully.', 'nemtly-booking' ); ?>
        </div>
    <?php endif; ?>

    <?php if ( empty( $bookings ) ) : ?>
        <p><?php esc_html_e( 'You have no bookings found.', 'nemtly-booking' ); ?></p>
    <?php else : ?>
        <div class="nb-table-responsive">
            <table class="nb-table">
                <thead>
                    <tr>
                        <th><?php esc_html_e( 'Date', 'nemtly-booking' ); ?></th>
                        <th><?php esc_html_e( 'Time', 'nemtly-booking' ); ?></th>
                        <th><?php esc_html_e( 'Status', 'nemtly-booking' ); ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ( $bookings as $booking ) : ?>
                        <tr>
                            <td><?php echo esc_html( $booking->get_booking_date() ); ?></td>
                            <td><?php echo esc_html( $booking->get_booking_start() ); ?></td>
                            <td>
                                <span class="nb-status nb-status-<?php echo esc_attr( $booking->get_booking_status() ); ?>">
                                    <?php echo esc_html( ucfirst( $booking->get_booking_status() ) ); ?>
                                </span>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    <?php endif; ?>
</div>
<style>
    /* Inline styles for MVP */
    .nemtly-customer-dashboard .nb-dashboard-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
    }

    .nemtly-customer-dashboard .nb-table {
        width: 100%;
        border-collapse: collapse;
    }

    .nemtly-customer-dashboard .nb-table th,
    .nemtly-customer-dashboard .nb-table td {
        padding: 10px;
        border-bottom: 1px solid #eee;
        text-align: left;
    }

    .nemtly-customer-dashboard .nb-btn-small {
        padding: 5px 10px;
        font-size: 14px;
    }

    .nemtly-customer-dashboard .nb-status {
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 12px;
        font-weight: bold;
    }

    .nemtly-customer-dashboard .nb-status-confirmed {
        background: #e6fffa;
        color: #2c7a7b;
    }

    .nemtly-customer-dashboard .nb-status-pending {
        background: #fffaf0;
        color: #dd6b20;
    }

    .nemtly-customer-dashboard .nb-status-cancelled {
        background: #fff5f5;
        color: #c53030;
    }
</style>