<%= content_for :page_title, @statement.filename %> <%= settings_section title: t(".title") do %>
<%= icon(account_statement_file_icon(@statement), size: "sm") %>

<%= @statement.filename %>

<%= account_statement_status_badge(@statement) %> <%= number_to_human_size(@statement.byte_size) %> <%= @statement.content_type %>
<% if @statement.original_file.attached? %> <%= link_to rails_blob_path(@statement.original_file, disposition: "attachment"), class: "inline-flex items-center gap-2 text-sm font-medium text-primary hover:text-primary-hover" do %> <%= icon("download", size: "sm") %> <%= t(".download") %> <% end %> <% end %> <% if @can_manage_statement %> <%= button_to account_statement_path(@statement), method: :delete, class: "inline-flex items-center gap-2 text-sm font-medium text-destructive", data: { turbo_confirm: CustomConfirm.for_resource_deletion("statement") } do %> <%= icon("trash-2", size: "sm", color: "destructive") %> <%= t(".delete") %> <% end %> <% end %>

<%= t(".metadata_title") %>

<% if @can_manage_statement %> <%= styled_form_with model: @statement, url: account_statement_path(@statement), method: :patch, class: "space-y-4" do |form| %>
<%= form.text_field :institution_name_hint, label: t(".institution_name_hint") %> <%= form.text_field :account_name_hint, label: t(".account_name_hint") %> <%= form.text_field :account_last4_hint, label: t(".account_last4_hint") %> <%= form.select :currency, account_statement_currency_options(@statement), { label: t(".currency"), selected: @statement.statement_currency } %> <%= form.date_field :period_start_on, label: t(".period_start_on") %> <%= form.date_field :period_end_on, label: t(".period_end_on") %> <%= form.number_field :opening_balance, label: t(".opening_balance"), step: "0.01" %> <%= form.number_field :closing_balance, label: t(".closing_balance"), step: "0.01" %>
<%= form.submit t(".save") %> <% end %> <% else %>
<%= t(".account_label") %>
<%= @statement.account&.name || t(".unmatched_account") %>
<%= t(".institution_name_hint") %>
<%= @statement.institution_name_hint.presence || t(".unknown_value") %>
<%= t(".account_name_hint") %>
<%= @statement.account_name_hint.presence || t(".unknown_value") %>
<%= t(".account_last4_hint") %>
<%= @statement.account_last4_hint.presence || t(".unknown_value") %>
<%= t(".currency") %>
<%= @statement.statement_currency %>
<%= t("account_statements.table.period") %>
<%= account_statement_period(@statement) %>
<%= t(".opening_balance") %>
<%= account_statement_balance_label(@statement, :opening_balance) %>
<%= t(".closing_balance") %>
<%= account_statement_balance_label(@statement, :closing_balance) %>
<% end %>

<%= t(".linking_title") %>

<% if @statement.account.present? %>

<%= t(".linked_to", account: @statement.account.name) %>

<% if @can_manage_statement %> <%= button_to unlink_account_statement_path(@statement), method: :patch, class: "inline-flex items-center gap-2 text-sm font-medium text-primary" do %> <%= icon("unlink", size: "sm") %> <%= t(".unlink") %> <% end %> <% end %> <% elsif @statement.suggested_account.present? %>

<%= t(".suggested_account", account: @statement.suggested_account.name, confidence: number_to_percentage(@statement.match_confidence.to_d * 100, precision: 0)) %>

<% if @can_manage_statement %>
<%= button_to link_account_statement_path(@statement), method: :patch, params: { account_id: @statement.suggested_account_id }, class: "inline-flex items-center gap-2 text-sm font-medium text-primary" do %> <%= icon("link", size: "sm") %> <%= t(".link_suggestion") %> <% end %> <%= button_to reject_account_statement_path(@statement), method: :patch, class: "inline-flex items-center gap-2 text-sm font-medium text-secondary" do %> <%= icon("x", size: "sm") %> <%= t(".reject") %> <% end %>
<% end %> <% else %>

<%= t(".no_suggestion") %>

<% end %>

<%= t(".reconciliation_title") %>

<% if @reconciliation_checks.any? %>
<% @reconciliation_checks.each do |check| %>

<%= account_statement_reconciliation_label(check) %>

<% if check[:status] == "matched" %> <%= render "shared/badge", color: "success" do %><%= t("account_statements.reconciliation.matched") %><% end %> <% else %> <%= render "shared/badge", color: "error" do %><%= t("account_statements.reconciliation.mismatched") %><% end %> <% end %>
<%= t(".statement_amount") %>
<%= Money.new(check[:statement_amount], @statement.statement_currency).format %>
<%= t(".ledger_amount") %>
<%= Money.new(check[:ledger_amount], @statement.statement_currency).format %>
<%= t(".difference") %>
<%= Money.new(check[:difference], @statement.statement_currency).format %>
<% end %>
<% else %>

<%= t(".reconciliation_unavailable") %>

<% end %>
<% end %>