import { Select, SelectProps } from 'antd';
import { useCommonCodes } from '@/hooks/useCommonCodes';

interface Props extends Omit<SelectProps, 'options'> {
  groupCode: string;
  includeAll?: boolean;
  allLabel?: string;
}

export default function CodeSelect({ groupCode, includeAll, allLabel = '전체', ...rest }: Props) {
  const { data = [], isLoading } = useCommonCodes(groupCode);
  const options = [
    ...(includeAll ? [{ value: '', label: allLabel }] : []),
    ...data.map((c) => ({ value: c.code, label: c.codeName })),
  ];
  return <Select loading={isLoading} options={options} allowClear {...rest} />;
}
