<template>
    <div class="farm-info-group">
        <!-- 顶部标题栏 -->
        <div class="info-header">
            <div class="back-btn" @click="handleBack">返回</div>
            <div class="title">
                <img class="title-icon" src="@/assets/images/common/chart-icon.png" alt="" />
                <span class="title-text">荔博园</span>
            </div>
        </div>

        <!-- 主要内容区域 -->
        <div class="info-content">
            <div class="farm-info">
                <div class="lz-icon">
                    <img src="@/assets/images/warningHome/lz-icon.png" alt="" />
                </div>
                <!-- 右侧信息区域 -->
                <div class="info-right">
                    <div class="info-item farm-code">
                        <span class="info-label">农场编号:</span>
                        <span class="info-value">GZ86770</span>
                        <div class="tags">
                            <span class="tag">荔枝</span>
                            <span class="tag">井岗红糯</span>
                        </div>
                    </div>
                    <div class="info-item">
                        <span class="info-label">农场面积:</span>
                        <span class="info-value">58亩</span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">农场位置:</span>
                        <span class="info-value">广东省广州市***</span>
                    </div>
                    <div class="info-item">
                        <span class="info-label">权属人:</span>
                        <span class="info-value">张扬</span>
                    </div>
                </div>
            </div>
            <div class="tabs">
                <div
                    v-for="tab in tabs"
                    :key="tab.key"
                    class="tab-item"
                    :class="{ active: activeTab === tab.key }"
                    @click="activeTab = tab.key"
                >
                    {{ tab.label }}
                </div>
            </div>
            <div class="tab-content">
                <div class="timeline" v-if="activeTab === 'crop'">
                    <div
                        class="timeline-item"
                        v-for="item in timelineList"
                        :key="item.id"
                    >
                        <div class="timeline-left">
                            <div class="dot"></div>
                            <div class="line"></div>
                        </div>
                        <div class="timeline-right">
                            <div class="date">{{ item.date }}</div>
                            <div class="text">{{ item.text }}</div>
                        </div>
                    </div>
                </div>
                <div v-else class="perception-content">
                    <div class="perception-tabs">
                        <div
                            v-for="tab in perceptionTabs"
                            :key="tab.key"
                            class="perception-tab"
                            :class="{ 'perception-tab--active': perceptionActive === tab.key }"
                            @click="perceptionActive = tab.key"
                        >
                            <span class="label">{{ tab.label }}</span>
                            <div class="underline"></div>
                        </div>
                    </div>
                    <div class="perception-wrap">
                        <equipment v-if="perceptionActive === 'device'"></equipment>
                        <crop v-else></crop>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref } from "vue";
import equipment from "./equipment.vue";
import crop from "./crop.vue";
// 底部 tabs 配置
const tabs = [
    { key: "crop", label: "作物档案" },
    { key: "perception", label: "感知记录" },
];

// 感知类型 tabs
const perceptionTabs = [
    { key: "device", label: "设备感知" },
    { key: "crop", label: "作物感知" },
];

const activeTab = ref("crop"); // 默认选中感知记录
const perceptionActive = ref("device"); // 默认选中设备感知

// 时间轴示例数据（后续可替换为接口数据）
const timelineList = ref([
    { id: 1, date: "8/1", text: "水稻进入拔节期，水稻进入拔节期" },
    { id: 2, date: "8/1", text: "水稻进入拔节期，水稻进入拔节期" },
    { id: 3, date: "8/1", text: "水稻进入拔节期，水稻进入拔节期" },
    { id: 4, date: "8/1", text: "水稻进入拔节期，水稻进入拔节期" },
    { id: 5, date: "8/1", text: "水稻进入拔节期，水稻进入拔节期" },
]);

const handleBack = () => {
    // 返回逻辑
};

const handleCropArchive = () => {
    // 作物档案逻辑
};

const handlePerceptionRecord = () => {
    // 感知记录逻辑
};
</script>
<style lang="scss" scoped>
.farm-info-group {
    position: absolute;
    top: 30px;
    right: 0;
    width: 376px;
    height: calc(100% - 20px);
    background: #232323;
    border-radius: 4px;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 0.16);
    .info-header {
        display: flex;
        align-items: center;
        padding: 6px 14px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.16);

        .back-btn {
            cursor: pointer;
            color: rgba(255, 255, 255, 0.55);
        }

        .title {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-size: 18px;
            .title-icon {
                width: 19px;
                height: 13px;
            }
        }
    }
    .info-content {
        padding: 5px 10px;
        height: calc(100% - 168px);
        .farm-info {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            .lz-icon {
                border-radius: 6px;
                background: rgba(70, 70, 70, 0.26);
                img {
                    width: 65px;
                    height: 65px;
                    padding: 7px;
                }
            }
            .info-right {
                font-size: 12px;
                color: #9f9f9f;
                .info-item {
                    display: flex;
                    align-items: center;
                    gap: 8px;
                    line-height: 18px;
                    &.farm-code {
                        font-weight: 700;
                        font-size: 16px;
                        margin-bottom: 4px;
                        color: #ffffff;
                    }
                    .tags {
                        display: flex;
                        gap: 4px;
                        margin-left: auto;

                        .tag {
                            padding: 1px 6px;
                            border: 1px solid #FFD489;
                            border-radius: 2px;
                            color: #FFD489;
                            font-size: 12px;
                            font-weight: 400;
                        }
                    }
                }
            }
        }
        .tabs {
            display: flex;
            gap: 10px;
            margin-top: 12px;
            
            .tab-item {
                padding: 6px 32px;
                text-align: center;
                border-radius: 4px;
                cursor: pointer;
                color: #ffffff;
                background: rgba(166, 166, 166, 0.08);
                border: 1px solid transparent;
                
                &.active {
                    color: #FFD489;
                    background: rgba(255, 212, 137, 0.2);
                    border: 1px solid #FFD489;
                }
            }
        }
        .tab-content{
            margin: 12px 0;
            height: calc(100% - 24px);
            overflow-y: auto;
            .timeline{
                padding-right: 12px;
                .timeline-item{
                    display: flex;
                    align-items: flex-start;
                    font-size: 14px;
                    color: #ffffff;
                    line-height: 22px;
                    & + .timeline-item{
                        margin-top: 24px;
                    }
                    .timeline-left{
                        width: 24px;
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                        .dot{
                            width: 6px;
                            height: 6px;
                            border-radius: 50%;
                            background: #FFD489;
                            margin-top: 6px;
                        }
                        .line{
                            border-left: 1px dashed rgba(255, 212, 137, 0.6);
                            margin-top: 4px;
                            height: 40px;
                        }
                    }
                    .timeline-right{
                        padding-left: 8px;
                        .date{
                            color: #FFD489;
                            font-weight: 500;
                            margin-bottom: 2px;
                        }
                        .text{
                            color: #D7D7D7;
                        }
                    }
                }
            }
            .perception-content{
                height: 100%;
                .perception-tabs{
                    display: flex;
                    align-items: flex-end;
                    gap: 20px;
                    margin-bottom: 12px;
                    .perception-tab{
                        color: #FFFFFF;
                        cursor: pointer;
                        .underline{
                            margin-top: 6px;
                            width: 56px;
                            height: 2px;
                            background: transparent;
                            border-radius: 2px;
                        }
                        &.perception-tab--active{
                            color: #FFD489;
                            .underline{
                                background: #FFD489;
                            }
                        }
                    }
                }
                .perception-wrap{
                    height: calc(100% - 40px);
                    overflow-y: auto;
                }
            }
        }
    }
}
</style>
