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 _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 _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 _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); }
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useMemo, useState } from 'react';
import { PisellSalesGrid } from "./index";
import { getRenderItemByKindRoundTable, getRenderItemByKindTable } from '@pisell/materials';

/** 列配置与 RecordBoard 的 columns 兼容 */

var meta = {
  title: 'Pro Components/PisellSalesGrid',
  component: PisellSalesGrid,
  parameters: {
    layout: 'padded',
    docs: {
      description: {
        component: 'RecordBoard 的上层组件，与 RecordBoard 一致采用打散传参（data、loading、total、pagination、onSearch、多选等）。根据 currentPerspective 选择对应的一组 RecordBoard 配置渲染，不提供 Tab 切换 UI。多选通过 props 传入，SalesGrid 会合并进 grid 再传给 RecordBoard。perspective 的 childComponentProps.grid 可含 columns、scroll、onRow、rowClassName 等 Table 透传。'
      }
    }
  },
  tags: ['autodocs'],
  argTypes: {
    currentPerspective: {
      description: '当前 Perspective key',
      control: 'text'
    },
    perspectives: {
      control: false
    }
  }
};
export default meta;
var mockData = Array.from({
  length: 20
}, function (_, i) {
  return {
    id: "id-".concat(i + 1),
    name: "\u5546\u54C1 ".concat(i + 1),
    sku: "SKU".concat(String(1000 + i).padStart(4, '0')),
    amount: 99 + i * 10,
    status: ['在售', '下架', '待上架'][i % 3],
    updateTime: "2024-02-".concat(String(10 + i % 18).padStart(2, '0'))
  };
});
var columnsFull = [{
  title: '名称',
  dataIndex: 'name',
  key: 'name',
  width: 120
}, {
  title: 'SKU',
  dataIndex: 'sku',
  key: 'sku',
  width: 100
}, {
  title: '金额',
  dataIndex: 'amount',
  key: 'amount',
  width: 100,
  type: 'currency',
  fieldProps: {
    currencySymbol: '¥'
  }
}, {
  title: '状态',
  dataIndex: 'status',
  key: 'status',
  width: 90
}, {
  title: '更新时间',
  dataIndex: 'updateTime',
  key: 'updateTime',
  width: 120
}];
var columnsBrief = [{
  title: '名称',
  dataIndex: 'name',
  key: 'name',
  width: 160
}, {
  title: '金额',
  dataIndex: 'amount',
  key: 'amount',
  width: 120,
  type: 'currency',
  fieldProps: {
    currencySymbol: '¥'
  }
}, {
  title: '状态',
  dataIndex: 'status',
  key: 'status',
  width: 100
}];
var perspectives = [{
  key: 'full',
  label: '完整列表',
  childComponentProps: {
    grid: {
      columns: columnsFull
    }
  }
}, {
  key: 'brief',
  label: '简要',
  childComponentProps: {
    grid: {
      columns: columnsBrief
    }
  }
}];
function useMockDataSourceProps() {
  var _useState = useState({
      pageNumber: 1,
      pageSize: 10
    }),
    _useState2 = _slicedToArray(_useState, 2),
    page = _useState2[0],
    setPage = _useState2[1];
  var _useState3 = useState({}),
    _useState4 = _slicedToArray(_useState3, 2),
    searchParams = _useState4[0],
    setSearchParams = _useState4[1];
  var _useState5 = useState([]),
    _useState6 = _slicedToArray(_useState5, 2),
    selectedKeys = _useState6[0],
    setSelectedKeys = _useState6[1];
  var _useState7 = useState([]),
    _useState8 = _slicedToArray(_useState7, 2),
    selectedRows = _useState8[0],
    setSelectedRows = _useState8[1];
  return useMemo(function () {
    return {
      data: mockData.slice((page.pageNumber - 1) * page.pageSize, page.pageNumber * page.pageSize),
      loading: false,
      total: mockData.length,
      pagination: page,
      onPageChange: function onPageChange(pageNumber, pageSize) {
        return setPage({
          pageNumber: pageNumber,
          pageSize: pageSize
        });
      },
      searchParams: searchParams,
      onSearch: function onSearch(params) {
        setSearchParams(params);
        setPage(function (p) {
          return _objectSpread(_objectSpread({}, p), {}, {
            pageNumber: 1
          });
        });
      },
      onReset: function onReset() {
        return setSearchParams({});
      },
      selectedKeys: selectedKeys,
      selectedRows: selectedRows,
      onSelectionChange: function onSelectionChange(keys, rows) {
        setSelectedKeys(keys);
        setSelectedRows(rows);
      },
      rowKey: 'id'
    };
  }, [page, searchParams, selectedKeys, selectedRows]);
}
export var CurrentPerspectiveFull = {
  render: function CurrentPerspectiveFullRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectives,
      currentPerspective: "full"
    })));
  }
};
export var CurrentPerspectiveBrief = {
  render: function CurrentPerspectiveBriefRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectives,
      currentPerspective: "brief"
    })));
  }
};
export var SinglePerspective = {
  render: function SinglePerspectiveRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: [perspectives[0]],
      currentPerspective: "full"
    })));
  }
};

