<template>
    <div class="home">
        <div class="home-container">
            <!-- 背景网格 -->
            <div class="grid-background"></div>

            <!-- 主要内容 -->
            <div class="home-content">
                <div class="home-tag-wrapper">
                    <el-icon class="tag-icon"><Message /></el-icon>
                    <span class="home-tag">短信发送系统 · 首页</span>
                </div>

                <h1 class="home-title">
                    <span class="title-line">欢迎进入</span>
                    <span class="title-line highlight">短信发送管理系统</span>
                </h1>

                <!-- 功能图标 -->
                <div class="decorative-icons">
                    <div
                        class="icon-item"
                        :key="index"
                        :title="item.title"
                        v-for="(item, index) in iconItems"
                        @click="handleIconClick(item.path)"
                        :style="{ animationDelay: `${index * 0.2}s` }"
                    >
                        <el-icon :size="24"><component :is="item.icon" /></el-icon>
                        <span class="icon-label">{{ item.title }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup name="Index">
import { ref, computed, markRaw } from 'vue'
import { useRouter } from 'vue-router'
import auth from '@/plugins/auth'
import {
    User,
    Lock,
    OfficeBuilding,
    UserFilled,
    Collection,
    RefreshRight,
    Message,
} from '@element-plus/icons-vue'

const router = useRouter()

// 功能图标列表配置 - 包含权限标识
const allIconItems = [
    {
        icon: markRaw(User),
        title: '用户管理',
        path: '/system/user',
        permissions: ['system:user:list', 'system:user:query'], // 只要有其中一个权限即可
    },
    {
        icon: markRaw(Lock),
        title: '角色管理',
        path: '/system/role',
        permissions: ['system:role:list', 'system:role:query'],
    },
    {
        icon: markRaw(OfficeBuilding),
        title: '部门管理',
        path: '/system/dept',
        permissions: ['system:dept:list', 'system:dept:query'],
    },
    {
        icon: markRaw(UserFilled),
        title: '人员管理',
        path: '/basicManage/personManage',
        permissions: ['person:person:list', 'person:person:query', 'basicManage:personManage:list'],
    },
    {
        icon: markRaw(Collection),
        title: '分组管理',
        path: '/basicManage/groupManage',
        permissions: [
            'basicManage:groupManage:list',
            'basicManage:groupManage:query',
            'group:group:list',
        ],
    },
    {
        icon: markRaw(Message),
        title: '短信任务',
        path: '/sMsSendManage/loopSend',
        permissions: [
            'sMsSendManage:loopSend:list',
            'sMsSendManage:loopSend:query',
            'sms:loopSend:list',
        ],
    },
]

// 根据权限过滤可见的图标列表
const iconItems = computed(() => {
    return allIconItems.filter((item) => {
        // 如果有权限配置，检查用户是否有权限（只要拥有权限列表中的任意一个即可）
        if (item.permissions && item.permissions.length > 0) {
            return auth.hasPermiOr(item.permissions)
        }
        // 如果没有权限配置，默认不显示（安全起见）
        return false
    })
})

// 处理图标点击
function handleIconClick(path) {
    router.push(path)
}
</script>

<style lang="scss" scoped>
.home {
    // height: 100vh;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f4ff 50%, #d6e4ff 100%);
    overflow: hidden;
}

// 网格背景
.grid-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: linear-gradient(rgba(22, 119, 255, 0.08) 1px, transparent 1px),
        linear-gradient(90deg, rgba(22, 119, 255, 0.08) 1px, transparent 1px);
    background-size: 50px 50px;
    animation: gridMove 20s linear infinite;
    opacity: 0.4;
}

@keyframes gridMove {
    0% {
        transform: translate(0, 0);
    }
    100% {
        transform: translate(50px, 50px);
    }
}

.home-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.home-content {
    text-align: center;
    animation: fadeInUp 0.8s ease-out;
    width: 100%;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.home-tag-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border-radius: 30px;
    font-size: 13px;
    letter-spacing: 0.5px;
    color: #1677ff;
    background: rgba(22, 119, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(22, 119, 255, 0.2);
    margin-bottom: 30px;
    animation: pulse 2s ease-in-out infinite;
    box-shadow: 0 2px 8px rgba(22, 119, 255, 0.15);
}

@keyframes pulse {
    0%,
    100% {
        box-shadow: 0 2px 8px rgba(22, 119, 255, 0.15);
    }
    50% {
        box-shadow: 0 4px 12px rgba(22, 119, 255, 0.25);
    }
}

.tag-icon {
    font-size: 16px;
    animation: rotate 3s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.home-tag {
    font-weight: 500;
}

.home-title {
    font-size: 48px;
    line-height: 1.4;
    font-weight: 700;
    margin: 0;
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.title-line {
    display: block;
    color: #303133;
    animation: slideInLeft 0.8s ease-out;

    &:nth-child(2) {
        animation-delay: 0.2s;
        animation-fill-mode: both;
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.highlight {
    background: linear-gradient(135deg, #1677ff 0%, #4096ff 50%, #69b1ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: relative;
    animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
    0%,
    100% {
        filter: brightness(1);
    }
    50% {
        filter: brightness(1.3);
    }
}

// 功能图标
.decorative-icons {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 40px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.icon-item {
    width: 100px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(22, 119, 255, 0.15);
    color: #1677ff;
    cursor: pointer;
    transition: all 0.3s ease;
    animation: float 3s ease-in-out infinite;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(22, 119, 255, 0.1);

    &:hover {
        background: rgba(22, 119, 255, 0.1);
        border-color: rgba(22, 119, 255, 0.3);
        transform: translateY(-5px) scale(1.05);
        box-shadow: 0 6px 16px rgba(22, 119, 255, 0.2);
        color: #0958d9;
    }
}

.icon-label {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    color: inherit;
}

@keyframes float {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

// 响应式设计
@media (max-width: 768px) {
    .home-container {
        padding: 15px;
    }

    .home-title {
        font-size: 32px;
        margin-bottom: 30px;
        gap: 12px;
    }

    .home-tag-wrapper {
        font-size: 12px;
        padding: 6px 16px;
        margin-bottom: 24px;
    }

    .decorative-icons {
        gap: 16px;
        margin-top: 30px;
    }

    .icon-item {
        width: 90px;
        min-height: 70px;
        padding: 10px;
    }

    .icon-label {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .home-title {
        font-size: 24px;
        margin-bottom: 24px;
        gap: 10px;
    }

    .home-tag-wrapper {
        margin-bottom: 20px;
    }

    .decorative-icons {
        gap: 12px;
        margin-top: 24px;
    }

    .icon-item {
        width: 80px;
        min-height: 65px;
        padding: 8px;
    }

    .icon-label {
        font-size: 10px;
    }
}
</style>
