import { jsx } from "react/jsx-runtime";
import "react";
import { useAPIClient, useRequest } from "../api-client/index.mjs";
import { CollectionManagerProvider } from "../data-source/collection/CollectionManagerProvider.mjs";
import { useDataSourceManager } from "../data-source/data-source/DataSourceManagerProvider.mjs";
import { useCollectionHistory } from "./CollectionHistoryProvider.mjs";
import { CollectionManagerSchemaComponentProvider } from "./CollectionManagerSchemaComponentProvider.mjs";
import { CollectionCategroriesContext } from "./context.mjs";
const CollectionManagerProvider_deprecated = (props)=>/*#__PURE__*/ jsx(CollectionManagerProvider, {
        children: /*#__PURE__*/ jsx(CollectionManagerSchemaComponentProvider, {
            children: props.children
        })
    });
const RemoteCollectionManagerProvider = (props)=>{
    const api = useAPIClient();
    const dm = useDataSourceManager();
    const { refreshCH } = useCollectionHistory();
    const coptions = {
        url: 'collectionCategories:list',
        params: {
            paginate: false,
            sort: [
                'sort'
            ]
        }
    };
    const service = useRequest(()=>dm.reload().then(refreshCH));
    const result = useRequest(coptions);
    if (service.loading) return;
    const refreshCategory = async ()=>{
        const { data } = await api.request(coptions);
        result.mutate(data);
        return (null == data ? void 0 : data.data) || [];
    };
    return /*#__PURE__*/ jsx(CollectionCategroriesProvider, {
        service: {
            ...result
        },
        refreshCategory: refreshCategory,
        children: /*#__PURE__*/ jsx(CollectionManagerProvider_deprecated, {
            ...props
        })
    });
};
const CollectionCategroriesProvider = (props)=>{
    var _service_data;
    const { service, refreshCategory } = props;
    return /*#__PURE__*/ jsx(CollectionCategroriesContext.Provider, {
        value: {
            data: null == service ? void 0 : null == (_service_data = service.data) ? void 0 : _service_data.data,
            refresh: refreshCategory,
            ...props
        },
        children: props.children
    });
};
export { CollectionCategroriesProvider, CollectionManagerProvider_deprecated, RemoteCollectionManagerProvider };
