<% content_for :title, "ユーザー編集" %>

<div class="max-w-2xl mx-auto">
  <div class="mb-6">
    <h1 class="text-3xl font-bold text-gray-900">ユーザー編集</h1>
    <p class="mt-2 text-sm text-gray-600"><%= @user.username %> の情報を編集</p>
  </div>

  <%= form_with model: @user, class: "space-y-6" do |f| %>
    <% if @user.errors.any? %>
      <div class="bg-red-100 border border-red-400 text-red-800 px-4 py-3 rounded relative" role="alert">
        <strong class="font-bold">エラーがあります:</strong>
        <ul class="mt-2 list-disc list-inside">
          <% @user.errors.full_messages.each do |message| %>
            <li><%= message %></li>
          <% end %>
        </ul>
      </div>
    <% end %>

    <div>
      <%= f.label :username, "ユーザー名", class: "block text-sm font-medium text-gray-700" %>
      <%= f.text_field :username, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500" %>
    </div>

    <div>
      <%= f.label :email, "メールアドレス", class: "block text-sm font-medium text-gray-700" %>
      <%= f.email_field :email, class: "mt-1 block w-full rounded-md border-gray-300 bg-gray-100 shadow-sm", disabled: true %>
      <p class="mt-1 text-sm text-gray-500">メールアドレスは変更できません</p>
    </div>

    <div class="border-t border-gray-200 pt-6">
      <h3 class="text-lg font-medium text-gray-900 mb-4">パスワード変更</h3>
      <p class="text-sm text-gray-600 mb-4">パスワードを変更する場合のみ入力してください。空欄の場合は変更されません。</p>

      <div class="space-y-4">
        <div>
          <%= f.label :password, "新しいパスワード", class: "block text-sm font-medium text-gray-700" %>
          <%= f.password_field :password, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500", autocomplete: "new-password" %>
          <p class="mt-1 text-sm text-gray-500">6文字以上</p>
        </div>

        <div>
          <%= f.label :password_confirmation, "新しいパスワード(確認)", class: "block text-sm font-medium text-gray-700" %>
          <%= f.password_field :password_confirmation, class: "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500", autocomplete: "new-password" %>
        </div>
      </div>
    </div>

    <div class="flex items-center justify-between pt-6 border-t border-gray-200">
      <%= link_to "キャンセル", user_path(@user), class: "inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50" %>
      <%= f.submit "更新", class: "inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" %>
    </div>
  <% end %>
</div>
