"use client";

import { useState } from "react";
import { ChangePasswordForm } from "@/components/change-password-form";
import { useAuth } from "@/lib/auth-context";

export default function ProfilPage() {
  const { employee, logout } = useAuth();
  const [isChangingPassword, setIsChangingPassword] = useState(false);

  return (
    <div className="space-y-4">
      <h1 className="text-lg font-semibold text-zinc-900 dark:text-zinc-50">Profil</h1>

      <div className="space-y-3 rounded-2xl bg-white p-5 shadow-sm dark:bg-zinc-900">
        <div>
          <p className="text-xs text-zinc-400">Nama</p>
          <p className="text-sm font-medium text-zinc-900 dark:text-zinc-50">{employee?.name}</p>
        </div>
        <div>
          <p className="text-xs text-zinc-400">Kode Karyawan</p>
          <p className="text-sm font-medium text-zinc-900 dark:text-zinc-50">{employee?.employee_code}</p>
        </div>
        <div>
          <p className="text-xs text-zinc-400">Email</p>
          <p className="text-sm font-medium text-zinc-900 dark:text-zinc-50">{employee?.email}</p>
        </div>
        <div>
          <p className="text-xs text-zinc-400">Cabang</p>
          <p className="text-sm font-medium text-zinc-900 dark:text-zinc-50">
            {employee?.office?.name ?? "Belum ditetapkan"}
          </p>
        </div>
        <div>
          <p className="text-xs text-zinc-400">Divisi</p>
          <p className="text-sm font-medium text-zinc-900 dark:text-zinc-50">
            {employee?.division?.name ?? "Belum ditetapkan"}
          </p>
        </div>
      </div>

      {isChangingPassword ? (
        <ChangePasswordForm onDone={() => setIsChangingPassword(false)} />
      ) : (
        <button
          type="button"
          onClick={() => setIsChangingPassword(true)}
          className="w-full rounded-full bg-[#0f2a43] px-4 py-3 text-sm font-medium text-white transition hover:bg-[#0c2236]"
        >
          Ganti Password
        </button>
      )}

      <button
        type="button"
        onClick={logout}
        className="w-full rounded-full border border-zinc-200 px-4 py-3 text-sm font-medium text-zinc-600 dark:border-zinc-700 dark:text-zinc-300"
      >
        Keluar
      </button>
    </div>
  );
}
