import React, { useRef, useMemo } from 'react';
import { Session } from '@/utils'
import { Base64 } from 'js-base64';
import styles from './index.less';

const ExternalRoute: React.FC = ({ location }: any) => {
  const iframeRef = useRef<any>(null);
  const token = Session.getAccessToken();
  const { query } = location;
  const url = useMemo(() => {
    const path = Base64.decode(query?._q);
    return `${path}${path.indexOf('?') >= 0 ? '&' : '?'}_k=${token}}`;
  }, [query?._q]);

  return (
    <div className={styles.iframeOuter}>
      <iframe
        title=""
        ref={iframeRef}
        className={styles.iframe}
        src={url}
      />
    </div>
  );
};

export default ExternalRoute;
