<!DOCTYPE html>
<html>
  <head>
    <title>Setup - Sanasto Wiki</title>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
    <%= javascript_importmap_tags %>
    <script src="https://cdn.tailwindcss.com"></script>
  </head>

  <body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen flex items-center justify-center p-4">
    <div class="w-full max-w-md mx-auto">
      <!-- Setup Card -->
      <div class="bg-white shadow-2xl rounded-lg overflow-hidden">
        <!-- Header -->
        <div class="bg-gradient-to-r from-blue-600 to-indigo-600 px-6 py-8 text-center">
          <h1 class="text-3xl font-bold text-white">Sanasto Wiki</h1>
          <p class="mt-2 text-blue-100">Initial Setup</p>
        </div>

        <!-- Form -->
        <div class="px-6 py-8">
          <div class="mb-6">
            <h2 class="text-xl font-semibold text-gray-900">Create Admin Account</h2>
            <p class="mt-2 text-sm text-gray-600">
              Welcome! Let's create your administrator account to get started.
            </p>
          </div>

          <%= form_with model: @user, url: setup_path, method: :post, class: "space-y-6" do |f| %>
            <% if @user.errors.any? %>
              <div class="rounded-md bg-red-50 p-4">
                <div class="flex">
                  <div class="flex-shrink-0">
                    <svg class="h-5 w-5 text-red-400" fill="currentColor" viewBox="0 0 20 20">
                      <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd" />
                    </svg>
                  </div>
                  <div class="ml-3">
                    <h3 class="text-sm font-medium text-red-800">
                      <%= pluralize(@user.errors.count, "error") %> prevented setup:
                    </h3>
                    <div class="mt-2 text-sm text-red-700">
                      <ul class="list-disc pl-5 space-y-1">
                        <% @user.errors.full_messages.each do |message| %>
                          <li><%= message %></li>
                        <% end %>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            <% end %>

            <div>
              <%= f.label :name, class: "block text-sm font-medium text-gray-700" %>
              <%= f.text_field :name, required: true, autofocus: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "Your full name" %>
            </div>

            <div>
              <%= f.label :email, class: "block text-sm font-medium text-gray-700" %>
              <%= f.email_field :email, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "admin@example.com" %>
              <p class="mt-1 text-xs text-gray-500">This will be the default contact email for the system.</p>
            </div>

            <div>
              <%= f.label :primary_language, "Preferred Language", class: "block text-sm font-medium text-gray-700" %>
              <%= f.select :primary_language, SupportedLanguage.order(:sort_order).pluck(:code, :native_name), { include_blank: "Select your primary language" }, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm" %>
            </div>

            <div>
              <%= f.label :password, class: "block text-sm font-medium text-gray-700" %>
              <%= f.password_field :password, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "Minimum 12 characters" %>
              <p class="mt-1 text-xs text-gray-500">Choose a strong password with at least 12 characters.</p>
            </div>

            <div>
              <%= f.label :password_confirmation, "Confirm Password", class: "block text-sm font-medium text-gray-700" %>
              <%= f.password_field :password_confirmation, required: true, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm", placeholder: "Re-enter your password" %>
            </div>

            <div class="bg-blue-50 border-l-4 border-blue-400 p-4">
              <div class="flex">
                <div class="flex-shrink-0">
                  <svg class="h-5 w-5 text-blue-400" fill="currentColor" viewBox="0 0 20 20">
                    <path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd" />
                  </svg>
                </div>
                <div class="ml-3">
                  <p class="text-sm text-blue-700">
                    <strong>Note:</strong> This account will have full administrator access and cannot be deleted through the UI.
                  </p>
                </div>
              </div>
            </div>

            <div>
              <%= f.submit "Complete Setup", class: "w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-700 hover:to-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all duration-200" %>
            </div>
          <% end %>
        </div>
      </div>
    </div>
  </body>
</html>
