"use client"
import CheckItem from "./CheckItem"
import { CheckItemType } from "@/types/CheckItem"

const checkList: CheckItemType[] = [
  {
    name: "公网 IPv6 地址",
    url: "https://6.ipv6test.online/ip/myip",
    content: (data) => {
      const success = data?.version == 6
      return {
        state: success ? "ok" : "error",
        text: (success ? `${data?.address}` : "未检测到"),
      }
    },
  },
  {
    name: "公网 IPv4 地址",
    url: "https://4.ipv6test.online/ip/myip",
    content: (data) => {
      const success = data?.version == 4
      return {
        state: success ? "ok" : "error",
        text: (success ? `${data?.address}` : "未检测到"),
      }
    },
  },
  {
    name: "双协议栈测试",
    url: "https://test.ipv6test.online/ip/myip",
    content: (data) => {
      const isIPv6 = data?.version == 6
      const isIPv4 = data?.version == 4

      return {
        state: isIPv6 ? "ok" : "error",
        text: isIPv6 ? "你的网络IPv6访问优先" : isIPv4 ? "你的网络IPv4访问优先" : "未检测到",
      }
    },
  },
]

export default function Checker() {
  return (
    <>
      {checkList.map((item, i) => {
        return <CheckItem key={i} name={item.name} url={item.url} content={item.content} />
      })}
    </>
  )
}
