/*
 * @Author: your name
 * @Date: 2021-09-28 13:57:19
 * @LastEditTime: 2021-11-24 10:54:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /MedicalWisdomCheckSys/src/pages/KeepImprove/questionGatherAndRevise/index.tsx
 */


import React, { useEffect,useState } from 'react'
import MccsPageContainer from '@/components/MccsPageContainer/index';
import { history, useModel } from 'umi'

import './index.less';

import type { menuDataItemType } from '@/app';


type QuestionGatherAndReviseProps = {}


const getCurrentRoutesData = (data: menuDataItemType[], path: string) => {
    let result;
    function looper (arr: menuDataItemType[]){
        for (const element of arr) {
            if (element.path == path) {
                result =  element
            } else if (element.children && element.children.length > 0) {
                    looper(element.children);
                }
        }
    }
    looper(data);
    return result;
}

const QuestionGatherAndRevise: React.FC<QuestionGatherAndReviseProps> = () => {

    const { initialState } = useModel('@@initialState');
    const [iframeUrl,setIframeUrl] = useState<string>();

    useEffect(() => {

        const { location: { pathname } } = history;
        if (initialState?.menu) {
            // console.log(getCurrentRoutesData(initialState.menu, pathname));
            const currentRouteData: any = getCurrentRoutesData(initialState.menu, pathname);
            if(currentRouteData){
                console.log({currentRouteData});
                setIframeUrl(currentRouteData.softUrl);
            }
        }

    }, []);

    return (
        <MccsPageContainer>
            {
                iframeUrl&&(
                    <iframe id="reportFrame" src={`${iframeUrl}`} width="100%" height="800px" />
                )
            }
        </MccsPageContainer>
    )
}

export default QuestionGatherAndRevise

