"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const html_1 = __importDefault(require("../../../../../client/html"));
const APINotImplementedError_1 = require("../../../../../exception/APINotImplementedError");
class Video_ extends html_1.default {
    constructor($props, $system) {
        super($props, $system, $system.api.document.createElement('video'), $system.style['video'], {
            autoplay: true,
            controls: true,
        }, {
            src: (src) => {
                if (src === undefined) {
                    this.$element.pause();
                    this.$element.removeAttribute('src'); // empty source
                    this.$element.load();
                }
                else {
                    this.$element.src = src;
                }
            },
            stream: (stream) => {
                if (stream === undefined) {
                    this.$element.srcObject = null;
                }
                else {
                    stream.$mediaStream({}, (_stream) => {
                        this.$element.srcObject = _stream;
                    });
                }
            },
            controls: (controls) => {
                if (controls === undefined) {
                    this.$element.removeAttribute('controls');
                }
                else {
                    this.$element.controls = controls;
                }
            },
            currentTime: (t) => {
                if (t === undefined) {
                    //
                }
                else {
                    this.$element.currentTime = t;
                }
            },
        });
        this.$input = {
            stream: ['MS'],
        };
        const { src, controls = true } = this.$props;
        this.$element.controls = controls;
        if (src) {
            this.$element.src = src;
        }
    }
    async captureStream({ frameRate, }) {
        // @ts-ignore
        if (this.$element.captureStream) {
            // @ts-ignore
            return this.$element.captureStream(frameRate);
        }
        else {
            throw new APINotImplementedError_1.APINotSupportedError('Capture Stream');
        }
    }
    async requestPictureInPicture() {
        if (this.$element.requestPictureInPicture) {
            try {
                return this.$element;
            }
            catch (err) {
                switch (err.name) {
                    case 'InvalidStateError':
                        throw new Error('video is not loaded');
                    case 'NotAllowedError':
                        throw new Error(`must be handling a user gesture if there isn't already an element in Picture-in-Picture`);
                    default:
                        throw new Error(err.message);
                }
            }
        }
        else {
            throw new APINotImplementedError_1.APINotSupportedError('Picture-in-Picture');
        }
    }
    play() {
        void this.$element.play();
    }
    pause() {
        this.$element.pause();
    }
    reset() {
        super.reset();
        this.$element.pause();
        this.$element.currentTime = 0;
    }
}
exports.default = Video_;
//# sourceMappingURL=Component.js.map