import { r as registerInstance, h } from './core-095fd691.js';
import { R as ResolveLocation } from './resolve-location-6b3481e9.js';
var BceElementVideo = /** @class */ (function () {
    function class_1(hostRef) {
        registerInstance(this, hostRef);
        this.resolveLocation = ResolveLocation.NOOP;
        this.url = '';
        this.youtube = false;
    }
    class_1.prototype.componentWillLoad = function () {
        var _this = this;
        if (!this.template)
            return;
        if (this.template.location.startsWith('BCE://')) {
            this.resolveLocation(this.template.location).then(function (url) { return (_this.url = url); });
            return;
        }
        var match1 = this.template.location.match(/youtube.com\/watch\?v=([^&]+)/);
        if (match1) {
            this.youtube = true;
            this.url = this.createYouTubeURL(match1[1]);
            return;
        }
        var match2 = this.template.location.match(/youtu\.be\/([^\?]+)/);
        if (match2) {
            this.youtube = true;
            this.url = this.createYouTubeURL(match2[1]);
            return;
        }
        this.url = this.template.location;
    };
    class_1.prototype.createYouTubeURL = function (id) {
        var url = this.template && new URL(this.template.location);
        var path = 'https://www.youtube.com/embed/' + id;
        var start = (url && url.searchParams.get('t')) || 0;
        var autoplay = this.template && this.template.autoplay;
        return path + "?start=" + start + "&autoplay=" + autoplay;
    };
    class_1.prototype.renderVideo = function () {
        if (!this.template || !this.url)
            return null;
        var autoplay = this.template.autoplay;
        return (h("video", { key: this.url, autoplay: autoplay, muted: autoplay, playsInline: autoplay, controls: true }, h("source", { src: this.url })));
    };
    class_1.prototype.renderYouTube = function () {
        return [
            h("img", { src: "http://placehold.it/16x9" }),
            h("iframe", { src: this.url, frameborder: "0", allowFullScreen: true })
        ];
    };
    class_1.prototype.render = function () {
        return this.youtube ? this.renderYouTube() : this.renderVideo();
    };
    Object.defineProperty(class_1, "style", {
        get: function () { return "bce-element-video{position:relative;display:block;margin:1rem auto;max-width:1200px;text-align:center}bce-element-video img,bce-element-video video{width:100%;height:auto}bce-element-video img{opacity:0}bce-element-video iframe{position:absolute;top:0;left:0;width:100%;height:100%}\@media screen and (min-width:1024px){bce-element-video{text-align:left;width:auto}}"; },
        enumerable: true,
        configurable: true
    });
    return class_1;
}());
export { BceElementVideo as bce_element_video };
