// #region Imports
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Listen } from '../../../../Events/Decorators/ListenDecorator';
import { Dimensionable } from '../../../Behaviors/Dimensionable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Attribute } from '../../../Decorators/AttributeDecorator';
import { Component } from '../../../Decorators/ComponentDecorator';
import { Property } from '../../../Decorators/PropertyDecorator';
import { Watch } from '../../../Decorators/WatchDecorator';
import { VideoFit } from '../../../Types/VideoFit';
import { VideoLegendPosition } from '../../../Types/VideoLegendPosition';
import { CustomElement } from '../../Abstracts/CustomElement';
import { TextElement } from '../../Primitives/Text/TextElement';
import { videoElementTemplate } from './VideoElementTemplate';
import { videoElementJoyStyle } from './Themes/VideoElement.Joy';
import { videoElementRetroStyle } from './Themes/VideoElement.Retro';
import { videoElementCosmopolitanStyle } from './Themes/VideoElement.Cosmopolitan';
import { Themeable } from '../../../Behaviors/Themeable';
import { CssAspectRatio } from '@breadstone/mosaik-themes';
// #endregion
/**
 * The `{@link VideoElement}` element.
 *
 * @public
 */
let VideoElement = class VideoElement extends Themeable(Disableable(Dimensionable(CustomElement))) {
    // #region Fields
    _videoElement;
    _src;
    _poster;
    _autoPlay;
    _autoFullScreen;
    _showControls;
    _fit;
    _legend;
    _legendPosition;
    _ratio;
    _muted;
    _loop;
    // #endregion
    // #region Ctor
    /**
     * @public
     */
    constructor() {
        super();
        this._src = null;
        this._poster = '';
        this._autoPlay = false;
        this._autoFullScreen = false;
        this._showControls = false;
        this._fit = VideoFit.None;
        this._legend = '';
        this._legendPosition = VideoLegendPosition.None;
        this._ratio = 'auto';
        this._muted = false;
        this._loop = false;
    }
    // #endregion
    // #region Properties
    /**
     * Returns the `{@link is}` property.
     * The `{@link is}` property represents natural name of this element.
     *
     * @public
     * @static
     * @readonly
     */
    static get is() {
        return 'mosaik-video';
    }
    /**
     * Gets or sets the `src` property.
     *
     * @public
     */
    get src() {
        return this._src;
    }
    set src(value) {
        if (this._src !== value) {
            this._src = value;
            this.requestUpdate('src');
        }
    }
    /**
     * Gets or sets the `poster` property.
     *
     * @public
     */
    get poster() {
        return this._poster;
    }
    set poster(value) {
        if (this._poster !== value) {
            this._poster = value;
            this.requestUpdate('poster');
        }
    }
    /**
     * Gets or sets the `autoPlay` property.
     *
     * @public
     * @attr
     */
    get autoPlay() {
        return this._autoPlay;
    }
    set autoPlay(value) {
        if (this._autoPlay !== value) {
            this._autoPlay = value;
            this.requestUpdate('autoPlay');
        }
    }
    /**
     * Gets or sets the `autoFullScreen` property.
     *
     * @public
     * @attr
     */
    get autoFullScreen() {
        return this._autoFullScreen;
    }
    set autoFullScreen(value) {
        if (this._autoFullScreen !== value) {
            this._autoFullScreen = value;
            this.requestUpdate('autoFullScreen');
        }
    }
    /**
     * Gets or sets the `showControls` property.
     *
     * @public
     * @attr
     */
    get showControls() {
        return this._showControls;
    }
    set showControls(value) {
        if (this._showControls !== value) {
            this._showControls = value;
            this.requestUpdate('showControls');
        }
    }
    /**
     * Gets or sets the `fit` property.
     *
     * @public
     * @attr
     */
    get fit() {
        return this._fit;
    }
    set fit(value) {
        if (this._fit !== value) {
            this._fit = value;
            this.requestUpdate('fit');
        }
    }
    /**
     * Gets or sets the `legend` property.
     *
     * @public
     * @attr
     */
    get legend() {
        return this._legend;
    }
    set legend(value) {
        if (this._legend !== value) {
            this._legend = value;
            this.requestUpdate('legend');
        }
    }
    /**
     * Gets or sets the `legendPosition` property.
     *
     * @public
     * @attr
     */
    get legendPosition() {
        return this._legendPosition;
    }
    set legendPosition(value) {
        if (this._legendPosition !== value) {
            this._legendPosition = value;
            this.requestUpdate('legendPosition');
        }
    }
    /**
     * Gets or sets the `ratio` property.
     *
     * @public
     * @attr
     */
    get ratio() {
        return this._ratio;
    }
    set ratio(value) {
        if (this._ratio !== value) {
            this._ratio = value;
            this.requestUpdate('ratio');
        }
    }
    /**
     * Returns the `muted` property.
     *
     * @public
     * @readonly
     */
    get muted() {
        return this._muted;
    }
    set muted(value) {
        if (this._muted !== value) {
            this._muted = value;
            this.requestUpdate('muted');
        }
    }
    /**
     * Returns the `loop` property.
     *
     * @public
     * @readonly
     */
    get loop() {
        return this._loop;
    }
    set loop(value) {
        if (this._loop !== value) {
            this._loop = value;
            this.requestUpdate('loop');
        }
    }
    /**
     * Returns the `hasSrc` property.
     *
     * @public
     * @readonly
     */
    get hasSrc() {
        return !!(this._videoElement.src || this._videoElement.srcObject);
    }
    // #endregion
    // #region Methods
    /**
     * @public
     */
    play() {
        return this._videoElement.play();
    }
    /**
     * @public
     */
    pause() {
        this._videoElement.pause();
    }
    /**
     * @public
     */
    toggle() {
        const isVideoPlaying = !!(this._videoElement.currentTime > 0 && !this._videoElement.paused && !this._videoElement.ended && this._videoElement.readyState > 2);
        if (isVideoPlaying) {
            this.pause();
        }
        else {
            void this.play();
        }
    }
    /**
     * @public
     */
    load() {
        this._videoElement.load();
    }
    /**
     * @protected
     * @override
     */
    onApplyTemplate() {
        super.onApplyTemplate();
        this._videoElement = this.getTemplatePart('video');
    }
    /**
     * @protected
     */
    onDisabledPropertyChanged(prevValue, nextValue) {
        if (nextValue) {
            this._videoElement.pause();
        }
    }
    onClick() {
        if (!this.showControls) {
            this.toggle();
        }
    }
};
__decorate([
    Property({ type: Object }),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], VideoElement.prototype, "src", null);
