<%
  header_title @user_exists ? t("oidc_accounts.link.title_link") : t("oidc_accounts.link.title_create")
%>

<% if @user_exists %>
  <div class="mb-6 p-4 bg-yellow-50 border border-yellow-200 rounded-md">
    <h3 class="text-sm font-medium text-yellow-800 mb-2"><%= t("oidc_accounts.link.verify_heading") %></h3>
    <p class="text-sm text-yellow-700">
      <% email_suffix = @pending_auth["email"].present? ? t("oidc_accounts.link.email_suffix_html", email: @pending_auth["email"]) : "" %>
      <%= t("oidc_accounts.link.verify_description_html", provider: @pending_auth["provider"], email_suffix: email_suffix).html_safe %>
    </p>
  </div>

  <%= styled_form_with url: create_link_oidc_account_path, class: "space-y-4", data: { turbo: false } do |form| %>
    <%= form.email_field :email,
                         label: t("oidc_accounts.link.email_label"),
                         autofocus: false,
                         autocomplete: "email",
                         required: "required",
                         placeholder: t("oidc_accounts.link.email_placeholder"),
                         value: @email %>

    <%= form.password_field :password,
                            label: t("oidc_accounts.link.password_label"),
                            required: "required",
                            placeholder: t("oidc_accounts.link.password_placeholder"),
                            autocomplete: "current-password" %>

    <div class="text-sm text-gray-600 mt-2">
      <p><%= t("oidc_accounts.link.verify_hint") %></p>
    </div>

    <%= form.submit t("oidc_accounts.link.submit_link") %>
  <% end %>
<% else %>
  <div class="mb-6 p-4 bg-blue-50 border border-blue-200 rounded-md">
    <h3 class="text-sm font-medium text-blue-800 mb-2"><%= t("oidc_accounts.link.create_heading") %></h3>
    <p class="text-sm text-blue-700">
      <%= t("oidc_accounts.link.create_description_html", email: @pending_auth["email"], provider: @pending_auth["provider"]).html_safe %>
    </p>
  </div>

  <div class="space-y-4">
    <div class="p-4 bg-container border border-secondary rounded-md">
      <p class="text-sm text-primary">
        <strong><%= t("oidc_accounts.link.info_email") %></strong> <%= @pending_auth["email"] %>
      </p>
      <% if @pending_auth["name"].present? %>
        <p class="text-sm text-primary mt-2">
          <strong><%= t("oidc_accounts.link.info_name") %></strong> <%= @pending_auth["name"] %>
        </p>
      <% end %>
    </div>

    <% if @allow_account_creation %>
      <%= render DS::Button.new(
        text: @pending_invitation ? t("oidc_accounts.link.submit_accept_invitation") : t("oidc_accounts.link.submit_create"),
        href: create_user_oidc_account_path,
        full_width: true,
        variant: :primary,
        method: :post,
        data: { turbo: false }
      ) %>
    <% else %>
      <p class="text-xs text-secondary">
        <%= t("oidc_accounts.link.account_creation_disabled") %>
      </p>
    <% end %>
  </div>
<% end %>

<div class="mt-6 text-center">
  <%= render DS::Link.new(
    text: t("oidc_accounts.link.cancel"),
    href: new_session_path,
    variant: :default,
    class: "font-medium text-sm text-primary hover:underline transition"
  ) %>
</div>
