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); }
/**
 * 列设置工具：持久化复用 @pisell/utils 的 saveColumnSettingToLocal / getColumnSettingFromLocal；
 * mergeColumnSettingSimple 为 Table 列与本地缓存的合并逻辑，保留在此。
 */

import { saveColumnSettingToLocal as saveColumnSettingToLocalFromUtils, getColumnSettingFromLocal, clearColumnSettingFromLocal } from '@pisell/utils';
export { getColumnSettingFromLocal, clearColumnSettingFromLocal };

/** 与 DataSourceContainer ColumnsSetting 调用处类型兼容的列设置项（含 React.ReactNode title） */

export var saveColumnSettingToLocal = function saveColumnSettingToLocal(params) {
  saveColumnSettingToLocalFromUtils({
    componentId: params.componentId,
    columnSetting: params.columnSetting
  });
};
export var mergeColumnSettingSimple = function mergeColumnSettingSimple(_ref) {
  var columns = _ref.columns,
    componentId = _ref.componentId;
  if (!componentId) {
    return columns.map(function (item, index) {
      var _item$isShow;
      return _objectSpread(_objectSpread({}, item), {}, {
        isShow: (_item$isShow = item.isShow) !== null && _item$isShow !== void 0 ? _item$isShow : true,
        sortIndex: index
      });
    });
  }
  var cachedColumns = getColumnSettingFromLocal(componentId);
  if (!cachedColumns || !Array.isArray(cachedColumns)) {
    return columns.map(function (item, index) {
      var _item$isShow2;
      return _objectSpread(_objectSpread({}, item), {}, {
        isShow: (_item$isShow2 = item.isShow) !== null && _item$isShow2 !== void 0 ? _item$isShow2 : true,
        sortIndex: index
      });
    });
  }
  var cachedMap = new Map(cachedColumns.map(function (item) {
    return [item.dataIndex, item];
  }));
  var mergedColumns = columns.map(function (item, index) {
    var _item$isShow3;
    var cached = cachedMap.get(item.dataIndex);
    if (cached) {
      var _cached$isShow, _cached$sortIndex;
      return _objectSpread(_objectSpread({}, item), {}, {
        isShow: (_cached$isShow = cached.isShow) !== null && _cached$isShow !== void 0 ? _cached$isShow : true,
        sortIndex: (_cached$sortIndex = cached.sortIndex) !== null && _cached$sortIndex !== void 0 ? _cached$sortIndex : index
      });
    }
    return _objectSpread(_objectSpread({}, item), {}, {
      isShow: (_item$isShow3 = item.isShow) !== null && _item$isShow3 !== void 0 ? _item$isShow3 : true,
      sortIndex: index
    });
  });
  mergedColumns.sort(function (a, b) {
    var _a$sortIndex, _b$sortIndex;
    return ((_a$sortIndex = a.sortIndex) !== null && _a$sortIndex !== void 0 ? _a$sortIndex : 0) - ((_b$sortIndex = b.sortIndex) !== null && _b$sortIndex !== void 0 ? _b$sortIndex : 0);
  });
  return mergedColumns;
};