'use client';

import { useRouter, useParams } from 'next/navigation';
import { useState, useEffect } from 'react';
import { EmployeeForm } from '@/components/hr/EmployeeManagement/EmployeeForm';
import { ContentLoadingSpinner } from '@/components/ui/loading-spinner';
import type { Employee, EmployeeFormData } from '@/components/hr/EmployeeManagement/types';

// TODO: 실제 API에서 데이터 가져오기
const mockEmployee: Employee = {
  id: '1',
  name: '김철수',
  employeeCode: 'EMP001',
  phone: '010-1234-5678',
  email: 'kimcs@company.com',
  status: 'active',
  hireDate: '2020-03-15',
  employmentType: 'regular',
  rank: '과장',
  gender: 'male',
  salary: 50000000,
  bankAccount: {
    bankName: '국민은행',
    accountNumber: '123-456-789012',
    accountHolder: '김철수',
  },
  address: {
    zipCode: '12345',
    address1: '서울시 강남구 테헤란로 123',
    address2: '101호',
  },
  departmentPositions: [
    { id: '1', departmentId: 'd1', departmentName: '개발본부', positionId: 'p1', positionName: '팀장' }
  ],
  clockInLocation: 'headquarters',
  clockOutLocation: 'headquarters',
  concurrentPosition: '',
  concurrentReason: '',
  userInfo: { userId: 'kimcs', role: 'manager', accountStatus: 'active' },
  createdAt: '2020-03-15T00:00:00Z',
  updatedAt: '2024-01-15T00:00:00Z',
};

export default function EmployeeEditPage() {
  const router = useRouter();
  const params = useParams();
  const [employee, setEmployee] = useState<Employee | null>(null);

  useEffect(() => {
    // TODO: API 연동
    // const id = params.id;
    setEmployee(mockEmployee);
  }, [params.id]);

  const handleSave = (data: EmployeeFormData) => {
    // TODO: API 연동
    console.log('Update employee:', params.id, data);
    router.push(`/ko/hr/employee-management/${params.id}`);
  };

  if (!employee) {
    return <ContentLoadingSpinner text="사원 정보를 불러오는 중..." />;
  }

  return <EmployeeForm mode="edit" employee={employee} onSave={handleSave} />;
}