<?php
/**
 * Design / Live Requests section for Noesia Smart Waiter.
 *
 * @package Noesia_Smart_Waiter
 */

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

$noesia_swa_design_parent_options = ( isset( $options ) && is_array( $options ) ) ? $options : null;
( static function ( $noesia_swa_design_parent_options ) {
    $options = $noesia_swa_design_parent_options;

if ( ! isset( $options ) || ! is_array( $options ) ) {
    $options = get_option( 'noesia_swa_options', array() );
}

$defaults = array(
    'shop_name'    => get_bloginfo( 'name' ),
    'logo_url'     => NOESIA_SWA_PLUGIN_URL . 'admin/img/noesia-menu-icon.png',
    'menu_active'  => 'yes',
    'menu_url'     => 'https://google.com',
    'btn_menu'     => 'View Our Menu',
    'icon_menu'    => '📜',
    'btn_order'    => 'New Order',
    'icon_order'   => '🍽️',
    'btn_waiter'   => 'Call Waiter',
    'icon_waiter'  => '🙋',
    'btn_bill'     => 'Bill Please',
    'icon_bill'    => '💳',
    'cst1_label'   => 'Urgent',
    'cst1_icon'    => '💧',
    'cst2_label'   => 'Pool pls',
    'cst2_icon'    => '✨',
    'rate_label'   => 'Rate Us on Google',
    'review_url'   => 'https://google.com',
    'color_bg'     => '#121212',
    'color_title'  => '#ffffff',
    'color_text'   => '#ffffff',
    'sound_enable' => 'yes',
);

$values = wp_parse_args( $options, $defaults );
if ( '' === trim( (string) $values['shop_name'] ) ) {
    $values['shop_name'] = $defaults['shop_name'];
}

if ( '' === trim( (string) $values['logo_url'] ) ) {
    $values['logo_url'] = $defaults['logo_url'];
}

if ( ! in_array( $values['menu_active'], array( 'yes', 'no' ), true ) ) {
    $values['menu_active'] = 'yes';
}

if ( '' === trim( (string) $values['menu_url'] ) ) {
    $values['menu_url'] = 'https://google.com';
}

if ( '' === trim( (string) $values['cst1_label'] ) ) {
    $values['cst1_label'] = 'Urgent';
}

if ( '' === trim( (string) $values['cst2_label'] ) ) {
    $values['cst2_label'] = 'Pool pls';
}

if ( '' === trim( (string) $values['review_url'] ) ) {
    $values['review_url'] = 'https://google.com';
}
?>

<?php
/**
 * Allow extensions (including Pro) to inject UI before the Design form.
 *
 * @param array $values  Current resolved option values.
 * @param array $options Raw saved options.
 */
do_action( 'noesia_swa_design_form_before', $values, $options );
?>

<div
    class="noesia-swa-design-module"
    data-noesia-swa-request-empty-text="<?php echo esc_attr__( 'No active requests right now.', 'noesia-smart-waiter' ); ?>"
    data-noesia-swa-request-label="<?php echo esc_attr__( 'Request', 'noesia-smart-waiter' ); ?>"
    data-noesia-swa-request-label-many="<?php echo esc_attr__( 'Active Requests', 'noesia-smart-waiter' ); ?>"
    data-noesia-swa-request-label-one="<?php echo esc_attr__( 'Active Request', 'noesia-smart-waiter' ); ?>"
>
<div class="noesia-swa-section-grid">
    <div class="noesia-swa-card noesia-swa-card--span2">
        <div class="noesia-swa-card-header">
            <div>
                <h3><?php esc_html_e( 'Design / Live Requests', 'noesia-smart-waiter' ); ?></h3>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Configure the customer screen, action buttons and live request behavior.', 'noesia-smart-waiter' ); ?></p>
            </div>

            <div class="noesia-swa-inline-actions">
                <?php submit_button( __( 'Save Changes', 'noesia-smart-waiter' ), 'primary', 'submit', false ); ?>
                <button type="button" class="button noesia-swa-design-restore-button" id="noesia-swa-design-restore"><?php esc_html_e( 'Restore Texts & Icons', 'noesia-smart-waiter' ); ?></button>
            </div>
        </div>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'BRAND SETUP', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'These values appear in the customer QR page.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-form-grid">
            <div class="noesia-swa-form-group">
                <label for="noesia-swa-shop-name"><?php esc_html_e( 'Shop Name', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-shop-name" name="noesia_swa_options[shop_name]" value="<?php echo esc_attr( $values['shop_name'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group">
                <label for="noesia-swa-logo-url"><?php esc_html_e( 'Logo URL', 'noesia-smart-waiter' ); ?></label>
                <input type="url" id="noesia-swa-logo-url" name="noesia_swa_options[logo_url]" value="<?php echo esc_url( $values['logo_url'] ); ?>" />
                <p class="noesia-swa-muted"><?php esc_html_e( 'Paste a full image URL or keep the default icon.', 'noesia-smart-waiter' ); ?></p>
            </div>

            <div class="noesia-swa-form-group">
                <label for="noesia-swa-sound-enable"><?php esc_html_e( 'Sound Alerts', 'noesia-smart-waiter' ); ?></label>
                <select id="noesia-swa-sound-enable" name="noesia_swa_options[sound_enable]">
                    <option value="yes" <?php selected( $values['sound_enable'], 'yes' ); ?>><?php esc_html_e( 'Enabled', 'noesia-smart-waiter' ); ?></option>
                    <option value="no" <?php selected( $values['sound_enable'], 'no' ); ?>><?php esc_html_e( 'Disabled', 'noesia-smart-waiter' ); ?></option>
                </select>
            </div>
        </div>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'LIVE REQUESTS PREVIEW', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Shows current requests from the live monitor in compact form.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div id="noesia-swa-live-requests-preview-design">
            <p class="noesia-swa-muted"><?php esc_html_e( 'Loading live requests…', 'noesia-smart-waiter' ); ?></p>
        </div>
    </div>

    <div class="noesia-swa-card noesia-swa-card--span2">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'PRIMARY ACTION BUTTONS', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Edit labels and icons for the buttons shown on the customer page.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-form-row">
            <div class="noesia-swa-form-group">
                <label for="noesia-swa-btn-menu"><?php esc_html_e( 'Menu Button Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-btn-menu" name="noesia_swa_options[btn_menu]" value="<?php echo esc_attr( $values['btn_menu'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-icon-menu"><?php esc_html_e( 'Menu Icon', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-icon-menu" name="noesia_swa_options[icon_menu]" value="<?php echo esc_attr( $values['icon_menu'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group">
                <label for="noesia-swa-menu-active"><?php esc_html_e( 'Menu Visibility', 'noesia-smart-waiter' ); ?></label>
                <select id="noesia-swa-menu-active" name="noesia_swa_options[menu_active]">
                    <option value="yes" <?php selected( $values['menu_active'], 'yes' ); ?>><?php esc_html_e( 'Show Menu Button', 'noesia-smart-waiter' ); ?></option>
                    <option value="no" <?php selected( $values['menu_active'], 'no' ); ?>><?php esc_html_e( 'Hide Menu Button', 'noesia-smart-waiter' ); ?></option>
                </select>
            </div>
        </div>

        <div class="noesia-swa-form-group">
            <label for="noesia-swa-menu-url"><?php esc_html_e( 'Menu URL', 'noesia-smart-waiter' ); ?></label>
            <input type="url" id="noesia-swa-menu-url" name="noesia_swa_options[menu_url]" value="<?php echo esc_url( $values['menu_url'] ); ?>" />
            <p class="noesia-swa-muted"><?php esc_html_e( 'Add the PDF or page URL that opens when customers tap the menu button.', 'noesia-smart-waiter' ); ?></p>
        </div>

        <hr />

        <div class="noesia-swa-form-row">
            <div class="noesia-swa-form-group">
                <label for="noesia-swa-btn-order"><?php esc_html_e( 'Order Button Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-btn-order" name="noesia_swa_options[btn_order]" value="<?php echo esc_attr( $values['btn_order'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-icon-order"><?php esc_html_e( 'Order Icon', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-icon-order" name="noesia_swa_options[icon_order]" value="<?php echo esc_attr( $values['icon_order'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group">
                <label for="noesia-swa-btn-waiter"><?php esc_html_e( 'Waiter Button Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-btn-waiter" name="noesia_swa_options[btn_waiter]" value="<?php echo esc_attr( $values['btn_waiter'] ); ?>" />
            </div>
        </div>

        <div class="noesia-swa-form-row">
            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-icon-waiter"><?php esc_html_e( 'Waiter Icon', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-icon-waiter" name="noesia_swa_options[icon_waiter]" value="<?php echo esc_attr( $values['icon_waiter'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group">
                <label for="noesia-swa-btn-bill"><?php esc_html_e( 'Bill Button Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-btn-bill" name="noesia_swa_options[btn_bill]" value="<?php echo esc_attr( $values['btn_bill'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-icon-bill"><?php esc_html_e( 'Bill Icon', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-icon-bill" name="noesia_swa_options[icon_bill]" value="<?php echo esc_attr( $values['icon_bill'] ); ?>" />
            </div>
        </div>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'CUSTOM BUTTON 1', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Optional quick action for your venue.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-form-grid">
            <div class="noesia-swa-form-group">
                <label for="noesia-swa-cst1-label"><?php esc_html_e( 'Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-cst1-label" name="noesia_swa_options[cst1_label]" value="<?php echo esc_attr( $values['cst1_label'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-cst1-icon"><?php esc_html_e( 'Icon', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-cst1-icon" name="noesia_swa_options[cst1_icon]" value="<?php echo esc_attr( $values['cst1_icon'] ); ?>" />
            </div>
        </div>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'CUSTOM BUTTON 2', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Second optional quick action for the customer page.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-form-grid">
            <div class="noesia-swa-form-group">
                <label for="noesia-swa-cst2-label"><?php esc_html_e( 'Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-cst2-label" name="noesia_swa_options[cst2_label]" value="<?php echo esc_attr( $values['cst2_label'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-cst2-icon"><?php esc_html_e( 'Icon', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-cst2-icon" name="noesia_swa_options[cst2_icon]" value="<?php echo esc_attr( $values['cst2_icon'] ); ?>" />
            </div>
        </div>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'REVIEW CTA', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Optional review link shown to customers.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-form-grid">
            <div class="noesia-swa-form-group">
                <label for="noesia-swa-rate-label"><?php esc_html_e( 'Review Button Label', 'noesia-smart-waiter' ); ?></label>
                <input type="text" id="noesia-swa-rate-label" name="noesia_swa_options[rate_label]" value="<?php echo esc_attr( $values['rate_label'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group">
                <label for="noesia-swa-review-url"><?php esc_html_e( 'Review URL', 'noesia-smart-waiter' ); ?></label>
                <input type="url" id="noesia-swa-review-url" name="noesia_swa_options[review_url]" value="<?php echo esc_url( $values['review_url'] ); ?>" />
            </div>
        </div>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'COLOR PALETTE', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Controls the customer interface background and text colors.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-form-row">
            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-color-bg"><?php esc_html_e( 'Background', 'noesia-smart-waiter' ); ?></label>
                <input type="color" id="noesia-swa-color-bg" name="noesia_swa_options[color_bg]" value="<?php echo esc_attr( $values['color_bg'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-color-title"><?php esc_html_e( 'Title', 'noesia-smart-waiter' ); ?></label>
                <input type="color" id="noesia-swa-color-title" name="noesia_swa_options[color_title]" value="<?php echo esc_attr( $values['color_title'] ); ?>" />
            </div>

            <div class="noesia-swa-form-group noesia-swa-form-group--small">
                <label for="noesia-swa-color-text"><?php esc_html_e( 'Text', 'noesia-smart-waiter' ); ?></label>
                <input type="color" id="noesia-swa-color-text" name="noesia_swa_options[color_text]" value="<?php echo esc_attr( $values['color_text'] ); ?>" />
            </div>
        </div>
    </div>

    <div class="noesia-swa-card noesia-swa-card--span2">
        <div class="noesia-swa-inline-actions">
            <?php submit_button( __( 'Save Changes', 'noesia-smart-waiter' ), 'primary', 'submit', false ); ?>
            <button type="button" class="button noesia-swa-design-restore-button"><?php esc_html_e( 'Restore Texts & Icons', 'noesia-smart-waiter' ); ?></button>
        </div>
    </div>
</div>
</div>

<?php
/**
 * Allow extensions (including Pro) to inject UI after the Design form.
 *
 * @param array $values  Current resolved option values.
 * @param array $options Raw saved options.
 */
do_action( 'noesia_swa_design_form_after', $values, $options );
?>


<?php
} )( $noesia_swa_design_parent_options );
