import type { Metadata } from "next";
import { loginAction } from "./actions";
import { HomeModernIcon } from "@heroicons/react/24/outline";

export const metadata: Metadata = { title: "Prijava | Angolo di Pace" };

export default async function LoginPage({
  searchParams,
}: {
  searchParams: Promise<{ error?: string }>;
}) {
  const { error } = await searchParams;

  return (
    <div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-sky-500 to-cyan-500 px-4">
      <div className="bg-white rounded-3xl shadow-xl p-8 w-full max-w-sm">
        <div className="text-center mb-8">
          <div className="mb-3"><HomeModernIcon className="w-14 h-14 mx-auto text-sky-600" /></div>
          <h1 className="text-2xl font-bold text-sky-800">Angolo di Pace</h1>
          <p className="text-gray-500 text-sm mt-1">Prijavite se za pristup</p>
        </div>

        <form action={loginAction} className="space-y-4">
          <div>
            <label className="block text-sm font-medium text-gray-700 mb-1">
              Korisničko ime
            </label>
            <input
              name="username"
              type="text"
              autoComplete="username"
              required
              className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:outline-none focus:ring-2 focus:ring-sky-400 text-gray-800"
            />
          </div>

          <div>
            <label className="block text-sm font-medium text-gray-700 mb-1">
              Lozinka
            </label>
            <input
              name="password"
              type="password"
              autoComplete="current-password"
              required
              className="w-full px-4 py-2.5 rounded-xl border border-gray-200 focus:outline-none focus:ring-2 focus:ring-sky-400 text-gray-800"
            />
          </div>

          {error && (
            <p className="text-sm text-red-600 bg-red-50 px-3 py-2 rounded-lg">
              Pogrešno korisničko ime ili lozinka.
            </p>
          )}

          <button
            type="submit"
            className="w-full bg-sky-600 text-white font-semibold py-2.5 rounded-xl hover:bg-sky-700 transition-colors"
          >
            Prijavi se
          </button>
        </form>
      </div>
    </div>
  );
}
