// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { useMemo } from 'react';
import { useLocale } from '../../localization';
/**
 * @internal
 */
export const useLocalSpotlightCallbacksWithPrompt = (onStartLocalSpotlight, onStopLocalSpotlight, setIsPromptOpen, setPromptProps) => {
    const strings = useLocale().strings.call;
    return useMemo(() => {
        if (!setIsPromptOpen || !setPromptProps) {
            return {
                onStartLocalSpotlightWithPrompt: onStartLocalSpotlight,
                onStopLocalSpotlightWithPrompt: onStopLocalSpotlight
            };
        }
        return {
            onStartLocalSpotlightWithPrompt: onStartLocalSpotlight ? getStartLocalSpotlightWithPromptCallback(onStartLocalSpotlight, setIsPromptOpen, setPromptProps, strings) : undefined,
            onStopLocalSpotlightWithPrompt: onStopLocalSpotlight ? getStopLocalSpotlightWithPromptCallback(onStopLocalSpotlight, setIsPromptOpen, setPromptProps, strings) : undefined
        };
    }, [onStartLocalSpotlight, onStopLocalSpotlight, setIsPromptOpen, setPromptProps, strings]);
};
const getStartLocalSpotlightWithPromptCallback = (onStartSpotlight, setIsPromptOpen, setPromptProps, strings) => {
    return () => __awaiter(void 0, void 0, void 0, function* () {
        setPromptProps({
            heading: strings.spotlightPrompt.startSpotlightHeading,
            text: strings.spotlightPrompt.startSpotlightOnSelfText,
            confirmButtonLabel: strings.spotlightPrompt.startSpotlightConfirmButtonLabel,
            cancelButtonLabel: strings.spotlightPrompt.startSpotlightCancelButtonLabel,
            closeButtonLabel: strings.spotlightPrompt.closeSpotlightPromptButtonLabel,
            onConfirm: () => {
                onStartSpotlight();
                setIsPromptOpen(false);
            },
            onCancel: () => setIsPromptOpen(false)
        });
        setIsPromptOpen(true);
    });
};
const getStopLocalSpotlightWithPromptCallback = (onStopSpotlight, setIsPromptOpen, setPromptProps, strings) => {
    return () => __awaiter(void 0, void 0, void 0, function* () {
        setPromptProps({
            heading: strings.spotlightPrompt.stopSpotlightOnSelfHeading,
            text: strings.spotlightPrompt.stopSpotlightOnSelfText,
            confirmButtonLabel: strings.spotlightPrompt.stopSpotlightOnSelfConfirmButtonLabel,
            cancelButtonLabel: strings.spotlightPrompt.stopSpotlightCancelButtonLabel,
            onConfirm: () => {
                onStopSpotlight();
                setIsPromptOpen(false);
            },
            onCancel: () => setIsPromptOpen(false)
        });
        setIsPromptOpen(true);
    });
};
/**
 * @internal
 */
export const useRemoteSpotlightCallbacksWithPrompt = (onStartRemoteSpotlight, onStopRemoteSpotlight, setIsPromptOpen, setPromptProps) => {
    const strings = useLocale().strings.call;
    return useMemo(() => {
        if (!setIsPromptOpen || !setPromptProps) {
            return {
                onStartRemoteSpotlightWithPrompt: onStartRemoteSpotlight,
                onStopRemoteSpotlightWithPrompt: onStopRemoteSpotlight
            };
        }
        return {
            onStartRemoteSpotlightWithPrompt: onStartRemoteSpotlight ? getStartRemoteSpotlightWithPromptCallback(onStartRemoteSpotlight, setIsPromptOpen, setPromptProps, strings) : undefined,
            onStopRemoteSpotlightWithPrompt: onStopRemoteSpotlight ? getStopRemoteSpotlightWithPromptCallback(onStopRemoteSpotlight, setIsPromptOpen, setPromptProps, strings) : undefined
        };
    }, [onStartRemoteSpotlight, onStopRemoteSpotlight, setIsPromptOpen, setPromptProps, strings]);
};
const getStartRemoteSpotlightWithPromptCallback = (onStartSpotlight, setIsPromptOpen, setPromptProps, strings) => {
    return (userIds) => __awaiter(void 0, void 0, void 0, function* () {
        if (userIds.length > 1) {
            onStartSpotlight(userIds);
        }
        setPromptProps({
            heading: strings.spotlightPrompt.startSpotlightHeading,
            text: strings.spotlightPrompt.startSpotlightText,
            confirmButtonLabel: strings.spotlightPrompt.startSpotlightConfirmButtonLabel,
            cancelButtonLabel: strings.spotlightPrompt.startSpotlightCancelButtonLabel,
            closeButtonLabel: strings.spotlightPrompt.closeSpotlightPromptButtonLabel,
            onConfirm: () => {
                onStartSpotlight(userIds);
                setIsPromptOpen(false);
            },
            onCancel: () => setIsPromptOpen(false)
        });
        setIsPromptOpen(true);
    });
};
const getStopRemoteSpotlightWithPromptCallback = (onStopSpotlight, setIsPromptOpen, setPromptProps, strings) => {
    return (userIds) => __awaiter(void 0, void 0, void 0, function* () {
        if (userIds.length > 1) {
            onStopSpotlight(userIds);
        }
        setPromptProps({
            heading: strings.spotlightPrompt.stopSpotlightHeading,
            text: strings.spotlightPrompt.stopSpotlightText,
            confirmButtonLabel: strings.spotlightPrompt.stopSpotlightConfirmButtonLabel,
            cancelButtonLabel: strings.spotlightPrompt.stopSpotlightCancelButtonLabel,
            closeButtonLabel: strings.spotlightPrompt.closeSpotlightPromptButtonLabel,
            onConfirm: () => {
                onStopSpotlight(userIds);
                setIsPromptOpen(false);
            },
            onCancel: () => setIsPromptOpen(false)
        });
        setIsPromptOpen(true);
    });
};
/**
 * @internal
 */
export const useStopAllSpotlightCallbackWithPrompt = (stopAllSpotlight, setIsPromptOpen, setPromptProps) => {
    const strings = useLocale().strings.call;
    return useMemo(() => {
        if (!setIsPromptOpen || !setPromptProps) {
            return {
                stopAllSpotlightWithPrompt: stopAllSpotlight
            };
        }
        return {
            stopAllSpotlightWithPrompt: stopAllSpotlight ? getStopAllSpotlightCallbackWithPromptCallback(stopAllSpotlight, setIsPromptOpen, setPromptProps, strings) : undefined
        };
    }, [stopAllSpotlight, setIsPromptOpen, setPromptProps, strings]);
};
const getStopAllSpotlightCallbackWithPromptCallback = (stopAllSpotlight, setIsPromptOpen, setPromptProps, strings) => {
    return () => __awaiter(void 0, void 0, void 0, function* () {
        setPromptProps({
            heading: strings.spotlightPrompt.stopAllSpotlightHeading,
            text: strings.spotlightPrompt.stopAllSpotlightText,
            confirmButtonLabel: strings.spotlightPrompt.stopSpotlightConfirmButtonLabel,
            cancelButtonLabel: strings.spotlightPrompt.stopSpotlightCancelButtonLabel,
            closeButtonLabel: strings.spotlightPrompt.closeSpotlightPromptButtonLabel,
            onConfirm: () => {
                stopAllSpotlight();
                setIsPromptOpen(false);
            },
            onCancel: () => setIsPromptOpen(false)
        });
        setIsPromptOpen(true);
    });
};
//# sourceMappingURL=spotlightUtils.js.map