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, useContext } from 'react';
import { Context } from "../../model";
import { Button } from 'antd';
import { getIsEdit } from "../../../utils";
import { isUsableProduct } from "../addTimeModal/utils";
import { getProductExtend } from "../../../info2/service/addService/utils";
import "./index.less";
import { locales } from '@pisell/utils';
var Actions = function Actions(_ref) {
  var _state$bookingConfig2;
  var currentService = _ref.currentService;
  var _useContext = useContext(Context),
    state = _useContext.state,
    dispatch = _useContext.dispatch;
  var appointment_card = useMemo(function () {
    var _state$bookingConfig;
    return (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.information_tab) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_card) || {
      quick_time: 1
    };
  }, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.information_tab]);
  var onAddTime = function onAddTime() {
    var cacheItem = getProductExtend({
      cacheItem: _objectSpread(_objectSpread({}, currentService), {}, {
        new: 0
      }),
      state: state
    });
    dispatch({
      type: 'setService',
      payload: {
        addTimeModal: true,
        cacheItem: cacheItem
      }
    });
  };
  var addTimeProducts = useMemo(function () {
    return (state.addTimeProducts || []).some(function (item) {
      return isUsableProduct(item.add_time, currentService);
    });
  }, [state.addTimeProducts, currentService]);
  var showAddTimeButton = useMemo(function () {
    if (state.renderType === 'eventBooking') {
      return false;
    }
    if (state.disabledEdit) {
      return false;
    }
    if (appointment_card.quick_time !== 1) {
      return false;
    }
    if (getIsEdit(state)) {
      return false;
    }
    if (!addTimeProducts) {
      return false;
    }
    return true;
  }, [state, appointment_card.quick_time, addTimeProducts]);
  return /*#__PURE__*/React.createElement("div", {
    className: "actions-wrap"
  }, showAddTimeButton && /*#__PURE__*/React.createElement(Button, {
    className: "action-item",
    size: "large",
    onClick: function onClick(e) {
      e.preventDefault();
      e.stopPropagation();
      onAddTime();
    }
  }, locales.getText('page.booking.text.add-time')));
};
export default Actions;