import _Select from "antd/es/select";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["style", "options"],
  _excluded2 = ["width"];
import { useEffect } from 'react';
import React, { useState } from 'react';
var provinceData = ['Zhejiang', 'Jiangsu'];
var cityData = {
  Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
  Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang']
};
var twoSelect = function twoSelect(props) {
  var style = props.style,
    options = props.options,
    twoSelectProps = _objectWithoutPropertiesLoose(props, _excluded);
  var width = style.width,
    otherStyle = _objectWithoutPropertiesLoose(style, _excluded2);
  //处理style的宽度
  var width = (style === null || style === void 0 ? void 0 : style.width) || (style === null || style === void 0 ? void 0 : style.minWidth.match(/\d+/g));
  width = (Number(width) - 10) / 2;
  var _useState = useState([]),
    cities = _useState[0],
    setCities = _useState[1];
  var _useState2 = useState([]),
    secondCity = _useState2[0],
    setSecondCity = _useState2[1];
  var _useState3 = useState(''),
    secondCityValue = _useState3[0],
    setSecondCityValue = _useState3[1];
  useEffect(function () {
    var _options$, _options$2, _options$3;
    var data = [];
    // let TwoData=[]
    options.map(function (item) {
      var i = {
        label: item.label,
        value: item.value
      };
      data.push(i);
    });
    console.log(options === null || options === void 0 ? void 0 : (_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.options);
    setSecondCity(options === null || options === void 0 ? void 0 : (_options$2 = options[0]) === null || _options$2 === void 0 ? void 0 : _options$2.options);
    setCities(data);
    setSecondCityValue(options === null || options === void 0 ? void 0 : (_options$3 = options[0]) === null || _options$3 === void 0 ? void 0 : _options$3.options[0].label);
  }, [options]);
  var handleProvinceChange = function handleProvinceChange(value) {
    console.log(value, '-------value');
    options.map(function (item) {
      if (value == item.value) {
        setSecondCityValue(item.options[0].label);
        setSecondCity(item.options);
      }
    });
  };
  var onSecondCityChange = function onSecondCityChange(value) {
    //   setSecondCity(value);
  };
  console.log(cities, '--------cities');
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_Select, _extends({
    // defaultValue={provinceData[0]}
    style: _extends({
      width: width
    }, otherStyle),
    onChange: handleProvinceChange,
    options: cities
  }, twoSelectProps)), /*#__PURE__*/React.createElement(_Select, _extends({
    style: _extends({
      width: width,
      marginLeft: 10
    }, otherStyle)
    //   defaultValue={secondCity}
    ,
    value: secondCityValue,
    onChange: onSecondCityChange,
    options: secondCity
  }, twoSelectProps)));
};
export default twoSelect;