<?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 number input field.
 *
 * @param array $args {
 *   @type string $id
 *   @type string $label
 *   @type mixed  $value
 *   @type mixed  $min
 *   @type mixed  $max
 *   @type mixed  $step
 *   @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'] )       ? $args['value']       : '';
$min      = isset( $args['min'] )         ? $args['min']         : '';
$max      = isset( $args['max'] )         ? $args['max']         : '';
$step     = isset( $args['step'] )        ? $args['step']        : '';
$desc     = isset( $args['description'] ) ? $args['description'] : '';
$disabled = ! empty( $args['disabled'] );
?>
<div class="tncfb-field tncfb-field-number<?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'] ); } ?></label>
    <?php endif; ?>
    <input
        type="number"
        id="<?php echo esc_attr( $id ); ?>"
        name="<?php echo esc_attr( $id ); ?>"
        value="<?php echo esc_attr( $value ); ?>"
        <?php echo '' !== $min  ? 'min="'  . esc_attr( $min )  . '"' : ''; ?>
        <?php echo '' !== $max  ? 'max="'  . esc_attr( $max )  . '"' : ''; ?>
        <?php echo '' !== $step ? 'step="' . esc_attr( $step ) . '"' : ''; ?>
        class="small-text"
        <?php disabled( $disabled, true ); ?>
    />
    <?php if ( $desc ) : ?>
        <p class="tncfb-field-desc"><?php echo esc_html( $desc ); ?></p>
    <?php endif; ?>
</div>
