function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import { PisellModal, Icon, PisellToast } from '@pisell/materials';
import { locales } from '@pisell/utils';
import CustomerCard from "../CustomerCard";
import CupInfoCard from "../CupInfoCard";
import "./index.less";
import { ECupActionType } from "../../types";
import { useCupAction } from "./hooks";
var CupActionModal = function CupActionModal(props) {
  var _cupData$rent_shop;
  var visible = props.visible,
    onCancel = props.onCancel,
    onOk = props.onOk,
    data = props.data;
  var _ref = data || {},
    type = _ref.type,
    cupData = _ref.cupData;
  var cupAction = useCupAction();
  var style = useMemo(function () {
    if ((data === null || data === void 0 ? void 0 : data.type) === ECupActionType.MISSING || (data === null || data === void 0 ? void 0 : data.type) === ECupActionType.BROKEN) {
      return {
        backgroundColor: '#FEE4E2',
        color: '#F04438'
      };
    }
    return {
      backgroundColor: '#F6F2FF',
      color: '#7F56DA'
    };
  }, [data === null || data === void 0 ? void 0 : data.type]);
  var _onCancel = function _onCancel() {
    if (cupAction !== null && cupAction !== void 0 && cupAction.loading) return;
    onCancel === null || onCancel === void 0 || onCancel();
  };
  var _onOk = function _onOk() {
    if (cupAction !== null && cupAction !== void 0 && cupAction.loading) return;
    cupAction.run((cupData === null || cupData === void 0 ? void 0 : cupData.eco_cup_id) || (cupData === null || cupData === void 0 ? void 0 : cupData.id), type).then(function (res) {
      if (res) {
        PisellToast({
          content: locales.getText("pisell2.text.ecocup.toast.success-".concat(type))
        });
        onOk === null || onOk === void 0 || onOk(cupData);
      }
    });
  };
  return /*#__PURE__*/React.createElement(PisellModal, {
    open: visible,
    headerDivider: false,
    title: locales.getText("pisell2.text.ecocup.cup-action-modal.title-".concat(data === null || data === void 0 ? void 0 : data.type)),
    onCancel: _onCancel,
    onOk: _onOk,
    okText: locales.getText("pisell2.text.ecocup.button.mark-as-".concat(data === null || data === void 0 ? void 0 : data.type)),
    cancelText: locales.getText('pisell2.text.ecocup.button.cancel'),
    okButtonProps: {
      loading: cupAction === null || cupAction === void 0 ? void 0 : cupAction.loading
    },
    width: 580,
    destroyOnClose: true,
    wrapClassName: "pisell2-ecocup-cup-action-modal"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell2-ecocup-cup-action-modal-content"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell2-ecocup-cup-action-modal-content-cup",
    style: _objectSpread({}, style)
  }, /*#__PURE__*/React.createElement(Icon, {
    type: "RestOutlined",
    size: 24
  }), /*#__PURE__*/React.createElement("span", {
    style: {
      color: (data === null || data === void 0 ? void 0 : data.type) === ECupActionType.RETURN ? '#667085' : '#F04438'
    }
  }, locales.getText('pisell2.text.ecocup.cup-action-modal.cup-id')), /*#__PURE__*/React.createElement("span", null, (cupData === null || cupData === void 0 ? void 0 : cupData.eco_cup_code) || (cupData === null || cupData === void 0 ? void 0 : cupData.code) || '')), /*#__PURE__*/React.createElement("div", {
    className: "pisell2-ecocup-cup-action-modal-info"
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell2-ecocup-cup-action-modal-info-left"
  }, /*#__PURE__*/React.createElement(CupInfoCard, {
    type: "rentInfo",
    data: {
      shop: cupData === null || cupData === void 0 || (_cupData$rent_shop = cupData.rent_shop) === null || _cupData$rent_shop === void 0 ? void 0 : _cupData$rent_shop.name,
      time: cupData === null || cupData === void 0 ? void 0 : cupData.rent_time
    }
  })), /*#__PURE__*/React.createElement("div", {
    className: "pisell2-ecocup-cup-action-modal-info-right"
  }, /*#__PURE__*/React.createElement(CustomerCard, data === null || data === void 0 ? void 0 : data.customerData)))));
};
export default CupActionModal;