<div class="space-y-4">
  <div class="prose prose-sm text-secondary">
    <p class="text-primary font-medium"><%= t("sophtron_items.sophtron_panel.setup_instructions_title") %></p>
    <ol>
      <li><%= t("sophtron_items.sophtron_panel.setup_instructions.step_1_html", url: "https://www.sophtron.com") %></li>
      <li><%= t("sophtron_items.sophtron_panel.setup_instructions.step_2") %></li>
      <li><%= t("sophtron_items.sophtron_panel.setup_instructions.step_3") %></li>
    </ol>

    <p class="text-primary font-medium"><%= t("sophtron_items.sophtron_panel.field_descriptions_title") %></p>
    <ul>
      <li><%= t("sophtron_items.sophtron_panel.field_descriptions.user_id_html") %></li>
      <li><%= t("sophtron_items.sophtron_panel.field_descriptions.access_key_html") %></li>
      <li><%= t("sophtron_items.sophtron_panel.field_descriptions.base_url_html") %></li>
    </ul>
  </div>

  <% error_msg = local_assigns[:error_message] || @error_message %>
  <% if error_msg.present? %>
    <div class="p-2 rounded-md bg-destructive/10 text-destructive text-sm overflow-hidden">
      <p class="line-clamp-3" title="<%= error_msg %>"><%= error_msg %></p>
    </div>
  <% end %>

  <%
    # Variables passed from controller
    sophtron_item = @sophtron_item || Current.family.sophtron_items.build
    is_new_record = @is_new_record || sophtron_item.new_record?
    sophtron_items = @sophtron_items
  %>

  <%= styled_form_with model: sophtron_item,
                       url: sophtron_item.new_record? ? sophtron_items_path : sophtron_item_path(sophtron_item),
                       scope: :sophtron_item,
                       method: sophtron_item.new_record? ? :post : :patch,
                       data: { turbo: true },
                       class: "space-y-3" do |form| %>
    <%= form.text_field :user_id,
                        label: t("sophtron_items.sophtron_panel.fields.user_id.label"),
                        placeholder: is_new_record ? t("sophtron_items.sophtron_panel.fields.user_id.placeholder_new") : t("sophtron_items.sophtron_panel.fields.user_id.placeholder_edit"),
                        type: :password %>

    <%= form.text_field :access_key,
                        label: t("sophtron_items.sophtron_panel.fields.access_key.label"),
                        placeholder: is_new_record ? t("sophtron_items.sophtron_panel.fields.access_key.placeholder_new") : t("sophtron_items.sophtron_panel.fields.access_key.placeholder_edit"),
                        type: :password %>

    <%= form.text_field :base_url,
                        label: t("sophtron_items.sophtron_panel.fields.base_url.label"),
                        placeholder: t("sophtron_items.sophtron_panel.fields.base_url.placeholder"),
                        value: sophtron_item.base_url %>

    <div class="flex justify-end">
      <%= form.submit is_new_record ? t("sophtron_items.sophtron_panel.save") : t("sophtron_items.sophtron_panel.update"),
                      class: "inline-flex items-center justify-center rounded-lg px-4 py-2 text-sm font-medium text-inverse bg-inverse hover:bg-inverse-hover focus:outline-none focus:ring-2 focus:ring-primary transition-colors" %>
    </div>
  <% end %>

  <div class="flex items-center gap-2">
    <% if Current.family.sophtron_items.any? %>
      <div class="w-2 h-2 bg-success rounded-full"></div>
      <p class="text-sm text-secondary"><%= t("sophtron_items.sophtron_panel.status.configured_html", accounts_path: accounts_path) %></p>
    <% else %>
      <div class="w-2 h-2 bg-muted rounded-full"></div>
      <p class="text-sm text-secondary"><%= t("sophtron_items.sophtron_panel.status.not_configured") %></p>
    <% end %>
  </div>
</div>