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/pay/toC/PaymentMethods/WalletPass/List/index.tsx
var List_exports = {};
__export(List_exports, {
  default: () => List_default
});
module.exports = __toCommonJS(List_exports);
var import_react = __toESM(require("react"));
var import_ahooks = require("ahooks");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_serve = require("../serve");
var import_utils2 = require("../utils");
var import_index = require("./index.less");
var WalletPassList = (0, import_react.forwardRef)(
  (props, ref) => {
    const { title, onChange, data: propsData, value, walletSetting, onLoadingChange, loading: propsLoading, onChangeDebounce, customer_id } = props;
    const [data, setData] = (0, import_react.useState)(
      propsData || []
    );
    const [loading, setLoading] = (0, import_react.useState)(false);
    (0, import_react.useEffect)(() => {
      if (propsData) {
        setData(propsData);
      }
    }, [propsData]);
    (0, import_react.useEffect)(() => {
      setLoading(!!propsLoading);
    }, [propsLoading]);
    const getList = async (params, formatList) => {
      setLoading(true);
      try {
        let list = await (0, import_serve.getMachineCodeList)(params) || [];
        list = list.map((item) => {
          return {
            ...item,
            customer_id: customer_id || item.customer_id
          };
        });
        if ((0, import_utils.isFunction)(formatList)) {
          list = formatList(list);
        }
        setData((0, import_utils2.formatMachineCodeServer2CardList)(list, value));
      } catch (err) {
        console.error(err);
      }
      setLoading(false);
    };
    const init = (params, formatList) => {
      getList(params, formatList);
    };
    (0, import_react.useImperativeHandle)(ref, () => ({
      init
    }));
    (0, import_react.useEffect)(() => {
      onLoadingChange == null ? void 0 : onLoadingChange(loading);
    }, [loading]);
    const { availableList, disabledList } = (0, import_react.useMemo)(() => {
      const _disabledList = [];
      const _availableList = [];
      data.forEach((item) => {
        if (item.disabled) {
          _disabledList.push(item);
        } else {
          _availableList.push(item);
        }
      });
      return {
        disabledList: _disabledList,
        availableList: _availableList
      };
    }, [data]);
    const handleChange = (0, import_ahooks.useMemoizedFn)((val) => {
      onChange == null ? void 0 : onChange(val, (0, import_utils2.getDataByIds)(data, val));
    });
    const empty = (0, import_react.useMemo)(() => {
      return /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellEmpty,
        {
          icon: /* @__PURE__ */ import_react.default.createElement(
            import_materials.Iconfont,
            {
              type: "pisell2-a-wallet-021",
              style: { color: "#667085" }
            }
          ),
          description: import_utils.locales.getText("tocPay.text.walletPassEmpty")(walletSetting == null ? void 0 : walletSetting.name)
        }
      );
    }, []);
    return /* @__PURE__ */ import_react.default.createElement(import_materials.PisellLoading, { loading }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-walletPass-list-wrap" }, title && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-walletPass-list-title" }, title), /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellCardList,
      {
        data: availableList,
        hasMore: false,
        value,
        onChange: handleChange,
        showEmpty: data.length === 0,
        empty,
        onChangeDebounce
      }
    ), !!disabledList.length && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-walletPass-list-disabled" }, import_utils.locales.getText("tocPay.text.walletPassDisabled")), /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellCardList,
      {
        mode: void 0,
        data: disabledList,
        hasMore: false
      }
    ))));
  }
);
var List_default = (0, import_react.memo)(WalletPassList);
