<template>
  <a-layout-footer class="footer">
    <div class="mx-auto max-w-screen-xl px-4 py-10">
      <a-row :gutter="[24, 24]">
        <a-col :xs="24" :md="8">
          <div class="text-base font-semibold text-white">联系我们</div>
          <div class="mt-4 grid gap-2 text-sm text-gray-300">
            <div>咨询服务：<NuxtLink class="text-gray-100 hover:text-white underline-offset-4 hover:underline" to="/consulting/intro">服务简介</NuxtLink></div>
            <div>建议反馈：<NuxtLink class="text-gray-100 hover:text-white underline-offset-4 hover:underline" to="/suggest">建言献策</NuxtLink></div>
            <div>联系方式：<NuxtLink class="text-gray-100 hover:text-white underline-offset-4 hover:underline" to="/contact">联系我们</NuxtLink></div>
          </div>
        </a-col>

        <a-col :xs="24" :md="8">
          <div class="text-base font-semibold text-white">快速入口</div>
          <div class="mt-4 grid gap-2 text-sm text-gray-400">
            <NuxtLink class="hover:text-white" to="/policy/latest">政策要闻</NuxtLink>
            <NuxtLink class="hover:text-white" to="/reference/data">数据服务</NuxtLink>
            <NuxtLink class="hover:text-white" to="/experts/apply">专家申请</NuxtLink>
            <NuxtLink class="hover:text-white" to="/downloads">资料下载</NuxtLink>
            <NuxtLink class="hover:text-white" to="/search">站内搜索</NuxtLink>
            <NuxtLink class="hover:text-white" to="/sitemap">站点地图</NuxtLink>
          </div>
        </a-col>

        <a-col :xs="24" :md="8">
          <div class="text-base font-semibold text-white">备案信息</div>
          <div class="mt-4 grid gap-2 text-sm text-gray-300">
            <div>{{ icpText }}</div>
            <div>{{ policeText }}</div>
            <div>{{ siteCodeText }}</div>
          </div>
        </a-col>
      </a-row>

      <div class="mt-10 border-t border-white/10 pt-6">
        <div class="text-base font-semibold text-white">友情链接</div>
        <div class="mt-3 flex flex-wrap gap-x-5 gap-y-2 text-sm text-gray-300">
          <a v-for="it in friendLinks" :key="it.url" class="hover:text-white hover:underline underline-offset-4" :href="it.url" target="_blank" rel="noreferrer">
            {{ it.name }}
          </a>
        </div>
      </div>

      <div
        class="mt-10 flex flex-col gap-2 border-t border-white/10 pt-6 text-xs text-gray-500 md:flex-row md:items-center md:justify-between"
      >
        <div>© {{ year }} {{ siteName }}. All rights reserved.</div>
        <div class="flex flex-wrap items-center gap-x-3 gap-y-1 text-gray-400">
          <NuxtLink class="hover:text-gray-200" to="/privacy">隐私政策</NuxtLink>
          <NuxtLink class="hover:text-gray-200" to="/terms">使用条款</NuxtLink>
          <NuxtLink class="hover:text-gray-200" to="/disclaimer">免责声明</NuxtLink>
        </div>
        <div class="tools flex items-center opacity-80 hover:opacity-90 text-gray-100 text-xs">
          Powered by
          <a
            rel="nofollow"
            href="https://glt.websoft.top"
            target="_blank"
            class="text-white visited:text-white hover:text-gray-200 ml-1"
          >
            云·企业官网
          </a>
        </div>
      </div>
    </div>
  </a-layout-footer>
</template>

<script setup lang="ts">
import { getCmsWebsiteFieldByCode } from '@/api/cms/cmsWebsiteField'

const { data: siteInfo } = useSiteInfo()
const siteName = computed(() => String((siteInfo.value as any)?.data?.websiteName || '广西决策咨询网'))

const { data: icpField } = useAsyncData('cms-website-field-icpNo', async () => {
  try {
    return await getCmsWebsiteFieldByCode('icpNo')
  } catch {
    return null
  }
})

const { data: policeField } = useAsyncData('cms-website-field-policeNo', async () => {
  try {
    return await getCmsWebsiteFieldByCode('policeNo')
  } catch {
    return null
  }
})

const { data: siteCodeField } = useAsyncData('cms-website-field-siteCode', async () => {
  try {
    return await getCmsWebsiteFieldByCode('siteCode')
  } catch {
    return null
  }
})

const icpNo = computed(() => {
  const v = icpField.value?.value ?? icpField.value?.defaultValue
  if (typeof v === 'string' && v.trim()) return v.trim()
  const fallback = (siteInfo.value as any)?.data?.icpNo
  return typeof fallback === 'string' ? fallback.trim() : ''
})

const policeNo = computed(() => {
  const v = policeField.value?.value ?? policeField.value?.defaultValue
  if (typeof v === 'string' && v.trim()) return v.trim()
  const fallback = (siteInfo.value as any)?.data?.policeNo
  return typeof fallback === 'string' ? fallback.trim() : ''
})

const siteCode = computed(() => {
  const v = siteCodeField.value?.value ?? siteCodeField.value?.defaultValue
  if (typeof v === 'string' && v.trim()) return v.trim()
  const fallback = (siteInfo.value as any)?.data?.siteCode
  return typeof fallback === 'string' ? fallback.trim() : ''
})

const icpText = computed(() => (icpNo.value ? `桂 ICP 备：${icpNo.value}` : '桂 ICP 备：'))
const policeText = computed(() => (policeNo.value ? `桂公网安备：${policeNo.value}` : '桂公网安备：'))
const siteCodeText = computed(() => (siteCode.value ? `网站标识码：${siteCode.value}` : '网站标识码：'))
const year = new Date().getFullYear()

const friendLinks = [
  { name: '广西壮族自治区人民政府', url: 'https://www.gxzf.gov.cn' },
  { name: '国务院发展研究中心', url: 'https://www.drc.gov.cn' },
  { name: '中国社会科学院', url: 'https://www.cass.cn' },
  { name: '广西社科联', url: 'http://www.gxskl.gov.cn' }
]
</script>

<style scoped>
.footer {
  background: #111827;
  padding: 0;
}
</style>
