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(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { BizSearchInput, IconFont, BizGlobalDataContext } from '@zgfe/business-lib';
import { Button, Result, Space, Table, Tooltip } from 'antd';
import _ from 'lodash';
import React, { useEffect, useState, useContext } from 'react';
import { classPrefix } from '../types';
import getColumnList from './columnList';
import './index.less';
import useIdMappingList from './useList';
var CdpIdMappingList = function CdpIdMappingList(_ref) {
  var onCreate = _ref.onCreate,
    onEdit = _ref.onEdit;
  var prefix = "".concat(classPrefix, "-list");
  var _useContext = useContext(BizGlobalDataContext),
    authority = _useContext.authority;
  var _useIdMappingList = useIdMappingList(),
    list = _useIdMappingList.list,
    reload = _useIdMappingList.reload,
    loading = _useIdMappingList.loading,
    failed = _useIdMappingList.failed;
  var _useState = useState(true),
    _useState2 = _slicedToArray(_useState, 2),
    showTip = _useState2[0],
    setShowTip = _useState2[1];
  var _useState3 = useState(''),
    _useState4 = _slicedToArray(_useState3, 2),
    search = _useState4[0],
    setSearch = _useState4[1];
  var _useState5 = useState([]),
    _useState6 = _slicedToArray(_useState5, 2),
    idList = _useState6[0],
    setIdList = _useState6[1];
  useEffect(function () {
    setShowTip(!Boolean(localStorage.getItem('hideIdMappingTip')));
  }, []);
  useEffect(function () {
    setIdList(list);
  }, [list]);
  function onCloseTip() {
    localStorage.setItem('hideIdMappingTip', 'true');
    setShowTip(false);
  }
  return /*#__PURE__*/React.createElement("div", {
    className: prefix
  }, showTip && /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-tip")
  }, /*#__PURE__*/React.createElement(IconFont, {
    type: "tishi1"
  }), "ID-Mapping\u80FD\u591F\u5F88\u597D\u7684\u5E2E\u52A9\u60A8\u7EDF\u4E00\u7528\u6237\u7684\u8EAB\u4EFD\u4FE1\u606F\uFF0C\u60A8\u53EF\u4EE5\u6839\u636E\u5B9E\u9645\u4E1A\u52A1\u60C5\u51B5\u901A\u8FC7\u5BF9\u5F53\u524D\u8868\u5355\u7684ID\u8FDB\u884C\u7BA1\u7406\u914D\u7F6E\u3002", /*#__PURE__*/React.createElement(IconFont, {
    type: "qingchu",
    onClick: onCloseTip
  })), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-main")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-head")
  }, /*#__PURE__*/React.createElement("span", {
    className: "_right"
  }, /*#__PURE__*/React.createElement(BizSearchInput, {
    placeholder: "\u641C\u7D22ID",
    onChange: setSearch
  }), /*#__PURE__*/React.createElement(Button, {
    onClick: onCreate,
    type: "primary",
    disabled: !authority[10016]
  }, /*#__PURE__*/React.createElement(IconFont, {
    type: "tianjia"
  }), "\u521B\u5EFAID"), /*#__PURE__*/React.createElement(Tooltip, {
    title: "\u60A8\u53EF\u4EE5\u901A\u8FC7\u6570\u636E\u96C6\u5F15\u5165\u65B0\u7684ID\u5230ID\u5339\u914D\u8868\u4E2D\uFF0C\u5B8C\u5584\u7528\u6237\u7684ID\u7EF4\u5EA6\u3002",
    placement: "bottomRight"
  }, /*#__PURE__*/React.createElement(IconFont, {
    type: "tishiicon",
    className: "".concat(prefix, "-icon")
  })))), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "-content")
  }, /*#__PURE__*/React.createElement(Space, {
    className: "title_"
  }, /*#__PURE__*/React.createElement("span", {
    style: {
      fontWeight: '500',
      fontSize: '16px'
    }
  }, "ID\u914D\u7F6E\u8868"), /*#__PURE__*/React.createElement(Tooltip, {
    title: "ID\u914D\u7F6E\u8868\u4E2D\u6240\u5C55\u793A\u7684\u662F\u60A8\u7528\u6237\u5F53\u524D\u7684\u6240\u6709ID\u7ED3\u6784\uFF0C\u5305\u542B\u4E86\u8BF8\u845B\u7CFB\u7EDF\u9884\u5236ID\u53CA\u60A8\u81EA\u5DF1\u521B\u5EFA\u7684\u81EA\u5B9A\u4E49ID\u4FE1\u606F\u3002",
    placement: "right",
    overlayInnerStyle: {
      width: '381px'
    }
  }, /*#__PURE__*/React.createElement(IconFont, {
    type: "tishiicon",
    className: "".concat(prefix, "-icon")
  }))), function () {
    if (failed) {
      return /*#__PURE__*/React.createElement(Result, {
        status: "error",
        className: "".concat(prefix, "-reload"),
        subTitle: "\u6570\u636E\u83B7\u53D6\u5931\u8D25",
        extra: /*#__PURE__*/React.createElement(Button, {
          type: "primary",
          size: "small",
          onClick: reload
        }, "\u91CD\u65B0\u52A0\u8F7D")
      });
    }
    return /*#__PURE__*/React.createElement(Table, {
      className: "".concat(prefix, "-table"),
      columns: getColumnList({
        idList: idList,
        setIdList: setIdList,
        onEdit: onEdit
      }),
      dataSource: idList.filter(function (item) {
        return !search || new RegExp(_.escapeRegExp(search)).test(item.idName);
      }),
      loading: loading,
      scroll: {
        x: true
      },
      rowKey: "id",
      pagination: false
    });
  }())));
};
export default CdpIdMappingList;