var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
    var useValue = arguments.length > 2;
    for (var i = 0; i < initializers.length; i++) {
        value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
    }
    return useValue ? value : void 0;
};
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
    var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
    var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
    var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
    var _, done = false;
    for (var i = decorators.length - 1; i >= 0; i--) {
        var context = {};
        for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
        for (var p in contextIn.access) context.access[p] = contextIn.access[p];
        context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
        var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
        if (kind === "accessor") {
            if (result === void 0) continue;
            if (result === null || typeof result !== "object") throw new TypeError("Object expected");
            if (_ = accept(result.get)) descriptor.get = _;
            if (_ = accept(result.set)) descriptor.set = _;
            if (_ = accept(result.init)) initializers.unshift(_);
        }
        else if (_ = accept(result)) {
            if (kind === "field") initializers.unshift(_);
            else descriptor[key] = _;
        }
    }
    if (target) Object.defineProperty(target, contextIn.name, descriptor);
    done = true;
};
import * as plugins from '../plugins.js';
import * as paths from '../paths.js';
/**
 * DevTools controller for TypedServer
 * Handles /typedserver/devtools and /typedserver/reloadcheck endpoints
 */
let DevToolsController = (() => {
    let _classDecorators = [plugins.smartserve.Route('/typedserver')];
    let _classDescriptor;
    let _classExtraInitializers = [];
    let _classThis;
    let _instanceExtraInitializers = [];
    let _getDevtools_decorators;
    let _reloadCheck_decorators;
    var DevToolsController = class {
        static { _classThis = this; }
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
            _getDevtools_decorators = [plugins.smartserve.Get('/devtools')];
            _reloadCheck_decorators = [plugins.smartserve.Post('/reloadcheck')];
            __esDecorate(this, null, _getDevtools_decorators, { kind: "method", name: "getDevtools", static: false, private: false, access: { has: obj => "getDevtools" in obj, get: obj => obj.getDevtools }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _reloadCheck_decorators, { kind: "method", name: "reloadCheck", static: false, private: false, access: { has: obj => "reloadCheck" in obj, get: obj => obj.reloadCheck }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
            DevToolsController = _classThis = _classDescriptor.value;
            if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
            __runInitializers(_classThis, _classExtraInitializers);
        }
        getLastReload = __runInitializers(this, _instanceExtraInitializers);
        getEnded;
        constructor(options) {
            // Default no-op functions for when controller is auto-instantiated without options
            this.getLastReload = options?.getLastReload ?? (() => 0);
            this.getEnded = options?.getEnded ?? (() => false);
        }
        async getDevtools(ctx) {
            const devtoolsContent = (await plugins.fsInstance
                .file(paths.injectBundlePath)
                .encoding('utf8')
                .read());
            return new Response(devtoolsContent, {
                status: 200,
                headers: {
                    'Content-Type': 'text/javascript',
                },
            });
        }
        async reloadCheck(ctx) {
            console.log('got request for reloadcheck');
            if (this.getEnded()) {
                return new Response('end', {
                    status: 200,
                    headers: {
                        'Content-Type': 'text/plain',
                    },
                });
            }
            return new Response(this.getLastReload().toString(), {
                status: 200,
                headers: {
                    'Content-Type': 'text/plain',
                },
            });
        }
    };
    return DevToolsController = _classThis;
})();
export { DevToolsController };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29udHJvbGxlci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