<template>
    <div class="list-wrap">
        <div class="task-content">
            <div
                class="task-item"
                :class="{ active: item.id === oldId }"
                v-for="(item, index) in taskList"
                :key="index"
                @click="handleItem(item.id)"
            >
                <div class="item-title">
                    <img src="@/assets/images/common/task-icon.png" alt="" />
                    <span class="title-text">无人机编号{{ item.code }}</span>
                    <span class="task-status" v-if="item.status">执行中</span>
                    <span class="task-status offline" v-else>已离线</span>
                </div>
                <div class="item-content">
                    <div class="item-img">
                        <img :src="item.icon" alt="" />
                    </div>
                    <div class="item-info">
                        <div class="info-item">
                            执行时间：<span class="val-text">{{ item.executeDate }}</span>
                        </div>
                        <div class="info-item">
                            飞巡河道：<span class="val-text">{{ item.region }}</span>
                        </div>
                        <div class="info-item">
                            当前位置：<span class="val-text">{{ item.location }}</span>
                        </div>
                    </div>
                </div>
                <div class="edit-btn" @click.stop="editLine(item)" v-show="item.id === oldId">编辑</div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { onMounted, ref } from "vue";

const taskList = ref([]);

const getList = () => {
    // VE_API.image.droneList().then(res =>{
    //     taskList.value = res.data || []
    // })
    taskList.value = [
        {
            id: 1,
            code: "F001",
            status: true,
            geom: "POINT(110.352173 20.8225)",
            icon: "https://birdseye-img.sysuimars.com/shuichan/image.png",
            executeDate: "2025-05-16",
            region: "湛江市雷州市东里镇",
            location: "110.352173，20.8225",
        },
        {
            id: 2,
            code: "F002",
            status: false,
            geom: "POINT(110.595729 21.371418)",
            icon: "https://birdseye-img.sysuimars.com/shuichan/image.png",
            executeDate: "2025-05-14",
            region: "河道2",
            location: "110.595729 21.371418",
        },
        {
            id: 3,
            code: "F003",
            status: false,
            geom: "POINT(110.793233 21.407839)",
            icon: "https://birdseye-img.sysuimars.com/shuichan/image.png",
            executeDate: "2025-05-14",
            region: "河道3",
            location: "110.793233 21.407839",
        },
        {
            id: 4,
            code: "F004",
            status: false,
            geom: "POINT(110.615398 21.197396)",
            icon: "https://birdseye-img.sysuimars.com/shuichan/image.png",
            executeDate: "2025-05-13",
            region: "河道4",
            location: "110.615398 21.197396",
        },
        {
            id: 5,
            code: "F005",
            status: false,
            geom: "POINT(110.63254 21.399645)",
            icon: "https://birdseye-img.sysuimars.com/shuichan/image.png",
            executeDate: "2025-05-13",
            region: "河道5",
            location: "110.63254 21.615908",
        },
    ];
};

const emit = defineEmits(["airLineCallback", "startEditLine"]);
const oldId = ref(null);
const handleItem = (id) => {
    if (id !== oldId.value) {
        oldId.value = id;
    } else {
        oldId.value = null;
    }
    const filterArr = taskList.value.filter((item) => item.id === oldId.value);
    emit("airLineCallback", filterArr[0] || {});
};

const isEdit = ref(false)
function editLine() {
    isEdit.value = true
    emit("startEditLine")
}

onMounted(() => {
    getList();
});
</script>

<style lang="scss" scoped>
.list-wrap {
    width: calc(100% - 54px - 10px);
    height: 100%;
    padding: 2px 0 20px 8px;
    box-sizing: border-box;
    overflow: auto;
    background: #101010;
    border: 1px solid #444444;
    border-radius: 8px 0 0 8px;

    .task-item {
        margin-top: 10px;
        background: #232323;
        border-radius: 8px;
        padding: 12px 16px;
        cursor: pointer;
        border: 1px solid transparent;
        &.active {
            border: 1px solid #ffd887;
        }
        .item-title {
            display: flex;
            align-items: center;
            padding-bottom: 10px;
            border-bottom: 1px solid rgba(245, 245, 245, 0.1);
            color: #fff;
            font-size: 16px;
            .title-text {
                padding-left: 8px;
            }
            .task-status {
                margin-left: 8px;
                border: 0.5px solid #ffd489;
                border-radius: 2px;
                height: 20px;
                line-height: 18px;
                padding: 1px 6px;
                box-sizing: border-box;
                font-size: 12px;
                color: #f7be5a;
                &.offline {
                    color: #727272;
                    border-color: #727272;
                }
            }
        }
        .item-content {
            padding: 12px 0;
            display: flex;
            align-items: center;
            .item-img {
                img {
                    width: 68px;
                    height: 68px;
                    object-fit: cover;
                    border-radius: 2px;
                }
            }
            .item-info {
                padding-left: 10px;
                color: #6c6c6c;
                font-size: 14px;
                .val-text {
                    color: #fff;
                }
                .info-item + .info-item {
                    padding-top: 2px;
                }
            }
        }
        .edit-btn {
            width: 100%;
            height: 36px;
            border-radius: 4px;
            text-align: center;
            line-height: 36px;
            color: #1D1D1D;
            font-size: 14px;
            background: linear-gradient(180deg, #FFD887, #ED9E1E);
        }
    }
}
</style>
