/*
 * @Author: your name
 * @Date: 2022-03-03 18:04:40
 * @LastEditTime: 2024-05-10 17:23:52
 * @LastEditors: code4eat awesomedema@gmail.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/reports/index.tsx
 */

import { useEffect, useState } from 'react';

import { Skeleton } from 'antd';
import BMSPagecontainer from '@/components/BMSPageContainer';
import { useModel } from '@umijs/max';

import { getPlatFormParams } from './service';
import { getUrlParams } from '@/utils/tooljs';


export default () => {
  const { initialState } = useModel('@@initialState');
  const [specialPageUrl, setspecialPageUrl] = useState<string | undefined>(undefined);
  const [loading, setloading] = useState(false);
  const { pathname } = location;

  
  

  const onLoadhandle = () => {
    setloading(false);
  };

  const getHost = async ()=>{
       const resp = await getPlatFormParams('1547394914533380096','1788836132977512448');
       if(resp){
          return resp
       }
  }

  const loadPage = ()=>{

    if (initialState && initialState.spacicalPageParamsType && initialState.userData) {
      const {
        spacicalPageParamsType,
        userData: { youshuToken },
      } = initialState;

  
      
      const spacialPage = spacicalPageParamsType.filter((t) => `/budgetManaSystem${t.path}` == pathname);

  
      if (spacialPage.length > 0) {
        //当前页面属于有数数据展示页面
        const url = `${spacialPage[0].url}`;

        const {noMenu=undefined,noTopbar=undefined} = getUrlParams(`http://localhost:8000${url}`);
        if(noMenu == 'true'&&noTopbar == 'true'){
          getHost().then((val)=>{
                setspecialPageUrl(`${val.value}${url}&userData=${localStorage.getItem('userData')}`);
          })
        }else{
          setspecialPageUrl(url);
        }
      }
    }
  }

  useEffect(() => {
    setloading(true); 
  }, [initialState]);

  useEffect(() => {
    loadPage();
  }, [pathname]);

  return (
    <BMSPagecontainer title={false}>
      <Skeleton loading={loading} paragraph={{ rows: 50 }} active />
      <iframe
        onLoad={() => onLoadhandle()}
        style={{ width: '100%', height: '90vh', border: 'none' }}
        src={specialPageUrl}
      ></iframe>
    </BMSPagecontainer>
  );
};