/** 使用 columnRenderers 覆盖 type 为 currency 的列渲染 */
var columnRenderers = [{
  type: 'currency',
  render: function render(value) {
    return /*#__PURE__*/React.createElement("span", {
      style: {
        color: '#52c41a',
        fontWeight: 600
      }
    }, "\xA5 ", typeof value === 'number' ? value.toFixed(2) : value);
  }
}];
export var WithColumnRenderers = {
  render: function WithColumnRenderersRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectives,
      currentPerspective: "full",
      columnRenderers: columnRenderers
    })));
  }
};

/** 配置默认隐藏列：grid.defaultHiddenColumnKeys 指定列 key，这些列初始为隐藏，用户可在表头设置中重新勾选显示 */
var perspectivesWithHiddenColumns = [{
  key: 'full',
  label: '完整列表',
  childComponentProps: {
    grid: {
      columns: columnsFull,
      defaultHiddenColumnKeys: ['sku', 'updateTime']
    }
  }
}];
export var WithDefaultHiddenColumns = {
  render: function WithDefaultHiddenColumnsRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectivesWithHiddenColumns,
      currentPerspective: "full"
    })));
  },
  parameters: {
    docs: {
      description: {
        story: 'perspectives[].childComponentProps.grid.defaultHiddenColumnKeys 配置默认隐藏的列（如 sku、updateTime），初始加载时这些列不展示，用户可通过工具栏列设置重新勾选显示。'
      }
    }
  }
};

/**
 * 在 toolbar 里直接配置 sort：childComponentProps.toolBar.sort 传 { list }，
 * list 为排序项数组，每项 name（字段 key）、label（展示名）、type（'string'|'number'|'date'|'option'）。
 * 排序值写入 searchParams.sort，由业务 onSearch 接收后请求带排序参数。
 */
var perspectivesWithToolbarSort = [{
  key: 'full',
  label: '完整列表（工具栏配置排序）',
  childComponentProps: {
    grid: {
      columns: columnsFull
    },
    toolBar: {
      sort: {
        list: [{
          name: 'amount',
          label: '按金额',
          type: 'number',
          isCustom: false
        }, {
          name: 'name',
          label: '按名称',
          type: 'string',
          isCustom: false
        }, {
          name: 'updateTime',
          label: '按更新时间',
          type: 'date',
          isCustom: false
        }]
      }
    }
  }
}];
export var WithToolbarSort = {
  render: function WithToolbarSortRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectivesWithToolbarSort,
      currentPerspective: "full"
    })));
  },
  parameters: {
    docs: {
      description: {
        story: '通过 perspectives[].childComponentProps.toolBar.sort 直接配置排序：传 { list: [{ name, label, type }] }，工具栏展示排序按钮，选择后写入 searchParams.sort，由 onSearch 带回后端。'
      }
    }
  }
};

/**
 * 自定义排序选项：用 getSortItems(fieldKey) 返回 { key, label }[]，
 * 完全自定义每个字段下的排序子项（key 为最终写入 searchParams.sort 的值，label 为展示文案）。
 */
