import type { Block } from 'payload'

export const ServicesList: Block = {
  slug: 'servicesList',
  interfaceName: 'ServicesListBlock',
  fields: [
    {
      name: 'services',
      type: 'array',
      required: true,
      admin: {
        initCollapsed: true,
      },
      fields: [
        {
          name: 'title',
          type: 'text',
          required: true,
        },
        {
          name: 'description',
          type: 'textarea',
          required: true,
        },
        {
          name: 'category',
          type: 'text',
          required: true,
        },
        {
          name: 'iconType',
          type: 'select',
          defaultValue: 'preset',
          options: [
            { label: 'Preset Icon', value: 'preset' },
            { label: 'Custom SVG', value: 'svg' },
            { label: 'Upload Image', value: 'upload' },
          ],
        },
        {
          name: 'icon',
          type: 'text',
          admin: {
            description: 'Preset icon name: facebook, google, ads, news, youtube, forum, web, video',
            condition: (_, siblingData) => siblingData?.iconType === 'preset',
          },
        },
        {
          name: 'iconSvg',
          type: 'textarea',
          admin: {
            description: 'Paste SVG code directly (e.g., <svg>...</svg>)',
            condition: (_, siblingData) => siblingData?.iconType === 'svg',
          },
        },
        {
          name: 'iconImage',
          type: 'upload',
          relationTo: 'media',
          admin: {
            description: 'Upload an icon image (SVG, PNG)',
            condition: (_, siblingData) => siblingData?.iconType === 'upload',
          },
        },
        {
          name: 'isHot',
          type: 'checkbox',
          defaultValue: false,
        },
        {
          name: 'image',
          type: 'upload',
          relationTo: 'media',
        },
        {
          name: 'link',
          type: 'text',
        },
      ],
    },
  ],
  labels: {
    singular: 'Services List',
    plural: 'Services Lists',
  },
}
