import { Block } from 'payload';
import { lexicalEditor } from '@payloadcms/richtext-lexical';

export const ProductTabs: Block = {
  slug: 'productTabs',
  interfaceName: 'ProductTabsBlock',
  fields: [
    {
      name: 'technicalItems',
      type: 'array',
      fields: [
        {
          name: 'label',
          type: 'text',
          required: true,
        },
        {
          name: 'value',
          type: 'text',
          required: true,
        },
        {
          name: 'unit',
          type: 'text',
        },
      ],
    },
    {
      name: 'voltageTables',
      type: 'array',
      fields: [
        {
          name: 'voltageLabel',
          type: 'text',
          required: true,
        },
        {
          name: 'metaItems',
          type: 'array',
          fields: [
            {
              name: 'label',
              type: 'text',
              required: true,
            },
            {
              name: 'value',
              type: 'text',
              required: true,
            },
            {
              name: 'unit',
              type: 'text',
            },
          ],
        },
        {
          name: 'columns',
          type: 'array',
          fields: [
            {
              name: 'key',
              type: 'text',
              required: true,
            },
            {
              name: 'label',
              type: 'text',
              required: true,
            },
          ],
        },
        {
          name: 'rows',
          type: 'array',
          fields: [
            {
              name: 'configuration',
              type: 'text',
              required: true,
            },
            {
              name: 'cells',
              type: 'array',
              fields: [
                {
                  name: 'value',
                  type: 'text',
                },
              ],
            },
          ],
        },
      ],
    },
    {
      name: 'content',
      type: 'richText',
      editor: lexicalEditor({
        features: ({ defaultFeatures }) => [
          ...defaultFeatures,
          // We don't need blocks inside ProductTabs for now to avoid complexity/recursion
        ],
      }),
    },
  ],
};
