var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { GrowthBookProvider } from '@growthbook/growthbook-react';
import selfless from '@komi-app/selfless';
import { init } from './flags.js';
export const useFeatureProvider = ({ children, context }) => {
    const [gb, setGb] = useState();
    function setup() {
        return __awaiter(this, void 0, void 0, function* () {
            if (gb)
                return;
            const instance = yield init(context);
            setGb(instance);
        });
    }
    useEffect(() => void setup(), []);
    return {
        children,
        gb
    };
};
export const FeatureProviderView = ({ children, gb }) => (_jsx(GrowthBookProvider, { growthbook: gb, children: children }));
export default selfless(FeatureProviderView, useFeatureProvider);
