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