import Taro from '@tarojs/taro'
import {useEffect, useState} from 'react'
import {Loading} from '@nutui/nutui-react-taro'
import {View, RichText} from '@tarojs/components'
import {wxParse} from "@/utils/common";
import {getCmsArticleByCode} from "@/api/cms/cmsArticle";
import {CmsArticle} from "@/api/cms/cmsArticle/model"
import Line from "@/components/Gap";

function Index() {
  const [loading, setLoading] = useState<boolean>(true)
  // 文章详情
  const [item, setItem] = useState<CmsArticle>()
  const reload = async () => {
    const item = await getCmsArticleByCode('xieyi')

    if (item && item.content) {
      item.content = wxParse(item.content)
      setItem(item)
      Taro.setNavigationBarTitle({
        title: `${item?.categoryName}`
      })
    }
  }

  useEffect(() => {
    reload().then(() => {
      setLoading(false)
    });
  }, []);

  if (loading) {
    return (
      <Loading className={'px-2'}>加载中</Loading>
    )
  }

  return (
    <div className={'bg-white'}>
      <View className={'content p-4'}>
        <RichText nodes={item?.content}/>
      </View>
      <Line height={44}/>
    </div>
  )
}

export default Index
