function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useEffect, useMemo, useState } from 'react';
import { Input, Modal } from 'antd';
import { Button } from '@pisell/materials';
import { locales } from '@pisell/utils';
import "./index.less";
/**
 * ManualPickupRefModal
 *
 * 当 scanOrder.checkManualPickupRef() 返回 enabled=true 时，弹出让用户输入
 * 昵称/buzzer 的弹窗。确认时回调 onConfirm(value)，由外部负责 setPickupRef 与下单。
 */
export default function ManualPickupRefModal(_ref) {
  var open = _ref.open,
    _ref$confirmLoading = _ref.confirmLoading,
    confirmLoading = _ref$confirmLoading === void 0 ? false : _ref$confirmLoading,
    onCancel = _ref.onCancel,
    onConfirm = _ref.onConfirm;
  var _useState = useState(''),
    _useState2 = _slicedToArray(_useState, 2),
    value = _useState2[0],
    setValue = _useState2[1];
  useEffect(function () {
    if (open) setValue('');
  }, [open]);
  var title = useMemo(function () {
    return String(locales.getText('pisell2.scan.order.pickup.ref.title'));
  }, []);
  var heading = useMemo(function () {
    return String(locales.getText('pisell2.scan.order.pickup.ref.heading'));
  }, []);
  var description = useMemo(function () {
    return String(locales.getText('pisell2.scan.order.pickup.ref.description'));
  }, []);
  var placeholder = useMemo(function () {
    return String(locales.getText('pisell2.scan.order.pickup.ref.placeholder'));
  }, []);
  var confirmText = useMemo(function () {
    return String(locales.getText('pisell2.event.confirm') || 'Confirm');
  }, []);
  var trimmed = value.trim();
  var canConfirm = !!trimmed && !confirmLoading;
  var handleConfirm = function handleConfirm() {
    if (!canConfirm) return;
    onConfirm(trimmed);
  };
  return /*#__PURE__*/React.createElement(Modal, {
    open: open,
    title: title,
    footer: null,
    onCancel: 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: placeholder,
    value: value,
    onChange: function 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, {
    type: "primary",
    block: true,
    size: "large",
    disabled: !canConfirm,
    loading: confirmLoading,
    onClick: handleConfirm
  }, confirmText)));
}