<%= render DS::Dialog.new(frame: "drawer") do |dialog| %> <% dialog.with_header(hide_close_icon: true) do %>
<%= tag.h3 @holding.name, class: "text-2xl font-medium text-primary" %> <%= tag.p @holding.ticker, class: "text-sm text-secondary" %>
<% if @holding.security.brandfetch_icon_url.present? %> <%= image_tag @holding.security.brandfetch_icon_url, loading: "lazy", class: "w-9 h-9 rounded-full" %> <% elsif @holding.security.logo_url.present? %> <%= image_tag @holding.security.logo_url, loading: "lazy", class: "w-9 h-9 rounded-full" %> <% else %> <%= render DS::FilledIcon.new(variant: :text, text: @holding.name, size: "md", rounded: true) %> <% end %>
<% end %> <% dialog.with_body do %> <% dialog.with_section(title: t(".overview"), open: true) do %>
<%= t(".security_label") %>
<%= @holding.ticker %> <% if @holding.security_remapped? %> (<%= t(".originally", ticker: @holding.provider_security.ticker) %>) <%= icon "lock", size: "xs", class: "text-secondary" %> <% end %>
<%= t(".current_market_price_label") %>
<% begin %> <%= @holding.security.current_price ? format_money(@holding.security.current_price) : t(".unknown") %> <% rescue ActiveRecord::RecordInvalid, StandardError %> <%= t(".unknown") %> <% end %>
<%= t(".portfolio_weight_label") %>
<%= @holding.weight ? number_to_percentage(@holding.weight, precision: 2) : t(".unknown") %>
<%# Average Cost with inline editor %> <% currency = Money::Currency.new(@holding.currency) current_per_share = @holding.cost_basis.present? && @holding.cost_basis.positive? ? @holding.cost_basis : nil current_total = current_per_share && @holding.qty.positive? ? (current_per_share * @holding.qty).round(2) : nil %>
<%= t(".avg_cost_label") %>
<%= @holding.avg_cost ? format_money(@holding.avg_cost) : t(".unknown") %> <% if @holding.cost_basis_locked? %> <%= icon "lock", size: "xs", class: "text-secondary" %> <% end %> <% if @holding.cost_basis_source.present? %> (<%= @holding.cost_basis_source_label %>) <% end %>
<%# Inline cost basis editor (hidden by default) %>
<%= t(".total_return_label") %>
<% if @holding.trend %>
<%= render("shared/trend_change", trend: @holding.trend) %>
<% else %>
<%= t(".unknown") %>
<% end %>
<% end %> <% dialog.with_section(title: t(".history"), open: true) do %>
<% if @holding.trades.any? %> <% else %>

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

<% end %>
<% end %> <% if @holding.cost_basis_locked? || @holding.security_remapped? || @holding.account.can_delete_holdings? %> <% dialog.with_section(title: t(".settings"), open: true) do %>
<% if @holding.security_remapped? %>

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

<%= t(".provider_sent", ticker: @holding.provider_security.ticker) %>

<%= button_to t(".reset_to_provider"), reset_security_holding_path(@holding), method: :post, class: "inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm font-medium text-primary bg-gray-200 hover:bg-gray-300 theme-dark:bg-gray-700 theme-dark:hover:bg-gray-600", form: { data: { turbo: false } }, data: { turbo_confirm: { title: t(".reset_confirm_title"), body: t(".reset_confirm_body", current: @holding.security.ticker, original: @holding.provider_security.ticker) } } %>
<% end %> <% if @holding.cost_basis_locked? %>

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

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

<%= button_to t(".unlock_cost_basis"), unlock_cost_basis_holding_path(@holding), method: :post, class: "inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm font-medium text-primary bg-gray-200 hover:bg-gray-300 theme-dark:bg-gray-700 theme-dark:hover:bg-gray-600", form: { data: { turbo: false } }, data: { turbo_confirm: { title: t(".unlock_confirm_title"), body: t(".unlock_confirm_body") } } %>
<% end %> <% if @holding.account.can_delete_holdings? %>

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

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

<%= button_to t(".delete"), holding_path(@holding), 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 %> <% end %> <% end %>