function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 _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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React from "react";
import DotsSix from "@pisell/icon/es/DotsSix";
import Lock01 from "@pisell/icon/es/Lock01";
import classNames from "classnames";
import { Tooltip } from "antd";
import { EyeInvisibleOutlined, EyeOutlined } from "@ant-design/icons";
import Sortable from "../../../../DragSortList";
import { isFixedOrderValid } from "./utils";
import "./PopoverContent.less";
import { getText } from "../../../../../locales";
var prefix = "pisell-lowcode-";
var DragItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var attributes = props.attributes,
    listeners = props.listeners,
    setActivatorNodeRef = props.setActivatorNodeRef,
    style = props.style,
    isLock = props.isLock;
  return /*#__PURE__*/React.createElement("div", _extends({
    ref: ref
  }, attributes, {
    style: style,
    className: "".concat(prefix, "table-action-column-drag-item")
  }), isLock ? /*#__PURE__*/React.createElement(Tooltip, {
    title: getText("table-column-group-lock-tip")
  }, /*#__PURE__*/React.createElement(Lock01, {
    className: "".concat(prefix, "table-action-column-drag-bar")
  })) : /*#__PURE__*/React.createElement(DotsSix, _extends({
    ref: setActivatorNodeRef
  }, listeners, {
    style: _objectSpread(_objectSpread({}, listeners.style || {}), {}, {
      touchAction: "none"
    }),
    className: "".concat(prefix, "table-action-column-drag-bar")
  })), props.children);
});
var defaultValue = [];
var PopoverContent = function PopoverContent(props) {
  var _props$value = props.value,
    value = _props$value === void 0 ? defaultValue : _props$value,
    _onChange = props.onChange,
    _props$isShowTitle = props.isShowTitle,
    isShowTitle = _props$isShowTitle === void 0 ? true : _props$isShowTitle,
    headerContent = props.headerContent;
  var handleChange = function handleChange(index, isShow) {
    value[index] = _objectSpread(_objectSpread({}, value[index]), {}, {
      isShow: isShow
    });
    _onChange === null || _onChange === void 0 ? void 0 : _onChange(_toConsumableArray(value));
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "table-action-column-popover-content-wrap")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "table-action-column-header")
  }, isShowTitle && /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "table-action-column-header-title")
  }, getText("table-action-column-title")), headerContent && headerContent), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "table-action-column-content")
  }, /*#__PURE__*/React.createElement(Sortable, {
    list: value,
    rowKey: function rowKey(item) {
      var _item$dataIndex;
      return "".concat(item.key, "-").concat((_item$dataIndex = item.dataIndex) === null || _item$dataIndex === void 0 ? void 0 : _item$dataIndex.toString());
    },
    onChange: function onChange(list) {
      if (!isFixedOrderValid(list)) return;
      _onChange === null || _onChange === void 0 ? void 0 : _onChange(list.map(function (item, index) {
        return _objectSpread(_objectSpread({}, item), {}, {
          sortIndex: index
        });
      }));
    }
  }, function (_ref) {
    var item = _ref.item,
      index = _ref.index,
      style = _ref.style,
      props = _ref.props,
      attributes = _ref.attributes,
      setActivatorNodeRef = _ref.setActivatorNodeRef,
      listeners = _ref.listeners;
    return /*#__PURE__*/React.createElement(DragItem, _extends({}, props, {
      isLock: item.fixed,
      index: index,
      attributes: attributes,
      setActivatorNodeRef: setActivatorNodeRef,
      listeners: listeners,
      style: style
    }), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefix, "table-action-column-drag-item-right")
    }, /*#__PURE__*/React.createElement("span", {
      className: classNames("".concat(prefix, "table-action-column-drag-item-right-text"), _defineProperty({}, "".concat(prefix, "table-action-column-drag-item-right-text-hidden"), !item.isShow))
    }, item.titleString || item.title), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
      className: "".concat(prefix, "table-action-column-drag-item-right-icon-wrap"),
      onClick: function onClick() {
        handleChange(index, !item.isShow);
      }
    }, item.isShow ? /*#__PURE__*/React.createElement(EyeOutlined, null) : /*#__PURE__*/React.createElement(EyeInvisibleOutlined, null)))));
  })));
};
export default PopoverContent;