import type { Field, GroupField } from 'payload'

import deepMerge from '@/utilities/deepMerge'

type AffiliateUnlockType = (options?: { overrides?: Partial<GroupField> }) => Field

export const affiliateUnlock: AffiliateUnlockType = ({ overrides = {} } = {}) => {
  const result: GroupField = {
    name: 'affiliateUnlock',
    type: 'group',
    label: 'Affiliate Unlock Button',
    admin: {
      hideGutter: true,
      description:
        'Shown as an unlock button below the preview of the chapter. Clicking it opens the link in a new tab.',
    },
    fields: [
      {
        type: 'row',
        fields: [
          {
            name: 'url',
            type: 'text',
            label: 'Affiliate Link',
            admin: { width: '50%' },
          },
          {
            name: 'label',
            type: 'text',
            label: 'Button Text',
            defaultValue: 'Mở khóa chương',
            admin: { width: '50%' },
          },
        ],
      },
    ],
  }

  return deepMerge(result, overrides)
}