var perspectivesWithCustomSortOptions = [{
  key: 'full',
  label: '完整列表（自定义排序文案）',
  childComponentProps: {
    grid: {
      columns: columnsFull
    },
    toolBar: {
      sort: {
        list: [{
          name: 'amount',
          label: '按金额',
          isCustom: true,
          getSortItems: function getSortItems(fieldKey) {
            return [{
              key: "".concat(fieldKey, ":asc"),
              label: '从低到高'
            }, {
              key: "".concat(fieldKey, ":desc"),
              label: '从高到低'
            }];
          }
        }, {
          name: 'name',
          label: '按名称',
          isCustom: true,
          getSortItems: function getSortItems(fieldKey) {
            return [{
              key: "".concat(fieldKey, ":asc"),
              label: 'A → Z'
            }, {
              key: "".concat(fieldKey, ":desc"),
              label: 'Z → A'
            }];
          }
        }]
      }
    }
  }
}];
export var WithToolbarSortCustomOptions = {
  render: function WithToolbarSortCustomOptionsRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectivesWithCustomSortOptions,
      currentPerspective: "full"
    })));
  },
  parameters: {
    docs: {
      description: {
        story: '用 toolBar.sort.list[].getSortItems(fieldKey) 自定义排序选项：返回 { key, label }[]，key 写入 searchParams.sort，label 为下拉展示文案。可完全自定义文案（如「从低到高」「从高到低」）。'
      }
    }
  }
};

/**
 * 在 toolbar 里直接配置 filter：childComponentProps.toolBar.filter 传对象，
 * 用 defaultFilterValue 提供筛选项列表（quickFilter / otherFilter 为 FilterItemProps[]），
 * 筛选值写入 searchParams.filter，由 onSearch 接收。
 */
var perspectivesWithToolbarFilter = [{
  key: 'full',
  label: '完整列表（工具栏配置筛选）',
  childComponentProps: {
    grid: {
      columns: columnsFull
    },
    toolBar: {
      filter: {
        hiddenQuickFilter: true,
        defaultFilterValue: {
          quickFilter: [],
          otherFilter: [{
            type: 'single',
            key: 'status',
            name: 'status',
            label: '状态',
            props: {
              options: [{
                label: '全部',
                value: 'all'
              }, {
                label: '在售',
                value: '在售'
              }, {
                label: '下架',
                value: '下架'
              }, {
                label: '待上架',
                value: '待上架'
              }]
            },
            other: {}
          }, {
            type: 'input',
            key: 'keyword',
            name: 'keyword',
            label: '关键词',
            props: {
              placeholder: '名称 / SKU'
            },
            other: {}
          }],
          values: {}
        }
      }
    }
  }
}];
export var WithToolbarFilter = {
  render: function WithToolbarFilterRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectivesWithToolbarFilter,
      currentPerspective: "full"
    })));
  },
  parameters: {
    docs: {
      description: {
        story: '通过 perspectives[].childComponentProps.toolBar.filter 直接配置筛选：传 defaultFilterValue.{ quickFilter, otherFilter, values }，otherFilter 为 FilterItemProps[]（type: single/input/rangePicker/rangePickerNew 等，key/name/label/props）。选择后写入 searchParams.filter，由 onSearch 带回。'
      }
    }
  }
};

/**
 * 同一 perspective 的 toolBar 里同时配置 sort 与 filter：
 * toolBar.sort 传 { list }，toolBar.filter 传 { defaultFilterValue }。
 */
var perspectivesWithToolbarSortAndFilter = [{
  key: 'full',
  label: '完整列表（排序 + 筛选）',
  childComponentProps: {
    grid: {
      columns: columnsFull
    },
    toolBar: {
      sort: {
        list: [{
          name: 'amount',
          label: '按金额',
          type: 'number',
          isCustom: false
        }, {
          name: 'name',
          label: '按名称',
          type: 'string',
          isCustom: false
        }, {
          name: 'updateTime',
          label: '按更新时间',
          type: 'date',
          isCustom: false
        }]
      },
      filter: {
        hiddenQuickFilter: true,
        defaultFilterValue: {
          quickFilter: [],
          otherFilter: [{
            type: 'single',
            key: 'status',
            name: 'status',
            label: '状态',
            props: {
              options: [{
                label: '全部',
                value: 'all'
              }, {
                label: '在售',
                value: '在售'
              }, {
                label: '下架',
                value: '下架'
              }, {
                label: '待上架',
                value: '待上架'
              }]
            },
            other: {}
          }, {
            type: 'input',
            key: 'keyword',
            name: 'keyword',
            label: '关键词',
            props: {
              placeholder: '名称 / SKU'
            },
            other: {}
          }],
          values: {}
        }
      }
    }
  }
}];
export var WithToolbarSortAndFilter = {
  render: function WithToolbarSortAndFilterRender() {
    var dataSourceProps = useMockDataSourceProps();
    return /*#__PURE__*/React.createElement("div", {
      style: {
        height: 400
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectivesWithToolbarSortAndFilter,
      currentPerspective: "full"
    })));
  },
  parameters: {
    docs: {
      description: {
        story: '在 toolBar 里同时配置排序与筛选：toolBar.sort 传 { list }，toolBar.filter 传 { defaultFilterValue }。排序写入 searchParams.sort，筛选写入 searchParams.filter，均由 onSearch 带回。'
      }
    }
  }
};

