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

/**
 * Reusable toggle switch field.
 *
 * @param array $args {
 *   @type string $id          Input id/name attribute (required)
 *   @type string $label       Label text
 *   @type bool   $value       Current value
 *   @type string $description Optional description below the field
 *   @type bool   $disabled    Whether the input is disabled
 * }
 */
if ( ! isset( $args ) ) { return; }
$id       = isset( $args['id'] )          ? $args['id']          : '';
$label    = isset( $args['label'] )       ? $args['label']       : '';
$value    = ! empty( $args['value'] );
$desc     = isset( $args['description'] ) ? $args['description'] : '';
$disabled = ! empty( $args['disabled'] );
?>
<div class="tncfb-field tncfb-field-switcher<?php echo $disabled ? ' tncfb-field-disabled' : ''; ?>">
    <label class="tncfb-switcher-wrap">
        <input
            type="checkbox"
            id="<?php echo esc_attr( $id ); ?>"
            name="<?php echo esc_attr( $id ); ?>"
            value="1"
            <?php checked( $value, true ); ?>
            <?php disabled( $disabled, true ); ?>
        />
        <span class="tncfb-switcher-slider"></span>
        <?php if ( $label ) : ?>
            <span class="tncfb-switcher-label"><?php echo esc_html( $label ); ?><?php if ( ! empty( $args['tip'] ) ) { tncfb3d_tip( $args['tip'] ); } ?></span>
        <?php endif; ?>
    </label>
    <?php if ( $desc ) : ?>
        <p class="tncfb-field-desc"><?php echo esc_html( $desc ); ?></p>
    <?php endif; ?>
</div>
