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 _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(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); }
import React from 'react';
import { useSortable } from '@dnd-kit/sortable';
import { CSS } from '@dnd-kit/utilities';
import classNames from "classnames";
import { Checkbox } from "antd";
import ButtonGroup from "../ButtonGroup";
import { DragOutlined, MoreOutlined } from "@ant-design/icons";

// 拖拽项组件
var SortableItem = function SortableItem(itemProps) {
  var item = itemProps.item,
    itemIndex = itemProps.itemIndex,
    _onClick = itemProps.onClick,
    parentProps = itemProps.parentProps;
  var optionName = parentProps.optionName,
    disabled = parentProps.disabled,
    selectedKeys = parentProps.selectedKeys,
    labelExtra = parentProps.labelExtra,
    codes = parentProps.codes,
    permissionCodes = parentProps.permissionCodes,
    buttonGroup = parentProps.buttonGroup,
    buttonGroupConfig = parentProps.buttonGroupConfig,
    multiple = parentProps.multiple,
    checkable = parentProps.checkable,
    labelRender = parentProps.labelRender,
    sortable = parentProps.sortable,
    _parentProps$handle = parentProps.handle,
    handle = _parentProps$handle === void 0 ? true : _parentProps$handle,
    handleRender = parentProps.handleRender,
    optionNodeAttr = parentProps.optionNodeAttr;
  var _useSortable = useSortable({
      id: item[optionName.value],
      // / 这里传入的id属性必须和SortableContext的items数组一一对应
      transition: {
        duration: 500,
        easing: 'cubic-bezier(0.25, 1, 0.5, 1)'
      }
    }),
    setNodeRef = _useSortable.setNodeRef,
    attributes = _useSortable.attributes,
    listeners = _useSortable.listeners,
    transform = _useSortable.transform,
    transition = _useSortable.transition,
    isDragging = _useSortable.isDragging;
  var styles = {
    transform: CSS.Transform.toString(transform),
    transition: transition
  };
  var customOptionAttr = (optionNodeAttr ? optionNodeAttr === null || optionNodeAttr === void 0 ? void 0 : optionNodeAttr(item, {
    index: itemIndex
  }) : optionNodeAttr) || {};
  return /*#__PURE__*/React.createElement("div", _extends({
    ref: setNodeRef
  }, sortable ? attributes : {}, !handle ? sortable ? listeners : undefined : undefined, customOptionAttr, {
    style: _objectSpread(_objectSpread({}, sortable ? styles : {}), (customOptionAttr === null || customOptionAttr === void 0 ? void 0 : customOptionAttr.style) || {}),
    className: classNames('spec-standard-list-selections-item', item[optionName === null || optionName === void 0 ? void 0 : optionName.disabled] || item.disabled || disabled ? "selections-item-is-disabled" : '', selectedKeys !== null && selectedKeys !== void 0 && selectedKeys.some(function (sItem) {
      return sItem && (sItem === item[optionName === null || optionName === void 0 ? void 0 : optionName.value] || sItem === (item === null || item === void 0 ? void 0 : item.value));
    }) ? "selections-item-is-selected" : '', customOptionAttr === null || customOptionAttr === void 0 ? void 0 : customOptionAttr.className),
    onClick: function onClick(event) {
      // event?.stopPropagation()
      // event?.preventDefault()
      !(item[optionName === null || optionName === void 0 ? void 0 : optionName.disabled] || item.disabled) && !disabled && (_onClick === null || _onClick === void 0 ? void 0 : _onClick(item));
    }
  }), /*#__PURE__*/React.createElement("div", {
    className: 'spec-standard-list-selections-label'
  }, sortable && handle ? /*#__PURE__*/React.createElement("span", _extends({
    className: 'spec-standard-list-selections-label-sortable'
  }, listeners), handleRender || /*#__PURE__*/React.createElement(DragOutlined, null)) : '', multiple && checkable && /*#__PURE__*/React.createElement(Checkbox, {
    disabled: item[optionName === null || optionName === void 0 ? void 0 : optionName.disabled] || item.disabled || disabled,
    checked: (selectedKeys || []).includes(item[optionName === null || optionName === void 0 ? void 0 : optionName.value] || (item === null || item === void 0 ? void 0 : item.value)),
    onChange: function onChange(evt) {
      // onClick?.(item)
    }
  }), " ", labelRender ? labelRender(item, {
    index: itemIndex
  }) : /*#__PURE__*/React.createElement("span", {
    className: 'spec-standard-list-selections-label-name'
  }, item[(optionName === null || optionName === void 0 ? void 0 : optionName.label) || 'label'])), labelExtra && /*#__PURE__*/React.createElement("div", {
    className: 'spec-standard-list-selections-extra'
  }, labelExtra === null || labelExtra === void 0 ? void 0 : labelExtra(item)), /*#__PURE__*/React.createElement("div", {
    className: 'spec-standard-list-selections-actions',
    onClick: function onClick(event) {
      // event.preventDefault()
      event.stopPropagation();
    }
  }, buttonGroup && /*#__PURE__*/React.createElement(ButtonGroup, _extends({
    options: buttonGroup,
    codes: codes,
    permissionCodes: permissionCodes,
    type: 'text',
    rowParams: {
      text: item[(optionName === null || optionName === void 0 ? void 0 : optionName.label) || 'label'],
      record: item,
      rowIndex: itemIndex
    },
    moreText: /*#__PURE__*/React.createElement(MoreOutlined, null),
    moreIcon: null,
    min: 1,
    showTextIcon: true
  }, buttonGroupConfig))));
};
export default SortableItem;