"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const html_1 = require("../../../../../client/html");
class AudioComp extends html_1.default {
    constructor($props, $system) {
        super($props, $system, $system.api.document.createElement('audio'), $system.style['audio']);
        const { className, src, controls = true } = this.$props;
        this.$element.controls = controls;
        if (className) {
            this.$element.className = className;
        }
        if (src) {
            this.$element.src = src;
        }
        this.$propHandler = {
            ...this.$propHandler,
            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;
                }
            },
        };
        this.$element = this.$element;
    }
    play() {
        this.$element.play();
    }
    pause() {
        this.$element.pause();
    }
    reset() {
        super.reset();
        this.$element.pause();
        this.$element.currentTime = 0;
    }
    captureStream(opt) {
        // @ts-ignore
        if (this.$element.captureStream) {
            // @ts-ignore
            return this.$element.captureStream();
        }
        return null;
    }
}
exports.default = AudioComp;
//# sourceMappingURL=Component.js.map