<?php
namespace Storzen\Fields;
use Storzen\Contracts\Field;
defined('ABSPATH') || exit;

class Text extends Field {
    /** @var string */ protected $placeholder = '';
    /** @var string */ protected $input_type  = 'text';

    /** @return static */
    public function set_placeholder( $p ) { $this->placeholder = $p; return $this; }
    /** @return static */
    public function placeholder( $p )     { return $this->set_placeholder($p); }

    public function sanitize( $raw ) { return sanitize_text_field( (string)$raw ); }
    public function render( $value ) {
    $id = $this->field_id();
    $is_pro_active = defined('STORZEN_IS_PRO') && STORZEN_IS_PRO === 'yes';
    $show_pro = $this->pro && ! $is_pro_active;
    echo '<input type="' . esc_attr($this->input_type) . '" class="sz-input"';
    echo ' id="' . esc_attr($id) . '" name="' . esc_attr($this->field_name()) . '"';
    echo ' value="' . esc_attr( (string)$value ) . '"';
    // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- disabled attribute may be added
    echo ' placeholder="' . esc_attr($this->placeholder) . '"' . ( $show_pro ? ' disabled' : '' ) . '>';
    if ( $show_pro ) echo '<span class="sz-pro-badge">PRO</span>';
    }
}