/**
 * 餐桌列表模拟数据（用于表格 + 平面图双视图）
 */
var tableMockDataInitial = [{
  id: 't1',
  name: '1号桌',
  status: '空闲',
  capacity: 2,
  area: '大厅'
}, {
  id: 't2',
  name: '2号桌',
  status: '用餐中',
  capacity: 4,
  area: '大厅'
}, {
  id: 't3',
  name: '3号桌',
  status: '已预订',
  capacity: 6,
  area: '包厢A'
}, {
  id: 't4',
  name: '4号桌',
  status: '空闲',
  capacity: 2,
  area: '大厅'
}, {
  id: 't5',
  name: '5号桌',
  status: '用餐中',
  capacity: 4,
  area: '大厅'
}, {
  id: 'r1',
  name: '圆桌1',
  status: '空闲',
  capacity: 6,
  area: '大厅'
}, {
  id: 't6',
  name: '6号桌',
  status: '空闲',
  capacity: 8,
  area: '包厢B'
}, {
  id: 't7',
  name: '7号桌',
  status: '已预订',
  capacity: 2,
  area: '大厅'
}, {
  id: 't8',
  name: '8号桌',
  status: '空闲',
  capacity: 4,
  area: '露台'
}];

/** 餐桌数据源记录表单列（与表格列一致：桌号、状态、可坐人数、区域） */
var salesFormColumns = [{
  key: 'name',
  label: '桌号',
  type: 'string'
}, {
  key: 'status',
  label: '状态',
  type: 'select',
  options: [{
    label: '空闲',
    value: '空闲'
  }, {
    label: '用餐中',
    value: '用餐中'
  }, {
    label: '已预订',
    value: '已预订'
  }]
}, {
  key: 'capacity',
  label: '可坐人数',
  type: 'number'
}, {
  key: 'area',
  label: '区域',
  type: 'string'
}];

/** 餐桌列表表格列 */
var columnsTable = [{
  title: '桌号',
  dataIndex: 'name',
  key: 'name',
  width: 100
}, {
  title: '状态',
  dataIndex: 'status',
  key: 'status',
  width: 100
}, {
  title: '可坐人数',
  dataIndex: 'capacity',
  key: 'capacity',
  width: 100
}, {
  title: '区域',
  dataIndex: 'area',
  key: 'area',
  width: 120
}];

/** 平面图初始配置（placements 由 state 持有，避免保存数据记录时被覆盖导致 xy 重置） */
var initialFloorMapConfig = {
  canvases: [{
    id: 'main',
    name: '主画布',
    order: 0,
    enabled: true
  }],
  canvasUi: {
    canCreate: true,
    canEdit: true
  },
  elementKinds: [{
    value: 'table',
    label: '方桌',
    dataSourceKey: 'sales',
    showInPalette: true
  }, {
    value: 'roundTable',
    label: '圆桌',
    dataSourceKey: 'sales',
    defaultShape: 'circle',
    showInPalette: true
  }, {
    value: 'marker',
    label: '标记',
    showInPalette: true
  }, {
    value: 'icon',
    label: '图标',
    defaultShape: 'circle',
    showInPalette: true
  }],
  dataSourcePlacements: [{
    dataSourceKey: 'sales',
    id: 't1',
    floorMapId: 'main',
    x: 80,
    y: 80,
    name: '1号桌',
    width: 180,
    height: 120,
    elementKind: 'table'
  }, {
    dataSourceKey: 'sales',
    id: 't2',
    floorMapId: 'main',
    x: 200,
    y: 80,
    name: '2号桌',
    width: 180,
    height: 120,
    elementKind: 'table'
  }, {
    dataSourceKey: 'sales',
    id: 't3',
    floorMapId: 'main',
    x: 320,
    y: 80,
    name: '3号桌',
    width: 180,
    height: 120,
    elementKind: 'table'
  }, {
    dataSourceKey: 'sales',
    id: 't4',
    floorMapId: 'main',
    x: 80,
    y: 180,
    name: '4号桌',
    width: 180,
    height: 120,
    elementKind: 'table'
  }, {
    dataSourceKey: 'sales',
    id: 't5',
    floorMapId: 'main',
    x: 200,
    y: 180,
    name: '5号桌',
    width: 180,
    height: 120,
    elementKind: 'table'
  }, {
    dataSourceKey: 'sales',
    id: 'r1',
    floorMapId: 'main',
    x: 380,
    y: 160,
    name: '圆桌1',
    width: 100,
    height: 100,
    elementKind: 'roundTable'
  }],
  decorations: []
};

