<%# locals: (goal:, linkable_accounts:, currently_linked_account_ids: []) %>
" data-goal-form-suggested-no-date-value="<%= t("goals.form.suggested_no_date") %>"> <%= styled_form_with model: goal, url: goal.persisted? ? goal_path(goal) : goals_path, method: goal.persisted? ? :patch : :post, class: "space-y-5", data: { action: "submit->goal-form#validateOnSubmit" } do |f| %>
<%= render "color_picker", form: f, colors: Goal::COLORS, icons: Goal::ICONS %>
<%= f.text_field :name, placeholder: t("goals.form.fields.name_placeholder"), autofocus: true, required: true, label: t("goals.form.fields.name"), data: { goal_form_target: "nameInput", action: "input->goal-form#nameChanged" } %>

mt-1.5 text-xs text-destructive" data-goal-form-target="nameError"><%= t("goals.form.errors.name_required") %>

<%= f.money_field :target_amount, label: t("goals.form.fields.target_amount"), hide_currency: true, required: true, amount_data: { goal_form_target: "amountInput", action: "input->goal-form#suggestedChanged" } %>

mt-1.5 text-xs text-destructive" data-goal-form-target="amountError"><%= t("goals.form.errors.amount_required") %>

<%= f.date_field :target_date, label: t("goals.form.fields.target_date"), data: { goal_form_target: "dateInput", action: "input->goal-form#suggestedChanged" } %>
<%= t("goals.form.fields.funding_accounts") %>

<%= t("goals.form.fields.funding_accounts_hint") %>

<%= t("goals.form.fields.earmark_hint") %>

<% linked_allocation_by_account = goal.goal_accounts.index_by(&:account_id) %> <% grouped = linkable_accounts.group_by { |a| a.subtype.to_s.presence || "other" } %> <% grouped.each_with_index do |(subtype, accts), group_idx| %>
<%= t("goals.form.subtypes.#{subtype}", default: subtype.titleize) %>
"> <% accts.each_with_index do |account, idx| %> <% linked_ga = linked_allocation_by_account[account.id] %>
0 %>"> <%= text_field_tag "goal[allocations][#{account.id}]", linked_ga&.allocated_amount&.to_s("F"), placeholder: t("goals.form.fields.whole_balance"), inputmode: "decimal", autocomplete: "off", aria: { label: t("goals.form.fields.earmark_for", account: account.name) }, class: "shrink-0 w-36 rounded-md border border-primary bg-container px-2.5 py-1.5 text-sm text-right tabular-nums text-primary placeholder:text-subdued focus-ring privacy-sensitive" %>
<% end %>
<% end %>

mt-1.5 text-xs text-destructive" data-goal-form-target="accountsError"><%= t("goals.form.errors.accounts_required") %>

<%= f.text_area :notes, label: t("goals.form.fields.notes"), rows: 2, placeholder: t("goals.form.fields.notes_placeholder") %>
<%= f.submit goal.persisted? ? t("goals.form.save") : t("goals.form.create"), data: { goal_form_target: "submitButton" } %>
<% end %>