const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_context = require("../../context.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/scanOrder/components/FulfillmentMode/index.tsx
/**
* FulfillmentMode
*
* 通过 scanOrder module 读取 getFulfillmentModes() 返回的 { enableTableService, enablePickup }：
* - 两个都开启：渲染可切换的 Radio.Group，默认 Table service，挂载即同步一次 setPickupReferenceMode。
* - 只开启一个：仅渲染单行文案提示当前取餐方式，并同步一次 setPickupReferenceMode。
* - 都未开启：不渲染。
*/
function FulfillmentMode() {
	const { scanOrderModule } = require_context.useScanOrderContext();
	const [modes, setModes] = (0, react.useState)({});
	const [mode, setMode] = (0, react.useState)("table_service");
	(0, react.useEffect)(() => {
		if (!scanOrderModule) return;
		const next = (typeof scanOrderModule.getFulfillmentModes === "function" ? scanOrderModule.getFulfillmentModes() : void 0) || {};
		setModes(next);
		const onlyTable = !!next.enableTableService && !next.enablePickup;
		const initial = !next.enableTableService && !!next.enablePickup ? "counter_pickup" : onlyTable ? "table_service" : "table_service";
		setMode(initial);
		if ((next.enableTableService || next.enablePickup) && typeof scanOrderModule.setPickupReferenceMode === "function") scanOrderModule.setPickupReferenceMode(initial);
	}, [scanOrderModule]);
	const { enableTableService, enablePickup } = modes;
	const labelTitle = (0, react.useMemo)(() => String(_pisell_utils.locales.getText("pisell2.scan.order.fulfillment.title")), []);
	const tableServiceText = (0, react.useMemo)(() => String(_pisell_utils.locales.getText("pisell2.scan.order.fulfillment.table_service")), []);
	const pickupText = (0, react.useMemo)(() => String(_pisell_utils.locales.getText("pisell2.scan.order.fulfillment.pickup")), []);
	if (!enableTableService && !enablePickup) return null;
	if (!enableTableService || !enablePickup) {
		const singleLabel = enablePickup ? pickupText : tableServiceText;
		return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-scan-order-fulfillment pisell-scan-order-fulfillment-single" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-scan-order-fulfillment-title" }, labelTitle), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-scan-order-fulfillment-value" }, singleLabel));
	}
	const handleChange = (next) => {
		if (next === mode) return;
		setMode(next);
		if (typeof (scanOrderModule === null || scanOrderModule === void 0 ? void 0 : scanOrderModule.setPickupReferenceMode) === "function") scanOrderModule.setPickupReferenceMode(next);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-scan-order-fulfillment" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-scan-order-fulfillment-title" }, labelTitle), /* @__PURE__ */ react.default.createElement(antd.Radio.Group, {
		className: "pisell-scan-order-fulfillment-group",
		optionType: "button",
		buttonStyle: "solid",
		value: mode,
		onChange: (event) => {
			var _event$target;
			return handleChange(event === null || event === void 0 || (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
		}
	}, /* @__PURE__ */ react.default.createElement(antd.Radio.Button, { value: "table_service" }, tableServiceText), /* @__PURE__ */ react.default.createElement(antd.Radio.Button, { value: "counter_pickup" }, pickupText)));
}
//#endregion
exports.default = FulfillmentMode;
