<template>
    <view class="page-container">
        <!-- 头部背景图 -->
        <image class="header-bg" src="/static/images/workbench/1.png" mode="widthFix"></image>

        <view class="header">
            <view class="header-content">
                <text class="header-title">工作台</text>
            </view>
        </view>

        <scroll-view class="page-content">
            <!-- 快捷功能卡片 -->
            <view class="quick-cards">
                <view v-for="(item, index) in quickFunctions" :key="index" class="quick-card" @click="handleQuickClick(item)">
                    <image class="quick-card-bg" :src="item.bgImage" mode="aspectFill"></image>
                    <view class="quick-card-content">
                        <text class="quick-card-title">{{ item.title }}</text>
                    </view>
                </view>
            </view>

            <!-- 库区管理 -->
            <view class="section">
                <view class="section-header">
                    <view class="section-indicator"></view>
                    <text class="section-title">库区管理</text>
                </view>
                <view class="management-grid">
                    <view v-for="(item, index) in managementList" :key="index" class="management-item" @click="handleManagementClick(item)" :style="{ backgroundColor: item.bgColor }">
                        <view class="management-icon-box">
                            <image class="management-icon" :src="item.icon" mode="aspectFit"></image>
                        </view>
                        <text class="management-title">{{ item.title }}</text>
                        <view v-if="item.badge" class="management-badge">
                            <text class="badge-text">{{ item.badge }}</text>
                        </view>
                    </view>
                </view>
            </view>
        </scroll-view>

        <!-- 底部 TabBar -->
        <custom-tabbar :current="1" />
    </view>
</template>

<script setup lang="uts">
    import { ref } from 'vue'

    // 快捷功能类型
    type QuickFunction = {
        id: number
        title: string
        bgImage: string
        icon: string
        path: string
    }

    // 库区管理功能类型
    type ManagementItem = {
        id: number
        title: string
        icon: string
        bgColor: string
        path: string
        badge: string
    }

    // 快捷功能列表
    const quickFunctions = ref<QuickFunction[]>([
        {
            id: 1,
            title: '在线会议',
            bgImage: '/static/images/workbench/2.png',
            icon: '',
            path: ''
        },
        {
            id: 2,
            title: '视频广场',
            bgImage: '/static/images/workbench/3.png',
            icon: '',
            path: ''
        },
        {
            id: 3,
            title: '四乱信息',
            bgImage: '/static/images/workbench/4.png',
            icon: '',
            path: ''
        },
        {
            id: 4,
            title: '六项机制',
            bgImage: '/static/images/workbench/5.png',
            icon: '',
            path: ''
        },
        {
            id: 5,
            title: '水库矩阵',
            bgImage: '/static/images/workbench/6.png',
            icon: '',
            path: ''
        },
        {
            id: 6,
            title: 'AI助手',
            bgImage: '/static/images/workbench/7.png',
            icon: '',
            path: ''
        }
    ])

    // 库区管理功能列表
    const managementList = ref<ManagementItem[]>([
        {
            id: 1,
            title: '列表',
            icon: '/static/images/workbench/8.png',
            bgColor: '#E3F2FD',
            path: '/pages/workbench/order/index',
            badge: '1'
        },
        {
            id: 2,
            title: '表单',
            icon: '/static/images/workbench/9.png',
            bgColor: '#FFF3E0',
            path: '/pages/workbench/form/index',
            badge: ''
        },
        {
            id: 3,
            title: '地图',
            icon: '/static/images/workbench/10.png',
            bgColor: '#FCE4EC',
            path: '/pages/workbench/map/index',
            badge: ''
        },
    ])

    // 快捷功能点击
    const handleQuickClick = (item: QuickFunction): void => {
        if (item.path.length > 0) {
            uni.navigateTo({
                url: item.path,
                fail: (err: any) => {
                    console.log('导航失败', err)
                }
            })
        } else {
            uni.showToast({
                title: item.title,
                icon: 'none'
            })
        }
    }

    // 库区管理功能点击
    const handleManagementClick = (item: ManagementItem): void => {
        if (item.path.length > 0) {
            uni.navigateTo({
                url: item.path,
                fail: (err: any) => {
                    console.log('导航失败', err)
                }
            })
        } else {
            uni.showToast({
                title: item.title,
                icon: 'none'
            })
        }
    }
</script>

<style lang="scss">
    .page-container {
        flex: 1;
        background-color: #f5f8fe;
        padding-top: env(safe-area-inset-top);
    }

    .page-content {
        flex: 1;
        padding: 32rpx;
        padding-bottom: 150rpx;
        box-sizing: border-box;

        border-radius: 24rpx;
        border: 1rpx solid rgba(255, 255, 255, 0.3);
        background: #f5f8fe;
        // background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, #f5f8fe 100%);
        // backdrop-filter: blur(20rpx);
    }

    .header-bg {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: auto;
        z-index: 0;
    }

    .header {
        position: relative;
        overflow: hidden;

        &-content {
            position: relative;
            z-index: 1;
            padding: 80rpx 30rpx 40rpx;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        &-title {
            font-size: 48rpx;
            color: #ffffff;
            font-weight: bold;
        }
    }

    .quick-cards {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;

        .quick-card {
            position: relative;
            width: 212rpx;
            height: 120rpx;
            margin-bottom: 20rpx;
            overflow: hidden;
            border-radius: 16rpx;

            &-bg {
                position: absolute;
                top: 0;
                left: 0;
                width: 226rpx;
                height: 140rpx;
                z-index: 0;
            }

            &-content {
                position: relative;
                z-index: 1;
                padding: 20rpx;
                height: 140rpx;
                justify-content: flex-start;
            }

            &-title {
                font-size: 28rpx;
                color: #333333;
                font-weight: bold;
            }
        }
    }

    .section {
        padding: 0 20rpx 30rpx;

        background: #ffffff;
        border-radius: 16rpx;

        &-header {
            flex-direction: row;
            align-items: center;
            padding: 30rpx 10rpx 20rpx;
        }

        &-indicator {
            width: 6rpx;
            height: 32rpx;
            background-color: #007aff;
            border-radius: 3rpx;
            margin-right: 12rpx;
        }

        &-title {
            font-size: 36rpx;
            color: #333333;
            font-weight: bold;
        }
    }

    .management-grid {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;

        .management-item {
            position: relative;
            width: 192rpx;
            height: 156rpx;
            margin-bottom: 24rpx;
            background-color: #edf5ff;
            border-radius: 8rpx;
            align-items: flex-start;
            justify-content: center;
            padding: 24rpx;
            box-sizing: border-box;

            .management-icon-box {
                width: 64rpx;
                height: 64rpx;
                justify-content: center;
                align-items: center;
                margin-bottom: 16rpx;
            }

            .management-icon {
                width: 100%;
                height: 100%;
            }

            .management-title {
                font-weight: bold;
                font-size: 24rpx;
                color: #333333;
                text-align: center;
            }

            .management-badge {
                position: absolute;
                top: 20rpx;
                right: 20rpx;
                width: 32rpx;
                height: 32rpx;
                background-color: #ff3b30;
                border-radius: 16rpx;
                justify-content: center;
                align-items: center;

                .badge-text {
                    font-size: 20rpx;
                    color: #ffffff;
                    line-height: 20rpx;
                }
            }
        }
    }
</style>
