import { getIsEdit } from "../../../utils.js";
import { Context } from "../../model.js";
import { isUsableProduct } from "../addTimeModal/utils.js";
import React, { useContext, useMemo } from "react";
import { Button } from "antd";
import { locales } from "@pisell/utils";
import "./index.less";
//#region src/components/booking/info/service/actions/index.tsx
const Actions = ({ currentService }) => {
	var _state$bookingConfig2;
	const { state, dispatch } = useContext(Context);
	const appointment_card = useMemo(() => {
		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]);
	const onAddTime = () => {
		dispatch({
			type: "setService",
			payload: {
				addTimeModal: true,
				cacheItem: currentService
			}
		});
	};
	const addTimeProducts = useMemo(() => {
		return (state.addTimeProducts || []).some((item) => isUsableProduct(item.add_time, currentService));
	}, [state.addTimeProducts, currentService]);
	const showAddTimeButton = useMemo(() => {
		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: (e) => {
			e.preventDefault();
			e.stopPropagation();
			onAddTime();
		}
	}, locales.getText("page.booking.text.add-time")));
};
//#endregion
export { Actions as default };
