function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { Tooltip } from 'antd';
import classnames from 'classnames';
import _, { isEmpty } from 'lodash';
import { useEffect, useState } from 'react';
import useSettings from "../../_hooks/useSettings";
import { ChartIcon, DateIcon, ListIcon } from "../../_util/iconSvgHtml";
import VmFilter from "../vm-filter";
import "./style";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var VMDatePicker = VmFilter.VMDatePicker,
  VMMonthPicker = VmFilter.VMMonthPicker,
  VMYearPicker = VmFilter.VMYearPicker,
  VMRangePicker = VmFilter.VMRangePicker;
export default function VmWrapper(props) {
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _props$title = props.title,
    title = _props$title === void 0 ? '' : _props$title,
    extra = props.extra,
    extraLeft = props.extraLeft,
    _props$extraStyle = props.extraStyle,
    extraStyle = _props$extraStyle === void 0 ? {} : _props$extraStyle,
    _props$needChange = props.needChange,
    needChange = _props$needChange === void 0 ? false : _props$needChange,
    _props$filterType = props.filterType,
    filterType = _props$filterType === void 0 ? '' : _props$filterType,
    _props$defaultValue = props.defaultValue,
    defaultValue = _props$defaultValue === void 0 ? null : _props$defaultValue,
    _props$dateValue = props.dateValue,
    dateValue = _props$dateValue === void 0 ? null : _props$dateValue,
    disabledDate = props.disabledDate,
    _props$headerStyle = props.headerStyle,
    headerStyle = _props$headerStyle === void 0 ? {} : _props$headerStyle,
    _props$contentStyle = props.contentStyle,
    contentStyle = _props$contentStyle === void 0 ? {} : _props$contentStyle,
    _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style,
    _props$showList = props.showList,
    showList = _props$showList === void 0 ? true : _props$showList,
    _props$showChart = props.showChart,
    showChart = _props$showChart === void 0 ? true : _props$showChart,
    _props$showCalendar = props.showCalendar,
    showCalendar = _props$showCalendar === void 0 ? false : _props$showCalendar,
    _props$showTitle = props.showTitle,
    showTitle = _props$showTitle === void 0 ? true : _props$showTitle,
    _props$showContent = props.showContent,
    showContent = _props$showContent === void 0 ? true : _props$showContent,
    _props$tabList = props.tabList,
    tabList = _props$tabList === void 0 ? [] : _props$tabList,
    _props$activeKey = props.activeKey,
    activeKey = _props$activeKey === void 0 ? '' : _props$activeKey,
    onChangeTab = props.onChangeTab,
    _props$pickerProps = props.pickerProps,
    pickerProps = _props$pickerProps === void 0 ? {} : _props$pickerProps;
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    changeList = _useState2[0],
    setChangeList = _useState2[1];
  var _useState3 = useState('chart'),
    _useState4 = _slicedToArray(_useState3, 2),
    active = _useState4[0],
    setActive = _useState4[1];
  useEffect(function () {
    (props === null || props === void 0 ? void 0 : props.onChange) && props.onChange(active);
  }, [active]);
  useEffect(function () {
    var changeList = [];
    if (showCalendar) {
      changeList.push({
        key: 'calendar',
        icon: DateIcon,
        name: '日历'
      });
    }
    if (showChart) {
      changeList.push({
        key: 'chart',
        icon: ListIcon,
        name: '图表'
      });
    }
    if (showList) {
      changeList.push({
        key: 'list',
        icon: ChartIcon,
        name: '列表'
      });
    }
    setChangeList(changeList);
    if (!_.isEmpty(changeList)) {
      setActive(changeList[0].key);
    }
  }, [showChart, showList, showCalendar]);
  var fill = {
    true: '#1670ff',
    false: '#8c8c8c'
  };
  var fillDark = {
    true: '#009DFF',
    false: '#ffffff'
  };
  return /*#__PURE__*/_jsxs("div", {
    className: "div-wrapper ".concat(isDark ? 'dark' : ''),
    style: style,
    children: [showTitle && /*#__PURE__*/_jsxs("div", {
      className: "div-wrapper-head",
      style: _objectSpread({}, headerStyle),
      children: [isEmpty(tabList) ? title : /*#__PURE__*/_jsx("div", {
        className: "div-wrapper-tabs-wrap",
        children: tabList.map(function (item) {
          return /*#__PURE__*/_jsx("div", {
            className: classnames('div-wrapper-tabs-item', {
              active: item.key === activeKey
            }),
            onClick: function onClick() {
              return onChangeTab(item.key);
            },
            children: item.label
          }, item.key);
        })
      }), /*#__PURE__*/_jsxs("div", {
        className: "extra",
        style: _objectSpread({}, extraStyle),
        children: [extraLeft ? extraLeft : null, needChange && /*#__PURE__*/_jsx("div", {
          className: "extra-type",
          children: changeList.map(function (item) {
            var Icon = item.icon;
            return /*#__PURE__*/_jsx("div", {
              className: "extra-type-item ".concat(active === item.key ? 'active' : '', " ").concat(isDark ? 'dark' : ''),
              onClick: function onClick() {
                return setActive(item.key);
              },
              children: /*#__PURE__*/_jsx(Tooltip, {
                title: item.name,
                children: /*#__PURE__*/_jsx(Icon, {
                  width: 14,
                  height: 14,
                  fill: isDark ? fillDark["".concat(active === item.key)] : fill["".concat(active === item.key)]
                })
              })
            }, item.key);
          })
        }), filterType === 'datePicker' ? /*#__PURE__*/_jsx(VMDatePicker, _objectSpread({
          defaultValue: defaultValue,
          value: dateValue,
          onChange: props.filterChange,
          disabledDate: disabledDate
        }, pickerProps)) : filterType === 'rangePicker' ? /*#__PURE__*/_jsx(VMRangePicker, _objectSpread({
          defaultValue: defaultValue || [],
          value: dateValue || [],
          onChange: props.filterChange,
          disabledDate: disabledDate
        }, pickerProps)) : filterType === 'monthPicker' ? /*#__PURE__*/_jsx(VMMonthPicker, _objectSpread({
          defaultValue: defaultValue,
          value: dateValue,
          onChange: props.filterChange,
          disabledDate: disabledDate
        }, pickerProps)) : filterType === 'yearPicker' ? /*#__PURE__*/_jsx(VMYearPicker, _objectSpread({
          defaultValue: defaultValue,
          value: dateValue,
          onChange: props.filterChange,
          disabledDate: disabledDate
        }, pickerProps)) : null, extra ? extra : null]
      })]
    }), showContent && /*#__PURE__*/_jsx("div", {
      className: "div-wrapper-content",
      style: contentStyle,
      children: props === null || props === void 0 ? void 0 : props.children
    })]
  });
}