import { GUI } from "dat.gui";
var PlayerConfig = /** @class */ (function () {
    function PlayerConfig(player) {
        this.player = player;
    }
    ;
    Object.defineProperty(PlayerConfig.prototype, "frameRate", {
        get: function () {
            return this.player.fps.value;
        },
        set: function (_) { },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "drawFrames", {
        get: function () {
            return this.player.runtime.fps;
        },
        set: function (_) { },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "drawCall", {
        get: function () {
            return this.player.runtime.drawCall;
        },
        set: function (_) { },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "resolution", {
        get: function () {
            return this.player.config.resolution;
        },
        set: function (value) {
            this.player.updateConfig({ resolution: value });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "size", {
        get: function () {
            var _a, _b;
            return "".concat((_a = this.player.view) === null || _a === void 0 ? void 0 : _a.width, "*").concat((_b = this.player.view) === null || _b === void 0 ? void 0 : _b.height);
        },
        set: function (_) { },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "minFPS", {
        get: function () {
            return this.player.config.minFPS;
        },
        set: function (value) {
            this.player.updateConfig({ minFPS: value, maxFPS: this.player.config.maxFPS });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "maxFPS", {
        get: function () {
            return this.player.config.maxFPS;
        },
        set: function (value) {
            this.player.updateConfig({ maxFPS: value, minFPS: this.player.config.minFPS });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "autoResolution", {
        get: function () {
            return this.player.config.autoResolution;
        },
        set: function (value) {
            this.player.updateConfig({ autoResolution: value });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "autoFPS", {
        get: function () {
            return this.player.config.autoFPS;
        },
        set: function (value) {
            this.player.updateConfig({ autoFPS: value });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "backgroundColor", {
        get: function () {
            return this.player.config.transactionBgColor;
        },
        set: function (value) {
            this.player.updateConfig({ transactionBgColor: value });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PlayerConfig.prototype, "maxResolutionLevel", {
        get: function () {
            return this.player.config.maxResolutionLevel;
        },
        set: function (value) {
            this.player.updateConfig({ maxResolutionLevel: value });
        },
        enumerable: false,
        configurable: true
    });
    return PlayerConfig;
}());
export { PlayerConfig };
var PlayerController = /** @class */ (function () {
    function PlayerController(player, anchor) {
        var _a;
        this.config = new PlayerConfig(player);
        this.anchor = anchor;
        _a = this.createControllerGUI(), this.gui = _a[0], this.controller = _a[1];
        this.createStats();
    }
    PlayerController.prototype.createStats = function () {
        var _this = this;
        this.stateId = setInterval(function () {
            _this.controller.frameRate.updateDisplay();
            _this.controller.size.updateDisplay();
            _this.controller.minFPS.updateDisplay();
            _this.controller.drawFrames.updateDisplay();
            _this.controller.maxFPS.updateDisplay();
            _this.controller.resolution.updateDisplay();
            _this.controller.autoFps.updateDisplay();
            _this.controller.autoResolution.updateDisplay();
            _this.controller.drawCall.updateDisplay();
        }, 16);
    };
    PlayerController.prototype.createControllerGUI = function () {
        var gui = new GUI({
            autoPlace: true,
            closed: true,
        });
        gui.domElement.style.opacity = ".6";
        gui.domElement.style.transformOrigin = "100% 0";
        gui.domElement.style.transform = "scale(1)";
        this.anchor.appendChild(gui.domElement);
        gui.domElement.style.position = "absolute";
        gui.domElement.style.right = "0";
        gui.domElement.style.top = "0";
        gui.domElement.style.zIndex = "2";
        var controller = {
            frameRate: gui.add(this.config, "frameRate"),
            drawFrames: gui.add(this.config, "drawFrames"),
            drawCall: gui.add(this.config, "drawCall"),
            size: gui.add(this.config, "size"),
            minFPS: gui.add(this.config, "minFPS", 0, 60),
            maxFPS: gui.add(this.config, "maxFPS", 0, 60),
            resolution: gui.add(this.config, "resolution", 0.5, 8, 0.5),
            autoResolution: gui.add(this.config, "autoResolution"),
            autoFps: gui.add(this.config, "autoFPS"),
            maxResolutionLevel: gui.add(this.config, "maxResolutionLevel", 0, 4, 1),
            transactionBgColor: gui.addColor(this.config, "backgroundColor"),
        };
        return [gui, controller];
    };
    PlayerController.prototype.destroy = function () {
        try {
            window.clearInterval(this.stateId);
            this.anchor.removeChild(this.gui.domElement);
            this.gui.destroy();
        }
        catch (_a) {
            //
        }
    };
    return PlayerController;
}());
export { PlayerController };
