<?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 range slider with live value display.
 *
 * @param array $args {
 *   @type string $id          Input id/name
 *   @type string $label
 *   @type float  $value       Current value
 *   @type float  $min         Minimum (default 0)
 *   @type float  $max         Maximum (default 100)
 *   @type float  $step        Step (default 1)
 *   @type string $unit        Unit suffix, e.g. '%', 'px' (optional)
 *   @type string $description
 *   @type bool   $disabled
 * }
 */
if ( ! isset( $args ) ) { return; }
$id       = isset( $args['id'] )          ? $args['id']          : '';
$label    = isset( $args['label'] )       ? $args['label']       : '';
$value    = isset( $args['value'] )       ? (float) $args['value']  : 0;
$min      = isset( $args['min'] )         ? (float) $args['min']    : 0;
$max      = isset( $args['max'] )         ? (float) $args['max']    : 100;
$step     = isset( $args['step'] )        ? (float) $args['step']   : 1;
$unit     = isset( $args['unit'] )        ? $args['unit']        : '';
$desc     = isset( $args['description'] ) ? $args['description'] : '';
$disabled = ! empty( $args['disabled'] );
?>
<div class="tncfb-field tncfb-field-slider<?php echo $disabled ? ' tncfb-field-disabled' : ''; ?>">
    <?php if ( $label ) : ?>
        <label for="<?php echo esc_attr( $id ); ?>" class="tncfb-label">
            <?php echo esc_html( $label ); ?><?php if ( ! empty( $args['tip'] ) ) { tncfb3d_tip( $args['tip'] ); } ?>
            <span class="tncfb-slider-value" id="<?php echo esc_attr( $id ); ?>_display">
                <?php echo esc_html( $value . $unit ); ?>
            </span>
        </label>
    <?php endif; ?>
    <input
        type="range"
        id="<?php echo esc_attr( $id ); ?>"
        name="<?php echo esc_attr( $id ); ?>"
        value="<?php echo esc_attr( $value ); ?>"
        min="<?php echo esc_attr( $min ); ?>"
        max="<?php echo esc_attr( $max ); ?>"
        step="<?php echo esc_attr( $step ); ?>"
        data-unit="<?php echo esc_attr( $unit ); ?>"
        data-display="<?php echo esc_attr( $id ); ?>_display"
        <?php disabled( $disabled, true ); ?>
    />
    <?php if ( $desc ) : ?>
        <p class="tncfb-field-desc"><?php echo esc_html( $desc ); ?></p>
    <?php endif; ?>
</div>
