// #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 { CssAspectRatio } from '@breadstone/mosaik-themes';
import { Listen } from '../../../../events/Decorators/ListenDecorator';
import { Dimensionable } from '../../../Behaviors/Dimensionable';
import { Disableable } from '../../../Behaviors/Disableable';
import { Themeable } from '../../../Behaviors/Themeable';
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 { videoElementCosmopolitanStyle } from './Themes/VideoElement.Cosmopolitan';
import { videoElementJoyStyle } from './Themes/VideoElement.Joy';
import { videoElementMemphisStyle } from './Themes/VideoElement.Memphis';
import { videoElementTemplate } from './VideoElementTemplate';
// #endregion
/**
 * Video - An enhanced video player element with controls, legend, and fit options.
 *
 * @description
 * The Video component wraps a native `<video>` element with design-system styling and
 * additional capabilities such as a legend overlay, aspect-ratio control, and auto-fullscreen.
 * Use the `show-controls` attribute to display native browser controls.
 * Use `auto-play` and `muted` together for inline autoplay (browser policy requirement).
 * The `src` and `poster` properties must be set via JavaScript since they are not reflected
 * as HTML attributes.
 *
 * @name Video
 * @element mosaik-video
 * @category Media
 *
 * @slot  - The default slot.
 * @slot legend - The legend slot.
 *
 * @csspart content - The content part.
 * @csspart legend - The legend part.
 * @csspart video - The video part.
 *
 * @cssprop {String} --video-aspect-ratio - The aspect ratio CSS custom property.
 * @cssprop {String} --video-background-color - Background color behind the video
 * @cssprop {String} --video-border-color - The border color CSS custom property.
 * @cssprop {String} --video-border-radius - Border radius of the video container
 * @cssprop {String} --video-border-style - The border style CSS custom property.
 * @cssprop {String} --video-border-width - The border width CSS custom property.
 * @cssprop {String} --video-font-family - The font family CSS custom property.
 * @cssprop {String} --video-font-letter-spacing - The font letter spacing CSS custom property.
 * @cssprop {String} --video-font-line-height - The font line height CSS custom property.
 * @cssprop {String} --video-font-size - The font size CSS custom property.
 * @cssprop {String} --video-font-text-decoration - The font text decoration CSS custom property.
 * @cssprop {String} --video-font-text-transform - The font text transform CSS custom property.
 * @cssprop {String} --video-font-weight - The font weight CSS custom property.
 * @cssprop {String} --video-foreground-color - The foreground color CSS custom property.
 * @cssprop {String} --video-gap - The gap CSS custom property.
 * @cssprop {String} --video-legend-font-family - The legend font family CSS custom property.
 * @cssprop {String} --video-legend-font-letter-spacing - The legend font letter spacing CSS custom property.
 * @cssprop {String} --video-legend-font-line-height - The legend font line height CSS custom property.
 * @cssprop {String} --video-legend-font-size - The legend font size CSS custom property.
 * @cssprop {String} --video-legend-font-text-decoration - The legend font text decoration CSS custom property.
 * @cssprop {String} --video-legend-font-text-transform - The legend font text transform CSS custom property.
 * @cssprop {String} --video-legend-font-weight - The legend font weight CSS custom property.
 * @cssprop {String} --video-padding-bottom - The padding bottom CSS custom property.
 * @cssprop {String} --video-padding-left - The padding left CSS custom property.
 * @cssprop {String} --video-padding-right - The padding right CSS custom property.
 * @cssprop {String} --video-padding-top - The padding top CSS custom property.
 * @cssprop {String} --video-shadow - The shadow CSS custom property.
 * @cssprop {String} --video-shadow-blur - The shadow blur CSS custom property.
 * @cssprop {String} --video-shadow-color - The shadow color CSS custom property.
 * @cssprop {String} --video-shadow-offset-x - The shadow offset x CSS custom property.
 * @cssprop {String} --video-shadow-offset-y - The shadow offset y CSS custom property.
 * @cssprop {String} --video-shadow-spread - The shadow spread CSS custom property.
 * @cssprop {String} --video-transition-duration - The transition duration CSS custom property.
 * @cssprop {String} --video-transition-mode - The transition mode CSS custom property.
 * @cssprop {String} --video-transition-property - The transition property CSS custom property.
 * @cssprop {String} --video-translate - The translate CSS custom property.
 *
 * @dependency mosaik-text - The Text element.
 *
 * @example
 * Video with controls and autoplay (muted required for autoplay):
 * ```html
 * <mosaik-video show-controls auto-play muted></mosaik-video>
 * ```
 *
 * @example
 * Video with legend and fixed aspect ratio:
 * ```html
 * <mosaik-video show-controls legend="Introduction" legend-position="bottom" ratio="16/9"></mosaik-video>
 * ```
 *
 * @example
 * Looping muted video with cover fit:
 * ```html
 * <mosaik-video auto-play muted loop fit="cover"></mosaik-video>
 * ```
 *
 * @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 `is` property.
     * The `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,
        useDefault: true
    }),
    __metadata("design:type", Boolean),
    __metadata("design:paramtypes", [Boolean])
], VideoElement.prototype, "muted", null);
__decorate([
    Attribute({
        type: Boolean,
        useDefault: true
    }),
    __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,
            memphis: videoElementMemphisStyle,
            cosmopolitan: videoElementCosmopolitanStyle
        },
        imports: [
            TextElement
        ]
    }),
    __metadata("design:paramtypes", [])
], VideoElement);
export { VideoElement };
//# sourceMappingURL=VideoElement.js.map