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/eftpos/table.tsx
var table_exports = {};
__export(table_exports, {
  default: () => table_default
});
module.exports = __toCommonJS(table_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_XClose = __toESM(require("@pisell/icon/es/XClose"));
var import_utils = require("@pisell/utils");
var import_const = require("./const");
var import_SettlementModal = __toESM(require("./SettlementModal"));
var { Column } = import_antd.Table;
var { Title, Text } = import_antd.Typography;
var App = ({
  type,
  eftposName,
  tableSize,
  getList,
  onEdit,
  onDel,
  onRepair,
  onLog,
  style,
  useTyroLog,
  systemConfigStatus,
  onClickByTip
}, ref) => {
  const size = (0, import_react.useMemo)(() => {
    if (Array.isArray(tableSize)) {
      return [
        tableSize[0] || 200,
        tableSize[1] || 120,
        tableSize[2] || 120,
        tableSize[3] || 260
      ];
    }
    return [200, 120, 120, 260];
  }, [tableSize]);
  const totalSize = (0, import_react.useMemo)(() => {
    return size.reduce(
      (accumulator, currentValue) => accumulator + currentValue,
      0
    );
  }, [size]);
  const [loading, setLoading] = (0, import_react.useState)(false);
  const deviceRef = (0, import_react.useRef)("");
  const [isModalOpen, setModalOpen] = (0, import_react.useState)(false);
  const [pagination, setPagination] = (0, import_react.useState)({
    pageSize: 10,
    current: 1,
    total: 0
  });
  const [data, setData] = (0, import_react.useState)([]);
  const [settlementModalOpen, setSettlementModalOpen] = (0, import_react.useState)(false);
  const [settlementModalData, setSettlementModalData] = (0, import_react.useState)(null);
  const loadData = async (current) => {
    if (typeof getList !== "function") {
      return Promise.reject(`getList ${getList} is not function`);
    }
    setLoading(true);
    const res = await getList({
      type,
      num: pagination.pageSize,
      skip: typeof current === "number" ? current : pagination.current
    }).catch((res2) => {
      setLoading(false);
    });
    setLoading(false);
    setPagination((p) => ({
      ...p,
      total: res.data.count,
      current: typeof current === "number" ? current : pagination.current
    }));
    setData(res.data.list);
  };
  (0, import_react.useEffect)(() => {
    loadData(1);
  }, []);
  const onAddDevice = () => {
    onEdit();
  };
  const onEditDevice = (device) => {
    const { connection, setting, ...other } = device;
    onEdit({
      ...other,
      ...connection || {},
      ...setting || {}
    });
  };
  const onRepairDevice = (device) => {
    const { connection, setting, ...other } = device;
    onRepair({
      ...other,
      ...connection || {},
      ...setting || {}
    });
  };
  const onLogDevice = (device) => {
    const { connection, setting, ...other } = device;
    onLog({
      ...other,
      ...connection || {},
      ...setting || {}
    });
  };
  const onDelDevice = (device) => {
    deviceRef.current = device.id;
    setModalOpen(true);
  };
  const onChangeSize = (num) => {
    loadData(num);
  };
  const onOk = () => {
    setModalOpen(false);
    if (deviceRef.current) {
      onDel(deviceRef.current).then(() => {
        return loadData();
      });
    }
  };
  (0, import_react.useImperativeHandle)(ref, () => ({
    loadData
  }));
  const onSettlement = (device) => {
    console.log("onSettlement", device);
    setSettlementModalOpen(true);
    setSettlementModalData({ type: "SETTLEMENT", card_reader_id: device.id });
  };
  const onSettlementEnquiry = (device) => {
    console.log("onSettlementEnquiry", device);
    setSettlementModalOpen(true);
    setSettlementModalData({ type: "ENQUIRY", card_reader_id: device.id });
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-lowcode__pos-table",
      style: {
        ...style || {}
      }
    },
    type === "windcave" && !systemConfigStatus ? /* @__PURE__ */ import_react.default.createElement(
      import_antd.Alert,
      {
        message: import_utils.locales.getText("page.eftpos.text.setting.tip"),
        type: "error",
        style: { margin: "10px 0 0 0" },
        action: /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { size: "small", type: "text", onClick: onClickByTip }, import_utils.locales.getText("page.eftpos.text.setting.btn"))
      }
    ) : null,
    /* @__PURE__ */ import_react.default.createElement(Title, { level: 4, className: "pisell-lowcode__pos-title" }, eftposName, " ", import_utils.locales.getText("page.eftpos.text.device")),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__pos-table-act" }, /* @__PURE__ */ import_react.default.createElement(Text, null, import_utils.locales.getText("page.eftpos.text.device.list")), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Button,
      {
        type: "primary",
        onClick: onAddDevice,
        style: { height: "48px" }
      },
      import_utils.locales.getText("page.eftpos.text.device.add")()
    )),
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Table,
      {
        dataSource: data,
        rowKey: "id",
        pagination: false,
        loading,
        bordered: true,
        scroll: { y: "600px", x: "100%" },
        tableLayout: "fixed"
      },
      /* @__PURE__ */ import_react.default.createElement(
        Column,
        {
          title: import_utils.locales.getText("page.eftpos.text.table.name"),
          dataIndex: "name",
          key: "name",
          width: size[0],
          className: "pisell-lowcode__pos-table-col"
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(
        Column,
        {
          title: import_utils.locales.getText("page.eftpos.text.table.status"),
          width: size[1],
          dataIndex: "status",
          key: "status",
          render: (status) => {
            return import_utils.locales.getText(
              `page.eftpos.text.${status.toLocaleLowerCase()}`
            );
          },
          className: "pisell-lowcode__pos-table-col"
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(
        Column,
        {
          title: import_utils.locales.getText("page.eftpos.text.table.surcharge"),
          dataIndex: "setting",
          key: "setting",
          width: size[2],
          render: (setting) => {
            if (!setting) {
              return /* @__PURE__ */ import_react.default.createElement(Text, null, "-");
            }
            if (setting.useOriginSurcharge) {
              return /* @__PURE__ */ import_react.default.createElement(Text, null, "-");
            }
            const array = [
              setting.constant_rate ? setting.constant_rate + "%" : "",
              setting.constant_money
            ].filter(Boolean);
            if (array.length === 0) {
              return /* @__PURE__ */ import_react.default.createElement(Text, null, "-");
            }
            return /* @__PURE__ */ import_react.default.createElement(Text, null, setting.surcharge ? array.length > 1 ? array.join("+") : array[0] : "-");
          },
          className: "pisell-lowcode__pos-table-col"
        }
      ),
      /* @__PURE__ */ import_react.default.createElement(
        Column,
        {
          title: import_utils.locales.getText("page.eftpos.text.table.opeartion"),
          width: type === import_const.Eftpos.MX51 ? 600 : size[3],
          key: "opeartion",
          className: "pisell-lowcode__pos-table-col",
          render: (record) => /* @__PURE__ */ import_react.default.createElement(import_antd.Space, { size: "middle" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "link", onClick: () => onRepairDevice(record) }, import_utils.locales.getText("page.eftpos.text.repair")), useTyroLog && type === "tyro" ? /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "link", onClick: () => onLogDevice(record) }, import_utils.locales.getText("page.eftpos.text.log")) : null, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "link", onClick: () => onEditDevice(record) }, import_utils.locales.getText("page.eftpos.text.edit")), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "link", onClick: () => onDelDevice(record) }, import_utils.locales.getText("page.eftpos.text.delete")), type === import_const.Eftpos.MX51 ? /* @__PURE__ */ import_react.default.createElement(import_antd.Space, null, /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "link", onClick: () => onSettlement(record) }, import_utils.locales.getText("page.eftpos.text.settlement")), /* @__PURE__ */ import_react.default.createElement(
            import_antd.Button,
            {
              type: "link",
              onClick: () => onSettlementEnquiry(record)
            },
            import_utils.locales.getText("page.eftpos.text.settlement_enquiry")
          )) : null)
        }
      )
    ),
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Pagination,
      {
        style: { textAlign: "right" },
        pageSize: pagination.pageSize,
        current: pagination.current,
        total: pagination.total,
        onChange: onChangeSize,
        onShowSizeChange: onChangeSize
      }
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Modal,
    {
      open: isModalOpen,
      width: 400,
      centered: true,
      onCancel: () => setModalOpen(false),
      closeIcon: /* @__PURE__ */ import_react.default.createElement(import_XClose.default, { size: 20, style: { fontSize: "24px" } }),
      footer: /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", gap: "12px" } }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          block: true,
          onClick: () => setModalOpen(false),
          style: { flex: 1, height: "48px", borderRadius: "8px" }
        },
        import_utils.locales.getText("page.eftpos.text.table.del.cancel")
      ), /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          type: "primary",
          block: true,
          onClick: onOk,
          style: { flex: 1, height: "48px", borderRadius: "8px" }
        },
        import_utils.locales.getText("page.eftpos.text.table.del.delete")
      ))
    },
    /* @__PURE__ */ import_react.default.createElement("div", { style: { height: "34px" } }),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__pos-table-del-title" }, import_utils.locales.getText("page.eftpos.text.table.del.title")),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__pos-table-del-text" }, import_utils.locales.getText("page.eftpos.text.table.del.text"))
  ), settlementModalOpen && /* @__PURE__ */ import_react.default.createElement(
    import_SettlementModal.default,
    {
      open: settlementModalOpen,
      onClose: () => setSettlementModalOpen(false),
      data: settlementModalData
    }
  ));
};
var table_default = import_react.default.forwardRef(App);
