import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import ButtonKDS from '../Buttons/ButtonKDS';
import { getElements } from '../utils/helperFunctions';
import { ButtonsWrapper } from './style';
import { useTranslation } from 'react-i18next';
const showProcessedButtons = (toDone) => toDone && toDone.length > 0;
const showDeliveredButton = (allDone, toDone) => allDone && allDone.length > 0 && toDone && toDone.length === 0;
const ButtonsContainer = (props) => {
    const { isZoomIn, setIsZoomIn, lines, callOrderApi, orderId, authProvider, kdsDeviceConfigs, viewMode } = props;
    const { toDone, allDone, toPrepare, toConfirm } = getElements(lines, kdsDeviceConfigs && kdsDeviceConfigs.KDS_STAGE_DONE
        ? kdsDeviceConfigs.KDS_STAGE_DONE
        : '');
    const { t } = useTranslation();
    const setOrderStatus = async (type, elements) => {
        try {
            const { token } = await authProvider();
            callOrderApi(orderId, type, token, elements, kdsDeviceConfigs && 'KDS_STAGE_DONE' in kdsDeviceConfigs
                ? kdsDeviceConfigs.KDS_STAGE_DONE
                : null);
        }
        catch (error) {
            console.warn(error);
        }
    };
    return (_jsxs(ButtonsWrapper, { children: [toConfirm.length > 0 && toPrepare.length === 0 && (_jsx(ButtonKDS, { small: viewMode === "2", text: t('OS.KDS.Card.Button.CancelPreparing'), callOrderApi: () => setOrderStatus('confirm', toConfirm) })), toPrepare.length > 0 && (_jsx(ButtonKDS, { small: viewMode === "2", text: t('OS.KDS.Card.Button.PrepareAll'), callOrderApi: () => setOrderStatus('prepare', toPrepare) })), showProcessedButtons(toDone) && (_jsxs(_Fragment, { children: [_jsx(ButtonKDS, { text: t('OS.KDS.Card.Button.DoneAll'), isIcon: true, small: viewMode === "2", callOrderApi: () => setOrderStatus('prepared', toDone) }), viewMode !== "2" && isZoomIn && (_jsx(ButtonKDS, { type: "white", text: t('OS.KDS.Card.Button.Minimize'), setIsZoomIn: setIsZoomIn, isZoomIn: isZoomIn })), viewMode !== "2" && !isZoomIn && ((_jsx(ButtonKDS, { type: "white", isIcon: true, text: t('OS.KDS.Card.Button.Enlarge'), setIsZoomIn: setIsZoomIn, isZoomIn: isZoomIn })))] })), showDeliveredButton(allDone, toDone) && (_jsx(ButtonKDS, { small: viewMode === "2", text: t('OS.KDS.Card.Button.Delivered'), type: "large", callOrderApi: () => setOrderStatus('deliver', []) }))] }));
};
export default ButtonsContainer;
//# sourceMappingURL=index.js.map