import React, { useEffect } from 'react';
import BasicLayout from './BasicLayout';

// 不同路由用不同的layout
const SwitchLayout = (props: any) => {
  if (props.location.pathname === '/user/login') {
    return props.children;
  }
  if (props.location.pathname?.includes('=')) {
    // sso 认证，参数被当成路由传递
    return props.children;
  }
  // 自定义layout switch
  if (typeof props.userConfig?.layoutSwitch === 'function') {
    const customLayout = props.userConfig.layoutSwitch(props);
    if (customLayout) {
      return customLayout;
    }
  }
  // 默认Layout
  return <BasicLayout {...props} />;
};

function isTranslated() {
  return /sas/.test(document.documentElement.className);
}

// 全网页翻译可能会导致react内部保存。parentNode.insertBefore(...),子节点被翻译替换，该操作报错
// 提示不能翻译
const NoTranslate = (props: any) => {
  useEffect(() => {
    if (isTranslated()) {
      //
    }
  }, []);

  return props.children;
};

const App = (props: any) => {
  //
  return (
    <NoTranslate>
      <SwitchLayout {...props} />
    </NoTranslate>
  );
};

export default App;
