<?php
/**
 * Provide a public-facing view for the live dashboard.
 *
 * @package Noesia_Smart_Waiter
 * @subpackage Noesia_Smart_Waiter/public/partials
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$noesia_swa_opt           = get_option( 'noesia_swa_options' );
$noesia_swa_sound_enabled = ( isset( $noesia_swa_opt['sound_enable'] ) && 'yes' === $noesia_swa_opt['sound_enable'] ) || ( isset( $noesia_swa_opt['sound_enable'] ) && '1' === (string) $noesia_swa_opt['sound_enable'] );
$noesia_swa_sound_url     = NOESIA_SWA_PLUGIN_URL . 'public/sounds/alert.mp3';
$noesia_swa_context       = array(
    'surface'       => 'dashboard',
    'options'       => is_array( $noesia_swa_opt ) ? $noesia_swa_opt : array(),
    'sound_enabled' => $noesia_swa_sound_enabled,
    'sound_url'     => $noesia_swa_sound_url,
);
?>

<?php do_action( 'noesia_swa_public_before_content', $noesia_swa_context ); ?>

<div class="ns-dashboard" data-noesia-swa-public-surface="dashboard">
    <?php do_action( 'noesia_swa_public_dashboard_before_header', $noesia_swa_context ); ?>

    <div class="ns-dash-head">
        <div class="ns-brand">
            <h1>⚡ Live Command</h1>
            <p><?php esc_html_e( 'Real-time updates', 'noesia-smart-waiter' ); ?></p>
        </div>

        <div class="ns-dash-actions">
            <?php if ( $noesia_swa_sound_enabled ) : ?>
                <button class="ns-status-btn ns-sound-toggle" data-status="off">
                    🔇 <?php esc_html_e( 'Sound Off', 'noesia-smart-waiter' ); ?>
                </button>
            <?php endif; ?>

            <div class="ns-status">
                <span class="ns-dot"></span> <?php esc_html_e( 'Online', 'noesia-smart-waiter' ); ?>
            </div>
        </div>
    </div>

    <?php do_action( 'noesia_swa_public_dashboard_after_header', $noesia_swa_context ); ?>

    <div class="ns-grid ns-feed">
        <?php do_action( 'noesia_swa_public_before_main_buttons', $noesia_swa_context ); ?>

        <div class="ns-loading-state">
            <?php esc_html_e( 'Connecting to tables...', 'noesia-smart-waiter' ); ?>
        </div>

        <?php do_action( 'noesia_swa_public_after_main_buttons', $noesia_swa_context ); ?>
    </div>

    <?php do_action( 'noesia_swa_public_before_footer', $noesia_swa_context ); ?>

    <div class="ns-dashboard-footer-notice">
        <span class="ns-clean-icon">🧹</span>
        <?php echo esc_html__( 'Automatic cleanup: Completed requests older than 15 days are removed daily to maintain performance.', 'noesia-smart-waiter' ); ?>
    </div>
</div>

<?php if ( $noesia_swa_sound_enabled ) : ?>
    <audio class="ns-alert-audio ns-d-none" preload="auto">
        <source src="<?php echo esc_url( $noesia_swa_sound_url ); ?>" type="audio/mpeg">
    </audio>
<?php endif; ?>

<?php do_action( 'noesia_swa_public_after_content', $noesia_swa_context ); ?>
