%= render DS::Dialog.new(variant: "drawer") do |dialog| %>
<% dialog.with_header do %>
<%= render "trades/header", entry: @entry %>
<% end %>
<% trade = @entry.trade %>
<% dialog.with_body do %>
<% dialog.with_section(title: t(".details"), open: true) do %>
<%= styled_form_with model: @entry,
url: trade_path(@entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.date_field :date,
label: t(".date_label"),
max: Date.current,
disabled: @entry.linked?,
"data-auto-submit-form-target": "auto" %>
<%= f.select :nature,
[["Buy", "outflow"], ["Sell", "inflow"]],
{ container_class: "w-1/3", label: "Type", selected: @entry.amount.negative? ? "inflow" : "outflow" },
{ data: { "auto-submit-form-target": "auto" }, disabled: @entry.linked? } %>
<%= f.fields_for :entryable do |ef| %>
<%= ef.number_field :qty,
label: t(".quantity_label"),
step: "any",
value: trade.qty.abs,
"data-auto-submit-form-target": "auto",
disabled: @entry.linked? %>
<% end %>
<%= f.fields_for :entryable do |ef| %>
<%= ef.money_field :price,
label: t(".cost_per_share_label"),
disable_currency: true,
auto_submit: true,
min: 0,
step: "any",
precision: 10,
disabled: @entry.linked? %>
<%= ef.select :category_id,
Current.family.categories.expenses.alphabetically.map { |c| [c.name, c.id] },
{ include_blank: t(".no_category"), label: t(".category_label") },
{ data: { "auto-submit-form-target": "auto" } } %>
<% end %>
<% end %>
<% end %>
<% dialog.with_section(title: t(".additional")) do %>
<%= styled_form_with model: @entry,
url: trade_path(@entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.text_area :notes,
label: t(".note_label"),
placeholder: t(".note_placeholder"),
rows: 5,
"data-auto-submit-form-target": "auto" %>
<% end %>
<% end %>
<% dialog.with_section(title: t(".settings")) do %>
<%= styled_form_with model: @entry,
url: trade_path(@entry),
class: "p-3",
data: { controller: "auto-submit-form" } do |f| %>
<%= t(".exclude_title") %>
<%= t(".exclude_subtitle") %>
<%= f.toggle :excluded, { data: { auto_submit_form_target: "auto" } } %>
<% end %>
<%= t(".delete_title") %>
<%= t(".delete_subtitle") %>
<%= button_to t(".delete"),
entry_path(@entry),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm
font-medium border border-secondary",
data: { turbo_confirm: true } %>
<% end %>
<% end %>
<% end %>