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; }
/**
 * venueBooking 移动端底栏
 * 参照 scanOrder/Footer 实现：总价显示 + Badge 购物车按钮 + 操作按钮
 * 购物车抽屉（Cart drawer）由此组件内部管理状态
 */
import React, { useMemo, useState } from 'react';
import { Badge, Button, Image } from '@pisell/materials';
import { locales } from '@pisell/utils';
import { useVenueBookingSymbol } from "../../hooks";
import Cart from "../Cart";
import shoppingCartSvg from "../../../appointmentBooking/assets/shopping-cart.svg";
import { useVenueBookingContext } from "../../context";
import "./index.less";
export default function Footer() {
  var _viewModel$cartItems;
  var symbol = useVenueBookingSymbol();
  var _useVenueBookingConte = useVenueBookingContext(),
    currentStep = _useVenueBookingConte.currentStep,
    viewModel = _useVenueBookingConte.viewModel,
    handlePrimaryAction = _useVenueBookingConte.handlePrimaryAction,
    isSubmittingOrder = _useVenueBookingConte.isSubmittingOrder;

  // 移动端购物车抽屉状态
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    cartOpen = _useState2[0],
    setCartOpen = _useState2[1];

  /** 从 OS summary 中提取总金额 */
  var totalAmount = useMemo(function () {
    var _ref, _ref2, _ref3, _ref4, _ref5, _viewModel$summary$to, _viewModel$summary, _viewModel$summary2, _viewModel$summary3, _viewModel$summary4, _viewModel$summary5, _viewModel$summary6;
    var rawAmount = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_viewModel$summary$to = (_viewModel$summary = viewModel.summary) === null || _viewModel$summary === void 0 ? void 0 : _viewModel$summary.total_amount) !== null && _viewModel$summary$to !== void 0 ? _viewModel$summary$to : (_viewModel$summary2 = viewModel.summary) === null || _viewModel$summary2 === void 0 ? void 0 : _viewModel$summary2.expect_amount) !== null && _ref5 !== void 0 ? _ref5 : (_viewModel$summary3 = viewModel.summary) === null || _viewModel$summary3 === void 0 ? void 0 : _viewModel$summary3.amount) !== null && _ref4 !== void 0 ? _ref4 : (_viewModel$summary4 = viewModel.summary) === null || _viewModel$summary4 === void 0 ? void 0 : _viewModel$summary4.total) !== null && _ref3 !== void 0 ? _ref3 : (_viewModel$summary5 = viewModel.summary) === null || _viewModel$summary5 === void 0 ? void 0 : _viewModel$summary5.totalAmount) !== null && _ref2 !== void 0 ? _ref2 : (_viewModel$summary6 = viewModel.summary) === null || _viewModel$summary6 === void 0 ? void 0 : _viewModel$summary6.payable_amount) !== null && _ref !== void 0 ? _ref : 0;
    var parsedAmount = Number(rawAmount);
    if (Number.isNaN(parsedAmount)) return '0.00';
    return parsedAmount.toFixed(2);
  }, [viewModel.summary]);

  /** 操作按钮文案：最后一步显示"立即支付"，其余步骤统一显示"下一步" */
  var actionText = useMemo(function () {
    return currentStep === 'checkout' ? String(locales.getText('pisell2.venue.action.pay.now') || '立即支付') : String(locales.getText('pisell2.venue.action.next') || '下一步');
  }, [currentStep]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "pisell-venue-booking-footer"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-venue-booking-footer-left"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-venue-booking-footer-total-label"
  }, locales.getText('pisell2.event.total') || '合计'), /*#__PURE__*/React.createElement("div", {
    className: "pisell-venue-booking-footer-total-amount"
  }, symbol, totalAmount)), /*#__PURE__*/React.createElement("div", {
    className: "pisell-venue-booking-footer-right"
  }, /*#__PURE__*/React.createElement(Badge, {
    count: ((_viewModel$cartItems = viewModel.cartItems) === null || _viewModel$cartItems === void 0 ? void 0 : _viewModel$cartItems.length) || 0,
    id: "venue-booking-cart-btn"
  }, /*#__PURE__*/React.createElement(Button, {
    size: "large",
    className: "pisell-venue-booking-footer-cart-btn",
    onClick: function onClick() {
      return setCartOpen(true);
    }
  }, /*#__PURE__*/React.createElement(Image, {
    src: shoppingCartSvg,
    preview: false
  }))), /*#__PURE__*/React.createElement(Button, {
    type: "primary",
    size: "large",
    className: "pisell-venue-booking-footer-btn",
    onClick: handlePrimaryAction,
    loading: isSubmittingOrder
  }, actionText))), /*#__PURE__*/React.createElement(Cart, {
    open: cartOpen,
    items: viewModel.cartItems || [],
    summary: viewModel.summary || {},
    onCancel: function onCancel() {
      return setCartOpen(false);
    },
    onNext: function onNext() {
      setCartOpen(false);
      handlePrimaryAction();
    },
    confirmLoading: isSubmittingOrder
  }));
}