<?php

namespace GriffinForms\Frontend\Html\Forms\Fields\Traits;

trait HtmlAttrs
{
    protected function requiredAttr()
    {
        if ($this->isRequired()) {
            return ' required="required"';
        }
    }
    
    protected function placeholderAttr()
    {
        return ' placeholder="' . esc_attr($this->item->getProp('placeholder')) . '"';
    }
    
    protected function valueAttr()
    {
        return ' value="' . esc_attr($this->value) . '"';
    }
    
    protected function readonlyAttr()
    {
        if ($this->isReadonly()) {
            return ' readOnly="readonly"';
        }
    }
    
    protected function autocompleteAttr()
    {
        $field_type = $this->item->getProp('field_type');

        if ($this->isAutocomplete()) {
            if ('inputemail' === $field_type) {
                return ' autocomplete="email"';
            }
            if ('inputphone' === $field_type) {
                return ' autocomplete="tel"';
            }
            return ' autocomplete="on"';
        }

        return ' autocomplete="off"';
    }
    
    protected function disabledAttr()
    {
        if ($this->isDisabled()) {
            return ' disabled="disabled"';
        }
    }
}

    