/**
 * 单一 Perspective：RecordBoard 工具栏「表格 | 平面图」切换；floorMap 挂在 childComponentProps。
 */
function buildTableFloorMapPerspective(tableData, options) {
  var _options$defaultBodyV;
  var dataSources = {
    sales: tableData
  };
  return [{
    key: 'tables',
    label: '餐桌',
    childComponentProps: {
      grid: {
        columns: columnsTable
      },
      defaultBodyView: (_options$defaultBodyV = options.defaultBodyView) !== null && _options$defaultBodyV !== void 0 ? _options$defaultBodyV : 'grid',
      floorMap: {
        floorMapConfig: options.floorMapConfig,
        dataSources: dataSources,
        mode: 'edit',
        onSave: options.onFloorMapConfigSave ? function (config) {
          return options.onFloorMapConfigSave(config);
        } : function (config) {
          // eslint-disable-next-line no-console
          console.log('========== [SalesGrid Story] 平面图 onSave ==========');
          // eslint-disable-next-line no-console
          console.log('floorMapViewConfig:', JSON.parse(JSON.stringify(config)));
          // eslint-disable-next-line no-console
          console.log('dataSources (当前 story 内):', JSON.parse(JSON.stringify(dataSources)));
        },
        onDataSourceRecordSave: options.onDataSourceRecordSave,
        dataSourceLabels: {
          sales: '餐桌'
        },
        dataSourceFormColumns: {
          sales: salesFormColumns
        },
        renderItemByKind: {
          table: getRenderItemByKindTable(dataSources),
          roundTable: getRenderItemByKindRoundTable(dataSources)
        }
      }
    }
  }];
}
function useTableDataSourceProps() {
  var tableData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : tableMockDataInitial;
  var _useState9 = useState({
      pageNumber: 1,
      pageSize: 10
    }),
    _useState10 = _slicedToArray(_useState9, 2),
    page = _useState10[0],
    setPage = _useState10[1];
  var _useState11 = useState({}),
    _useState12 = _slicedToArray(_useState11, 2),
    searchParams = _useState12[0],
    setSearchParams = _useState12[1];
  var _useState13 = useState([]),
    _useState14 = _slicedToArray(_useState13, 2),
    selectedKeys = _useState14[0],
    setSelectedKeys = _useState14[1];
  var _useState15 = useState([]),
    _useState16 = _slicedToArray(_useState15, 2),
    selectedRows = _useState16[0],
    setSelectedRows = _useState16[1];
  return useMemo(function () {
    return {
      data: tableData.slice((page.pageNumber - 1) * page.pageSize, page.pageNumber * page.pageSize),
      loading: false,
      total: tableData.length,
      pagination: page,
      onPageChange: function onPageChange(pageNumber, pageSize) {
        return setPage({
          pageNumber: pageNumber,
          pageSize: pageSize
        });
      },
      searchParams: searchParams,
      onSearch: function onSearch(params) {
        setSearchParams(params);
        setPage(function (p) {
          return _objectSpread(_objectSpread({}, p), {}, {
            pageNumber: 1
          });
        });
      },
      onReset: function onReset() {
        return setSearchParams({});
      },
      selectedKeys: selectedKeys,
      selectedRows: selectedRows,
      onSelectionChange: function onSelectionChange(keys, rows) {
        setSelectedKeys(keys);
        setSelectedRows(rows);
      },
      rowKey: 'id'
    };
  }, [page, searchParams, selectedKeys, selectedRows, tableData]);
}
export var FloorMapView = {
  render: function FloorMapViewRender() {
    var _useState17 = useState(function () {
        return [].concat(tableMockDataInitial);
      }),
      _useState18 = _slicedToArray(_useState17, 2),
      tableData = _useState18[0],
      setTableData = _useState18[1];
    var _useState19 = useState(function () {
        return _objectSpread(_objectSpread({}, initialFloorMapConfig), {}, {
          dataSourcePlacements: _toConsumableArray(initialFloorMapConfig.dataSourcePlacements),
          decorations: []
        });
      }),
      _useState20 = _slicedToArray(_useState19, 2),
      floorMapConfig = _useState20[0],
      setFloorMapConfig = _useState20[1];
    var dataSourceProps = useTableDataSourceProps(tableData);
    var perspectives = useMemo(function () {
      return buildTableFloorMapPerspective(tableData, {
        floorMapConfig: floorMapConfig,
        defaultBodyView: 'grid',
        onFloorMapConfigSave: function onFloorMapConfigSave(config) {
          // eslint-disable-next-line no-console
          console.log('========== [SalesGrid Story] 平面图 onSave（含当前数据源）==========');
          // eslint-disable-next-line no-console
          console.log('floorMapViewConfig:', JSON.parse(JSON.stringify(config)));
          // eslint-disable-next-line no-console
          console.log('dataSources:', {
            sales: JSON.parse(JSON.stringify(tableData))
          });
          // eslint-disable-next-line no-console
          console.log('完整快照 snapshot:', {
            floorMapViewConfig: JSON.parse(JSON.stringify(config)),
            dataSources: {
              sales: JSON.parse(JSON.stringify(tableData))
            }
          });
          setFloorMapConfig(config);
        },
        onDataSourceRecordSave: function onDataSourceRecordSave(dataSourceKey, id, newData) {
          // eslint-disable-next-line no-console
          console.log('========== [SalesGrid Story] onDataSourceRecordSave ==========');
          // eslint-disable-next-line no-console
          console.log({
            dataSourceKey: dataSourceKey,
            id: id,
            newData: JSON.parse(JSON.stringify(newData))
          });
          setTableData(function (prev) {
            var next = prev.map(function (r) {
              return r.id === id ? _objectSpread(_objectSpread({}, r), newData) : r;
            });
            // eslint-disable-next-line no-console
            console.log('合并后 dataSources.sales 全量:', JSON.parse(JSON.stringify(next)));
            // eslint-disable-next-line no-console
            console.log('当前 floorMapViewConfig（保存记录瞬间）:', JSON.parse(JSON.stringify(floorMapConfig)));
            return next;
          });
        }
      });
    }, [tableData, floorMapConfig]);
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        height: 480
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minHeight: 0
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectives,
      currentPerspective: "tables"
    }))));
  },
  parameters: {
    docs: {
      description: {
        story: '同一份餐桌数据：在 RecordBoard **工具栏**用「表格 | 平面图」切换。表格展示列表列；平面图编辑态可选中桌台编辑落位与数据源记录（桌号、状态、可坐人数、区域）。'
      }
    }
  }
};

