"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _select = _interopRequireDefault(require("antd/lib/select"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
var _excluded = ["style", "options"],
  _excluded2 = ["width"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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 = (0, _objectWithoutPropertiesLoose2["default"])(props, _excluded);
  var width = style.width,
    otherStyle = (0, _objectWithoutPropertiesLoose2["default"])(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 = (0, _react.useState)([]),
    cities = _useState[0],
    setCities = _useState[1];
  var _useState2 = (0, _react.useState)([]),
    secondCity = _useState2[0],
    setSecondCity = _useState2[1];
  var _useState3 = (0, _react.useState)(''),
    secondCityValue = _useState3[0],
    setSecondCityValue = _useState3[1];
  (0, _react.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["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_select["default"], (0, _extends2["default"])({
    // defaultValue={provinceData[0]}
    style: (0, _extends2["default"])({
      width: width
    }, otherStyle),
    onChange: handleProvinceChange,
    options: cities
  }, twoSelectProps)), /*#__PURE__*/_react["default"].createElement(_select["default"], (0, _extends2["default"])({
    style: (0, _extends2["default"])({
      width: width,
      marginLeft: 10
    }, otherStyle)
    //   defaultValue={secondCity}
    ,
    value: secondCityValue,
    onChange: onSecondCityChange,
    options: secondCity
  }, twoSelectProps)));
};
var _default = twoSelect;
exports["default"] = _default;