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 from 'react';
import { Button, Space, Tag } from 'antd';
import PisellGroupView from "./PisellGroupView";

/**
 * PisellGroupView 分组展示组件
 *
 * 通用、数据无关的「分组展示容器」：先按条件把列表分组，
 * 再为每个分组渲染 头部 / 统计 / 主体 / 操作 四块，各块均可自定义渲染。
 */
var meta = {
  title: 'Layout 布局组件/PisellGroupView',
  component: PisellGroupView,
  parameters: {
    layout: 'padded',
    docs: {
      description: {
        component: '通用、数据无关的分组展示容器。先按 groupBy 分组，再为每组渲染头部/统计/主体/操作四块，全部通过 render 函数自定义。'
      }
    }
  },
  tags: ['autodocs']
};
export default meta;
var bookings = [{
  id: 1,
  productName: '羽毛球场 A',
  time: '10:00',
  customer: 'Tom',
  amount: 100
}, {
  id: 2,
  productName: '羽毛球场 A',
  time: '10:00',
  customer: 'Tom',
  amount: 50
}, {
  id: 3,
  productName: '羽毛球场 A',
  time: '11:00',
  customer: 'Amy',
  amount: 80
}, {
  id: 4,
  productName: '网球场 B',
  time: '11:00',
  customer: 'Jerry',
  amount: 120
}, {
  id: 5,
  productName: '网球场 B',
  time: '11:00',
  customer: 'Jerry',
  amount: 60
}];
var groupCardStyle = {
  border: '1px solid #eee',
  borderRadius: 8,
  padding: 16,
  marginBottom: 16
};

/**
 * 基础用法：按「商品 + 时间」组合分组，展示四块结构
 */
export var Basic = {
  render: function render() {
    return /*#__PURE__*/React.createElement(PisellGroupView, {
      dataSource: bookings,
      groupBy: ['productName', 'time'],
      rowKey: "id",
      renderGroup: function renderGroup(g, blocks) {
        return /*#__PURE__*/React.createElement("div", {
          style: groupCardStyle,
          "data-id": g.groupId
        }, blocks.header, blocks.stats, blocks.body, blocks.actions);
      },
      renderHeader: function renderHeader(g) {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            fontWeight: 600,
            fontSize: 15
          }
        }, String(g.keyMap.productName), /*#__PURE__*/React.createElement(Tag, {
          style: {
            marginLeft: 8
          }
        }, String(g.keyMap.time)));
      },
      renderStats: function renderStats(g) {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            color: '#888',
            margin: '6px 0'
          }
        }, "\u5171 ", g.items.length, " \u9879 \xB7 \u5408\u8BA1 \uFFE5", g.items.reduce(function (s, i) {
          return s + i.amount;
        }, 0));
      },
      renderItem: function renderItem(item) {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            display: 'flex',
            justifyContent: 'space-between',
            padding: '6px 0',
            borderTop: '1px solid #f0f0f0'
          }
        }, /*#__PURE__*/React.createElement("span", null, "#", item.id, " ", item.customer), /*#__PURE__*/React.createElement("span", null, "\uFFE5", item.amount));
      },
      renderActions: function renderActions() {
        return /*#__PURE__*/React.createElement(Space, {
          style: {
            marginTop: 10
          }
        }, /*#__PURE__*/React.createElement(Button, {
          size: "small"
        }, "\u6279\u91CF\u52A0\u65F6"), /*#__PURE__*/React.createElement(Button, {
          size: "small",
          type: "primary"
        }, "\u6279\u91CF\u7F16\u8F91"));
      }
    });
  }
};

/**
 * 单字段分组 + 主体多列布局（itemLayout 对象，内部使用 PisellBasicGrid）
 */
export var GridBody = {
  render: function render() {
    return /*#__PURE__*/React.createElement(PisellGroupView, {
      dataSource: bookings,
      groupBy: "productName",
      rowKey: "id",
      itemLayout: {
        columns: 2,
        gap: 8
      },
      renderGroup: function renderGroup(g, blocks) {
        return /*#__PURE__*/React.createElement("div", {
          style: groupCardStyle
        }, blocks.header, blocks.body);
      },
      renderHeader: function renderHeader(g) {
        return /*#__PURE__*/React.createElement("h4", {
          style: {
            margin: '0 0 8px'
          }
        }, String(g.keyMap.productName));
      },
      renderItem: function renderItem(item) {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            padding: 12,
            border: '1px solid #eee',
            borderRadius: 6,
            background: '#fafafa'
          }
        }, item.time, " \xB7 ", item.customer, " \xB7 \uFFE5", item.amount);
      }
    });
  }
};

/**
 * 利用 ItemContext.groupKeys 在主体卡片中省略「头部已展示」的字段
 */
export var OmitHeaderFields = {
  render: function render() {
    return /*#__PURE__*/React.createElement(PisellGroupView, {
      dataSource: bookings,
      groupBy: ['productName', 'time'],
      rowKey: "id",
      renderGroup: function renderGroup(g, blocks) {
        return /*#__PURE__*/React.createElement("div", {
          style: groupCardStyle
        }, blocks.header, blocks.body);
      },
      renderHeader: function renderHeader(g) {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            fontWeight: 600
          }
        }, String(g.keyMap.productName), " \xB7 ", String(g.keyMap.time));
      },
      renderItem: function renderItem(item, ctx) {
        // 头部已展示 productName / time，这里据 ctx.groupKeys 仅展示其余字段
        var omitted = new Set(ctx.groupKeys);
        var entries = Object.entries(item).filter(function (_ref) {
          var _ref2 = _slicedToArray(_ref, 1),
            key = _ref2[0];
          return key !== 'id' && !omitted.has(key);
        });
        return /*#__PURE__*/React.createElement("div", {
          style: {
            padding: '6px 0',
            borderTop: '1px solid #f0f0f0'
          }
        }, "#", item.id, ' ', entries.map(function (_ref3) {
          var _ref4 = _slicedToArray(_ref3, 2),
            k = _ref4[0],
            v = _ref4[1];
          return "".concat(k, ": ").concat(String(v));
        }).join(' · '));
      }
    });
  }
};

/**
 * 空数据态
 */
export var Empty = {
  render: function render() {
    return /*#__PURE__*/React.createElement(PisellGroupView, {
      dataSource: [],
      groupBy: "productName",
      renderEmpty: function renderEmpty() {
        return /*#__PURE__*/React.createElement("div", {
          style: {
            color: '#bbb',
            padding: 24,
            textAlign: 'center'
          }
        }, "\u6682\u65E0\u6570\u636E");
      }
    });
  }
};