<template>
    <div class="container">
        <!-- 顶部信息 -->
        <div class="containertop">
            <div class="topleft">
                <img src="../../../assets/images/detailsicon/1.png" alt="">
                <span>现场实况</span>
            </div>
            <div class="topright" v-if="action === 'fill' || !action" style="visibility: hidden;">
                <el-button type="primary" size="medium" plain
                    style="border: none;background-color: rgba(43,98,241,0.1);color: #2B62F1;" @click="">
                    <img src="../../../assets/images/detailsicon/icon-xz@2x.png" alt="编辑"
                        style="width: 0.6rem; height: 0.6rem; margin-right: 4px;">
                    新增
                </el-button>
            </div>
        </div>
        <!-- 视频 -->
        <div class="image-container">
            <div v-for="(image, index) in images" :key="index" class="image-box">
                <img :src="image.src" alt="现场实况" class="image">
                <!-- 播放按钮 -->
                <div class="player-button">
                    <img src="../../../assets/images/detailsicon/icon-bf@2x (1).png" alt="">
                </div>
                <!-- 关闭按钮 -->
                <div class="close-button" @click="removeImage(index)">
                    <img src="../../../assets/images/detailsicon/icon-关闭@2x.png" alt="">
                </div>
                <!-- 是否在线 -->
                <div v-if="image.isOnline" class="online-status online">在线</div>
                <div v-else class="online-status offline">离线</div>
            </div>
            <div v-if="images.length === 0" class="no-data"
                style="width: 100%; display: flex;align-items: center;justify-content: center;color: gray;">
                暂无数据
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        action: {
            type: String,
            required: true
        }
    },
    data() {
        return {
            images: [
                // { src: 'https://picsum.photos/300/200?random=1', isOnline: true },
                // { src: 'https://picsum.photos/300/200?random=2', isOnline: false },
                // { src: 'https://picsum.photos/300/200?random=3', isOnline: true },
            ]
        };
    },
    methods: {
        removeImage(index) {
            this.$confirm('确定要删除该实况吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.images.splice(index, 1);
            }).catch(() => {
                // 用户点击了取消按钮，无需处理
            });
        }
    }
};
</script>

<style scoped>
.container {
    display: flex;
    flex-direction: column;
    width: 100%;
    background-color: #FFFFFF;
    box-shadow: 0rem 0.13rem 0.63rem 0rem rgba(177, 177, 177, 0.1);
    border-radius: 0.5rem 0.5rem 0.5rem 0.5rem;
    padding: .3rem 0 1rem 0;
    gap: 1rem;
    overflow: auto;
}

.containertop {
    height: auto;
    display: flex;
    justify-content: space-between;
    padding: .5rem;
    border-bottom: 1px solid #E5E5E5;
}

.topleft {
    height: 2rem;
    width: 8rem;
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.topleft img {
    width: 0.81rem;
    height: 0.81rem;
}

.topleft span {
    width: auto;
    height: 1rem;
    font-family: aliregular;
    font-weight: 500;
    font-size: 1rem;
    color: #3D424C;
    line-height: 1rem;
    text-align: right;
    font-style: normal;
    text-transform: none;
}

.image-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.image-box {
    position: relative;
    width: 21.75rem;
    height: 12.44rem;
    background-color: #f0f0f0;
    border-radius: 0.5rem;
    overflow: hidden;
}

.image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.close-button {
    width: 1.25rem;
    height: 1.25rem;
    position: absolute;
    top: 0.2rem;
    right: 0.2rem;
}

.close-button img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.player-button {
    position: absolute;
    top: 4.8rem;
    left: 8.8rem;
    width: 25%;
}

.player-button img {
    width: 4.19rem;
    height: 4.19rem;
}

.online-status {
    position: absolute;
    top: 1rem;
    right: 1.3rem;
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
    color: white;
    box-shadow: 0rem 0.13rem 0.31rem 0rem rgba(0, 0, 0, 0.3);
    border-radius: 0.63rem 0.63rem 0.63rem 0.63rem
}

.online-status.online {
    background: #0DB770;
}

.online-status.offline {
    background: #E34242;
}
</style>