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/webPosLogin/WebPosLoginCpt.tsx
var WebPosLoginCpt_exports = {};
__export(WebPosLoginCpt_exports, {
  default: () => WebPosLoginCpt_default
});
module.exports = __toCommonJS(WebPosLoginCpt_exports);
var import_utils = require("@pisell/utils");
var import_react = __toESM(require("react"));
var import_WebPosLoginCpt = require("./WebPosLoginCpt.less");
var import_BrandPanel = __toESM(require("./components/BrandPanel"));
var import_LoginPanel = __toESM(require("./components/LoginPanel"));
var import_SelectDevice = __toESM(require("./components/SelectDevice"));
var import_SelectStore = __toESM(require("./components/SelectStore"));
var import_UserFooter = __toESM(require("./components/UserFooter"));
var import_locales = __toESM(require("./locales"));
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_appDevicePlanning = __toESM(require("../saasDevice/appDevicePlanning"));
var DEFAULT_BACKGROUND = "http://static.pisellcdn.com/defaultBg1.jpg";
var WebPosLoginCpt = (0, import_react.memo)((props) => {
  var _a;
  const {
    className = "",
    style,
    loginConfig,
    backgroundImage,
    brandConfig,
    step = "login",
    showBackButton = true,
    storeList = [],
    deviceList = [],
    userInfo,
    selectedStore,
    lastUsedStoreId,
    lastUsedDeviceId,
    locale = "en",
    loading = false,
    onStoreSelect,
    onDeviceSelect,
    onChangeAccount,
    onChangeStore,
    onBack,
    onLoginSuccess,
    onIotDeviceLinked,
    loginSlot,
    variant,
    onIotBack
  } = props;
  const isMobile = variant === "phone" || variant === "mobile";
  const context = (0, import_useEngineContext.default)();
  const { isIotLogin = false, iotKind } = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.constants) || {};
  console.log(props, onLoginSuccess, "onLoginSuccess");
  import_utils.locales.init(import_locales.default, locale);
  const stepTitle = (0, import_react.useMemo)(() => {
    const titles = {
      login: "",
      store: import_utils.locales.getText("webpos-login-select-store-title"),
      device: import_utils.locales.getText("webpos-login-select-device-title")
    };
    return titles[step];
  }, [step, locale]);
  const shouldShowBackButton = (0, import_react.useMemo)(() => {
    if (step === "login") return false;
    return showBackButton;
  }, [step, showBackButton]);
  const renderRightContent = () => {
    switch (step) {
      case "login":
        return /* @__PURE__ */ import_react.default.createElement(import_LoginPanel.default, { onLoginSuccess, config: loginConfig });
      case "store":
        return /* @__PURE__ */ import_react.default.createElement(
          import_SelectStore.default,
          {
            storeList,
            locale,
            loading,
            lastUsedStoreId,
            onSelect: onStoreSelect
          }
        );
      case "device":
        return /* @__PURE__ */ import_react.default.createElement(
          import_SelectDevice.default,
          {
            deviceList,
            locale,
            loading,
            lastUsedDeviceId,
            onSelect: onDeviceSelect
          }
        );
      default:
        return null;
    }
  };
  const renderFooter = () => {
    if (step === "login") return null;
    return /* @__PURE__ */ import_react.default.createElement(
      import_UserFooter.default,
      {
        isShowChangeStore: storeList.length > 1,
        userInfo,
        selectedStore,
        step,
        locale,
        onChangeAccount,
        onChangeStore
      }
    );
  };
  console.log("xxxx=>>>>", isIotLogin, step);
  return isIotLogin && step === "device" ? /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__iot-device" }, /* @__PURE__ */ import_react.default.createElement(import_appDevicePlanning.default, { kind: iotKind, onLinked: onIotDeviceLinked, showBack: true, onBack: onIotBack })) : /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `webpos-login ${isMobile ? "webpos-login--mobile" : ""} ${className}`.trim(),
      style: {
        ...style,
        backgroundImage: `url(${backgroundImage || DEFAULT_BACKGROUND})`
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__backdrop" }),
    /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__card" }, /* @__PURE__ */ import_react.default.createElement(import_BrandPanel.default, { config: brandConfig }), /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__right-panel" }, step === "login" ? loginSlot ? loginSlot : null : /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__header" }, shouldShowBackButton && /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        className: "webpos-login__back-btn",
        onClick: onBack,
        type: "button",
        "aria-label": import_utils.locales.getText("webpos-login-back")
      },
      /* @__PURE__ */ import_react.default.createElement(
        "svg",
        {
          width: "24",
          height: "24",
          viewBox: "0 0 24 24",
          fill: "none",
          xmlns: "http://www.w3.org/2000/svg"
        },
        /* @__PURE__ */ import_react.default.createElement(
          "path",
          {
            d: "M15 18L9 12L15 6",
            stroke: "currentColor",
            strokeWidth: "2",
            strokeLinecap: "round",
            strokeLinejoin: "round"
          }
        )
      )
    ), stepTitle && /* @__PURE__ */ import_react.default.createElement("h1", { className: "webpos-login__title" }, stepTitle)), /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__content" }, renderRightContent()), /* @__PURE__ */ import_react.default.createElement("div", { className: "webpos-login__footer" }, renderFooter())))
  );
});
WebPosLoginCpt.displayName = "WebPosLoginCpt";
var WebPosLoginCpt_default = WebPosLoginCpt;
