<% content_for :title, "Accept Invitation" %>

<div class="min-h-screen flex flex-col">
  <header class="bg-white border-b border-slate-200">
    <div class="max-w-7xl mx-auto px-4">
      <div class="h-16 flex items-center">
        <%= link_to root_path, class: "flex items-center gap-2" do %>
          <span class="text-xl font-bold tracking-tight text-indigo-600">Sanasto</span>
          <span class="text-xl font-light text-slate-400">Wiki</span>
        <% end %>
      </div>
    </div>
  </header>

  <div class="flex-1 flex items-center justify-center px-4 py-12 bg-slate-50">
    <div class="w-full max-w-md">
      <div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
        <div class="mb-8">
          <h1 class="text-2xl font-bold text-slate-900 mb-2">Accept Invitation</h1>
          <p class="text-sm text-slate-600">
            You've been invited to join Sanasto Wiki as <%= @user.name %> (<%= @user.email %>)
          </p>
          <p class="text-sm text-slate-600 mt-1">
            Role: <span class="font-medium text-indigo-600"><%= @user.role.titleize %></span>
          </p>
        </div>

        <% if @user.errors.any? %>
          <div class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-lg mb-6" role="alert">
            <h3 class="font-medium mb-2"><%= pluralize(@user.errors.count, "error") %> prevented acceptance:</h3>
            <ul class="list-disc pl-5 space-y-1 text-sm">
              <% @user.errors.full_messages.each do |message| %>
                <li><%= message %></li>
              <% end %>
            </ul>
          </div>
        <% end %>

        <%= form_with model: @user, url: accept_invitation_path(params[:token]), method: :patch, local: true, class: "space-y-5" do |form| %>
          <div>
            <%= form.label :password, "Set Your Password", class: "block text-sm font-medium text-slate-700 mb-2" %>
            <%= form.password_field :password,
                                    autofocus: true,
                                    required: true,
                                    placeholder: "Minimum 12 characters",
                                    class: "block w-full px-4 py-3 bg-white border border-slate-200 rounded-lg shadow-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition" %>
            <p class="mt-1 text-xs text-slate-500">Choose a strong password with at least 12 characters.</p>
          </div>

          <div>
            <%= form.label :password_confirmation, "Confirm Password", class: "block text-sm font-medium text-slate-700 mb-2" %>
            <%= form.password_field :password_confirmation,
                                    required: true,
                                    placeholder: "Re-enter your password",
                                    class: "block w-full px-4 py-3 bg-white border border-slate-200 rounded-lg shadow-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition" %>
          </div>

          <div class="pt-2">
            <%= form.submit "Accept Invitation & Join",
                           class: "w-full bg-indigo-600 text-white px-4 py-3 rounded-lg text-sm font-semibold hover:bg-indigo-700 transition cursor-pointer" %>
          </div>
        <% end %>

        <div class="mt-6 text-center">
          <%= link_to root_path, class: "text-sm text-slate-600 hover:text-indigo-600 transition inline-flex items-center gap-1" do %>
            <svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
            </svg>
            Back to Wiki
          <% end %>
        </div>
      </div>
    </div>
  </div>
</div>
