import configPromise from '@payload-config'
import { getPayload } from 'payload'

const seed = async () => {
  const payload = await getPayload({ config: configPromise })

  await payload.updateGlobal({
    slug: 'header',
    data: {
      navItems: [
        { link: { type: 'custom', url: '/', label: 'Trang Chủ', newTab: false } },
        { link: { type: 'custom', url: '/truyen-moi', label: 'Truyện Mới', newTab: false } },
        { link: { type: 'custom', url: '/tags', label: 'Tags', newTab: false } },
      ],
    },
    overrideAccess: true,
    context: { disableRevalidate: true },
  })
  console.log('✓ Header seeded')

  await payload.updateGlobal({
    slug: 'footer',
    data: {
      navItems: [
        { link: { type: 'custom', url: '/', label: 'Trang Chủ', newTab: false } },
        { link: { type: 'custom', url: '/the-loai', label: 'Thể Loại', newTab: false } },
        { link: { type: 'custom', url: '/tags', label: 'Tags', newTab: false } },
        { link: { type: 'custom', url: '/search', label: 'Tìm Kiếm', newTab: false } },
      ],
    },
    overrideAccess: true,
    context: { disableRevalidate: true },
  })
  console.log('✓ Footer seeded')

  process.exit(0)
}

seed().catch((err) => {
  console.error(err)
  process.exit(1)
})
