<?php
/**
 * QR / Setup section for Noesia Smart Waiter.
 *
 * @package Noesia_Smart_Waiter
 */

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

$noesia_swa_qr_plugin_assets_url = isset( $plugin_assets_url ) ? (string) $plugin_assets_url : '';
( static function ( $noesia_swa_qr_plugin_assets_url ) {
    $plugin_assets_url = $noesia_swa_qr_plugin_assets_url;

$plugin_assets_url = defined( 'NOESIA_SWA_PLUGIN_URL' ) ? trailingslashit( NOESIA_SWA_PLUGIN_URL . 'admin/assets' ) : '';
$default_base_url  = home_url( '/smartmenu/' );
?>

<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( 'QR / Setup', 'noesia-smart-waiter' ); ?></h3>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Generate QR codes for table locations and prepare your venue setup.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <?php
        /**
         * Fires after the QR / Setup form grid.
         *
         * @param string $default_base_url Suggested default base URL.
         * @param string $plugin_assets_url Plugin admin assets URL.
         */
        do_action( 'noesia_swa_qr_setup_form_after', $default_base_url, $plugin_assets_url );
        ?>
    </div>

    <div class="noesia-swa-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'QR / SETUP', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Create printable QR codes for table names or location labels.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <?php
        /**
         * Fires before the QR / Setup form grid.
         *
         * @param string $default_base_url Suggested default base URL.
         * @param string $plugin_assets_url Plugin admin assets URL.
         */
        do_action( 'noesia_swa_qr_setup_form_before', $default_base_url, $plugin_assets_url );
        ?>

        <div class="noesia-swa-form-grid">
            <div class="noesia-swa-form-group">
                <label for="qr_base_url"><?php esc_html_e( 'Base URL', 'noesia-smart-waiter' ); ?></label>
                <input
                    type="url"
                    id="qr_base_url"
                    value="<?php echo esc_url( $default_base_url ); ?>"
                />
                <p class="noesia-swa-muted">
                    <strong><?php esc_html_e( 'Important:', 'noesia-smart-waiter' ); ?></strong>
                    <?php esc_html_e( 'The public customer page used for QR scans should use the exact slug', 'noesia-smart-waiter' ); ?>
                    <code>/smartmenu</code>
                    <?php esc_html_e( 'and this field should use the full absolute URL.', 'noesia-smart-waiter' ); ?>
                </p>
                <p class="noesia-swa-muted">
                    <?php esc_html_e( 'ex: Recommended default:', 'noesia-smart-waiter' ); ?>
                    <code><?php echo esc_html( $default_base_url ); ?></code>
                </p>
            </div>

            <div class="noesia-swa-form-row">
                <div class="noesia-swa-form-group">
                    <label for="qr_prefix"><?php esc_html_e( 'Label Prefix', 'noesia-smart-waiter' ); ?></label>
                    <input
                        type="text"
                        id="qr_prefix"
                        value="<?php echo esc_attr__( 'Table', 'noesia-smart-waiter' ); ?>"
                    />
                </div>

                <div class="noesia-swa-form-group noesia-swa-form-group--small">
                    <label for="qr_start"><?php esc_html_e( 'Start', 'noesia-smart-waiter' ); ?></label>
                    <input
                        type="number"
                        id="qr_start"
                        min="1"
                        step="1"
                        value="1"
                    />
                </div>

                <div class="noesia-swa-form-group noesia-swa-form-group--small">
                    <label for="qr_end"><?php esc_html_e( 'End', 'noesia-smart-waiter' ); ?></label>
                    <input
                        type="number"
                        id="qr_end"
                        min="1"
                        step="1"
                        value="12"
                    />
                </div>
            </div>

            <div class="noesia-swa-inline-actions">
                <button type="button" id="btn-gen-qr" class="button button-primary">
                    <?php esc_html_e( 'Generate & Print QR Codes', '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( 'QR STAND TEMPLATE', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( '💡 Clever Idea: The "Always-On" Tablet. 
Want to provide a frictionless experience? Instead of having guests scan the QR code with their personal phones, mount a dedicated tablet on the table or host stand. Simply load your Smart Waiter URL once, and your digital menu will be instantly ready and waiting for every new customer—no scanning required!', 'noesia-smart-waiter' ); ?></p>
            </div>

            <?php if ( '' !== $plugin_assets_url ) : ?>
                <div class="noesia-swa-inline-actions">
                    <a
                        class="button"
                        href="<?php echo esc_url( $plugin_assets_url . 'stand-mockup.png' ); ?>"
                        target="_blank"
                        rel="noopener noreferrer"
                    >
                        <?php esc_html_e( 'View full image ↗ ', 'noesia-smart-waiter' ); ?>
                    </a>
                </div>
            <?php endif; ?>
        </div>

        <?php if ( '' !== $plugin_assets_url ) : ?>
            <img
                class="noesia-swa-doc-image"
                src="<?php echo esc_url( $plugin_assets_url . 'stand-mockup.png' ); ?>"
                alt="<?php esc_attr_e( 'QR stand template preview', 'noesia-smart-waiter' ); ?>"
            />
        <?php else : ?>
            <p class="noesia-swa-muted"><?php esc_html_e( 'Template preview unavailable.', 'noesia-smart-waiter' ); ?></p>
        <?php endif; ?>
    </div>

    <div class="noesia-swa-card noesia-swa-card--span2 noesia-swa-qr-deploy-card">
        <div class="noesia-swa-card-header">
            <div>
                <div class="noesia-swa-kicker"><?php esc_html_e( 'QUICK DEPLOYMENT NOTES', 'noesia-smart-waiter' ); ?></div>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Recommended setup before printing the QR labels.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>

        <div class="noesia-swa-qr-deploy-list">
            <div class="noesia-swa-qr-deploy-item">
                <div class="noesia-swa-qr-deploy-step"><?php esc_html_e( 'STEP 1', 'noesia-smart-waiter' ); ?></div>
                <strong class="noesia-swa-qr-deploy-title"><?php esc_html_e( 'Create the public customer page as /smartmenu', 'noesia-smart-waiter' ); ?></strong>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Add your customer shortcode on a public page using the exact slug /smartmenu, then use its full absolute URL as the Base URL above.', 'noesia-smart-waiter' ); ?></p>
                <div class="noesia-swa-qr-shortcode-row">
                    <code class="noesia-swa-qr-shortcode" data-noesia-swa-copy-source>[noesia_swa_client]</code>
                    <button type="button" class="button noesia-swa-qr-copy-btn" data-noesia-swa-copy-target="[noesia_swa_client]"><?php esc_html_e( 'Copy', 'noesia-smart-waiter' ); ?></button>
                </div>
            </div>

            <div class="noesia-swa-qr-deploy-item">
                <div class="noesia-swa-qr-deploy-step"><?php esc_html_e( 'STEP 2', 'noesia-smart-waiter' ); ?></div>
                <strong class="noesia-swa-qr-deploy-title"><?php esc_html_e( 'Create a private staff page', 'noesia-smart-waiter' ); ?></strong>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Use the live dashboard shortcode on a private or staff-only page.', 'noesia-smart-waiter' ); ?></p>
                <div class="noesia-swa-qr-shortcode-row">
                    <code class="noesia-swa-qr-shortcode" data-noesia-swa-copy-source>[noesia_swa_dashboard]</code>
                    <button type="button" class="button noesia-swa-qr-copy-btn" data-noesia-swa-copy-target="[noesia_swa_dashboard]"><?php esc_html_e( 'Copy', 'noesia-smart-waiter' ); ?></button>
                </div>
            </div>

            <div class="noesia-swa-qr-deploy-item">
                <div class="noesia-swa-qr-deploy-step"><?php esc_html_e( 'STEP 3', 'noesia-smart-waiter' ); ?></div>
                <strong class="noesia-swa-qr-deploy-title"><?php esc_html_e( 'Print and place the stands', 'noesia-smart-waiter' ); ?></strong>
                <p class="noesia-swa-muted"><?php esc_html_e( 'Generate QR labels, print them, and place them on tables, umbrellas or counters.', 'noesia-smart-waiter' ); ?></p>
            </div>
        </div>
    </div>
</div>

<?php
} )( $noesia_swa_qr_plugin_assets_url );
