<template>
    <div :class="['app-rawitem-video',model.sysCss]" :style="containerStyle">
        <video :src="playerParams.path" :autoplay="playerParams.autoplay" :controls="playerParams.showcontrols"
            :loop="playerParams.replay" :muted="playerParams.mute">
            <source :src="playerParams.path" type="video/mp4">
            <source :src="playerParams.path" type="video/ogg">
            <source :src="playerParams.path" type="video/webm">
        </video>
    </div>
</template>

<script lang="ts">
import { Util } from '@/utils';
import { Component, Vue, Prop } from 'vue-property-decorator';
@Component({})
export default class AppRawItemVideo extends Vue {
     /**
     * 名称
     *
     * @type {*}
     * @memberof AppRawItemImage
     */
     @Prop() public name!: string;

    /**
     * 模型
     *
     * @type {*}
     * @memberof AppRawItemImage
     */
    @Prop() public layoutModelDetails!: any;


    /**
     * 视频播放数据
     * @memberof AppRawItemVideo
     */
    @Prop() public videoParmas?: any;

    /**
     * 模型
     *
     * @type {*}
     * @memberof @memberof AppRawItemVideo
     */
    public model: any;

    /**
     * 播放器唯一标识
     * @memberof AppRawItemVideo
     */
    public uuid: string = Util.createUUID();

    /**
     * 容器样式
     *
     * @type {any}
     * @memberof AppRawItemVideo
     */
    public containerStyle: any = null;



    /**
     * 视频播放参数
     *
     * @type {any}
     * @memberof AppRawItemVideo
     */
    public playerParams = {
        id: this.uuid,
        height: '100%',
        width: '100%',
        path: "",
        mute: 0.8,
        autoplay: false,
        replay: false,
        showcontrols: false
    };

    created() {
        if (this.layoutModelDetails && this.name) {
            this.model = this.layoutModelDetails[this.name];
            this.containerStyle = this.model.getElementStyle();
        }
    }

    /**
     * 生命周期
     * @memberof AppRawItemVideo
     */
    public mounted() {
        this.handleStaticVideo();
    }

    /**
     * 处理静态视频播放
     *
     * @memberof AppRawItemVideo
     */
    protected handleStaticVideo() {
        if (this.videoParmas && this.videoParmas.length > 0) {
            const rawParams: any = {};
            this.videoParmas.forEach((param: any) => {
                rawParams[param.key] = param.value;
            })
            Object.assign(this.playerParams, rawParams);
        }
    }
}
</script>

<style lang='less'>
@import "./app-rawitem-video.less";
</style>