__decorate([
    Property({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], VideoElement.prototype, "poster", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], VideoElement.prototype, "autoPlay", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], VideoElement.prototype, "autoFullScreen", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], VideoElement.prototype, "showControls", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], VideoElement.prototype, "fit", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], VideoElement.prototype, "legend", null);
__decorate([
    Attribute({ type: VideoLegendPosition }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], VideoElement.prototype, "legendPosition", null);
__decorate([
    Attribute({ type: String }),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [String])
], VideoElement.prototype, "ratio", null);
__decorate([
    Attribute({ type: Boolean }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], VideoElement.prototype, "muted", null);
__decorate([
    Attribute({ type: Boolean }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], VideoElement.prototype, "loop", null);
__decorate([
    Watch('disabled', { waitUntilFirstUpdate: true }),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Boolean, Boolean]),
    __metadata("design:returntype", void 0)
], VideoElement.prototype, "onDisabledPropertyChanged", null);
__decorate([
    Listen('click'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], VideoElement.prototype, "onClick", null);
VideoElement = __decorate([
    Component({
        selector: 'mosaik-video',
        template: videoElementTemplate,
        themes: {
            joy: videoElementJoyStyle,
            retro: videoElementRetroStyle,
            cosmopolitan: videoElementCosmopolitanStyle
        },
        imports: [
            TextElement
        ]
    }),
    __metadata("design:paramtypes", [])
], VideoElement);
export { VideoElement };
//# sourceMappingURL=VideoElement.js.map