<template>
    <div class="labs">
        <div class="el-dropdown-link" title="实验室" @click="openLabs">
            <img :src="imgIcon" alt="" class="header_right_icon left">
            <span class="header_right_title_span">实验室</span>
        </div>
        <el-dialog v-model="dialogVisible" title="" :show-close="false">
            <template #header="{ close }">
                <div class="my-header">
                    <span class="labs_title">CocoBlockly Pi 实验室</span>
                    <i class="material-icons right" style="margin-top: 5px;cursor: pointer;margin-right:-15px"
                        @click="labsClose">close</i>
                </div>
            </template>
            <el-row v-if="activeContent == 0" class="labs_body">
                <el-col class="labs_class_content" :span="6">
                    <p class="all_class">所有分类：</p>
                    <ul class="labs_class_left">
                        <li :class="calssActive == 1 ? 'active' : ''" @click="getClassData(1, '人工智能')">人工智能</li>
                        <li :class="calssActive == 2 ? 'active' : ''" @click="getClassData(2, '物联网')">物联网</li>
                        <li :class="calssActive == 3 ? 'active' : ''" @click="getClassData(3, '机器人控制')">机器人控制</li>
                        <li :class="calssActive == 4 ? 'active' : ''" @click="getClassData(4, '科学实验')">科学实验</li>
                        <li :class="calssActive == 5 ? 'active' : ''" @click="getClassData(5, '互动游戏')">互动游戏</li>
                        <li :class="calssActive == 6 ? 'active' : ''" @click="getClassData(6, 'AR/VR')">AR/VR</li>
                    </ul>
                </el-col>
                <el-col :span="18" style="padding:0 0.75rem;">
                    <h5>{{ titleNmae }}</h5>
                    <ul class="labs_class_right">
                        <li v-if="calssActive == 1">
                            <AI @getNextValueAI="getNextValueAI"></AI>
                        </li>
                        <li v-else-if="calssActive == 2">
                            <Iot></Iot>
                        </li>
                        <li v-else-if="calssActive == 3">
                            <RobotContro></RobotContro>
                        </li>
                        <li v-else-if="calssActive == 4">
                            <Science></Science>
                        </li>
                        <li v-else-if="calssActive == 5">
                            <interactiveGames></interactiveGames>
                        </li>
                        <li v-else>
                            <ARVR></ARVR>
                        </li>
                    </ul>
                </el-col>
            </el-row>
            <el-row :gutter="20" v-else-if="activeContent == 1" class="activeContent">
                <el-col :span="12" style="background-color: #fff;box-shadow: 1px 2px 3px #eeeeee;">
                    <img style="width: 100%;" :src="disposition.img" alt="">
                    <h3>{{ disposition.title }}</h3>
                    <p>{{ disposition.content }}</p>
                </el-col>
                <el-col :span="12">
                    <div class="labs_card_container">
                        <h4>最低配置要求</h4>
                        <p>系统：{{ disposition.system }}</p>
                        <p>内存：{{ disposition.memory }}</p>
                        <p>硬盘：{{ disposition.HardDisk }}</p>
                        <p>显卡：{{ disposition.GraphicsCard }}</p>
                        <p>摄像头：{{ disposition.camera ? '需要' : '不需要' }}</p>
                        <p>麦克风：{{ disposition.microphone ? '需要' : '不需要' }}</p>
                    </div>
                    <el-button @click="goNext()">进入</el-button>
                </el-col>
            </el-row>
        </el-dialog>
        <el-dialog v-model="iframVisible" :width="disposition.iframeSrc ? '95%' : ''" :show-close="false">
            <template #header="{ close }">
                <span v-if="disposition.iframeSrc">
                    <i class="material-icons right" style="margin-top: -15px;cursor: pointer;margin-right:0px"
                        @click="close">close</i>
                </span>
                <div class="my-header" v-else>
                    <span class="labs_title">{{ disposition.title }}</span>
                    <i class="material-icons right" style="margin-top: 5px;cursor: pointer;margin-right:-15px"
                        @click="labsClose">close</i>
                </div>
            </template>
            <iframe id="postMessage" v-if="disposition.iframeSrc" :src="disposition.iframeSrc" ref="labsData" frameborder="0"
                style="width: 100%;height:700px;"></iframe>
            <div v-else style="padding: 0 20px;max-height: 600px;overflow-y: auto;min-height: 500px;">
                <gesture />
            </div>
        </el-dialog>
    </div>
