<%= content_for :page_title, t(".page_title") %>

<%= settings_section title: t(".general_title"), subtitle: t(".general_subtitle") do %>
  <div>
    <%= styled_form_with model: @user, class: "space-y-4", data: { controller: "auto-submit-form" } do |form| %>
      <%= form.hidden_field :redirect_to, value: "preferences" %>

      <%= form.select :locale,
          language_options,
          { label: t(".language"), include_blank: t(".language_auto") },
          { data: { auto_submit_form_target: "auto" } } %>

      <%= form.fields_for :family do |family_form| %>
        <%= family_form.select :currency,
            Money::Currency.as_options.map { |currency| [ "#{currency.name} (#{currency.iso_code})", currency.iso_code ] },
            { label: t(".currency") }, disabled: true %>

        <%= family_form.select :timezone,
            timezone_options,
            { label: t(".timezone") },
            { data: { auto_submit_form_target: "auto" } } %>

        <%= family_form.select :date_format,
            Family::DATE_FORMATS,
            { label: t(".date_format") },
            { data: { auto_submit_form_target: "auto" } } %>

        <%= form.select :default_period,
            Period.all.map { |period| [ period.label, period.key ] },
            { label: t(".default_period") },
            { data: { auto_submit_form_target: "auto" } } %>

        <%= form.select :default_account_order,
            AccountOrder.all.map { |order| [ order.label, order.key ] },
            { label: t(".default_account_order") },
            { data: { auto_submit_form_target: "auto" } } %>

        <%= family_form.select :country,
            country_options,
            { label: t(".country") },
            { data: { auto_submit_form_target: "auto" } } %>

        <%= family_form.select :month_start_day,
            (1..28).map { |day| [day.ordinalize, day] },
            { label: t(".month_start_day"), hint: t(".month_start_day_hint") },
            { data: { auto_submit_form_target: "auto" } } %>

        <% if @user.family.uses_custom_month_start? %>
          <div class="text-sm text-warning bg-warning/10 p-3 rounded-lg">
            <%= t(".month_start_day_warning") %>
          </div>
        <% end %>

        <p class="text-xs italic pl-2 text-secondary">Please note, we are still working on translations for various languages.</p>
      <% end %>
    <% end %>
  </div>
<% end %>

<% if Current.user.admin? %>
  <%= settings_section title: t(".sharing_title", moniker: family_moniker), subtitle: t(".sharing_subtitle", moniker: family_moniker_downcase) do %>
    <div>
      <%= styled_form_with model: @user, class: "space-y-4", data: { controller: "auto-submit-form" } do |form| %>
        <%= form.hidden_field :redirect_to, value: "preferences" %>
        <%= form.fields_for :family do |family_form| %>
          <%= family_form.select :default_account_sharing,
              [
                [t(".sharing_shared"), "shared"],
                [t(".sharing_private"), "private"]
              ],
              { label: t(".sharing_default_label") },
              { data: { auto_submit_form_target: "auto" } } %>
        <% end %>
      <% end %>
    </div>
  <% end %>
<% end %>
