<?php
/**
 * Public Verification Form and Result Template
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }
?>

<div class="cloudi7-icg-verification-wrap">
    <form method="post" action="" class="cloudi7-icg-verify-form no-print">
        <h3><?php echo esc_html__( 'Verify ID Card', 'cloudi7-id-card-generator' ); ?></h3>
        <div class="cloudi7-icg-form-group">
            <?php wp_nonce_field( 'cloudi7_icg_verify_action', 'cloudi7_icg_nonce' ); ?>
            <input type="text" name="cloudi7_icg_id_number" placeholder="<?php echo esc_attr__( 'Enter ID Number', 'cloudi7-id-card-generator' ); ?>" required>
            <button type="submit" name="cloudi7_icg_verify_id" class="cloudi7-icg-btn"><?php echo esc_html__( 'Verify', 'cloudi7-id-card-generator' ); ?></button>
        </div>
    </form>

    <?php if ( ! empty( $cloudi7_icg_error ) ) : ?>
        <div class="cloudi7-icg-error no-print"><?php echo esc_html( $cloudi7_icg_error ); ?></div>
    <?php endif; ?>

    <?php if ( $cloudi7_icg_card ) : ?>
        <div class="cloudi7-icg-verification-result">
            <div class="cloudi7-icg-result-header no-print">
                <div class="cloudi7-icg-status-badge">
                    <span class="dashicons dashicons-yes-alt"></span>
                    <?php echo esc_html__( 'Authorized & Verified', 'cloudi7-id-card-generator' ); ?>
                </div>
                <div class="cloudi7-icg-card-actions">
                    <button type="button" class="cloudi7-icg-btn cloudi7-icg-btn-download-main" onclick="event.preventDefault(); window.cloudi7_icg_download_card('.cloudi7-icg-card-downloadable', 'ID-Card-<?php echo esc_js($cloudi7_icg_card->id_number); ?>');">
                        <span class="dashicons dashicons-download"></span>
                        <?php echo esc_html__( 'Download Card', 'cloudi7-id-card-generator' ); ?>
                    </button>
                </div>
            </div>

            <?php 
            $cloudi7_icg_skin        = get_option( 'cloudi7_icg_template_skin', 'modern' );
            $cloudi7_icg_front_file  = Cloudi7_ICG_PLUGIN_DIR . 'templates/' . $cloudi7_icg_skin . '/front.php';
            $cloudi7_icg_back_file   = Cloudi7_ICG_PLUGIN_DIR . 'templates/' . $cloudi7_icg_skin . '/back.php';
            
            if ( file_exists( $cloudi7_icg_front_file ) ) {
                echo '<div class="cloudi7-icg-card-preview-wrapper">';
                echo '<div class="cloudi7-icg-card-downloadable">';
                echo '<div class="cloudi7-icg-card-front-wrap">';
                include $cloudi7_icg_front_file;
                echo '</div>';
                if ( file_exists( $cloudi7_icg_back_file ) ) {
                    echo '<div class="cloudi7-icg-card-back-wrap">';
                    include $cloudi7_icg_back_file;
                    echo '</div>';
                }
                echo '</div>';
                echo '</div>';
            } else {
                echo '<div class="cloudi7-icg-error">' . esc_html__( 'Template not found.', 'cloudi7-id-card-generator' ) . '</div>';
            }
            ?>
        </div>
    <?php endif; ?>
</div>