</template>
<script setup>
import { ref } from 'vue';
import imgIcon from '../../assets/img/cocoblockly-navbar_labs-icon.png'
import AI from '../labs/ai.vue'
import Iot from '../labs/iot.vue'
import RobotContro from '../labs/robotContro.vue';
import Science from '../labs/science.vue'
import interactiveGames from '../labs/interactiveGames.vue'
import ARVR from '../labs/ARVR.vue'
import deepLearningImg from '../../assets/img/AppCenter_ai_teachableMachine.jpg'
import emotionImg from '../../assets/img/AppCenter_ai_emotion.jpg'
import gestureImg from '../../assets/img/AppCenter_ai_gesture_recognition.jpg'
import objectImg from '../../assets/img/object_recognition_header.jpg'
import postureImg from '../../assets/img/posenet_recogition.png'
import discerningEyeImg from '../../assets/img/tm_with_pose.jpg'
import speechImg from '../../assets/img/AppCenter_ai_speech.jpg'
import gesture from '../labs/gesture.vue';
import emotion from '../labs/emotion.vue';
import useUserinfo from '@/stores/modules/userInfo';

const dialogVisible = ref(false)
const calssActive = ref(1)
const titleNmae = ref("人工智能")
const activeContent = ref(0)
const dispositionList = [
    {
        title: "深度学习机器",
        content: "机器人发展的趋势是人工智能化，深度学习是智能机器人的前沿技术，也是机器学习领域的新课题。深度学习技术被广泛运用于农业、工业、军事、航空等领域，与机器让人的有机结合能设计出具有高工作效率、高实时性、高精确度的智能机器人。",
        img: deepLearningImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: true,
        microphone: false,
        iframeSrc: "https://ai-demos.cocorobo.cn/teachable-machine-2/public/"
    },
    {
        title: "情绪识别",
        content: "情绪识别发展的趋势是人工智能化，情绪识别是智能识别的前沿技术，也是识别领域的新课题。情绪识别技术被广泛运用于农业、工业、军事、航空等领域。",
        img: emotionImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: true,
        microphone: false,
        iframeSrc: "https://beta.ai-demos.cocorobo.cn/labs/emotion-cloud/index.html"
    },
    {
        title: "手势识别",
        content: "手势识别发展的趋势是人工智能化，手势识别是智能识别的前沿技术，也是识别领域的新课题。手势识别技术被广泛运用于农业、工业、军事、航空等领域。",
        img: gestureImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: true,
        microphone: false,
        iframeSrc: "https://beta.ai-demos.cocorobo.cn/labs/gesture-cloud/index.html"
    },
    {
        title: "物体识别",
        content: "物体识别发展的趋势是人工智能化，物体识别是智能识别的前沿技术，也是识别领域的新课题。物体识别技术被广泛运用于农业、工业、军事、航空等领域。",
        img: objectImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: true,
        microphone: false,
        iframeSrc: ""
    },
    {
        title: "姿态识别",
        content: "姿态识别发展是人工智能发展的大趋势，姿态识别运用了许多智能识别的前沿技术，是识别领域的新课题。姿态识别技术被广泛运用于多中领域",
        img: postureImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: true,
        microphone: false,
        iframeSrc: "https://ai-demos.cocorobo.cn/posenet-2/demos/dist/"
    },
    {
        title: "慧眼识人",
        content: "机器人发展的趋势是人工智能化，深度学习是智能机器人的前沿技术，也是机器学习领域的新课题。深度学习技术被广泛运用于农业、工业、军事、航空等领域，与机器让人的有机结合能设计出具有高工作效率、高实时性、高精确度的智能机器人。",
        img: discerningEyeImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: true,
        microphone: false,
        iframeSrc: "https://ai-demos.cocorobo.cn/teachable-machine-pose-recognition-2/public/"
    },
    {
        title: "语音识别",
        content: "语音识别发展的趋势是人工智能化，语音识别是智能识别的前沿技术，也是识别领域的新课题。语音识别技术被广泛运用于农业、工业、军事、航空等领域。",
        img: speechImg,
        system: "Windows (>Windows7), macOS (>10.11)",
        resolution: "1440*768",
        memoryCapacity: "8GB-16GB",
        HardDisk: "256GB-512GB",
        GraphicsCard: "650M",
        camera: false,
        microphone: true,
        iframeSrc: "https://beta.ai-demos.cocorobo.cn/labs/speech-cloud/index.html"
    }
]
const disposition = ref({})
const iframVisible = ref(false)
const labsData = ref(null)

