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/ecocup/cupProject/index.tsx
var cupProject_exports = {};
__export(cupProject_exports, {
  default: () => EcoCupProject
});
module.exports = __toCommonJS(cupProject_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_index = require("./index.less");
var import_hooks = require("../hooks");
var import_locales = __toESM(require("../locales"));
var import_const = require("./const");
var import_SearchBar = __toESM(require("../components/SearchBar"));
var import_AddCustomerModal = __toESM(require("../components/AddCustomerModal"));
var import_CustomerAndCupModal = __toESM(require("../components/CustomerAndCupModal"));
var import_SettingModal = __toESM(require("../components/SettingModal"));
var SCAN_LISTENER_KEY = "eco-cup-project-scan-listener";
function EcoCupProject() {
  const language = (0, import_hooks.useLanguage)();
  import_utils.locales.init(import_locales.default, language);
  const getApp = (0, import_hooks.useGetApp)();
  const addCustomerModal = (0, import_hooks.useModal)("ecocup-add-customer-modal");
  const settingModal = (0, import_hooks.useModal)("ecocup-setting-modal");
  const customerAndCupModal = (0, import_hooks.useModal)("ecocup-customer-and-cup-modal");
  const { goalShopId } = (0, import_hooks.useGetGoalShopInfo)();
  const onSearchResult = (result) => {
    console.log("onSearchResult", result);
    if ((result == null ? void 0 : result.type) === "customer") {
      customerAndCupModal.open({
        data: {
          firstType: result == null ? void 0 : result.type,
          customerData: result == null ? void 0 : result.data
        }
      });
    } else if ((result == null ? void 0 : result.type) === "cup") {
      customerAndCupModal.open({
        data: {
          firstType: result == null ? void 0 : result.type,
          cupData: result == null ? void 0 : result.data
        }
      });
    }
  };
  const onClickNewCustomer = () => {
    console.log("onClickNewCustomer");
    addCustomerModal.open();
  };
  const onClickSetting = () => {
    console.log("onClickSetting");
    settingModal.open();
  };
  const onClickCustomerList = () => {
    var _a, _b;
    console.log("onClickCustomerList");
    const app = getApp == null ? void 0 : getApp();
    if (goalShopId) {
      (_a = app == null ? void 0 : app.history) == null ? void 0 : _a.push(`/ecocup/customer-list?goal_shop_id=${goalShopId}`);
    } else {
      (_b = app == null ? void 0 : app.history) == null ? void 0 : _b.push("/ecocup/customer-list");
    }
  };
  const onClickCupList = () => {
    var _a, _b;
    console.log("onClickCupList");
    const app = getApp == null ? void 0 : getApp();
    if (goalShopId) {
      (_a = app == null ? void 0 : app.history) == null ? void 0 : _a.push(`/ecocup/cup-list?goal_shop_id=${goalShopId}`);
    } else {
      (_b = app == null ? void 0 : app.history) == null ? void 0 : _b.push("/ecocup/cup-list");
    }
  };
  const onClickButton = (key) => {
    switch (key) {
      case "add-new-customer":
        onClickNewCustomer();
        break;
      case "customer-list":
        onClickCustomerList();
        break;
      case "cup-list":
        onClickCupList();
        break;
      case "setting":
        onClickSetting();
        break;
    }
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "ecocup-cup-project" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "ecocup-cup-project-title" }, import_utils.locales.getText("pisell2.text.cup-project.title")), /* @__PURE__ */ import_react.default.createElement("div", { className: "ecocup-cup-project-search-bar" }, /* @__PURE__ */ import_react.default.createElement(
    import_SearchBar.default,
    {
      scanListenerKey: SCAN_LISTENER_KEY,
      onSearchResult
    }
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "ecocup-cup-project-actions" }, import_const.CUP_PROJECT_FOOTER_BUTTONS.map((button) => /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      key: button.key,
      type: button.type,
      size: "large",
      icon: /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: button.icon, size: 32 }),
      onClick: () => onClickButton(button.key),
      className: "ecocup-cup-project-actions-button"
    },
    import_utils.locales.getText(button.languageKey)
  ))), addCustomerModal.visible && /* @__PURE__ */ import_react.default.createElement(import_AddCustomerModal.default, { ...addCustomerModal.modalProps }), customerAndCupModal.visible && /* @__PURE__ */ import_react.default.createElement(import_CustomerAndCupModal.default, { ...customerAndCupModal.modalProps }), settingModal.visible && /* @__PURE__ */ import_react.default.createElement(import_SettingModal.default, { ...settingModal.modalProps }));
}