/**
 * 平面图添加数据图源与添加方式：左侧栏展示「添加数据图元」（数据源落位）和「添加装饰」，
 * 选择后到画布点击即可放置。默认进入平面图便于查看侧栏。
 */
export var FloorMapAddSourceAndDecoration = {
  render: function FloorMapAddSourceAndDecorationRender() {
    var dataSourceProps = useTableDataSourceProps();
    var perspectives = useMemo(function () {
      return buildTableFloorMapPerspective(tableMockDataInitial, {
        floorMapConfig: initialFloorMapConfig,
        defaultBodyView: 'floorMap',
        onDataSourceRecordSave: undefined
      });
    }, []);
    return /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        flexDirection: 'column',
        height: 520
      }
    }, /*#__PURE__*/React.createElement("div", {
      style: {
        flex: 1,
        minHeight: 0
      }
    }, /*#__PURE__*/React.createElement(PisellSalesGrid, _extends({}, dataSourceProps, {
      perspectives: perspectives,
      currentPerspective: "tables"
    }))));
  },
  parameters: {
    docs: {
      description: {
        story: '默认首屏为平面图（defaultBodyView）。工具栏可切回表格。左侧栏：① 添加数据图元；② 添加装饰。选中后可「取消新建」。'
      }
    }
  }
};