var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/table/model.tsx
var model_exports = {};
__export(model_exports, {
  Context: () => Context,
  Provider: () => Provider,
  formatColumn: () => formatColumn
});
module.exports = __toCommonJS(model_exports);
var import_miniRedux = __toESM(require("../../utils/miniRedux"));
var defaultState = {
  // 表格id 用于缓存配置到localStorage
  tableId: "",
  // 是否使用本地数据模式
  localPagination: false,
  dataSource: [],
  // 原始数据 用于回显
  originDataSource: [],
  defaultColumns: [],
  // 原始列 用于列操作时还原
  originColumns: [],
  originColumnsMap: /* @__PURE__ */ new Map(),
  currentCell: null,
  quickFilter: [],
  otherFilter: [],
  utils: {},
  isTerminal: false,
  setting: {
    field: {
      edit: 0
    },
    data: {
      edit: 0
    }
  },
  tableWidth: 700,
  // 当前页展示的数据
  currentDataSource: [],
  // 经过一系列格式化之后的所有数据
  originResultDataSource: []
};
var { Provider, Context } = (0, import_miniRedux.default)({
  namespace: "state",
  state: defaultState,
  reducers: {
    setDataSource(state, payload) {
      return { ...state, dataSource: payload };
    },
    setOriginDataSource(state, payload) {
      return { ...state, originDataSource: payload };
    },
    setDefaultColumns(state, payload) {
      return {
        ...state,
        defaultColumns: payload.map((d) => formatColumn(d))
      };
    },
    setOriginColumns(state, payload) {
      const originColumns = payload.map((d) => formatColumn(d));
      const originColumnsMap = new Map(
        originColumns.map((item) => [item.key, item])
      );
      return {
        ...state,
        originColumns,
        originColumnsMap
      };
    },
    setCurrentCell(state, payload) {
      return { ...state, currentCell: payload };
    },
    setQuickFilter(state, payload) {
      return { ...state, quickFilter: payload };
    },
    setUtils(state, payload) {
      return { ...state, utils: payload };
    },
    setIsTerminal(state, payload) {
      return { ...state, isTerminal: payload };
    },
    syncStorage(state, payload) {
      return { ...state };
    },
    init(state, payload) {
      return { ...state };
    },
    setOtherFilter(state, payload) {
      return { ...state, otherFilter: payload };
    },
    setTableId(state, payload) {
      return { ...state, tableId: payload };
    },
    setLocalPagination(state, payload) {
      return { ...state, localPagination: payload };
    },
    setTableWidth(state, payload) {
      return { ...state, tableWidth: payload };
    },
    setCurrentDataSource(state, payload) {
      return { ...state, currentDataSource: payload };
    },
    setOriginResultDataSource(state, payload) {
      return { ...state, originResultDataSource: payload };
    }
  }
});
var formatColumn = (item) => {
  let _other = {
    editable: true,
    field_type: "text",
    lock: true,
    ...item.other || {}
  };
  return {
    ..._other,
    ...item
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Context,
  Provider,
  formatColumn
});
