import React, { useEffect } from 'react';
import { Select } from 'antd';
import { useModel } from '@umijs/max';

const { Option } = Select;

function DDProjectField(props) {
  const { value, disabled = false, onChange } = props;
  const { projectList, loading, run } = useModel('projectList');
  useEffect(() => {
    run();
  }, []);
  return (
    <Select
      showSearch
      loading={loading}
      style={{ width: '100%' }}
      disabled={disabled}
      defaultValue={value ? Number(value) : undefined}
      onChange={(value) => {
        console.log(value);
        onChange(String(value));
      }}
      filterOption={(input, option) =>
        (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
      }
      options={projectList.map((item) => {
        return {
          label: `${item.project_name}(${item.project_full_code})`,
          value: item.id,
        };
      })}
    ></Select>
  );
}

export default DDProjectField;
