<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound, WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Template-scope variables and single-post admin meta reads, not globals or slow queries.
if ( ! defined( 'ABSPATH' ) ) { exit; }

/**
 * Tab 3 - Display (Lite version)
 * Settings: Color Scheme (7 palettes), Default Theme, Render Mode
 * Variables: $post, $meta, $schema, $global
 */

$p = TNC_FLIPBOOK_3D_PREFIX;

// Helper: get effective value (override check)
if ( ! function_exists( 'tncfb3d_field' ) ) {
    function tncfb3d_field( $meta, $global, $key, $fallback = '' ) {
        $override = ! empty( $meta[ $key . '_override' ] );
        if ( $override && isset( $meta[ $key ] ) ) {
            return $meta[ $key ];
        }
        if ( isset( $global[ $key ] ) ) {
            return $global[ $key ];
        }
        return $fallback;
    }
}

$lite_chromes = array(
    'slate'    => array( 'label' => __( 'Slate',    'tnc-flipbook-3d-lite' ), 'desc' => __( 'Neutral cool-gray surfaces.', 'tnc-flipbook-3d-lite' ),               'preview' => 'linear-gradient(to bottom right, #1c1c22 50%, #f5f5f7 50%)', 'pro' => false ),
    'paper'    => array( 'label' => __( 'Paper',    'tnc-flipbook-3d-lite' ), 'desc' => __( 'Clean off-white surfaces.', 'tnc-flipbook-3d-lite' ),                 'preview' => 'linear-gradient(to bottom right, #ffffff 50%, #1c1c22 50%)', 'pro' => false  ),
    'midnight' => array( 'label' => __( 'Midnight', 'tnc-flipbook-3d-lite' ), 'desc' => __( 'Deep blue-black tones.', 'tnc-flipbook-3d-lite' ),                    'preview' => 'linear-gradient(to bottom right, #1a2540 50%, #dde4f3 50%)', 'pro' => false  ),
    'ocean'    => array( 'label' => __( 'Ocean',    'tnc-flipbook-3d-lite' ), 'desc' => __( 'Cool teal/blue tint.', 'tnc-flipbook-3d-lite' ),                     'preview' => 'linear-gradient(to bottom right, #1d4148 50%, #cfe6ea 50%)', 'pro' => false  ),
    'forest'   => array( 'label' => __( 'Forest',   'tnc-flipbook-3d-lite' ), 'desc' => __( 'Subtle green tint.', 'tnc-flipbook-3d-lite' ),                       'preview' => 'linear-gradient(to bottom right, #1f3a26 50%, #cfe2d4 50%)', 'pro' => false  ),
    'glass'    => array( 'label' => __( 'Glass',    'tnc-flipbook-3d-lite' ), 'desc' => __( 'Translucent frosted surfaces.', 'tnc-flipbook-3d-lite' ),             'preview' => 'linear-gradient(135deg, rgba(20,20,24,0.55), rgba(80,80,90,0.35))', 'pro' => false ),
    'sepia'    => array( 'label' => __( 'Sepia',    'tnc-flipbook-3d-lite' ), 'desc' => __( 'Warm cream tones for editorial reading.', 'tnc-flipbook-3d-lite' ),   'preview' => 'linear-gradient(to bottom right, #4a341f 50%, #f4ecd8 50%)', 'pro' => false  ),
);
?>
<div class="tncfb-appearance-tab">

    <!-- Color Scheme -->
    <?php
    $key      = 'chrome';
    $override = ! empty( $meta[ $key . '_override' ] );
    $args     = array( 'meta_key' => $p . $key, 'override_val' => $override, 'label' => __( 'Color Scheme', 'tnc-flipbook-3d-lite' ), 'tip' => 'chrome' );
    include TNC_FLIPBOOK_3D_DIR . 'admin/partials/field-global-override.php';
    ?>
        <div class="tncfb-chrome-cards">
            <?php foreach ( $lite_chromes as $ch_key => $ch ) : ?>
                <label class="tncfb-chrome-card <?php echo $ch_key === ( isset( $meta['chrome'] ) ? $meta['chrome'] : 'slate' ) ? 'is-active' : ''; ?>"
                       data-value="<?php echo esc_attr( $ch_key ); ?>"
                       <?php if ( $ch['pro'] ) : ?>style="opacity:0.55;pointer-events:none;cursor:not-allowed;"<?php endif; ?>>
                    <input type="radio"
                           name="<?php echo esc_attr( $p . $key ); ?>"
                           value="<?php echo esc_attr( $ch_key ); ?>"
                           <?php checked( $ch_key, isset( $meta['chrome'] ) ? $meta['chrome'] : 'slate' ); ?>
                           <?php disabled( $ch['pro'] || ! $override, true ); ?> />
                    <span class="tncfb-chrome-card-preview" style="background:<?php echo esc_attr( $ch['preview'] ); ?>"></span>
                    <span class="tncfb-chrome-card-body">
                        <span class="tncfb-chrome-card-label">
                            <?php echo esc_html( $ch['label'] ); ?>
                            <?php if ( $ch['pro'] ) : ?><?php endif; ?>
                        </span>
                        <span class="tncfb-chrome-card-desc"><?php echo esc_html( $ch['desc'] ); ?></span>
                    </span>
                </label>
            <?php endforeach; ?>
        </div>
        <p class="tncfb-field-desc" style="margin-top:8px;"><?php esc_html_e( 'Surface palette for the toolbar, sidebars, and popups.', 'tnc-flipbook-3d-lite' ); ?></p>
    </div>
    </div>

    <!-- Default Theme (color mode polarity) -->
    <?php
    $cm_key      = 'colorMode';
    $cm_override = ! empty( $meta[ $cm_key . '_override' ] );
    $cm_value    = tncfb3d_field( $meta, $global, $cm_key, 'auto' );
    $args        = array( 'meta_key' => $p . $cm_key, 'override_val' => $cm_override, 'label' => __( 'Default Theme', 'tnc-flipbook-3d-lite' ), 'tip' => 'colorMode' );
    include TNC_FLIPBOOK_3D_DIR . 'admin/partials/field-global-override.php';
    $args = array(
        'id'          => $p . $cm_key,
        'label'       => __( 'Default Theme', 'tnc-flipbook-3d-lite' ),
        'value'       => $cm_value,
        'options'     => array(
            'auto'  => __( 'Auto (use chrome default)', 'tnc-flipbook-3d-lite' ),
            'dark'  => __( 'Dark',  'tnc-flipbook-3d-lite' ),
            'light' => __( 'Light', 'tnc-flipbook-3d-lite' ),
        ),
        'description' => __( 'Initial polarity on load. Readers can flip via the toolbar toggle.', 'tnc-flipbook-3d-lite' ),
        'disabled'    => ! $cm_override,
    );
    include TNC_FLIPBOOK_3D_DIR . 'admin/partials/field-select.php';
    ?>
    </div>
    </div>

    <!-- Render Mode -->
    <?php
    $key      = 'renderMode';
    $override = ! empty( $meta[ $key . '_override' ] );
    $value    = ( $override && isset( $meta[ $key ] ) ) ? $meta[ $key ] : ( $global[ $key ] ?? 'auto' );
    $args     = array( 'meta_key' => $p . $key, 'override_val' => $override, 'label' => __( 'Render Mode', 'tnc-flipbook-3d-lite' ), 'tip' => 'renderMode' );
    include TNC_FLIPBOOK_3D_DIR . 'admin/partials/field-global-override.php';
    $args = array(
        'id'          => $p . $key,
        'value'       => $value,
        'options'     => array(
            'auto' => __( 'Auto (3D if WebGL, 2D fallback)', 'tnc-flipbook-3d-lite' ),
            '3d'   => __( '3D Only', 'tnc-flipbook-3d-lite' ),
            '2d'   => __( '2D CSS Only', 'tnc-flipbook-3d-lite' ),
        ),
        'description' => __( 'Auto detects WebGL support and falls back to a CSS-based 2D flip mode.', 'tnc-flipbook-3d-lite' ),
        'disabled'    => ! $override,
    );
    include TNC_FLIPBOOK_3D_DIR . 'admin/partials/field-select.php';
    ?>
    </div>
    </div>

    <!-- Pro Features Teaser -->
    <?php
    $pro_teaser = array(
        'title' => __( 'More Display Settings in Pro', 'tnc-flipbook-3d-lite' ),
        'icon'  => 'dashicons-art',
        'features' => array(
            __( '4 flip effects: Realistic, Hard Cover, Slide, Fade', 'tnc-flipbook-3d-lite' ),
            __( '3 book styles: Default, Hardcover, Spiral', 'tnc-flipbook-3d-lite' ),
            __( 'Page curl intensity control', 'tnc-flipbook-3d-lite' ),
            __( '13 flip sound effects + custom upload', 'tnc-flipbook-3d-lite' ),
            __( 'Glossy reflections, paper types', 'tnc-flipbook-3d-lite' ),
            __( 'Custom brand logo (dark + light)', 'tnc-flipbook-3d-lite' ),
            __( 'Camera and scene controls', 'tnc-flipbook-3d-lite' ),
            __( 'Custom flip animation duration', 'tnc-flipbook-3d-lite' ),
            __( 'Render scale (quality) control', 'tnc-flipbook-3d-lite' ),
        ),
    );
    include TNC_FLIPBOOK_3D_DIR . 'admin/views/pro-teaser-inline.php';
    ?>

</div><!-- .tncfb-appearance-tab -->
