<%
  # headmin/forms/password
  #
  # ==== Options
  # * <tt>form<tt> - Form object
  # * <tt>attribute<tt> - Name of the attribute of the form model
  # * <tt>label<tt> - Text to show as label. Label will be hidden if value is false
  # * <tt>float<tt> - Set to true if you want to show floating labels
  # * <tt>append<tt> - Text or icon to be shown on the left hand side of the input, Doesn't work with float
  # * <tt>prepend<tt> - Text or icon to be shown on the right hand side of the input, Doesn't work with float
  #
  # ==== Examples
  #   Basic version
  #   <%= render 'headmin/forms/password', form: form, attribute: :password %#>

  append = local_assigns.has_key?(:append) ? append : nil
  class_names = local_assigns.has_key?(:class) ? local_assigns[:class] : false
  data = local_assigns.has_key?(:data) ? data : nil
  disabled = local_assigns.has_key?(:disabled) ? disabled : false
  float = local_assigns.has_key?(:float) ? float : false
  label = local_assigns.has_key?(:label) ? label : nil
  prepend = local_assigns.has_key?(:prepend) ? prepend : nil
  readonly = local_assigns.has_key?(:readonly) ? readonly : false
  required = local_assigns.has_key?(:required) ? required : false

  options = {
    'aria-describedby': form_field_validation_id(form, attribute),
    class: "form-control #{form_field_validation_class(form, attribute)} #{class_names}",
    data: data,
    disabled: disabled,
    placeholder: attribute,
    readonly: readonly,
    required: required,
  }

  show_label = label != false
%>

<div class="<%= 'form-floating' if float %> <%= ('mb-3 text-start' if show_label) %>">
  <% if show_label && !float %>
    <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
  <% end %>

  <% if float %>
    <%= form.password_field(attribute, options) %>
    <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
  <% else %>
    <div class="input-group">
      <% if prepend %>
      <span class="input-group-text">
        <%= prepend %>
      </span>
      <% end %>

      <%= form.password_field(attribute, options) %>
      <%= render 'headmin/forms/validation', form: form, attribute: attribute %>

      <% if append %>
      <span class="input-group-text">
        <%= append %>
      </span>
      <% end %>
    </div>
  <% end %>

  <% if show_label && float %>
    <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
  <% end %>
</div>