import withResponsive from "../../../responsive/withResponsive.js";
import { useGetApp, useGetGoalShopInfo, useLanguage, useModal } from "../hooks.js";
import locales_default from "../locales.js";
import { CUP_PROJECT_FOOTER_BUTTONS } from "./const.js";
import SearchBar from "../components/SearchBar/index.js";
import AddCustomerModal_default from "../components/AddCustomerModal/index.js";
import CustomerAndCupModal from "../components/CustomerAndCupModal/index.js";
import SettingModal_default from "../components/SettingModal/index.js";
import React from "react";
import { locales } from "@pisell/utils";
import { Button, Icon } from "@pisell/materials";
import classNames from "classnames";
import "./index.less";
//#region src/components/ecocup/cupProject/index.tsx
const SCAN_LISTENER_KEY = "eco-cup-project-scan-listener";
function EcoCupProject(props) {
	const { className, style, variant } = props;
	const currentVariant = variant || "desktop";
	const language = useLanguage();
	locales.init(locales_default, language);
	const getApp = useGetApp();
	const addCustomerModal = useModal("ecocup-add-customer-modal");
	const settingModal = useModal("ecocup-setting-modal");
	const customerAndCupModal = useModal("ecocup-customer-and-cup-modal");
	const { goalShopId } = useGetGoalShopInfo();
	const onSearchResult = (result) => {
		console.log("onSearchResult", result);
		if ((result === null || result === void 0 ? void 0 : result.type) === "customer") customerAndCupModal.open({ data: {
			firstType: result === null || result === void 0 ? void 0 : result.type,
			customerData: result === null || result === void 0 ? void 0 : result.data
		} });
		else if ((result === null || result === void 0 ? void 0 : result.type) === "cup") customerAndCupModal.open({ data: {
			firstType: result === null || result === void 0 ? void 0 : result.type,
			cupData: result === null || result === void 0 ? void 0 : result.data
		} });
	};
	const onClickNewCustomer = () => {
		console.log("onClickNewCustomer");
		addCustomerModal.open();
	};
	const onClickSetting = () => {
		console.log("onClickSetting");
		settingModal.open();
	};
	const onClickCustomerList = () => {
		console.log("onClickCustomerList");
		const app = getApp === null || getApp === void 0 ? void 0 : getApp();
		if (goalShopId) {
			var _app$history;
			app === null || app === void 0 || (_app$history = app.history) === null || _app$history === void 0 || _app$history.push(`/ecocup/customer-list?goal_shop_id=${goalShopId}`);
		} else {
			var _app$history2;
			app === null || app === void 0 || (_app$history2 = app.history) === null || _app$history2 === void 0 || _app$history2.push("/ecocup/customer-list");
		}
	};
	const onClickCupList = () => {
		console.log("onClickCupList");
		const app = getApp === null || getApp === void 0 ? void 0 : getApp();
		if (goalShopId) {
			var _app$history3;
			app === null || app === void 0 || (_app$history3 = app.history) === null || _app$history3 === void 0 || _app$history3.push(`/ecocup/cup-list?goal_shop_id=${goalShopId}`);
		} else {
			var _app$history4;
			app === null || app === void 0 || (_app$history4 = app.history) === null || _app$history4 === void 0 || _app$history4.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__ */ React.createElement("div", {
		className: classNames("ecocup-cup-project", `ecocup-cup-project--${currentVariant}`, className),
		style
	}, /* @__PURE__ */ React.createElement("div", { className: "ecocup-cup-project-title" }, locales.getText("pisell2.text.cup-project.title")), /* @__PURE__ */ React.createElement("div", { className: "ecocup-cup-project-search-bar" }, /* @__PURE__ */ React.createElement(SearchBar, {
		scanListenerKey: SCAN_LISTENER_KEY,
		onSearchResult
	})), /* @__PURE__ */ React.createElement("div", { className: "ecocup-cup-project-actions" }, CUP_PROJECT_FOOTER_BUTTONS.map((button) => /* @__PURE__ */ React.createElement(Button, {
		key: button.key,
		type: button.type,
		size: "large",
		icon: /* @__PURE__ */ React.createElement(Icon, {
			type: button.icon,
			size: 32
		}),
		onClick: () => onClickButton(button.key),
		className: "ecocup-cup-project-actions-button"
	}, locales.getText(button.languageKey)))), addCustomerModal.visible && /* @__PURE__ */ React.createElement(AddCustomerModal_default, addCustomerModal.modalProps), customerAndCupModal.visible && /* @__PURE__ */ React.createElement(CustomerAndCupModal, customerAndCupModal.modalProps), settingModal.visible && /* @__PURE__ */ React.createElement(SettingModal_default, settingModal.modalProps));
}
EcoCupProject.displayName = "EcoCupProject";
var cupProject_default = withResponsive(EcoCupProject);
//#endregion
export { cupProject_default as default };