const getClassData = (val, name) => {
    calssActive.value = val
    titleNmae.value = name
}

const getNextValueAI = (val) => {
    activeContent.value = 1
    disposition.value = dispositionList.find(item => item.title == val)
}

const goNext = () => {
    iframVisible.value = true
    setTimeout(() => {
        iframeMessage()
    }, 100)
}

const iframeMessage = () => {
    console.log(document.getElementById("postMessage"))
    const data = {
        data:useUserinfo().userInfo,
        id:"loginVerify",
        url:"zh-hans"
    }
    if(labsData.value){
        labsData.value.contentWindow.postMessage(JSON.parse(JSON.stringify(data)), "*")
    }
}

const labsClose = () => {
    console.log(activeContent.value,disposition.value.iframeSrc)
    if (disposition.value.iframeSrc == "" && iframVisible.value) {
        iframVisible.value = false
        activeContent.value = 1
    }
    else if (activeContent.value == 1) {
        activeContent.value = 0
    } 
    else {
        dialogVisible.value = false
    }
}

const openLabs = () => {
    if(useUserinfo().userInfo){
        dialogVisible.value = true
        activeContent.value = 0
    }else{
        // dialogVisible.value = false
        ElMessage({
            message: '请先登录',
            type: 'warning'
        })
    }
}

</script>
<style lang="scss">
.labs {
    color: #000;
    cursor: default;

    .el-dropdown-link {
        cursor: pointer;
    }

    .my-header {
        padding: 0 20px 20px;
    }

    .labs_title {
        color: #000;
        font-size: 2.28rem;
    }

    .labs_body {
        border-top: 1px solid #ddd;
        margin: 0px 20px;
        padding-bottom: 20px;

        h5 {
            font-size: 1.64rem;
            line-height: 110%;
            margin: 1.0933333333rem 0 0.656rem 0;
        }

        .labs_class_content {
            .all_class {
                font-weight: bold;
                margin: 1rem 0;
            }


            ul.labs_class_left {
                border: 1px solid #dddddd;
                border-bottom: none;
                border-radius: 2px;

                li {
                    background-color: #fff;
                    line-height: 1.5rem;
                    padding: 10px 20px;
                    margin: 0;
                    border-bottom: 1px solid #e0e0e0;
                    font-weight: bold;
                    cursor: pointer;
                }

                .active {
                    background-color: #2196F3;
                    color: white;
                    border-radius: 2px;
                }
            }

            ul.labs_class_right {}
        }
    }

    .activeContent {
        border-top: 1px solid #ddd;
        background-color: rgb(250, 250, 250);
        // padding-top: 10px;
        padding: 10px;

        .el-col {
            position: relative;
            padding: 10px;

            img {
                width: 100%;
            }

            h3 {
                font-size: 1.64rem;
                line-height: 110%;
                padding: 10px 0 15px;
                color: #212121;
            }

            .labs_card_container {
                background-color: #fff;

                h4 {
                    background-color: rgb(33, 150, 243);
                    color: #fff;
                    padding: 5px 10px;
                    font-size: 15px;
                    border-top-left-radius: 5px;
                    border-top-right-radius: 5px;
                }

                p {
                    padding: 3px;
                }
            }

            .el-button {
                position: absolute;
                width: calc(100% - 20px);
                bottom: 0px;
                background-color: #2979FF;
                color: #fff;
            }
        }

    }
}
</style>