{% extends "base.html" %}
{% import "macros/ui.html" as ui %}

{% block title %}{{ t(key="password-change-title", lang=lang | default(value='sk')) }}{% endblock title %}

{% block content %}
<div class="mx-auto max-w-md">
  <h1 class="text-3xl font-bold text-on-surface-strong dark:text-on-surface-dark-strong">{{ t(key="password-change-title", lang=lang | default(value='sk')) }}</h1>

  {% if changed %}
  <div class="mt-4 rounded-radius border border-success bg-success/10 px-4 py-3 text-sm text-success" role="status">
    {{ t(key="password-changed", lang=lang | default(value='sk')) }}
  </div>
  {% endif %}
  {% if error == "current" %}
  {{ ui::alert_danger(message=t(key="password-current-wrong", lang=lang | default(value='sk')), extra="mt-4") }}
  {% elif error == "mismatch" %}
  {{ ui::alert_danger(message=t(key="set-password-mismatch", lang=lang | default(value='sk')), extra="mt-4") }}
  {% elif error == "weak" %}
  {{ ui::alert_danger(message=t(key="set-password-weak", lang=lang | default(value='sk')), extra="mt-4") }}
  {% endif %}

  <form method="post" action="/account/password" hx-boost="false" class="mt-6 flex flex-col gap-4"
    x-data="{ password: '', confirm: '' }">
  {{ ui::csrf_field() }}
    <div class="flex flex-col gap-1">
      <label for="current_password" class="text-sm font-medium text-on-surface-strong dark:text-on-surface-dark-strong">{{ t(key="password-current", lang=lang | default(value='sk')) }}</label>
      {{ ui::input(name="current_password", id="current_password", type="password", required=true, autocomplete="current-password") }}
    </div>
    <div class="flex flex-col gap-1">
      <label for="password" class="text-sm font-medium text-on-surface-strong dark:text-on-surface-dark-strong">{{ t(key="set-password-new", lang=lang | default(value='sk')) }}</label>
      {{ ui::input(name="password", id="password", type="password", required=true, autocomplete="new-password", attrs='x-model="password"') }}
    </div>
    <div class="flex flex-col gap-1">
      <label for="password_confirm" class="text-sm font-medium text-on-surface-strong dark:text-on-surface-dark-strong">{{ t(key="set-password-confirm", lang=lang | default(value='sk')) }}</label>
      {{ ui::input(name="password_confirm", id="password_confirm", type="password", required=true, autocomplete="new-password", attrs='x-model="confirm"') }}
      <span x-cloak x-show="confirm.length > 0 && password !== confirm" class="text-xs text-danger dark:text-danger">
        {{ t(key="set-password-mismatch", lang=lang | default(value='sk')) }}
      </span>
    </div>
    {{ ui::button(label=t(key="password-change-title", lang=lang | default(value='sk')), type="submit", extra="mt-1 w-full", attrs=':disabled="password !== confirm"') }}
  </form>
</div>
{% endblock content %}
