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, { useMemo, useState } from 'react';
import { Badge, Button, Image } from '@pisell/materials';
import { locales } from '@pisell/utils';
import Cart from "../Cart";
import shoppingCartSvg from "../../../appointmentBooking/assets/shopping-cart.svg";
import "./index.less";
export default function Footer(props) {
  var cartItems = props.cartItems,
    summary = props.summary,
    actionText = props.actionText,
    onAction = props.onAction,
    _props$disabled = props.disabled,
    disabled = _props$disabled === void 0 ? false : _props$disabled;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    cartOpen = _useState2[0],
    setCartOpen = _useState2[1];
  var totalAmount = useMemo(function () {
    var _ref, _ref2, _ref3, _ref4, _ref5, _summary$total_amount;
    var rawAmount = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_summary$total_amount = summary === null || summary === void 0 ? void 0 : summary.total_amount) !== null && _summary$total_amount !== void 0 ? _summary$total_amount : summary === null || summary === void 0 ? void 0 : summary.expect_amount) !== null && _ref5 !== void 0 ? _ref5 : summary === null || summary === void 0 ? void 0 : summary.amount) !== null && _ref4 !== void 0 ? _ref4 : summary === null || summary === void 0 ? void 0 : summary.total) !== null && _ref3 !== void 0 ? _ref3 : summary === null || summary === void 0 ? void 0 : summary.totalAmount) !== null && _ref2 !== void 0 ? _ref2 : summary === null || summary === void 0 ? void 0 : summary.payable_amount) !== null && _ref !== void 0 ? _ref : 0;
    var parsedAmount = Number(rawAmount);
    if (Number.isNaN(parsedAmount)) return '0.00';
    return parsedAmount.toFixed(2);
  }, [summary]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "pisell-scan-order-footer"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-scan-order-footer-left"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-scan-order-footer-total-label"
  }, locales.getText('pisell2.event.total')), /*#__PURE__*/React.createElement("div", {
    className: "pisell-scan-order-footer-total-amount"
  }, "$", totalAmount)), /*#__PURE__*/React.createElement("div", {
    className: "pisell-scan-order-footer-right"
  }, /*#__PURE__*/React.createElement(Badge, {
    count: (cartItems === null || cartItems === void 0 ? void 0 : cartItems.length) || 0,
    id: "scan-order-v2-cart-btn"
  }, /*#__PURE__*/React.createElement(Button, {
    size: "large",
    className: "pisell-scan-order-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-scan-order-footer-btn".concat(disabled ? ' pisell-scan-order-footer-btn-disabled' : ''),
    onClick: onAction
  }, actionText))), /*#__PURE__*/React.createElement(Cart, {
    open: cartOpen,
    items: cartItems || [],
    summary: summary || {},
    onCancel: function onCancel() {
      setCartOpen(false);
    },
    onNext: function onNext() {
      setCartOpen(false);
      onAction();
    }
  }));
}