import { Select } from 'antd';
import styles from './index.less';

import services from '@/services';
import { useModel } from '@umijs/max';
import { useRequest } from 'ahooks';

/**
 * @description 区域选择
 */

const RegionSelect = () => {
  const { setSelectAreaId } = useModel('safetyAreaId');
  const { data } = useRequest(services.DataBase.getSjdzInfoData, {
    defaultParams: [
      {
        typeCode: 'tssj-qulb',
      },
    ],
  });

  return (
    <div className={styles.regionSelectWrap}>
      <Select
        placeholder='成都市'
        allowClear
        options={data?.data?.data?.records?.map(
          (item: { tsqy: string; tsqy_code: string }) => ({
            label: item?.tsqy,
            value: item?.tsqy_code,
          }),
        )}
        onChange={(e) => {
          setSelectAreaId(e);
        }}
      />
    </div>
  );
};

export default RegionSelect;
