<?php

namespace GriffinForms\Admin\Html\FormControls;

class InputDate extends \GriffinForms\Admin\Html\FormControls\Format
{
    protected function setCssClass()
    {
        if (!empty($this->data['app_context'])) {
            $this->css_class = 'class="form-control gf-app-control-input griffinforms-' . $this->purgeString($this->name) . ' griffinforms-' . strtolower($this->meta) . ' griffinforms-formcontrol"';
        }
    }

    private function formatDate()
    {
        if (!empty($this->value) && is_numeric($this->value)) {
            $this->value = wp_date('m/d/Y', $this->value);
        }
    }

    public function html()
    {
        $this->formatDate();
        
        echo '<input type="text" ' . wp_kses_post($this->attr_name) . ' ';
        $this->getAttr('css_class');
        $this->getAttr('css_id');
        echo 'value="' . esc_attr($this->value) . '">';
    }
}
