
import { __decorate, __param } from '../../../../../../external/tslib/tslib.es6.js';
import { isHotReloadEnabled } from '../../../base/common/hotReload.js';
import '../../../base/common/observableInternal/index.js';
import { IInstantiationService } from '../../instantiation/common/instantiation.js';
import { autorunWithStore } from '../../../base/common/observableInternal/autorun.js';

function hotClassGetOriginalInstance(value) {
    if (value instanceof BaseClass) {
        return value._instance;
    }
    return value;
}
class BaseClass {
    constructor(instantiationService) {
        this.instantiationService = instantiationService;
    }
    init(...params) { }
}
function createWrapper(clazz, B) {
    return (class ReloadableWrapper extends B {
        constructor() {
            super(...arguments);
            this._autorun = undefined;
        }
        init(...params) {
            this._autorun = autorunWithStore((reader, store) => {
                const clazz_ = clazz.read(reader);
                this._instance = store.add(this.instantiationService.createInstance(clazz_, ...params));
            });
        }
        dispose() {
            this._autorun?.dispose();
        }
    });
}
function wrapInHotClass1(clazz) {
    return !isHotReloadEnabled() ? clazz.get() : createWrapper(clazz, BaseClass1);
}
let BaseClass1 = class BaseClass1 extends BaseClass {
    constructor(param1, i) { super(i); this.init(param1); }
};
BaseClass1 = ( __decorate([
    ( __param(1, IInstantiationService))
], BaseClass1));

export { hotClassGetOriginalInstance, wrapInHotClass1 };
