import {useEffect, useState} from 'react'
import { Dialog } from '@nutui/nutui-react-taro'
import {getCmsNavigation} from "@/api/cms/cmsNavigation";
import {CmsNavigation} from "@/api/cms/cmsNavigation/model";
import {RichText} from '@tarojs/components'

const PopUpAd = () => {
  const [visible, setVisible] = useState(false)
  const [item, setItem] = useState<CmsNavigation>()
  const reload = async () => {
    const navigation = await getCmsNavigation(4426)
    if(navigation && navigation.hide == 0){
      setItem(navigation)
      setVisible(true)
    }
  }

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

  return (
    <>
      <Dialog
        title={
          <div className={'font-bold mb-3'}>重要通知</div>
        }
        footer={null}
        closeIcon
        closeIconPosition="top-right"
        style={{
          // @ts-ignore
          '--nutui-dialog-close-color': '#8c8c8c',
        }}
        onConfirm={() => setVisible(false)}
        onCancel={() => setVisible(false)}
        visible={visible}
        onClose={() => {
          setVisible(false)
        }}
      >
        <RichText nodes={item?.design?.content}/>
      </Dialog>
    </>
  )
}
export default PopUpAd
