"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
exports.uuid = uuid;
var _cascader = _interopRequireDefault(require("antd/lib/cascader"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.scss");
var _excluded = ["defaultValue", "style", "disabled", "placeholder", "options", "followTrigger", "canOnlyCheckLeaf", "value", "isPreview", "size", "hasArrow", "expandTrigger", "readOnly", "label", "showSearch", "allowClear", "bordered", "autoFocus", "clearIcon", "changeOnSelect", "hasClear", "fieldNames", "maxTagCount", "notFoundContent", "placement", "status", "open", "multiple", "childrenFlag"];
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 antcaderName = function antcaderName(_ref) {
  var defaultValue = _ref.defaultValue,
    _ref$style = _ref.style,
    style = _ref$style === void 0 ? {} : _ref$style,
    disabled = _ref.disabled,
    placeholder = _ref.placeholder,
    options = _ref.options,
    followTrigger = _ref.followTrigger,
    canOnlyCheckLeaf = _ref.canOnlyCheckLeaf,
    value = _ref.value,
    isPreview = _ref.isPreview,
    size = _ref.size,
    hasArrow = _ref.hasArrow,
    expandTrigger = _ref.expandTrigger,
    readOnly = _ref.readOnly,
    label = _ref.label,
    showSearch = _ref.showSearch,
    allowClear = _ref.allowClear,
    bordered = _ref.bordered,
    autoFocus = _ref.autoFocus,
    clearIcon = _ref.clearIcon,
    changeOnSelect = _ref.changeOnSelect,
    hasClear = _ref.hasClear,
    fieldNames = _ref.fieldNames,
    maxTagCount = _ref.maxTagCount,
    notFoundContent = _ref.notFoundContent,
    placement = _ref.placement,
    status = _ref.status,
    open = _ref.open,
    multiple = _ref.multiple,
    childrenFlag = _ref.childrenFlag,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _style = style || {};
  var newstyle = JSON.stringify(_style);
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  _otherProps.style.paddingRight = '0px';
  _otherProps.style.paddingLfet = '0px';
  _otherProps.style.paddingTop = '0px';
  _otherProps.style.paddingBottom = '0px';
  _otherProps.style.marginRight = '0px';
  _otherProps.style.marginLeft = '0px';
  _otherProps.style.marginTop = '0px';
  _otherProps.style.marginBottom = '0px';
  var _useState = (0, React.useState)(''),
    ID = _useState[0],
    setID = _useState[1];
  var _useState2 = (0, React.useState)([]),
    value2 = _useState2[0],
    editarr = _useState2[1];
  (0, React.useEffect)(function () {
    ChangeSize();
  }, [ID, _otherProps.style]);
  (0, React.useEffect)(function () {
    setID("casID" + uuid());
  }, []);
  var ChangeSize = function ChangeSize() {
    setTimeout(function () {
      var _ref2, _ref3;
      var elemsMax = document.getElementById(ID) || document;
      newstyle = JSON.parse(newstyle);
      elemsMax.style.paddingRight = newstyle.paddingRight;
      elemsMax.style.paddingLfet = newstyle.paddingLfet;
      elemsMax.style.paddingTop = newstyle.paddingTop;
      elemsMax.style.paddingBottom = newstyle.paddingBottom;
      elemsMax.style.marginRight = newstyle.marginRight;
      elemsMax.style.marginLeft = newstyle.marginLeft;
      elemsMax.style.marginTop = newstyle.marginTop;
      elemsMax.style.marginBottom = newstyle.marginBottom;

      // 1.控制下拉框的高度，选中组件设置高度后，应该拉高下拉框本身的高度。
      var elems = (_ref2 = document.getElementById(ID) || document) === null || _ref2 === void 0 ? void 0 : _ref2.querySelectorAll('.ant-select-selector');
      var index = 0,
        length = elems.length;
      for (; index < length; index++) {
        elems[index].style.height = _otherProps.style.height; //高度
        elems[index].style.width = _otherProps.style.width; //宽度
      }

      var elems01 = (_ref3 = document.getElementById(ID) || document) === null || _ref3 === void 0 ? void 0 : _ref3.querySelectorAll('.ant-select-single .ant-select-selector .ant-select-selection-item, .ant-select-single .ant-select-selector .ant-select-selection-placeholder');
      var index01 = 0,
        length01 = elems01.length;
      for (; index01 < length01; index01++) {
        elems01[index01].style.lineHeight = _otherProps.style.height; //高度
      }
    }, 0);
  };
  var value1 = [];

  //  优化传入字段字符串转数组
  if (value && !(value instanceof Array)) {
    value1 = value.split('，');
  }
  if (value && value instanceof Array) {
    value1 = value;
  }

  // console.log(value1, 'ceshi');

  if (multiple) {
    var arr1 = [];
    // let arr3 = [{
    //     value: '全选',
    //     label: '全选',
    // }]
    // options.forEach((element, index) => {

    //     // let arr3 = [{
    //     //     value: '全选',
    //     //     label: '全选',
    //     // }]
    //     // arr3.concat(element.children)
    //     // console.log( options[index].children,9999999);
    //     arr1.push({
    //         value: '全选',
    //         label: '全选',
    //     })

    //     if (options[index].children[0].value != '全选') {
    //         options[index].children.unshift(arr1[0])
    //     }

    // });

    // options.forEach((item, index) => {
    //     // console.log(options[0],999999);
    //     // console.log(arr1,999999);
    //     // options[0].children =
    // })

    // console.log(value1, '处理前的值1')
    // if (
    //     value1[0] && (value1[0][0] == options[0].value && value1[0].length == 1)
    // ) {
    //     options.forEach((item, index) => {
    //         if (value1[0] && value1[0][0] == item.value) {

    //            let  newChildren=item.children.slice(0,item.children.length-1)
    //            newChildren.forEach((item1, index) => {
    //                 arr1.push([value1[0][0], item1.value])
    //             })
    //         }
    //     })
    // } else {
    //     if (!(value[0] instanceof Array)) { arr1 = [value1] } else {
    //         arr1 = value1
    //     }
    // }
    // console.log(arr1, '处理后的值');

    if (value1[0] && !(value1[0] instanceof Array)) {
      arr1 = [value1];
    } else {
      arr1 = value1;
    }
    return /*#__PURE__*/React.createElement("div", {
      id: ID,
      className: "CascaderStyle"
    }, /*#__PURE__*/React.createElement(_cascader["default"], (0, _extends2["default"])({
      options: options,
      size: size,
      placeholder: placeholder,
      disabled: disabled,
      defaultValue: defaultValue,
      value: arr1,
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: bordered,
      clearIcon: clearIcon,
      changeOnSelect: changeOnSelect,
      expandTrigger: expandTrigger,
      maxTagCount: maxTagCount,
      fieldNames: fieldNames,
      notFoundContent: notFoundContent
      // open={open}
      ,
      placement: placement,
      showSearch: showSearch,
      status: status,
      multiple: multiple
    }, _otherProps)));
  } else {
    return /*#__PURE__*/React.createElement("div", {
      id: ID,
      className: "CascaderStyle"
    }, /*#__PURE__*/React.createElement(_cascader["default"], (0, _extends2["default"])({
      options: options,
      size: size,
      placeholder: placeholder,
      defaultValue: defaultValue,
      value: value1,
      allowClear: allowClear,
      disabled: disabled,
      autoFocus: autoFocus,
      bordered: bordered,
      clearIcon: clearIcon,
      changeOnSelect: changeOnSelect,
      expandTrigger: expandTrigger,
      maxTagCount: maxTagCount,
      fieldNames: fieldNames,
      notFoundContent: notFoundContent
      // open={open}
      ,
      placement: placement,
      showSearch: showSearch,
      status: status,
      multiple: multiple
    }, _otherProps)));
  }
};
antcaderName.displayName = 'antcaderName';
var _default = antcaderName;
exports["default"] = _default;
function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}