import { Drawer as OriginDrawer } from "antd";
import React from "react";
import { Shell } from "../../utils/shell";
import { isMobile } from "../../utils/helper";
import { tools } from "../../utils/shell/tools";

// 苹果安全区高度
const IOSSAFEAREAHIGH = 32

// Drawer代理-方便统一修改antd的参数
export const Drawer: React.FC<any> = (props) => {
  // 所有高度都走一遍这个设置-方便后续统一修改-移动端会自动加上这个高度
  const newProps = { ...props }
  const isIOS = !Shell.hasShell() && isMobile() && !tools.isAndroid
  // ios 弹窗特殊处理
  if (isIOS) {
    newProps.height = `calc(${newProps.height || '100%'} - ${IOSSAFEAREAHIGH}px)`
    if (!newProps?.style?.bottom && !newProps?.style?.top)
      //移动端 调整底部设置
      newProps.style = { bottom: IOSSAFEAREAHIGH, top: -IOSSAFEAREAHIGH }
  }
  return <OriginDrawer {...newProps}></OriginDrawer>
}