/*
 * @Author: your name
 * @Date: 2022-03-03 18:04:40
 * @LastEditTime: 2023-05-30 15:46:46
 * @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 { useModel } from 'umi';
import { Skeleton } from 'antd';

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


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

  useEffect(() => {
    setloading(true);

  }, [initialState]);

  useEffect(()=>{
    console.log({pathname});
    if (initialState && initialState.spacicalPageParamsType && initialState.userData) {
      const {
        spacicalPageParamsType,
        userData: { youshuToken },
      } = initialState;
      const { pathname } = location;
      const spacialPage = spacicalPageParamsType.filter((t) => t.path == pathname);

      // console.log({pathname,spacialPage,spacicalPageParamsType,initialState});

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

        const url = `${spacialPage[0].url}&token=${youshuToken}`;
        setspecialPageUrl(url);
      }
    }
  },[pathname])

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