"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DrupalBridge = DrupalBridge;
exports.useDrupalSettings = useDrupalSettings;
exports.useDrupalApi = useDrupalApi;
exports.useDrupalUser = useDrupalUser;
const jsx_runtime_1 = require("react/jsx-runtime");
/**
 * @file
 * Drupal Bridge Component
 *
 * Provides integration between React components and Drupal's
 * server-side rendering and configuration system.
 */
const react_1 = require("react");
const DrupalContext = (0, react_1.createContext)({});
/**
 * Drupal Bridge Provider Component
 *
 * Wraps React components with Drupal-specific context and configuration.
 * This allows components to access Drupal settings, user information,
 * and API endpoints seamlessly.
 */
function DrupalBridge({ children, settings }) {
    return ((0, jsx_runtime_1.jsx)(DrupalContext.Provider, { value: settings, children: children }));
}
/**
 * Hook to access Drupal settings from React components
 */
function useDrupalSettings() {
    return (0, react_1.useContext)(DrupalContext);
}
/**
 * Hook to get API configuration for Drupal integration
 */
function useDrupalApi() {
    const settings = useDrupalSettings();
    return {
        baseUrl: settings.path?.baseUrl || '',
        apiEndpoint: settings.llmUi?.apiEndpoint || '/api/llm',
        csrfToken: settings.llmUi?.csrfToken || '',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-Token': settings.llmUi?.csrfToken || '',
        },
    };
}
/**
 * Hook to access current Drupal user information
 */
function useDrupalUser() {
    const settings = useDrupalSettings();
    return {
        uid: settings.user?.uid || '0',
        name: settings.user?.name || 'Anonymous',
        roles: settings.user?.roles || ['anonymous'],
        isAuthenticated: settings.user?.uid !== '0',
        hasRole: (role) => settings.user?.roles?.includes(role) || false,
    };
}
//# sourceMappingURL=DrupalBridge.js.map