import {useEffect, useState} from 'react'
import Taro from '@tarojs/taro';
import UserCard from "./components/UserCard";
import UserOrder from "./components/UserOrder";
import UserCell from "./components/UserCell";
import UserFooter from "./components/UserFooter";
import {useUser} from "@/hooks/useUser";
import {NavBar} from '@nutui/nutui-react-taro';
import {Home} from '@nutui/icons-react-taro'
import './user.scss'
import IsDealer from "./components/IsDealer";

function User() {
  const [statusBarHeight, setStatusBarHeight] = useState<number>()
  const {
    isAdmin
  } = useUser();

  useEffect(() => {
    Taro.getSystemInfo({
      success: (res) => {
        setStatusBarHeight(res.statusBarHeight)
      },
    })
  }, []);

  /**
   * 门店核销管理
   */
  if (isAdmin()) {
    return <>
      <div className={'w-full'} style={{
        background: 'linear-gradient(to bottom, #e9fff2, #f9fafb)'
      }}>
        <UserCard/>
        <UserOrder/>
        <IsDealer/>
        <UserCell/>
        <UserFooter/>
      </div>
    </>
  }

  return (
    <>
      <NavBar
        fixed={true}
        style={{marginTop: `${statusBarHeight}px`, backgroundColor: 'transparent'}}
        onBackClick={() => {
        }}
        left={
          <div style={{
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center',
            width: '30px',
            height: '30px',
            backgroundColor: 'white',
            textAlign: 'center',
            borderRadius: '50%',
          }}>
            <Home size={15} onClick={() => Taro.reLaunch({url: '/pages/index/index'})} style={{color: 'black', marginBottom: '1px'}} />
          </div>
        }
      >
        <span>我的</span>
      </NavBar>
      <div className={'w-full'} style={{
        background: 'linear-gradient(to bottom, #e9fff2, #f9fafb)'
      }}>
        <UserCard/>
        {/*<UserOrder/>*/}
        <IsDealer/>
        <UserCell/>
        <UserFooter/>
      </div>
    </>
  )
}

export default User
