import _Cascader from "antd/es/cascader";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["defaultValue", "style", "disabled", "placeholder", "dataSource", "options", "followTrigger", "canOnlyCheckLeaf", "value", "isPreview", "size", "hasArrow", "expandTrigger", "readOnly", "label", "showSearch", "block", "allowClear", "ID", "bordered", "autoFocus", "clearIcon", "changeOnSelect", "hasClear", "fieldNames", "maxTagCount", "notFoundContent", "placement", "status", "open", "multiple", "childrenFlag"];
import * as React from 'react';
import { useEffect, useState } from 'react';
import "./index.scss";
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,
    dataSource = _ref.dataSource,
    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,
    block = _ref.block,
    allowClear = _ref.allowClear,
    ID = _ref.ID,
    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 = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _style = style || {};
  var newstyle = JSON.stringify(_style);
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var arrObj = Object.keys(_otherProps.style);
  if (arrObj.length > 0) {
    for (var k in _otherProps.style) {
      // if (k == 'width' || k == 'height') {
      //     // _otherProps.style[k] = '100%'
      // }
      if (k == 'paddingRight' || k == 'paddingLeft' || k == 'paddingTop' || k == 'paddingBottom' || k == 'marginRight' || k == 'marginLeft' || k == 'marginTop' || k == 'marginBottom') {
        _otherProps.style[k] = '0px';
      }
    }
  }
  var _useState = useState(''),
    CasId = _useState[0],
    setID = _useState[1];
  var _useState2 = useState([]),
    value2 = _useState2[0],
    editarr = _useState2[1];
  useEffect(function () {
    ChangeSize();
  }, [CasId, _otherProps]);
  useEffect(function () {
    setID("CasId" + uuid());
  }, []);
  var ChangeSize = function ChangeSize() {
    setTimeout(function () {
      if (CasId) {
        var _ref2, _ref3;
        var elemsMax = document.getElementById(CasId) || document;
        newstyle = JSON.parse(newstyle);
        elemsMax.style.paddingRight = newstyle.paddingRight ? newstyle.paddingRight : 0;
        elemsMax.style.paddingLeft = newstyle.paddingLeft ? newstyle.paddingLeft : 0;
        elemsMax.style.paddingTop = newstyle.paddingTop ? newstyle.paddingTop : 0;
        elemsMax.style.paddingBottom = newstyle.paddingBottom ? newstyle.paddingBottom : 0;
        elemsMax.style.marginRight = newstyle.marginRight ? newstyle.marginRight : 0;
        elemsMax.style.marginLeft = newstyle.marginLeft ? newstyle.marginLeft : 0;
        elemsMax.style.marginTop = newstyle.marginTop ? newstyle.marginTop : 0;
        elemsMax.style.marginBottom = newstyle.marginBottom ? newstyle.marginBottom : 0;
        // elemsMax.style.width = newstyle.width?newstyle.width:'100px'
        // elemsMax.style.height = newstyle.height?newstyle.height:'36px'
        // elemsMax.style.height = newstyle.height&&newstyle.height.slice(newstyle.height.length-1,newstyle.height)=='x'?newstyle.height:newstyle.height.slice(0,newstyle.height.length-1)+'vh'
        // 1.控制下拉框的高度，选中组件设置高度后，应该拉高下拉框本身的高度。
        var elems = (_ref2 = document.getElementById(CasId) || 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(CasId) || 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 + 10 + 'px'; //高度
        }
      }
    }, 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(value1, '处理后的值');
    if (value1[0] && !(value1[0] instanceof Array)) {
      arr1 = [value1];
    } else {
      // 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])
      //         })
      //     }
      // })
      arr1 = value1;
    }
    console.log(style, 'stylestylestyle');
    return /*#__PURE__*/React.createElement("div", {
      id: CasId,
      className: "CascaderStyle",
      style: {
        width: style.width,
        height: style.height,
        display: block ? 'inline-block' : 'none'
      }
    }, /*#__PURE__*/React.createElement(_Cascader, _extends({
      options: dataSource,
      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: CasId,
      className: "CascaderStyle",
      style: {
        width: style.width,
        height: style,
        display: block ? 'inline-block' : 'none'
      }
    }, /*#__PURE__*/React.createElement(_Cascader, _extends({
      options: dataSource,
      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';
export default antcaderName;
export function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}