import Taro from '@tarojs/taro'
import {View} from '@tarojs/components'
import {useShopInfo} from "@/hooks/useShopInfo"
import './Role.scss'
import navTo from "@/utils/common";
import {useEffect, useState} from "react";

const Page = () => {
  const [isDoctor, setIsDoctor] = useState<boolean>(false)
  // 使用 useShopInfo hooks 获取导航数据
  const {
    error,
  } = useShopInfo()

  // 获取顶部导航菜单
  useEffect(() => {
    setIsDoctor(Taro.getStorageSync('Doctor') || Taro.getStorageSync('Doctor') == 'true')
  }, []);

  // 处理错误状态
  if (error) {
    return (
      <View className={'p-2 text-center text-red-500'}>
        加载导航菜单失败
      </View>
    )
  }

  return (
    <View className={'p-2 z-50 mt-1 gap-2 flex justify-between'}>
      {isDoctor && (
        <View className={'doctor-user rounded-lg w-full block'} onClick={() => navTo(`/clinic/index`)}></View>
      )}
      {!isDoctor && (
        <View className={'doctor-user rounded-lg w-full block'} onClick={() => Taro.switchTab({
          url: `/pages/chat/chat`
        })}></View>
      )}
      <View className={'patient-user rounded-lg bg-white w-full'}
            onClick={() => navTo(`/clinic/clinicPatientUser/prescription`, true)}></View>
    </View>
  )
}
export default Page

