/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { useState, useCallback, useEffect } from 'react';
import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
import { loadTrustedFolders, TrustLevel, isWorkspaceTrusted, } from '../../config/trustedFolders.js';
import * as process from 'process';
export const useFolderTrust = (settings, config) => {
    const [isTrusted, setIsTrusted] = useState(config.isTrustedFolder());
    const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(config.isTrustedFolder() === undefined);
    const [isRestarting, setIsRestarting] = useState(false);
    // Folder trust feature flag removed - now using settings directly
    const { folderTrust } = settings.merged;
    useEffect(() => {
        const trusted = isWorkspaceTrusted({
            folderTrust,
        });
        setIsTrusted(trusted);
        if (trusted === undefined) {
            setIsFolderTrustDialogOpen(true);
        }
    }, [folderTrust]);
    const handleFolderTrustSelect = useCallback((choice) => {
        const trustedFolders = loadTrustedFolders();
        const cwd = process.cwd();
        let trustLevel;
        const wasTrusted = isTrusted ?? true;
        switch (choice) {
            case FolderTrustChoice.TRUST_FOLDER:
                trustLevel = TrustLevel.TRUST_FOLDER;
                break;
            case FolderTrustChoice.TRUST_PARENT:
                trustLevel = TrustLevel.TRUST_PARENT;
                break;
            case FolderTrustChoice.DO_NOT_TRUST:
                trustLevel = TrustLevel.DO_NOT_TRUST;
                break;
            default:
                return;
        }
        trustedFolders.setValue(cwd, trustLevel);
        const newIsTrusted = trustLevel === TrustLevel.TRUST_FOLDER ||
            trustLevel === TrustLevel.TRUST_PARENT;
        setIsTrusted(newIsTrusted);
        // Trust state is managed by trustedFolders and doesn't need to be set on config
        const needsRestart = wasTrusted !== newIsTrusted;
        if (needsRestart) {
            setIsRestarting(true);
            setIsFolderTrustDialogOpen(true);
        }
        else {
            setIsFolderTrustDialogOpen(false);
        }
    }, [isTrusted]);
    return {
        isFolderTrustDialogOpen,
        handleFolderTrustSelect,
        isRestarting,
    };
};
//# sourceMappingURL=useFolderTrust.js.map