import PageCustom from "@/components/page-custom/index";
import NavBarNormal from "@/components/NavBarNormal";
import { View, Image } from "@tarojs/components";
import ListWrapper from "@/components/list/ListWrapper";
import ListRow from "@/components/list/ListRow";
import { useEffect, useState } from "react";
import { getSysAgreements } from "@/service/system";

import { TAgreementItem } from "@/service/system";
import { isSuccess, navToWebView } from "@/utils";
import {restrictedPage} from '@/utils'

export default function Index() {
  restrictedPage()
  const [agreements, setAgreements] = useState<TAgreementItem[]>([])
  const fetchPageData = async () => {
    const response = await getSysAgreements('register')
    
    if(isSuccess(response.status)){
      setAgreements(response.data)
    }
  }

  useEffect(()=> {
    fetchPageData()
  }, [])
  
  return (
    <PageCustom>
      <NavBarNormal backText="服务协议"></NavBarNormal>
      <View className="w-full px-16 py-24 flex flex-col gap-16">
        <ListWrapper>
          { agreements.map((item)=> {
            return <ListRow underline arrow onClick={()=> navToWebView(item.link)}>
            {item.name}
          </ListRow>
          }) }
        </ListWrapper>
      </View>
    </PageCustom>
  );
}
