<?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; }

/**
 * Wraps a field group with a "Use Global Default" toggle.
 *
 * When the toggle is ON  → the wrapped fields are disabled and the global value is used.
 * When the toggle is OFF → the wrapped fields are enabled for per-flipbook override.
 *
 * Usage:
 *   $args = [
 *       'meta_key'     => '_tncfb3d_toolbar_share',        // Base meta key (without _override suffix)
 *       'override_val' => false,                          // Current _override meta value
 *       'label'        => __('Share Button', 'tnc-flipbook-3d-lite'),
 *   ];
 *   include TNCFB_VIEWS . 'field-global-override.php';
 *   // ... render inner field(s) here ...
 *   include TNCFB_VIEWS . 'field-global-override-end.php';  // closes the wrapper
 *
 * This partial only renders the opening wrapper + toggle. The caller must echo the inner fields,
 * then close `.tncfb-override-body` and `.tncfb-override-wrap` themselves (or use the -end partial).
 *
 * @param array $args {
 *   @type string $meta_key     Base meta key (the companion key is "{$meta_key}_override")
 *   @type bool   $override_val Current value of the _override flag (true = use per-flipbook value)
 *   @type string $label        Field group label shown next to the toggle
 * }
 */
if ( ! isset( $args ) ) { return; }
$meta_key     = isset( $args['meta_key'] )     ? $args['meta_key']     : '';
$override_val = ! empty( $args['override_val'] );
$label        = isset( $args['label'] )        ? $args['label']        : '';
$override_id  = esc_attr( $meta_key ) . '_override';
?>
<div class="tncfb-override-wrap" data-override-key="<?php echo esc_attr( $meta_key ); ?>">
    <div class="tncfb-override-header">
        <span class="tncfb-override-label"><?php echo esc_html( $label ); ?><?php if ( ! empty( $args['tip'] ) ) { tncfb3d_tip( $args['tip'] ); } ?></span>
        <label class="tncfb-override-toggle">
            <input
                type="checkbox"
                class="tncfb-override-checkbox"
                id="<?php echo esc_attr( $override_id ); ?>"
                name="<?php echo esc_attr( $override_id ); ?>"
                value="1"
                <?php checked( $override_val, true ); ?>
            />
            <span class="tncfb-switcher-slider tncfb-switcher-small"></span>
            <span class="tncfb-override-toggle-label">
                <?php echo $override_val
                    ? esc_html__( 'Custom value', 'tnc-flipbook-3d-lite' )
                    : esc_html__( 'Using global default', 'tnc-flipbook-3d-lite' ); ?>
            </span>
        </label>
    </div>
    <div class="tncfb-override-body <?php echo $override_val ? '' : 'is-disabled'; ?>">
