import React, { FC } from 'react';
import { Cascader } from 'antd';
import { ALL_ADDRESS } from './address';
import type { DefaultOptionType } from 'antd/es/cascader';

interface Option {
  value: string;
  label: string;
  children?: Option[];
  disabled?: boolean;
}
interface CascaderSearchProps {
  changeAddressKey: (a: string[], b: Option[]) => void;
}

const CascaderSearch: FC<CascaderSearchProps> = (props) => {
  const onChange = (value: string[], selectedOptions: any[]) => {
    props.changeAddressKey(value, selectedOptions);
  };
  const filter = (inputValue: string, path: DefaultOptionType[]) =>
    path.some(
      (option) =>
        (option.label as string)
          .toLowerCase()
          .indexOf(inputValue.toLowerCase()) > -1,
    );
  return (
    <Cascader
      options={ALL_ADDRESS}
      onChange={onChange}
      placeholder="请选择地区"
      showSearch={{ filter }}
      onSearch={(value) => {}}
    />
  );
};
export default CascaderSearch;
