import {Cell} from '@nutui/nutui-react-taro'
import navTo from "@/utils/common";
import {View, Text} from '@tarojs/components'
import {ArrowRight, Reward, Setting} from '@nutui/icons-react-taro'
import {useUser} from '@/hooks/useUser'
import {useDealerUser} from "@/hooks/useDealerUser";
import {useThemeStyles} from "@/hooks/useTheme";
import { useConfig } from "@/hooks/useConfig"; // 使用新的自定义Hook
import Taro from '@tarojs/taro'

const IsDealer = () => {
  const themeStyles = useThemeStyles();
  const { config } = useConfig(); // 使用新的Hook
  const {isSuperAdmin} = useUser();
  const {dealerUser, loading: dealerLoading} = useDealerUser()

  /**
   * 管理中心
   */
  if (isSuperAdmin()) {
    return (
      <>
        <View className={'px-4'} style={{ marginTop: '8px', position: 'relative', zIndex: 25 }}>
          <Cell
            className="nutui-cell-clickable"
            style={themeStyles.primaryBackground}
            title={
              <View style={{display: 'inline-flex', alignItems: 'center'}}>
                <Setting className={'text-white '} size={16}/>
                <Text style={{fontSize: '16px'}} className={'pl-3 text-white font-medium'}>管理中心</Text>
              </View>
            }
            extra={<ArrowRight color="#ffffff" size={18}/>}
            onClick={() => navTo('/admin/index', true)}
          />
        </View>
      </>
    )
  }

  /**
   * 分销中心
   */
  if (dealerUser) {
    return (
      <>
        <View className={'px-4'} style={{ marginTop: '8px', position: 'relative', zIndex: 25 }}>
          <Cell
            className="nutui-cell-clickable"
            style={themeStyles.primaryBackground}
            title={
              <View style={{display: 'inline-flex', alignItems: 'center'}}>
                <Reward className={'text-orange-100 '} size={16}/>
                <Text style={{fontSize: '16px'}}
                      className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '桂乐淘分享中心'}</Text>
                {/*<Text className={'text-white opacity-80 pl-3'}>门店核销</Text>*/}
              </View>
            }
            extra={<ArrowRight color="#cccccc" size={18}/>}
            onClick={() => navTo('/dealer/index', true)}
          />
        </View>
      </>
    )
  }

  /**
   * 普通用户
   */
  return (
    <>
      <View className={'px-4'} style={{ marginTop: '8px', position: 'relative', zIndex: 25 }}>
        <Cell
          className="nutui-cell-clickable"
          style={themeStyles.primaryBackground}
          title={
            <View style={{display: 'inline-flex', alignItems: 'center'}}>
              <Reward className={'text-orange-100 '} size={16}/>
              <Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>{config?.vipText || '桂乐淘分享中心'}</Text>
              <Text className={'text-white opacity-80 pl-3'}>{config?.vipComments || ''}</Text>
            </View>
          }
          extra={<ArrowRight color="#cccccc" size={18}/>}
          onClick={() => {
            if (dealerLoading) {
              Taro.showToast({ title: '正在加载信息，请稍等...', icon: 'none' })
              return
            }
            navTo('/dealer/apply/add', true)
          }}
        />
      </View>
    </>
  )
}
export default IsDealer
