<?php
/**
 * Public Application Form Template
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

$cloudi7_icg_org_type = get_option( 'cloudi7_icg_org_type', 'School' );
$cloudi7_icg_org_name = get_option( 'cloudi7_icg_org_name', '' );
?>

<div class="cloudi7-icg-apply-wrap">
    <div class="cloudi7-icg-apply-container">
        <header class="cloudi7-icg-apply-header">
            <h2>
                <?php
                /* translators: %s: organization name */
                printf( esc_html__( 'Apply for %s ID Card', 'cloudi7-id-card-generator' ), esc_html( $cloudi7_icg_org_name ) );
                ?>
            </h2>
            <p><?php esc_html_e( 'Please fill out the form below to request your digital ID card. Your application will be reviewed by our administration.', 'cloudi7-id-card-generator' ); ?></p>
        </header>

        <?php
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if ( isset( $_GET['app_success'] ) ) : ?>
            <div class="cloudi7-icg-success">
                <span class="dashicons dashicons-yes-alt"></span>
                <h3><?php esc_html_e( 'Application Submitted!', 'cloudi7-id-card-generator' ); ?></h3>
                <p><?php esc_html_e( 'Thank you for applying. We have received your details and will notify you once your ID card is approved and ready for use.', 'cloudi7-id-card-generator' ); ?></p>
            </div>
        <?php else : ?>

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

            <form action="<?php echo esc_url( remove_query_arg( 'app_success' ) ); ?>" method="post" enctype="multipart/form-data" class="cloudi7-icg-apply-form">
                <?php wp_nonce_field( 'cloudi7_icg_action', 'cloudi7_icg_nonce' ); ?>
                <input type="hidden" name="cloudi7_icg_form_submitted" value="1">
                <input type="hidden" name="org_type" value="<?php echo esc_attr( $cloudi7_icg_org_type ); ?>">

                <div class="cloudi7-icg-form-section">
                    <h3><?php esc_html_e( 'Personal Information', 'cloudi7-id-card-generator' ); ?></h3>
                    
                    <div class="cloudi7-icg-form-row">
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Full Name', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                            <input type="text" name="name" required placeholder="<?php esc_attr_e( 'Enter your full name', 'cloudi7-id-card-generator' ); ?>">
                        </div>
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Photo', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                            <input type="file" name="photo" accept="image/*" required>
                            <small><?php esc_html_e( 'Passport size photo (JPG/PNG)', 'cloudi7-id-card-generator' ); ?></small>
                        </div>
                    </div>

                    <div class="cloudi7-icg-form-row">
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Date of Birth', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                            <input type="date" name="dob" required>
                        </div>
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Blood Group', 'cloudi7-id-card-generator' ); ?></label>
                            <select name="blood_group">
                                <option value="">-- <?php esc_html_e( 'Select', 'cloudi7-id-card-generator' ); ?> --</option>
                                <option value="A+">A+</option>
                                <option value="A-">A-</option>
                                <option value="B+">B+</option>
                                <option value="B-">B-</option>
                                <option value="O+">O+</option>
                                <option value="O-">O-</option>
                                <option value="AB+">AB+</option>
                                <option value="AB-">AB-</option>
                            </select>
                        </div>
                    </div>

                    <div class="cloudi7-icg-form-row">
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Email Address', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                            <input type="email" name="email" required placeholder="example@email.com">
                        </div>
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Phone Number', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                            <input type="text" name="phone" required placeholder="+1234567890">
                        </div>
                    </div>

                    <div class="cloudi7-icg-form-row">
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Government ID Number', 'cloudi7-id-card-generator' ); ?></label>
                            <input type="text" name="gov_id" placeholder="<?php esc_attr_e( 'Aadhar, License, etc.', 'cloudi7-id-card-generator' ); ?>">
                        </div>
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Address', 'cloudi7-id-card-generator' ); ?></label>
                            <input type="text" name="address" placeholder="<?php esc_attr_e( 'Full residential address', 'cloudi7-id-card-generator' ); ?>">
                        </div>
                    </div>
                </div>

                <div class="cloudi7-icg-form-section">
                    <h3><?php esc_html_e( 'Guardian / Parent Information', 'cloudi7-id-card-generator' ); ?></h3>
                    <div class="cloudi7-icg-form-row">
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Parent / Guardian Name', 'cloudi7-id-card-generator' ); ?></label>
                            <input type="text" name="parent_name" placeholder="<?php esc_attr_e( 'Father/Mother name', 'cloudi7-id-card-generator' ); ?>">
                        </div>
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Parent / Guardian Phone', 'cloudi7-id-card-generator' ); ?></label>
                            <input type="text" name="parent_phone" placeholder="<?php esc_attr_e( 'Emergency contact number', 'cloudi7-id-card-generator' ); ?>">
                        </div>
                    </div>
                </div>

                <div class="cloudi7-icg-form-section">
                    <h3>
                        <?php
                        /* translators: %s: organization type */
                        printf( esc_html__( '%s Details', 'cloudi7-id-card-generator' ), esc_html( $cloudi7_icg_org_type ) );
                        ?>
                    </h3>
                    
                    <?php if ( 'School' === $cloudi7_icg_org_type ) : ?>
                        <div class="cloudi7-icg-form-row">
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Class / Grade', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                                <input type="text" name="school_class" required placeholder="e.g. Grade 10">
                            </div>
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Student ID / Roll No', 'cloudi7-id-card-generator' ); ?></label>
                                <input type="text" name="school_roll" placeholder="e.g. 123456">
                            </div>
                        </div>

                    <?php elseif ( 'Corporate' === $cloudi7_icg_org_type ) : ?>
                        <div class="cloudi7-icg-form-row">
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Department', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                                <input type="text" name="dept" required placeholder="e.g. Marketing">
                            </div>
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Designation', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                                <input type="text" name="designation" required placeholder="e.g. Senior Manager">
                            </div>
                        </div>
                        <div class="cloudi7-icg-form-group">
                            <label><?php esc_html_e( 'Employee ID', 'cloudi7-id-card-generator' ); ?></label>
                            <input type="text" name="emp_id" placeholder="e.g. EMP-101">
                        </div>

                    <?php elseif ( 'Event' === $cloudi7_icg_org_type ) : ?>
                        <div class="cloudi7-icg-form-row">
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Role at Event', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                                <input type="text" name="event_role" required placeholder="e.g. Attendee, Speaker">
                            </div>
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Company / Organization', 'cloudi7-id-card-generator' ); ?></label>
                                <input type="text" name="company" placeholder="Your organization name">
                            </div>
                        </div>

                    <?php elseif ( 'Club' === $cloudi7_icg_org_type ) : ?>
                        <div class="cloudi7-icg-form-row">
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Member ID', 'cloudi7-id-card-generator' ); ?></label>
                                <input type="text" name="member_id" placeholder="e.g. CLUB-55">
                            </div>
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Membership Type', 'cloudi7-id-card-generator' ); ?></label>
                                <input type="text" name="mem_type" placeholder="e.g. Gold, Silver">
                            </div>
                        </div>

                    <?php elseif ( 'Media' === $cloudi7_icg_org_type ) : ?>
                        <div class="cloudi7-icg-form-row">
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Media House', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                                <input type="text" name="media_house" required placeholder="e.g. News Corp">
                            </div>
                            <div class="cloudi7-icg-form-group">
                                <label><?php esc_html_e( 'Role', 'cloudi7-id-card-generator' ); ?> <span>*</span></label>
                                <input type="text" name="media_role" required placeholder="e.g. Reporter">
                            </div>
                        </div>
                    <?php endif; ?>
                </div>

                <div class="cloudi7-icg-form-footer">
                    <button type="submit" name="cloudi7_icg_submit_app" class="cloudi7-icg-btn cloudi7-icg-btn-large">
                        <?php esc_html_e( 'Submit Application', 'cloudi7-id-card-generator' ); ?>
                    </button>
                </div>
            </form>
        <?php endif; ?>
    </div>
</div>



