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

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

<%= form_with url: settings_llm_usage_path, method: :get, class: "flex gap-4 items-end flex-wrap" do |f| %>
<%= f.label :start_date, t(".start_date"), class: "block text-sm font-medium text-primary mb-1" %> <%= f.date_field :start_date, value: @start_date, class: "rounded-lg border border-primary px-3 py-2 text-sm bg-container-inset text-primary w-full" %>
<%= f.label :end_date, t(".end_date"), class: "block text-sm font-medium text-primary mb-1" %> <%= f.date_field :end_date, value: @end_date, class: "rounded-lg border border-primary px-3 py-2 text-sm bg-container-inset text-primary w-full" %>
<%= render DS::Button.new(variant: :primary, size: :md, type: "submit", text: t(".filter"), class: "md:w-auto w-full justify-center") %> <% end %>
<%= icon "activity", class: "w-5 h-5 text-secondary" %>

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

<%= number_with_delimiter(@statistics[:total_requests]) %>

<%= icon "hash", class: "w-5 h-5 text-secondary" %>

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

<%= number_with_delimiter(@statistics[:total_tokens]) %>

<%= number_with_delimiter(@statistics[:total_prompt_tokens]) %> <%= t(".prompt") %> / <%= number_with_delimiter(@statistics[:total_completion_tokens]) %> <%= t(".completion") %>

<%= icon "dollar-sign", class: "w-5 h-5 text-secondary" %>

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

$<%= sprintf("%.2f", @statistics[:total_cost]) %>

<%= icon "trending-up", class: "w-5 h-5 text-secondary" %>

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

$<%= sprintf("%.4f", @statistics[:avg_cost]) %>

<% if @statistics[:requests_with_cost] < @statistics[:total_requests] %>

<%= t(".based_on_requests", with_cost: number_with_delimiter(@statistics[:requests_with_cost]), total: number_with_delimiter(@statistics[:total_requests])) %>

<% end %>
<% if @statistics[:by_operation].any? %>

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

<% @statistics[:by_operation].each do |operation, cost| %>
<%= operation.humanize %> $<%= sprintf("%.4f", cost) %>
<% end %>
<% end %> <% if @statistics[:by_model].any? %>

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

<% @statistics[:by_model].each do |model, cost| %>
<%= model %> $<%= sprintf("%.4f", cost) %>
<% end %>
<% end %>

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

<% if @llm_usages.any? %> <% @llm_usages.each do |usage| %> "> <% end %>
<%= t(".col_date") %> <%= t(".col_operation") %> <%= t(".col_model") %> <%= t(".col_tokens") %> <%= t(".col_cost") %>
<%= usage.created_at.strftime("%b %d, %Y %I:%M %p") %> <%= usage.operation.humanize %> <%= usage.model %> <% if usage.failed? %>
<%= icon "alert-circle", class: "w-4 h-4 text-red-600 theme-dark:text-red-400" %> <%= t(".failed") %>
<% else %> <%= number_with_delimiter(usage.total_tokens) %> (<%= number_with_delimiter(usage.prompt_tokens) %>/<%= number_with_delimiter(usage.completion_tokens) %>) <% end %>
<%= usage.formatted_cost %>
<% else %>

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

<% end %>
<%= icon "info", class: "w-5 h-5 text-blue-600 mt-0.5" %>

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

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