import React, { useEffect, useMemo, useState } from "react";
import { Input, Modal } from "antd";
import { locales } from "@pisell/utils";
import { Button as Button$1 } from "@pisell/materials";
import "./index.less";
//#region src/components/scanOrder/components/ManualPickupRefModal/index.tsx
/**
* ManualPickupRefModal
*
* 当 scanOrder.checkManualPickupRef() 返回 enabled=true 时，弹出让用户输入
* 昵称/buzzer 的弹窗。确认时回调 onConfirm(value)，由外部负责 setPickupRef 与下单。
*/
function ManualPickupRefModal({ open, confirmLoading = false, onCancel, onConfirm }) {
	const [value, setValue] = useState("");
	useEffect(() => {
		if (open) setValue("");
	}, [open]);
	const title = useMemo(() => String(locales.getText("pisell2.scan.order.pickup.ref.title")), []);
	const heading = useMemo(() => String(locales.getText("pisell2.scan.order.pickup.ref.heading")), []);
	const description = useMemo(() => String(locales.getText("pisell2.scan.order.pickup.ref.description")), []);
	const placeholder = useMemo(() => String(locales.getText("pisell2.scan.order.pickup.ref.placeholder")), []);
	const confirmText = useMemo(() => String(locales.getText("pisell2.event.confirm") || "Confirm"), []);
	const trimmed = value.trim();
	const canConfirm = !!trimmed && !confirmLoading;
	const handleConfirm = () => {
		if (!canConfirm) return;
		onConfirm(trimmed);
	};
	return /* @__PURE__ */ React.createElement(Modal, {
		open,
		title,
		footer: null,
		onCancel,
		maskClosable: false,
		destroyOnClose: true,
		centered: true,
		className: "pisell-scan-order-pickup-ref-modal"
	}, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-pickup-ref-body" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-pickup-ref-heading" }, heading), /* @__PURE__ */ React.createElement("div", { className: "pisell-scan-order-pickup-ref-desc" }, description), /* @__PURE__ */ React.createElement(Input, {
		size: "large",
		placeholder,
		value,
		onChange: (event) => {
			var _event$target;
			return setValue((event === null || event === void 0 || (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value) || "");
		},
		onPressEnter: handleConfirm,
		className: "pisell-scan-order-pickup-ref-input",
		maxLength: 32,
		allowClear: true
	}), /* @__PURE__ */ React.createElement(Button$1, {
		type: "primary",
		block: true,
		size: "large",
		disabled: !canConfirm,
		loading: confirmLoading,
		onClick: handleConfirm
	}, confirmText)));
}
//#endregion
export { ManualPickupRefModal as default };
