import { jsx } from "react/jsx-runtime";
import { createContext, useContext, useMemo, useState } from "react";
import { createForm } from "@tachybase/schema";
import { FormProvider, SchemaComponent } from "../../../schema-component/index.mjs";
import { scopesSchema } from "./schemas/scopes.mjs";
const RolesResourcesScopesSelectedRowKeysContext = /*#__PURE__*/ createContext(null);
RolesResourcesScopesSelectedRowKeysContext.displayName = 'RolesResourcesScopesSelectedRowKeysContext';
const RolesResourcesScopesSelectedRowKeysProvider = (props)=>{
    const [keys, setKeys] = useState([]);
    return /*#__PURE__*/ jsx(RolesResourcesScopesSelectedRowKeysContext.Provider, {
        value: [
            keys,
            setKeys
        ],
        children: props.children
    });
};
const useRolesResourcesScopesSelectedRowKeys = ()=>useContext(RolesResourcesScopesSelectedRowKeysContext);
const ScopeSelect = (props)=>{
    const form = useMemo(()=>createForm({
            values: {
                scope: props.value
            }
        }), []);
    return /*#__PURE__*/ jsx(FormProvider, {
        form: form,
        children: /*#__PURE__*/ jsx(SchemaComponent, {
            components: {
                RolesResourcesScopesSelectedRowKeysProvider
            },
            scope: {
                onChange (value) {
                    var _props_onChange;
                    null == props || null == (_props_onChange = props.onChange) || _props_onChange.call(props, value);
                }
            },
            schema: scopesSchema
        })
    });
};
export { ScopeSelect, useRolesResourcesScopesSelectedRowKeys };
