/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 11:30:33
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-06-06 17:23:30
 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { createFromIconfontCN } from '@ant-design/icons';

import { Skeleton } from 'antd';
import { useEffect, useRef, useState } from 'react';
import { useLocation } from 'umi';

import KCIMPagecontainer from '@/components/KCIMPageContainer';



const IconFont = createFromIconfontCN({
  scriptUrl: '',
});


function getQueryParams() {
  const params = new URLSearchParams(window.location.search);
  // 例如，获取名为 "id" 的查询参数
  const softUrl = params.get('softUrl');
  return { softUrl };
}



export default function StaticPage() {

  const [specialPageUrl, setspecialPageUrl] = useState<string | undefined>(undefined);
  const [loading, setloading] = useState(false);
  const { softUrl } = getQueryParams();
  const location = useLocation();
  const [scale,set_scale] = useState(0.5);
  const [translate,set_translate] = useState({x:0,y:0});


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

  const adjustIframeScale = ()=>{
    const desiredWidth = 1200
    const windowWidth = window.innerWidth - 232;
    let scale = windowWidth / desiredWidth;
    // scale = Math.min(scale, 1); // 限制最大缩放比例为1
    const  translateX = (windowWidth - desiredWidth * scale) / 2 / scale;
    const translateY = 0; // 如果需要，也可以计算垂直平移
    set_translate({x:translateX,y:translateY});
    set_scale(scale);
  }


  useEffect(() => {
    setloading(true);
    setspecialPageUrl(softUrl ? softUrl : '');

  }, [location]);

  useEffect(() => {
    adjustIframeScale();
    window.addEventListener('resize', adjustIframeScale);
    return ()=>{
      window.removeEventListener('resize', adjustIframeScale);
    }
  }, [])

  return (
    <KCIMPagecontainer className="StaticPage" title={false}>
      <Skeleton loading={loading} paragraph={{ rows: 50 }} active />
      <iframe
        onLoad={() => onLoadhandle()}
        style={{ width: '100%', height: '90vh', border: 'none',transformOrigin:'top left',paddingLeft:100,overflow:'hidden'}}
        src={specialPageUrl}
      ></iframe>
    </KCIMPagecontainer>
  );
}
