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/pisellGoodPassCard/index.tsx
var pisellGoodPassCard_exports = {};
__export(pisellGoodPassCard_exports, {
  default: () => pisellGoodPassCard_default
});
module.exports = __toCommonJS(pisellGoodPassCard_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import__ = require("../../index");
var import_locales = require("../../locales");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_index = require("./index.less");
var clsPrefix = "pisell-good-pass-card";
var index = (props) => {
  var _a;
  const context = (0, import_useEngineContext.default)();
  const { translation } = (_a = context.appHelper) == null ? void 0 : _a.utils;
  const { dataSource = [], onChange, style = {}, mixedSort } = props;
  const [showModal, setShowModal] = (0, import_react.useState)(false);
  console.log("pisell good card datasource", dataSource);
  const handleChange = (newValue) => {
    if (onChange) {
      onChange(newValue);
    }
  };
  const handleItemChange = (item, checked) => {
    handleChange({
      id: item.id,
      isSelected: checked
    });
  };
  const renderVoucherContent = (item) => {
    return /* @__PURE__ */ import_react.default.createElement("span", { className: `voucher-item-content-save` }, (0, import_locales.getText)("pisell2.text.goodpass.save"), " ", /* @__PURE__ */ import_react.default.createElement(import__.PisellText.Amount, { value: item.savedAmount }));
  };
  const renderActionElement = (item) => {
    const isChecked = item.isSelected;
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Checkbox,
      {
        disabled: item.isDisabled,
        style: { marginLeft: 8 },
        checked: isChecked,
        onChange: (e) => handleItemChange(item, e.target.checked)
      },
      renderVoucherContent(item)
    );
  };
  const renderVoucherItem = (item) => {
    return /* @__PURE__ */ import_react.default.createElement("div", { key: item.id, className: `${clsPrefix}-voucher-item` }, /* @__PURE__ */ import_react.default.createElement("div", { className: "item-title" }, translation(item.format_title), item.isEditMode && (0, import_locales.getText)("pisell2.text.goodpass.last-settlement")), /* @__PURE__ */ import_react.default.createElement("div", { className: "item-content" }, renderActionElement(item)));
  };
  const renderModal = () => {
    return /* @__PURE__ */ import_react.default.createElement(
      import__.PisellModal,
      {
        title: (0, import_locales.getText)("pisell2.text.goodpass.product-vouchers"),
        footer: null,
        open: showModal,
        onCancel: () => setShowModal(false),
        className: `${clsPrefix}-all-items-modal`
      },
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          style: {
            padding: "10px 0",
            display: "flex",
            flexDirection: "column",
            gap: 12
          }
        },
        dataSource.map(renderVoucherItem)
      )
    );
  };
  const renderMixedMode = () => {
    const sortList = (mixedSort == null ? void 0 : mixedSort(dataSource)) || dataSource;
    const list = sortList.length > 3 ? sortList.slice(0, 3) : sortList;
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: `${clsPrefix}-header` }, /* @__PURE__ */ import_react.default.createElement("div", null, (0, import_locales.getText)("pisell2.text.goodpass.product-vouchers")), /* @__PURE__ */ import_react.default.createElement(import_antd.Typography.Text, { underline: true, onClick: () => setShowModal(true) }, (0, import_locales.getText)("pisell2.text.goodpass.view-more"))), /* @__PURE__ */ import_react.default.createElement(import_antd.Divider, { style: { margin: 4 } }), /* @__PURE__ */ import_react.default.createElement("div", { className: `${clsPrefix}-body` }, list.map(renderVoucherItem)));
  };
  const renderModalMode = () => {
    const sortList = (mixedSort == null ? void 0 : mixedSort(dataSource)) || dataSource;
    if (sortList.length === 0) return null;
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          padding: "10px 0",
          display: "flex",
          flexDirection: "column",
          gap: 12
        }
      },
      sortList.map(renderVoucherItem)
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, !props.isInModal ? renderModal() : null, dataSource.length > 0 ? /* @__PURE__ */ import_react.default.createElement(
    import__.PisellCard,
    {
      padding: 8,
      borderRadius: 8,
      style: {
        width: 378,
        ...style
      },
      className: clsPrefix
    },
    props.isInModal ? renderModalMode() : renderMixedMode()
  ) : null);
};
var pisellGoodPassCard_default = index;
