var _excluded = ["type", "dataSource", "props"];
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 _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; }
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; }
// 数据过滤组件
// @author Pluto <huarse@gmail.com>
// @create 2020/06/22 21:17

import React, { useState, useEffect } from 'react';
import { Form } from 'antd';
import CascaderSelect from "../compose-form/mod/cascaderSelect";
import useRequest from "../common/use-request";
import { ProFormText, ProFormSelect, ProFormDatePicker, ProFormDateTimeRangePicker, ProFormDateRangePicker } from '@ant-design/pro-form';
export default function FilterItem(_ref) {
  var type = _ref.type,
    dataSource = _ref.dataSource,
    props = _ref.props,
    others = _objectWithoutProperties(_ref, _excluded);
  var _useRequest = useRequest(!Array.isArray(dataSource) ? dataSource : null, {}, function (data) {
      return (data === null || data === void 0 ? void 0 : data.dataSource) || (data === null || data === void 0 ? void 0 : data.formValue) || data;
    }),
    _useRequest2 = _slicedToArray(_useRequest, 1),
    remoteSource = _useRequest2[0];
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    localSource = _useState2[0],
    setLocalSource = _useState2[1];
  useEffect(function () {
    if (Array.isArray(dataSource)) {
      setLocalSource(dataSource);
    }
  }, [dataSource]);
  var name = others.name,
    label = others.label;
  if (type === 'select') {
    return /*#__PURE__*/React.createElement(ProFormSelect, _extends({}, props, others, {
      options: remoteSource || localSource,
      fieldProps: props,
      allowClear: true
    }));
  }
  if (type === 'cascader-select') {
    return /*#__PURE__*/React.createElement(Form.Item, {
      name: name,
      label: label,
      style: {
        minWidth: 280
      }
    }, /*#__PURE__*/React.createElement(CascaderSelect, _extends({}, props, {
      dataSource: remoteSource || localSource
    })));
  }
  if (type === 'search') {
    return /*#__PURE__*/React.createElement(ProFormText, _extends({}, props, others, {
      fieldProps: props,
      style: {
        minWidth: 300
      }
    }));
  }
  if (type === 'datepicker') {
    return /*#__PURE__*/React.createElement(ProFormDatePicker, _extends({}, props, others, {
      fieldProps: props,
      style: {
        minWidth: 280
      }
    }));
  }
  if (type === 'dateRangePicker') {
    return /*#__PURE__*/React.createElement(ProFormDateRangePicker, _extends({}, props, others, {
      fieldProps: props,
      style: {
        minWidth: 280
      }
    }));
  }
  if (type === 'dateTimeRangePicker') {
    return /*#__PURE__*/React.createElement(ProFormDateTimeRangePicker, _extends({}, props, others, {
      fieldProps: props,
      style: {
        minWidth: 280
      },
      width: "lg",
      colSize: "8",
      props: {
        width: 'lg',
        colSize: 8
      }

      // onChange={() => {
      //   console.log(33);
      // }}
      // width="xs"
      // colSize={3}
    }));
  }

  // datepicker

  return null;
}