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/Sales/Customer/index.tsx
var Customer_exports = {};
__export(Customer_exports, {
  CustomerContext: () => CustomerContext,
  CustomerProvider: () => CustomerProvider,
  default: () => Customer_default,
  useCustomer: () => useCustomer
});
module.exports = __toCommonJS(Customer_exports);
var import_react = __toESM(require("react"));
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var defaultState = {};
var CustomerContext = (0, import_react.createContext)(
  void 0
);
var CustomerProvider = ({
  children
}) => {
  const context = (0, import_useEngineContext.default)();
  const utils = context.appHelper.utils || {};
  const isLogin = () => {
    var _a, _b;
    return !!((_b = (_a = utils == null ? void 0 : utils.token) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a));
  };
  const openLoginModal = (params) => {
    const { callback } = params || {};
    utils.action({
      type: "pisell1.login",
      data: {
        type: "plugin"
      },
      callback
    });
  };
  const getUserInfo = () => {
    var _a, _b;
    const userInfo = (_b = (_a = utils.getStore().getState()) == null ? void 0 : _a.global) == null ? void 0 : _b.userInfo;
    const localUserInfo = JSON.parse(utils.storage.get("customer") || "{}");
    return (userInfo == null ? void 0 : userInfo.id) ? userInfo : localUserInfo;
  };
  const contextValue = {
    appContext: context,
    appUtils: utils,
    isLogin,
    openLoginModal,
    getUserInfo
  };
  return /* @__PURE__ */ import_react.default.createElement(CustomerContext.Provider, { value: contextValue }, children);
};
var useCustomer = () => {
  const context = import_react.default.useContext(CustomerContext);
  if (!context) {
    throw new Error("useCustomer must be used within a CustomerContext");
  }
  return context;
};
var Customer_default = {
  defaultState
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CustomerContext,
  CustomerProvider,
  useCustomer
});
