import { UnityAction } from '@/utils/utils';
import { CloseOutlined, LeftOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { ConfigProvider } from 'antd';
import locale from 'antd/es/locale/zh_CN';
import styles from './index.less';

export default (props) => {
  const {
    children,
    style,
    closeable = true,
    returnable = false,
    tabs = false,
  } = props;

  const handleClose = () => {
    UnityAction.sendMsg('closePage');
  };
  const handleReturn = () => {
    history.back();
  };

  return (
    <ConfigProvider locale={locale}>
      <div className={styles.page} style={style}>
        {returnable && (
          <LeftOutlined
            onClick={handleReturn}
            className={styles.return}
            style={{ top: tabs ? 42.5 : '' }}
          />
        )}
        {closeable && (
          <CloseOutlined
            onClick={handleClose}
            className={styles.close}
            style={{ top: tabs ? 42.5 : '' }}
          />
        )}

        {children}
      </div>
    </ConfigProvider>
  );
};
