var _excluded = ["dataSource", "value", "onChange", "allowClear", "disabled"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { Cascader } from 'antd';
export default function cascader(_ref) {
  var _ref$dataSource = _ref.dataSource,
    dataSource = _ref$dataSource === void 0 ? [] : _ref$dataSource,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? [] : _ref$value,
    onChange = _ref.onChange,
    _ref$allowClear = _ref.allowClear,
    allowClear = _ref$allowClear === void 0 ? true : _ref$allowClear,
    disabled = _ref.disabled,
    others = _objectWithoutProperties(_ref, _excluded);
  // console.log('cascader', value, dataSource);
  var onValueChange = function onValueChange(val) {
    onChange(val);
  };
  var getReadOnlyValue = function getReadOnlyValue() {
    var startData = dataSource === null || dataSource === void 0 ? void 0 : dataSource.find(function (item) {
      return item.value === value[0];
    });
    var finalArr = [];
    function recursion() {
      var param = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      param === null || param === void 0 || param.forEach(function (item) {
        finalArr.push({
          label: item.label,
          value: item.value
        });
        if (item !== null && item !== void 0 && item.children) {
          recursion(item.children);
        }
      });
    }
    recursion(startData === null || startData === void 0 ? void 0 : startData.children);
    var dizData = finalArr.filter(function (item) {
      return value === null || value === void 0 ? void 0 : value.some(function (iv) {
        return iv === (item === null || item === void 0 ? void 0 : item.value);
      });
    });
    return /*#__PURE__*/React.createElement(React.Fragment, null, startData === null || startData === void 0 ? void 0 : startData.label, dizData && dizData !== null && dizData !== void 0 && dizData.length ? dizData.map(function (item) {
      return /*#__PURE__*/React.createElement(React.Fragment, null, '/', item.label);
    }) : /*#__PURE__*/React.createElement("span", null, "-"));
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, disabled ? value.length && dataSource.length ? getReadOnlyValue() : /*#__PURE__*/React.createElement("span", null, "-") : /*#__PURE__*/React.createElement(Cascader, _extends({
    allowClear: allowClear,
    options: dataSource,
    value: value,
    placeholder: "\u8BF7\u9009\u62E9",
    onChange: onValueChange
  }, others)));
}