'use client';

import { useMemo } from 'react';
import { GenericCRUDDialog, type CRUDFieldDefinition } from '@/components/molecules/GenericCRUDDialog';
import type { RankDialogProps } from './types';

const RANK_FIELDS: CRUDFieldDefinition[] = [
  { key: 'name', label: '직급명', type: 'text', placeholder: '직급명을 입력하세요' },
];

/**
 * 직급 추가/수정 다이얼로그
 */
export function RankDialog({
  isOpen,
  onOpenChange,
  mode,
  rank,
  onSubmit,
  isLoading = false,
}: RankDialogProps) {
  const initialData = useMemo(
    () => (rank ? { name: rank.name } : undefined),
    [rank]
  );

  return (
    <GenericCRUDDialog
      isOpen={isOpen}
      onOpenChange={onOpenChange}
      mode={mode}
      entityName="직급"
      fields={RANK_FIELDS}
      initialData={initialData}
      onSubmit={(data) => onSubmit(data.name)}
      isLoading={isLoading}
    />
  );
}