import { jsx } from "react/jsx-runtime";
import { createContext, useContext } from "react";
import { useCollection_deprecated } from "../collection-manager/index.mjs";
import { CollectionRecordProvider } from "../data-source/index.mjs";
import { useCurrentUserContext } from "../user/index.mjs";
const RecordContext_deprecated = /*#__PURE__*/ createContext({});
RecordContext_deprecated.displayName = 'RecordContext_deprecated';
const RecordIndexContext = /*#__PURE__*/ createContext(null);
RecordIndexContext.displayName = 'RecordIndexContext';
const RecordProvider = (props)=>{
    const { record, children, parent, isNew } = props;
    const { name: __collectionName } = useCollection_deprecated();
    const value = {
        ...record
    };
    value['__parent'] = parent;
    value['__collectionName'] = __collectionName;
    return /*#__PURE__*/ jsx(RecordContext_deprecated.Provider, {
        value: value,
        children: /*#__PURE__*/ jsx(CollectionRecordProvider, {
            isNew: isNew,
            record: record,
            parentRecord: parent,
            children: children
        })
    });
};
const RecordSimpleProvider = (props)=>/*#__PURE__*/ jsx(RecordContext_deprecated.Provider, {
        ...props
    });
const RecordIndexProvider = (props)=>{
    const { index, children } = props;
    return /*#__PURE__*/ jsx(RecordIndexContext.Provider, {
        value: index,
        children: children
    });
};
function useRecord() {
    return useContext(RecordContext_deprecated);
}
function useRecordIndex() {
    return useContext(RecordIndexContext);
}
const useRecordIsOwn = ()=>{
    var _ctx_data_data, _ctx_data;
    const record = useRecord();
    const ctx = useCurrentUserContext();
    if (!(null == record ? void 0 : record.createdById)) return false;
    return (null == record ? void 0 : record.createdById) === (null == ctx ? void 0 : null == (_ctx_data = ctx.data) ? void 0 : null == (_ctx_data_data = _ctx_data.data) ? void 0 : _ctx_data_data.id);
};
export { RecordContext_deprecated, RecordIndexContext, RecordIndexProvider, RecordProvider, RecordSimpleProvider, useRecord, useRecordIndex, useRecordIsOwn };
