<?php
/**
 * Classic Horizontal Template
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

// Organization Data
$cloudi7_icg_org_logo    = get_option( 'cloudi7_icg_org_logo', '' );
$cloudi7_icg_org_name    = get_option( 'cloudi7_icg_org_name', 'Your Organization' );
$cloudi7_icg_org_address = get_option( 'cloudi7_icg_org_address', '' );
$cloudi7_icg_org_phone   = get_option( 'cloudi7_icg_org_phone', '' );
$cloudi7_icg_org_email   = get_option( 'cloudi7_icg_org_email', '' );
$cloudi7_icg_org_website = get_option( 'cloudi7_icg_org_website', '' );
$cloudi7_icg_org_terms   = get_option( 'cloudi7_icg_org_terms', '' );
$cloudi7_icg_back_text   = get_option( 'cloudi7_icg_back_text', '' );

// Card Data
$cloudi7_icg_id_number = $cloudi7_icg_card->id_number;
$cloudi7_icg_name      = $cloudi7_icg_card->name;
$cloudi7_icg_photo     = $cloudi7_icg_card->photo ? $cloudi7_icg_card->photo : plugins_url( 'assets/images/default-avatar.png', dirname( dirname( __FILE__ ) ) );
$cloudi7_icg_org_type  = $cloudi7_icg_card->organization_type;
$cloudi7_icg_extra_data = json_decode( $cloudi7_icg_card->extra_data, true );

// QR Code Path
$cloudi7_icg_upload_dir = wp_upload_dir();
$cloudi7_icg_qr_url = $cloudi7_icg_upload_dir['baseurl'] . '/cloudi7-icg-qrcodes/' . $cloudi7_icg_id_number . '.png';
?>

<div class="cloudi7-icg-card-wrapper cloudi7-icg-template-classic cloudi7-icg-orientation-horizontal">
    <!-- FRONT SIDE -->
    <div class="cloudi7-icg-card cloudi7-icg-card-front">
        <div class="cloudi7-icg-card-header">
            <?php if ( $cloudi7_icg_org_logo ) : ?>
                <img src="<?php echo esc_url( $cloudi7_icg_org_logo ); ?>" class="cloudi7-icg-org-logo">
            <?php endif; ?>
            <div class="cloudi7-icg-header-text">
                <h2 class="cloudi7_icg_org_name"><?php echo esc_html( $cloudi7_icg_org_name ); ?></h2>
                <div class="cloudi7-icg-org-type"><?php echo esc_html( $cloudi7_icg_org_type ); ?> IDENTITY</div>
            </div>
        </div>
        
        <div class="cloudi7-icg-card-body">
            <div class="cloudi7-icg-body-left">
                <div class="cloudi7-icg-photo-frame">
                    <img src="<?php echo esc_url( $cloudi7_icg_photo ); ?>" class="cloudi7-icg-user-photo">
                </div>
            </div>
            
            <div class="cloudi7-icg-body-right">
                <h3 class="cloudi7-icg-user-name"><?php echo esc_html( $cloudi7_icg_name ); ?></h3>
                <div class="cloudi7-icg-id-row">
                    <strong>ID NO:</strong> <span><?php echo esc_html( $cloudi7_icg_id_number ); ?></span>
                </div>
                
                <div class="cloudi7-icg-details-list">
                    <?php if ( ! empty( $cloudi7_icg_extra_data ) ) : ?>
                        <?php foreach ( $cloudi7_icg_extra_data as $cloudi7_icg_label => $cloudi7_icg_value ) : ?>
                            <div class="cloudi7-icg-detail-item">
                                <span class="cloudi7-icg-label"><?php echo esc_html( strtoupper( str_replace('_', ' ', $cloudi7_icg_label) ) ); ?>:</span>
                                <span class="cloudi7-icg-val"><?php echo esc_html( $cloudi7_icg_value ); ?></span>
                            </div>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </div>
            </div>
            
            <div class="cloudi7-icg-qr-classic">
                <img src="<?php echo esc_url( $cloudi7_icg_qr_url ); ?>" class="cloudi7-icg-qr-code">
            </div>
        </div>
    </div>

    <!-- BACK SIDE -->
    <div class="cloudi7-icg-card cloudi7-icg-card-back">
        <div class="cloudi7-icg-back-inner">
            <div class="cloudi7-icg-back-header">Information & Instructions</div>
            
            <div class="cloudi7-icg-back-body">
                <?php if ( $cloudi7_icg_org_address ) : ?>
                    <div class="cloudi7-icg-addr-block">
                        <strong>Office Address:</strong><br>
                        <?php echo esc_html( $cloudi7_icg_org_address ); ?>
                    </div>
                <?php endif; ?>

                <div class="cloudi7-icg-contact-block">
                    <?php if ( $cloudi7_icg_org_phone ) : ?><span>Tel: <?php echo esc_html( $cloudi7_icg_org_phone ); ?></span><br><?php endif; ?>
                    <?php if ( $cloudi7_icg_org_email ) : ?><span>Email: <?php echo esc_html( $cloudi7_icg_org_email ); ?></span><br><?php endif; ?>
                    <?php if ( $cloudi7_icg_org_website ) : ?><span>Web: <?php echo esc_url( $cloudi7_icg_org_website ); ?></span><?php endif; ?>
                </div>
                
                <?php if ( $cloudi7_icg_back_text ) : ?>
                    <div class="cloudi7-icg-classic-back-text">
                        <?php echo wp_kses_post( wpautop( $cloudi7_icg_back_text ) ); ?>
                    </div>
                <?php endif; ?>

                <?php if ( $cloudi7_icg_org_terms ) : ?>
                    <div class="cloudi7-icg-classic-terms">
                        <strong>Terms of Use:</strong>
                        <div class="cloudi7-icg-terms-scroll">
                            <?php echo wp_kses_post( wpautop( $cloudi7_icg_org_terms ) ); ?>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
            
            <div class="cloudi7-icg-back-footer">
                If found, please return to the address mentioned above.
            </div>
        </div>
    </div>
</div>
