import React from 'react';
import OrderActionsDropdown from '../../Dropdown';
import { useAtom } from 'jotai';
import { useOrderStaticData } from '../../../store';
import { selectedDocumentTypeAtom } from '../../store';

function DocumentTypeDropdown() {
  const [hello, setSelectedDocumentType] = useAtom(selectedDocumentTypeAtom);
  const [staticOrderData] = useOrderStaticData();

  const documentOptions = staticOrderData?.resource_document_type?.map(
    (x: any) => ({
      id: x?.id,
      type: x?.type,
      value: x?.value,
    })
  );

  const onSelectCancelReason = (selectedValue: any) => {
    const selectedOption = documentOptions?.find(
      (option: any) => option?.value === selectedValue
    );
    if (selectedOption) {
      setSelectedDocumentType(selectedOption.value);
    }
  };

  console.log(hello, 'hellohello');

  return (
    <OrderActionsDropdown
      label="Document Type"
      required
      placeholder="Select Document Type"
      options={documentOptions}
      onSelect={onSelectCancelReason}
    />
  );
}

export default DocumentTypeDropdown;
