"use strict";
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const binding_1 = require("../binding");
const assert_1 = require("../../assert");
const NativeRNRealm_1 = __importDefault(require("./NativeRNRealm"));
try {
    NativeRNRealm_1.default.injectModuleIntoJSGlobal();
    // Read the global into the local scope
    const { __injectedRealmBinding: nativeModule } = global;
    // Delete the global again
    delete global.__injectedRealmBinding;
    // Inject the native module into the binding
    assert_1.assert.object(nativeModule, "nativeModule");
    (0, binding_1.injectNativeModule)(nativeModule, {
        Int64: (global.HermesInternal ? binding_1.NativeBigInt : binding_1.PolyfilledBigInt),
        WeakRef: class WeakRef {
            native;
            constructor(obj) {
                // eslint-disable-next-line @typescript-eslint/no-explicit-any -- See "createWeakRef" protocol in the jsi bindgen template
                this.native = nativeModule.createWeakRef(obj);
            }
            deref() {
                // eslint-disable-next-line @typescript-eslint/no-explicit-any -- See "createWeakRef" protocol in the jsi bindgen template
                return nativeModule.lockWeakRef(this.native);
            }
        },
    });
}
catch (err) {
    throw new Error("Could not find the Realm binary. Please consult our troubleshooting guide: https://www.mongodb.com/docs/realm-sdks/js/latest/#md:troubleshooting-missing-binary");
}
//# sourceMappingURL=binding.js.map