'use client';

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

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

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

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