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/pisellFloorMapLayout/components/FigmaTableCard.tsx
var FigmaTableCard_exports = {};
__export(FigmaTableCard_exports, {
  getFigmaTableCardFromMerged: () => getFigmaTableCardFromMerged,
  getRenderItemByKindRoundTable: () => getRenderItemByKindRoundTable,
  getRenderItemByKindTable: () => getRenderItemByKindTable,
  renderFigmaStyleRoundTableCard: () => renderFigmaStyleRoundTableCard,
  renderFigmaStyleTableCard: () => renderFigmaStyleTableCard
});
module.exports = __toCommonJS(FigmaTableCard_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_utils = require("@pisell/utils");
var import_floorMapElementNameAsTitle = require("../utils/floorMapElementNameAsTitle");
var I18N_CARD = "pisell-floor-map-layout.card-placeholder";
var I18N_FIGMA = "pisell-floor-map-layout.figma-card";
var FIGMA = {
  white: "#FFFFFF",
  gray100: "#F2F4F7",
  gray200: "#EAECF0",
  gray400: "#98A2B3",
  gray700: "#344054",
  gray900: "#101828",
  shadowSm: "0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1)",
  fontFamily: 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
  barFillAvailable: "#EAECF0",
  reserved: "#9254de",
  waiting: "#fa8c16",
  dining: "#1890ff",
  billed: "#52c41a",
  availableSoon: "#f5222d"
};
var STATUS_BORDER = {
  available: FIGMA.gray200,
  reserved: FIGMA.reserved,
  waiting: FIGMA.waiting,
  dining: FIGMA.dining,
  billed: FIGMA.billed,
  availableSoon: FIGMA.availableSoon
};
var STATUS_TAG_BG = {
  available: "#F2F4F7",
  reserved: "#F4ECFB",
  waiting: "#FEF0E0",
  dining: "#E6F4FF",
  billed: "#E8F8EA",
  availableSoon: "#FEE4E2"
};
var STATUS_TAG_FG = {
  available: "#475467",
  reserved: "#7B3CCB",
  waiting: "#C4690D",
  dining: "#0E6FD0",
  billed: "#347D3A",
  availableSoon: "#B42318"
};
var STATUS_MAP = {
  available: "available",
  reserved: "reserved",
  waiting: "waiting",
  dining: "dining",
  billed: "billed",
  availableSoon: "availableSoon",
  空闲: "available",
  已预订: "reserved",
  等待: "waiting",
  用餐中: "dining",
  已结账: "billed",
  即将可用: "availableSoon"
};
function getFigmaTableCardFromMerged(item, dataSources) {
  const el = item._sceneElement;
  const binding = el == null ? void 0 : el.dataBinding;
  const titleFromElement = (el == null ? void 0 : el.name) != null && String(el.name).trim() ? String(el.name).trim() : "";
  const kindLabel = import_utils.locales.getText(
    item.elementKind === "roundTable" ? `${I18N_FIGMA}.kind-round-table` : `${I18N_FIGMA}.kind-square-table`
  );
  const hasDataSource = Boolean(
    (binding == null ? void 0 : binding.dataSourceKey) && String(binding.dataSourceKey).trim() !== ""
  );
  const rid = (binding == null ? void 0 : binding.recordId) != null ? String(binding.recordId).trim() : "";
  const boundToData = Boolean(hasDataSource && rid !== "");
  const list = (binding == null ? void 0 : binding.dataSourceKey) ? dataSources[binding.dataSourceKey] : void 0;
  const record = boundToData && list ? list.find((r) => r.id === rid) : void 0;
  const hasLiveRow = Boolean(record);
  if (!hasLiveRow) {
    const borderColor = "#bfbfbf";
    const hint = !hasDataSource || !rid ? hasDataSource ? import_utils.locales.getText(`${I18N_CARD}.hint-select-row`) : import_utils.locales.getText(`${I18N_CARD}.hint-bind-datasource`) : rid.startsWith("new_") ? import_utils.locales.getText(`${I18N_CARD}.hint-new-slot`).replace(/\{kind\}/g, kindLabel) : import_utils.locales.getText(`${I18N_CARD}.hint-row-not-found`);
    return {
      id: item.id,
      isNoDataPlaceholder: true,
      placeholderBorderColor: borderColor,
      placeholderHint: hint,
      placeholderTitle: titleFromElement || kindLabel
    };
  }
  const displayId = (binding == null ? void 0 : binding.recordId) ?? item.id;
  const rawStatus = record == null ? void 0 : record.status;
  const status = rawStatus && STATUS_MAP[rawStatus] || "available";
  const recordName = (record == null ? void 0 : record.name) != null ? String(record.name) : void 0;
  const resolvedTitle = (0, import_floorMapElementNameAsTitle.resolveSceneElementDisplayTitle)({
    sceneElement: el,
    recordTitle: recordName,
    fallback: kindLabel
  });
  return {
    id: displayId,
    displayName: resolvedTitle || void 0,
    status,
    customerName: record == null ? void 0 : record.customerName,
    reserveTime: record == null ? void 0 : record.reserveTime,
    guests: record == null ? void 0 : record.guests,
    capacity: record == null ? void 0 : record.capacity,
    dishes: record == null ? void 0 : record.dishes,
    duration: record == null ? void 0 : record.duration,
    area: record == null ? void 0 : record.area
  };
}
function getBarCountFromItemId(id) {
  const upper = id.toUpperCase();
  if (upper.startsWith("XL-") || id.endsWith("-XL")) return 4;
  if (upper.startsWith("L-") || upper.startsWith("X-") || id.endsWith("-L") || id.endsWith("-X"))
    return 3;
  if (upper.startsWith("M-") || id.endsWith("-M")) return 2;
  return 1;
}
var CARD_BAR_WIDTH = 80;
var CARD_BAR_HEIGHT = 12;
function CardBars({
  count,
  position,
  barColor
}) {
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        display: "flex",
        flexDirection: "row",
        gap: 30,
        justifyContent: "center",
        flexShrink: 0,
        padding: position === "top" ? "0 0 4px 0" : "4px 0 0 0"
      }
    },
    Array.from({ length: count }, (_, i) => /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: i,
        style: {
          width: CARD_BAR_WIDTH,
          height: CARD_BAR_HEIGHT,
          borderRadius: 6,
          background: barColor
        }
      }
    ))
  );
}
function FigmaCardRow({
  icon,
  children
}) {
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        display: "flex",
        alignItems: "center",
        gap: 4,
        fontFamily: FIGMA.fontFamily,
        fontSize: 14,
        lineHeight: "20px",
        fontWeight: 400,
        color: FIGMA.gray700,
        flexShrink: 0,
        minHeight: "20px"
      }
    },
    /* @__PURE__ */ import_react.default.createElement("span", { style: { flexShrink: 0, color: FIGMA.gray400, fontSize: 14 } }, icon),
    /* @__PURE__ */ import_react.default.createElement("span", { style: { flexShrink: 0 } }, children)
  );
}
function ResourceHeaderBar({
  cardItem,
  variant
}) {
  const hasCapacity = cardItem.capacity != null;
  const hasArea = cardItem.area != null && cardItem.area !== "";
  const titleText = cardItem.displayName ?? cardItem.id;
  const hasTitle = titleText != null && String(titleText).trim() !== "";
  const status = cardItem.status ?? "available";
  const statusLabel = import_utils.locales.getText(`${I18N_FIGMA}.status-${status}`);
  if (!hasTitle && !hasCapacity && !hasArea) return null;
  const metaEntries = [];
  if (hasCapacity) {
    metaEntries.push({
      key: "capacity",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.TeamOutlined, { style: { marginRight: 3 } }),
      text: import_utils.locales.getText(`${I18N_FIGMA}.capacity-seats`).replace(/\{n\}/g, String(cardItem.capacity))
    });
  }
  if (hasArea) {
    metaEntries.push({
      key: "area",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.EnvironmentOutlined, { style: { marginRight: 3 } }),
      text: String(cardItem.area)
    });
  }
  const isRound = variant === "round";
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        display: "flex",
        flexDirection: "column",
        gap: 2,
        padding: isRound ? "4px 8px 6px" : "6px 8px",
        borderBottom: isRound ? "none" : `1px dashed ${FIGMA.gray200}`,
        flexShrink: 0,
        fontFamily: FIGMA.fontFamily
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          display: "flex",
          alignItems: "center",
          gap: 8,
          minHeight: 18
        }
      },
      hasTitle ? /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          style: {
            fontWeight: 600,
            fontSize: 14,
            lineHeight: "18px",
            color: FIGMA.gray900,
            whiteSpace: "nowrap",
            overflow: "hidden",
            textOverflow: "ellipsis",
            flex: "1 1 auto",
            minWidth: 0,
            textAlign: isRound ? "center" : "left"
          },
          title: String(titleText)
        },
        titleText
      ) : /* @__PURE__ */ import_react.default.createElement("span", { style: { flex: "1 1 auto" } }),
      /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          style: {
            display: "inline-flex",
            alignItems: "center",
            justifyContent: "center",
            padding: "1px 6px",
            borderRadius: 999,
            fontSize: 10,
            lineHeight: "14px",
            fontWeight: 600,
            background: STATUS_TAG_BG[status],
            color: STATUS_TAG_FG[status],
            flexShrink: 0,
            whiteSpace: "nowrap",
            letterSpacing: 0.2
          }
        },
        statusLabel
      )
    ),
    metaEntries.length > 0 ? /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        style: {
          fontSize: 11,
          lineHeight: "16px",
          color: FIGMA.gray400,
          whiteSpace: "nowrap",
          overflow: "hidden",
          textOverflow: "ellipsis",
          display: "block",
          textAlign: isRound ? "center" : "left"
        }
      },
      metaEntries.map((entry, index) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, { key: entry.key }, index === 0 ? null : /* @__PURE__ */ import_react.default.createElement("span", { style: { margin: "0 4px" } }, "·"), entry.icon, entry.text))
    ) : null
  );
}
function TableCardContent({ cardItem }) {
  const status = cardItem.status ?? "available";
  const borderColor = STATUS_BORDER[status];
  const isAvailable = status === "available";
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        flex: 1,
        minHeight: 0,
        /** 方桌内容区内边距：原 8 减半为 4，留出更多内容显示空间 */
        padding: 4,
        boxSizing: "border-box",
        background: FIGMA.white,
        border: isAvailable ? `4px solid ${FIGMA.gray200}` : `4px solid ${borderColor}`,
        borderTopLeftRadius: 0,
        borderTopRightRadius: 0,
        borderBottomLeftRadius: 8,
        borderBottomRightRadius: 8,
        display: "flex",
        flexDirection: "column",
        justifyContent: "center",
        alignItems: isAvailable ? "stretch" : "center",
        gap: 4
      }
    },
    isAvailable ? null : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, status === "reserved" && (cardItem.customerName != null && cardItem.customerName !== "" || cardItem.reserveTime != null && cardItem.reserveTime !== "") && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, cardItem.customerName != null && cardItem.customerName !== "" && /* @__PURE__ */ import_react.default.createElement(
      FigmaCardRow,
      {
        icon: /* @__PURE__ */ import_react.default.createElement(
          import_antd.Avatar,
          {
            size: 16,
            icon: /* @__PURE__ */ import_react.default.createElement(import_icons.UserOutlined, null),
            style: { backgroundColor: FIGMA.gray200 }
          }
        )
      },
      /* @__PURE__ */ import_react.default.createElement("span", null, cardItem.customerName)
    ), cardItem.reserveTime != null && cardItem.reserveTime !== "" && /* @__PURE__ */ import_react.default.createElement(FigmaCardRow, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.ClockCircleOutlined, null) }, /* @__PURE__ */ import_react.default.createElement("span", null, cardItem.reserveTime))), (status === "dining" || status === "waiting" || status === "billed" || status === "availableSoon") && cardItem.guests != null && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(FigmaCardRow, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.TeamOutlined, null) }, /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText(`${I18N_FIGMA}.guests-count`).replace(/\{n\}/g, String(cardItem.guests)))), cardItem.dishes && /* @__PURE__ */ import_react.default.createElement(FigmaCardRow, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.AuditOutlined, null) }, /* @__PURE__ */ import_react.default.createElement("span", null, cardItem.dishes)), cardItem.duration && /* @__PURE__ */ import_react.default.createElement(FigmaCardRow, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.FieldTimeOutlined, null) }, /* @__PURE__ */ import_react.default.createElement("span", null, cardItem.duration))))
  );
}
function renderTableKindNoDataPlaceholder(cardItem, shape) {
  const borderColor = cardItem.placeholderBorderColor ?? "#bfbfbf";
  const title = cardItem.placeholderTitle ?? import_utils.locales.getText(`${I18N_FIGMA}.default-table`);
  const hint = cardItem.placeholderHint ?? "";
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        width: "100%",
        height: "100%",
        boxSizing: "border-box",
        padding: "8px 10px",
        display: "flex",
        flexDirection: "column",
        justifyContent: "center",
        minHeight: 0,
        fontSize: 11,
        lineHeight: 1.35,
        background: "#fafafa",
        borderRadius: shape === "circle" ? "50%" : 8,
        border: `2px dashed ${borderColor}`,
        boxShadow: "none",
        overflow: "hidden"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          fontWeight: 600,
          color: "#595959",
          overflow: "hidden",
          textOverflow: "ellipsis",
          whiteSpace: "nowrap",
          textAlign: shape === "circle" ? "center" : void 0
        }
      },
      title
    ),
    hint ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          color: "#8c8c8c",
          marginTop: 6,
          flexShrink: 0,
          fontSize: 10,
          textAlign: shape === "circle" ? "center" : void 0
        }
      },
      hint
    ) : null
  );
}
function ResourceHeaderShell({
  cardItem,
  variant
}) {
  const status = cardItem.status ?? "available";
  const borderColor = status === "available" ? FIGMA.gray200 : STATUS_BORDER[status];
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        background: FIGMA.white,
        border: `4px solid ${borderColor}`,
        /** 去掉底部边，与下方 TableCardContent 拼合成一张卡片，再由内部 dashed line 分隔上下两段 */
        borderBottom: "none",
        borderTopLeftRadius: 8,
        borderTopRightRadius: 8,
        flexShrink: 0,
        boxSizing: "border-box"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(ResourceHeaderBar, { cardItem, variant })
  );
}
function renderFigmaStyleTableCard(cardItem) {
  if (cardItem.isNoDataPlaceholder) {
    return renderTableKindNoDataPlaceholder(cardItem, "rect");
  }
  const status = cardItem.status ?? "available";
  const borderColor = STATUS_BORDER[status];
  const isAvailable = status === "available";
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        width: "100%",
        height: "100%",
        boxSizing: "border-box",
        display: "flex",
        flexDirection: "column",
        justifyContent: "flex-start",
        gap: 0,
        fontFamily: FIGMA.fontFamily,
        overflow: "hidden"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      CardBars,
      {
        count: getBarCountFromItemId(cardItem.id),
        position: "top",
        barColor: isAvailable ? FIGMA.barFillAvailable : borderColor
      }
    ),
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          flex: 1,
          minHeight: 0,
          display: "flex",
          flexDirection: "column",
          borderRadius: 8,
          boxShadow: FIGMA.shadowSm,
          overflow: "hidden"
        }
      },
      /* @__PURE__ */ import_react.default.createElement(ResourceHeaderShell, { cardItem, variant: "rect" }),
      /* @__PURE__ */ import_react.default.createElement(TableCardContent, { cardItem })
    ),
    /* @__PURE__ */ import_react.default.createElement(
      CardBars,
      {
        count: getBarCountFromItemId(cardItem.id),
        position: "bottom",
        barColor: isAvailable ? FIGMA.barFillAvailable : borderColor
      }
    )
  );
}
function RoundResourceHeaderChip({
  cardItem
}) {
  const status = cardItem.status ?? "available";
  const borderColor = status === "available" ? FIGMA.gray200 : STATUS_BORDER[status];
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        flexShrink: 0,
        background: FIGMA.white,
        border: `2px solid ${borderColor}`,
        borderRadius: 999,
        boxShadow: FIGMA.shadowSm,
        margin: "0 auto 4px",
        boxSizing: "border-box",
        maxWidth: "100%"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(ResourceHeaderBar, { cardItem, variant: "round" })
  );
}
function renderFigmaStyleRoundTableCard(cardItem) {
  if (cardItem.isNoDataPlaceholder) {
    return renderTableKindNoDataPlaceholder(cardItem, "circle");
  }
  const status = cardItem.status ?? "available";
  const borderColor = STATUS_BORDER[status];
  const isAvailable = status === "available";
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        width: "100%",
        height: "100%",
        boxSizing: "border-box",
        display: "flex",
        flexDirection: "column",
        alignItems: "stretch",
        gap: 0,
        fontFamily: FIGMA.fontFamily,
        overflow: "hidden"
      }
    },
    /* @__PURE__ */ import_react.default.createElement(RoundResourceHeaderChip, { cardItem }),
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          flex: 1,
          minHeight: 0,
          display: "flex",
          flexDirection: "column",
          justifyContent: "center",
          alignItems: "center",
          overflow: "hidden",
          borderRadius: "50%",
          border: isAvailable ? `4px solid ${FIGMA.gray200}` : `4px solid ${borderColor}`,
          background: FIGMA.white,
          boxShadow: FIGMA.shadowSm,
          padding: 8
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          style: {
            flex: 1,
            minHeight: 0,
            display: "flex",
            flexDirection: "column",
            justifyContent: "center",
            alignItems: "center",
            width: "100%",
            overflow: "hidden",
            gap: 2
          }
        },
        isAvailable ? null : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, status === "reserved" && cardItem.customerName && /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 12, color: FIGMA.gray700 } }, cardItem.customerName), status === "reserved" && cardItem.reserveTime && /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 12, color: FIGMA.gray700 } }, cardItem.reserveTime), (status === "dining" || status === "waiting" || status === "billed" || status === "availableSoon") && cardItem.guests != null && /* @__PURE__ */ import_react.default.createElement("div", { style: { fontSize: 12, color: FIGMA.gray700 } }, import_utils.locales.getText(`${I18N_FIGMA}.guests-count`).replace(/\{n\}/g, String(cardItem.guests))))
      )
    )
  );
}
function getRenderItemByKindTable(dataSources) {
  return (item) => {
    const cardItem = getFigmaTableCardFromMerged(
      item,
      dataSources
    );
    return renderFigmaStyleTableCard(cardItem);
  };
}
function getRenderItemByKindRoundTable(dataSources) {
  return (item) => {
    const cardItem = getFigmaTableCardFromMerged(
      item,
      dataSources
    );
    return renderFigmaStyleRoundTableCard(cardItem);
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getFigmaTableCardFromMerged,
  getRenderItemByKindRoundTable,
  getRenderItemByKindTable,
  renderFigmaStyleRoundTableCard,
  renderFigmaStyleTableCard
});
