"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAlerts = exports.AlertsContextProvider = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const reducers_1 = require("../reducers");
const use_translation_wrapper_1 = require("../../common/hooks/use-translation-wrapper");
const { addAlert: addAlertAction, removeAlert: removeAlertAction, clearAlerts: clearAlertsAction, } = reducers_1.alertsSlice.actions;
const alertsReducer = reducers_1.alertsSlice.reducer;
const AlertsContext = react_1.default.createContext(null);
const AlertsContextProvider = ({ children }) => {
    const [alerts, dispatch] = react_1.default.useReducer(alertsReducer, []);
    const context = {
        alerts,
        addAlert: react_1.default.useCallback((alert) => dispatch(addAlertAction(alert)), []),
        removeAlert: react_1.default.useCallback((alertKey) => dispatch(removeAlertAction(alertKey)), []),
        clearAlerts: react_1.default.useCallback(() => dispatch(clearAlertsAction()), []),
    };
    return react_1.default.createElement(AlertsContext.Provider, { value: context }, children);
};
exports.AlertsContextProvider = AlertsContextProvider;
const useAlerts = () => {
    const context = react_1.default.useContext(AlertsContext);
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    if (!context) {
        throw new Error(t('ai:useAlerts must be used within AlertsContextProvider'));
    }
    return context;
};
exports.useAlerts = useAlerts;
//# sourceMappingURL=AlertsContextProvider.js.map