import {FC, useEffect, useState} from "react";
import {Image, Text, View} from "@tarojs/components";
import Taro, {useRouter} from "@tarojs/taro";
import {ArticleRecord, brandApi} from "@/api";
import styles from "@/pages/preview/illness/article/article.module.scss";
import down from "@/static/img/doubleDown.png";
import {Profile} from "@/store";


const article:FC = () => {
  const {token,empty} = Profile.useContainer()
  const {id} = useRouter().params as unknown as { id: number}
  const [articleInfo,setArticleInfo] = useState<ArticleRecord>()
  useEffect(() => {
    getData()
  }, [id])

  const getData = async () => {
    try {
      const data = await brandApi.articleInfo(id)
      Taro.setNavigationBarTitle({title:data.title})
      setArticleInfo(data)
    } catch (e) {
    }
  }
  function helloWorld() {
    const html = articleInfo?.content;
    return (
      <>
        <View style={{padding:'10px',height:!token ? Taro.getWindowInfo().windowHeight-60+'px' : 'auto',overflow:!token ? 'hidden':'auto'}} dangerouslySetInnerHTML={{ __html: html! }}></View>
        {
          !token &&
          <View className={styles.fixedBox}>
            <View className={styles['fixedBox-inner']}>
              <View className={styles['fixedBox-inner-icon']}>
                <Image src={down}></Image>
              </View>
              <View className={styles['fixedBox-inner-box']} onClick={empty}>
                <Text>登录查看更多内容</Text>
              </View>
            </View>
          </View>
        }
      </>
      )

  }
  return helloWorld()
}
export default article
