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/pro/priceKeyboard/components/cashKeyboard/CashKeyboardIntact.tsx
var CashKeyboardIntact_exports = {};
__export(CashKeyboardIntact_exports, {
  default: () => CashKeyboardIntact_default
});
module.exports = __toCommonJS(CashKeyboardIntact_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_ahooks = require("ahooks");
var import_lodash = require("lodash");
var import_utils = require("@pisell/utils");
var import_shortcuts = __toESM(require("../shortcuts"));
var import_CashKeyboardSimple = __toESM(require("./CashKeyboardSimple"));
var import_utils2 = require("../../utils");
var import_index = require("./index.less");
var import_decimal = __toESM(require("decimal.js"));
var import_materials = require("@pisell/materials");
var import_utils3 = require("@pisell/utils");
var import_materials2 = require("@pisell/materials");
var CashKeyboardIntact = (props) => {
  var _a, _b, _c;
  const {
    amountSymbol,
    titleArea = {},
    displayField = {},
    originalValue,
    presets,
    style,
    selectType = "light",
    placeholder,
    doneText,
    resetText,
    disabled,
    hiddenChangeDue,
    shortcutsSize
  } = props;
  const [internalValue, setInternalValue] = (0, import_ahooks.useControllableValue)(props);
  const [isShowModal, setIsShowModal] = (0, import_react.useState)(false);
  const changeDue = (0, import_react.useMemo)(() => {
    return Math.max(
      0,
      new import_decimal.default(internalValue || 0).minus(new import_decimal.default(originalValue || 0)).toNumber()
    );
  }, [internalValue, originalValue]);
  const _restProps = (0, import_react.useMemo)(() => {
    return (0, import_lodash.omit)(props, [
      "defaultValue",
      "value",
      "onChange",
      "onEnter",
      "onReset",
      "style"
    ]);
  }, [props]);
  (0, import_react.useEffect)(() => {
    (0, import_utils2.setKeyboardTheme)(selectType);
  }, [selectType]);
  const getDefaultPresets = () => {
    const defaultEndPresets = [
      {
        label: import_utils.locales.getText("cash-keyboard-other"),
        value: "other",
        style: {
          color: "#344054",
          backgroundColor: "white"
        },
        onClick: () => {
          setIsShowModal(true);
        },
        render: () => /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            style: {
              position: "absolute",
              left: 0,
              top: 0,
              bottom: 0,
              right: 0,
              display: "flex",
              alignItems: "center",
              justifyContent: "center"
            }
          },
          import_utils.locales.getText("cash-keyboard-other")
        )
      },
      {
        label: resetText || import_utils.locales.getText("cash-keyboard-reset"),
        value: "reset",
        style: {
          color: "#D92D20",
          backgroundColor: "white"
        },
        onClick: () => {
          var _a2;
          setInternalValue(String(originalValue) || "");
          (_a2 = props == null ? void 0 : props.onReset) == null ? void 0 : _a2.call(props);
        }
      },
      {
        label: doneText || import_utils.locales.getText("cash-keyboard-pay"),
        value: "pay",
        style: {
          color: "white",
          backgroundColor: "#7F56DA",
          gridColumn: "span 2"
        },
        onClick: () => {
          var _a2;
          (_a2 = props.onEnter) == null ? void 0 : _a2.call(props, internalValue);
        }
      }
    ];
    const userPresets = presets || [];
    const maxUserPresets = 7 - defaultEndPresets.length;
    const limitedUserPresets = userPresets.slice(0, maxUserPresets);
    return [...limitedUserPresets, ...defaultEndPresets];
  };
  const getDefaultDisplayField = () => {
    return {
      cashReceived: {
        visible: true,
        label: import_utils.locales.getText("cash-keyboard-cash-received")
      },
      balanceDue: {
        visible: true,
        label: import_utils.locales.getText("cash-keyboard-balance-due")
      },
      changeDue: {
        visible: true,
        label: import_utils.locales.getText("cash-keyboard-change-due")
      },
      gridRatio: [1, 2, 1]
      // 左中右布局，中间占 2 份
    };
  };
  const defaultTitleArea = {
    visible: true,
    title: {
      visible: true
    },
    subtitle: {
      visible: true
    },
    alignment: "space-between",
    padding: "0px"
  };
  const mergedTitleArea = (0, import_lodash.merge)({}, defaultTitleArea, titleArea);
  const mergedDisplayField = (0, import_lodash.merge)({}, getDefaultDisplayField(), displayField);
  const renderTitleArea = () => {
    var _a2, _b2;
    const { title, subtitle } = mergedTitleArea || {};
    if (!(title == null ? void 0 : title.visible) && !(subtitle == null ? void 0 : subtitle.visible)) {
      return null;
    }
    if (!(title == null ? void 0 : title.text) && !(subtitle == null ? void 0 : subtitle.text)) {
      return null;
    }
    const titleStyle = {
      display: "flex",
      justifyContent: mergedTitleArea.alignment,
      alignItems: "center",
      padding: mergedTitleArea.padding,
      marginBottom: "8"
    };
    return /* @__PURE__ */ import_react.default.createElement("div", { style: titleStyle }, ((_a2 = mergedTitleArea.title) == null ? void 0 : _a2.visible) && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-cash-keyboard-title",
        style: {
          fontSize: mergedTitleArea.title.fontSize,
          color: mergedTitleArea.title.color,
          fontWeight: mergedTitleArea.title.fontWeight
        }
      },
      mergedTitleArea.title.text
    ), ((_b2 = mergedTitleArea.subtitle) == null ? void 0 : _b2.visible) && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-cash-keyboard-subtitle",
        style: {
          fontSize: mergedTitleArea.subtitle.fontSize,
          color: mergedTitleArea.subtitle.color,
          fontWeight: mergedTitleArea.subtitle.fontWeight
        }
      },
      mergedTitleArea.subtitle.text
    ));
  };
  const getGridStyle = (index) => {
    if (!mergedDisplayField.gridRatio) {
      return { flex: 1 };
    }
    const ratio = mergedDisplayField.gridRatio[index] || 1;
    return { flex: ratio };
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `pisell-cash-keyboard pisell-cash-keyboard-intact ${disabled ? "disabled" : ""}`,
      style: { ...style || {} }
    },
    renderTitleArea(),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-cash-keyboard-intact-container" }, /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", gap: "16px" } }, ((_a = mergedDisplayField.balanceDue) == null ? void 0 : _a.visible) && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-cash-keyboard-intact-container-top",
        style: { ...getGridStyle(0), overflow: "hidden" }
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-cash-keyboard-intact-container-top-label" }, mergedDisplayField.balanceDue.label),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-cash-keyboard-intact-container-top-value" }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Tooltip,
        {
          title: (0, import_utils3.formatAmountWithOptions)(
            originalValue || "",
            amountSymbol,
            {
              precision: 2,
              hideDecimalForWholeNumbers: false,
              showCurrencySymbol: true
            }
          )
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.AutoResizeText,
          {
            minFontSizePx: 10,
            maxFontSizePx: 18,
            fontSizePrecisionPx: 0.5
          },
          (0, import_utils3.formatAmountWithOptions)(
            originalValue || "",
            amountSymbol,
            {
              precision: 2,
              hideDecimalForWholeNumbers: false,
              showCurrencySymbol: true
            }
          )
        )
      ))
    ), ((_b = mergedDisplayField.cashReceived) == null ? void 0 : _b.visible) && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          ...getGridStyle(1),
          padding: "0px 16px",
          borderRadius: "8px",
          backgroundColor: "white",
          boxShadow: "inset 0 2px 4px rgba(16, 24, 40, 0.08), inset 0 -2px 4px rgba(16, 24, 40, 0.08), inset 2px 0 4px rgba(16, 24, 40, 0.08), inset -2px 0 4px rgba(16, 24, 40, 0.08)",
          overflow: "hidden",
          maxWidth: 188,
          cursor: "pointer",
          border: "1px solid #7f56da",
          borderBottom: "1px solid #7f56da"
        },
        onClick: () => {
          setIsShowModal(true);
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "pisell-cash-keyboard-intact-container-top",
          style: { ...getGridStyle(0), overflow: "hidden", padding: "5px 0" }
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-cash-keyboard-intact-container-top-label" }, mergedDisplayField.cashReceived.label),
        /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: "pisell-cash-keyboard-intact-container-top-value"
          },
          /* @__PURE__ */ import_react.default.createElement(
            import_materials.AutoResizeText,
            {
              minFontSizePx: 10,
              maxFontSizePx: 18,
              fontSizePrecisionPx: 0.5,
              style: { color: "#7f56da", textDecoration: "underline", textUnderlineOffset: "3px" }
            },
            internalValue ? (0, import_utils3.formatAmountWithOptions)(
              internalValue || "",
              amountSymbol,
              {
                value: internalValue,
                hideDecimalForWholeNumbers: false,
                precision: 2,
                showCurrencySymbol: true
              }
            ) : ""
          ),
          /* @__PURE__ */ import_react.default.createElement(import_materials2.Iconfont, { type: "pisell2-edit-05", style: { color: "#7f56da", fontSize: "18px", marginLeft: "4px", marginTop: "4px" } })
        )
      )
    ), ((_c = mergedDisplayField.changeDue) == null ? void 0 : _c.visible) && /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "pisell-cash-keyboard-intact-container-top",
        style: { ...getGridStyle(2), overflow: "hidden" }
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-cash-keyboard-intact-container-top-label" }, mergedDisplayField.changeDue.label),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-cash-keyboard-intact-container-top-value" }, /* @__PURE__ */ import_react.default.createElement(
        import_antd.Tooltip,
        {
          title: (0, import_utils3.formatAmountWithOptions)(
            hiddenChangeDue ? 0 : changeDue,
            amountSymbol,
            {
              value: hiddenChangeDue ? 0 : changeDue,
              showCurrencySymbol: true,
              hideDecimalForWholeNumbers: false,
              precision: 2
            }
          )
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.AutoResizeText,
          {
            minFontSizePx: 10,
            maxFontSizePx: 18,
            fontSizePrecisionPx: 0.5
          },
          (0, import_utils3.formatAmountWithOptions)(
            hiddenChangeDue ? 0 : changeDue,
            amountSymbol,
            {
              value: hiddenChangeDue ? 0 : changeDue,
              showCurrencySymbol: true,
              hideDecimalForWholeNumbers: false,
              precision: 2
            }
          )
        )
      ))
    )), /* @__PURE__ */ import_react.default.createElement(
      import_shortcuts.default,
      {
        size: shortcutsSize || "default",
        presets: getDefaultPresets(),
        onChange: setInternalValue,
        disabled
      }
    ))
  ), /* @__PURE__ */ import_react.default.createElement(
    import_CashKeyboardSimple.default,
    {
      containerProps: {
        renderType: "modal",
        open: isShowModal,
        onCancel: () => setIsShowModal(false)
      },
      ..._restProps,
      titleArea: {
        ...mergedTitleArea,
        subtitle: { visible: false }
      },
      selectType: "dark",
      value: internalValue,
      onChange: (value) => {
        console.log("CashKeyboardSimple>value", value);
        setInternalValue(value);
      },
      onEnter: () => {
        var _a2;
        (_a2 = props.onEnter) == null ? void 0 : _a2.call(props, internalValue);
        setIsShowModal(false);
      }
    }
  ));
};
var CashKeyboardIntact_default = CashKeyboardIntact;
