"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    buildLlmConfigurationsUrl: ()=>buildLlmConfigurationsUrl,
    platformNavigation: ()=>platformNavigation,
    useUserFolders: ()=>useUserFolders,
    useCanManageByo: ()=>useCanManageByo
});
const external_react_namespaceObject = require("react");
const FOLDERS_PAGE_SIZE = 100;
function useUserFolders(ctx) {
    const [folders, setFolders] = (0, external_react_namespaceObject.useState)([]);
    const [loading, setLoading] = (0, external_react_namespaceObject.useState)(false);
    const [error, setError] = (0, external_react_namespaceObject.useState)(null);
    const abortRef = (0, external_react_namespaceObject.useRef)(null);
    const fetchFolders = (0, external_react_namespaceObject.useCallback)(async ()=>{
        if (!ctx) return;
        abortRef.current?.abort();
        const ctrl = new AbortController();
        abortRef.current = ctrl;
        setLoading(true);
        setError(null);
        const base = (ctx.baseUrl ?? '').replace(/\/$/, '');
        const url = `${base}/${ctx.tenantName}/orchestrator_/api/FoldersNavigation/GetFoldersForCurrentUser?take=${FOLDERS_PAGE_SIZE}`;
        try {
            const res = await fetch(url, {
                headers: {
                    Authorization: `Bearer ${ctx.token}`,
                    Accept: 'application/json'
                },
                signal: ctrl.signal
            });
            if (!res.ok) throw new Error(`FoldersNavigation API ${res.status} ${res.statusText}`);
            const data = await res.json();
            if (!ctrl.signal.aborted) setFolders((data.PageItems ?? []).map((f)=>({
                    id: f.Key,
                    label: f.DisplayName,
                    numericId: f.Id
                })));
        } catch (err) {
            if (err?.name === 'AbortError') return;
            if (!ctrl.signal.aborted) setError(err instanceof Error ? err : new Error(String(err)));
        } finally{
            if (!ctrl.signal.aborted) setLoading(false);
        }
    }, [
        ctx
    ]);
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (!ctx) {
            abortRef.current?.abort();
            setFolders([]);
            setLoading(false);
            setError(null);
            return;
        }
        fetchFolders();
        return ()=>abortRef.current?.abort();
    }, [
        ctx,
        fetchFolders
    ]);
    return {
        folders,
        loading,
        error,
        refetch: fetchFolders
    };
}
const ORG_ADMIN_ROLES = [
    'ACCOUNT_ADMIN',
    'ACCOUNT_OWNER'
];
function useCanManageByo(ctx) {
    const [canManage, setCanManage] = (0, external_react_namespaceObject.useState)(void 0);
    const [loading, setLoading] = (0, external_react_namespaceObject.useState)(false);
    const [error, setError] = (0, external_react_namespaceObject.useState)(null);
    const abortRef = (0, external_react_namespaceObject.useRef)(null);
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (!ctx) {
            abortRef.current?.abort();
            setCanManage(void 0);
            setLoading(false);
            setError(null);
            return;
        }
        abortRef.current?.abort();
        const ctrl = new AbortController();
        abortRef.current = ctrl;
        setCanManage(void 0);
        setLoading(true);
        setError(null);
        const base = (ctx.baseUrl ?? '').replace(/\/$/, '');
        const url = `${base}/portal_/api/organization/UserOrganizationInfo`;
        fetch(url, {
            headers: {
                Authorization: `Bearer ${ctx.token}`,
                Accept: 'application/json'
            },
            signal: ctrl.signal
        }).then(async (res)=>{
            if (!res.ok) throw new Error(`UserOrganizationInfo API ${res.status} ${res.statusText}`);
            const data = await res.json();
            if (!ctrl.signal.aborted) setCanManage(ORG_ADMIN_ROLES.includes(data.accountRoleType ?? ''));
        }).catch((err)=>{
            if (err?.name === 'AbortError') return;
            if (!ctrl.signal.aborted) {
                setError(err instanceof Error ? err : new Error(String(err)));
                setCanManage(false);
            }
        }).finally(()=>{
            if (!ctrl.signal.aborted) setLoading(false);
        });
        return ()=>ctrl.abort();
    }, [
        ctx
    ]);
    return {
        canManage,
        loading,
        error
    };
}
function buildLlmConfigurationsUrl(ctx, options) {
    const base = (ctx.baseUrl ?? '').replace(/\/$/, '');
    const root = `${base}/portal_/admin/ai-trust-layer/llm-configurations`;
    const { intent, folderNumericId, configurationId } = options;
    if (ctx.tenantId && null != folderNumericId) {
        if ('edit' === intent && configurationId) return `${root}/${ctx.tenantId}/${folderNumericId}/edit/${encodeURIComponent(configurationId)}`;
        if ('add' === intent) {
            const params = new URLSearchParams();
            if (ctx.requestingProduct) params.set('product', ctx.requestingProduct);
            if (ctx.requestingFeature) params.set('feature', ctx.requestingFeature);
            const qs = params.toString();
            return `${root}/${ctx.tenantId}/${folderNumericId}/add${qs ? `?${qs}` : ''}`;
        }
    }
    const params = new URLSearchParams();
    if (ctx.tenantId) params.set('tenantId', ctx.tenantId);
    if (null != folderNumericId) params.set('folderId', String(folderNumericId));
    const qs = params.toString();
    return `${root}${qs ? `?${qs}` : ''}`;
}
const platformNavigation = {
    assign (url) {
        globalThis.location?.assign(url);
    }
};
exports.buildLlmConfigurationsUrl = __webpack_exports__.buildLlmConfigurationsUrl;
exports.platformNavigation = __webpack_exports__.platformNavigation;
exports.useCanManageByo = __webpack_exports__.useCanManageByo;
exports.useUserFolders = __webpack_exports__.useUserFolders;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "buildLlmConfigurationsUrl",
    "platformNavigation",
    "useCanManageByo",
    "useUserFolders"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
