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/plus/walletEditor/components/sortableWalletPassTypes/index.tsx
var sortableWalletPassTypes_exports = {};
__export(sortableWalletPassTypes_exports, {
  DEFAULT_WALLET_PASS_TYPES_CONFIG: () => DEFAULT_WALLET_PASS_TYPES_CONFIG,
  default: () => sortableWalletPassTypes_default
});
module.exports = __toCommonJS(sortableWalletPassTypes_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_classnames = __toESM(require("classnames"));
var import_materials = require("@pisell/materials");
var import_index = require("./index.less");
var { Editable } = import_materials.PisellText;
var WALLET_PASS_TYPES = [
  "rechargeable",
  "point",
  "voucher",
  "discount"
];
var DEFAULT_WALLET_PASS_TYPES_CONFIG = [
  {
    type: "rechargeable",
    custom_title: {
      original: "Balance",
      en: "Balance",
      "zh-CN": "余额",
      "zh-HK": "餘額",
      "ja": "残高",
      "pt": "Saldo"
    }
  },
  {
    type: "point",
    custom_title: {
      original: "Points",
      en: "Points",
      "zh-CN": "积分",
      "zh-HK": "積分",
      "ja": "ポイント",
      "pt": "Pontos"
    }
  },
  {
    type: "voucher",
    custom_title: {
      original: "Voucher",
      en: "Voucher",
      "zh-CN": "代金券",
      "zh-HK": "代金券",
      "ja": "クーポン",
      "pt": "Cupom"
    }
  },
  {
    type: "discount",
    custom_title: {
      original: "Discount",
      en: "Discount",
      "zh-CN": "折扣券",
      "zh-HK": "折扣券",
      "ja": "割引カード",
      "pt": "Cartão de desconto"
    }
  }
];
var SortableWalletPassTypes = (props) => {
  const { value = [], onChange, disabled = false, className, style } = props;
  const dataSource = (0, import_react.useMemo)(() => {
    const result = [];
    const processedTypes = /* @__PURE__ */ new Set();
    value.forEach((item) => {
      if (WALLET_PASS_TYPES.includes(item.type) && !processedTypes.has(item.type)) {
        result.push(item);
        processedTypes.add(item.type);
      }
    });
    DEFAULT_WALLET_PASS_TYPES_CONFIG.forEach((defaultType) => {
      if (!processedTypes.has(defaultType.type)) {
        result.push({
          type: defaultType.type,
          display: 0,
          custom_title: defaultType.custom_title
        });
      }
    });
    return result;
  }, [value]);
  const handleSortChange = (0, import_react.useCallback)(
    (newList) => {
      if (!onChange || disabled) return;
      onChange(newList);
    },
    [onChange, disabled]
  );
  const handleToggleDisplay = (0, import_react.useCallback)(
    (index) => {
      if (!onChange || disabled) return;
      const newList = [...dataSource];
      newList[index] = {
        ...newList[index],
        display: newList[index].display === 1 ? 0 : 1
      };
      onChange(newList);
    },
    [dataSource, onChange, disabled]
  );
  const handleTitleChange = (0, import_react.useCallback)(
    (index, newTitle) => {
      if (!onChange || disabled) return;
      const newList = [...dataSource];
      newList[index] = {
        ...newList[index],
        custom_title: typeof newTitle === "string" ? { original: newTitle, en: newTitle } : newTitle
      };
      onChange(newList);
    },
    [dataSource, onChange, disabled]
  );
  const getDisplayTitle = (0, import_react.useCallback)((item) => {
    const defaultType = DEFAULT_WALLET_PASS_TYPES_CONFIG.find(
      (t) => t.type === item.type
    );
    return item.custom_title || (defaultType == null ? void 0 : defaultType.custom_title) || { original: item.type, en: item.type };
  }, []);
  const renderItem = (0, import_react.useCallback)(
    (item, index) => {
      const displayTitle = getDisplayTitle(item);
      const isVisible = item.display === 1;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)("sortable-wallet-pass-item", {
            "sortable-wallet-pass-item-disabled": disabled,
            "sortable-wallet-pass-item-hidden": !isVisible
          })
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "sortable-wallet-pass-drag-handle" }, /* @__PURE__ */ import_react.default.createElement(import_icons.HolderOutlined, { className: "drag-dots", size: 20 })),
        /* @__PURE__ */ import_react.default.createElement("div", { className: "sortable-wallet-pass-title" }, /* @__PURE__ */ import_react.default.createElement(
          Editable,
          {
            value: displayTitle,
            editable: !disabled && {
              maxLength: 10
            },
            onChange: (newValue) => handleTitleChange(index, newValue)
          }
        )),
        /* @__PURE__ */ import_react.default.createElement("div", { className: "sortable-wallet-pass-toggle" }, /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            style: {
              cursor: "pointer",
              border: "none",
              background: "transparent"
            },
            onClick: () => handleToggleDisplay(index)
          },
          isVisible ? /* @__PURE__ */ import_react.default.createElement(import_icons.EyeOutlined, { className: "eye-icon eye-icon-visible" }) : /* @__PURE__ */ import_react.default.createElement(import_icons.EyeInvisibleOutlined, { className: "eye-icon eye-icon-hidden" })
        ))
      );
    },
    [disabled, getDisplayTitle, handleTitleChange, handleToggleDisplay]
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("sortable-wallet-pass-types", className, {
        "sortable-wallet-pass-types-disabled": disabled
      }),
      style
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.SortableList,
      {
        dataSource,
        onChange: handleSortChange,
        rowKey: "type",
        renderItem,
        activationConstraint: {
          distance: 5
        }
      }
    )
  );
};
var sortableWalletPassTypes_default = SortableWalletPassTypes;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DEFAULT_WALLET_PASS_TYPES_CONFIG
});
