import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useState } from "react";
import { useEditContext } from "../../client/editContext";
import { Card } from "../../../components/ui/card";
import { Button } from "../../../components/ui/button";
import { Settings, ExternalLink, RefreshCw } from "lucide-react";
/**
 * Settings panel for Parhelia System Settings.
 * Provides a link to open the settings item in the content editor.
 */
export function SettingsPanel() {
    const editContext = useEditContext();
    const [loading, setLoading] = useState(false);
    const [error, setError] = useState(null);
    const handleOpenSettings = useCallback(async () => {
        if (!editContext)
            return;
        try {
            setLoading(true);
            setError(null);
            const item = await editContext.loadItem("/sitecore/system/Parhelia/Settings");
            if (item) {
                editContext.switchWorkspace("editor");
            }
            else {
                setError("Failed to load Parhelia settings item: item not found");
            }
        }
        catch (err) {
            setError(err?.message || "Failed to load Parhelia settings item");
        }
        finally {
            setLoading(false);
        }
    }, [editContext]);
    return (_jsx("div", { className: "h-full overflow-auto p-4", children: _jsx("div", { className: "mx-auto", children: _jsx(Card, { icon: _jsx(Settings, { strokeWidth: 1, className: "h-5 w-5" }), title: "Parhelia System Settings", description: "Open and edit the Parhelia system settings item.", children: _jsxs("div", { className: "space-y-4", children: [_jsx("p", { className: "text-sm text-gray-600", children: "The Parhelia Settings item contains system-wide configuration options such as default languages, security settings, and integration options." }), _jsxs(Button, { onClick: handleOpenSettings, disabled: loading, className: "w-full", children: [loading ? (_jsx(RefreshCw, { strokeWidth: 1, className: "mr-2 h-4 w-4 animate-spin" })) : (_jsx(ExternalLink, { strokeWidth: 1, className: "mr-2 h-4 w-4" })), "Open Settings Item"] }), error && (_jsx("div", { className: "rounded border border-red-200 bg-red-50 p-2 text-xs whitespace-pre-wrap text-red-700", children: error }))] }) }) }) }));
}
export default SettingsPanel;
//# sourceMappingURL=SettingsPanel.js.map