import { Node } from '../../node.js'

class PageItemHeadingContainerDirective extends Node {
  structure (data) {
    const children = [
      {
        type: 'heading',
        depth: 3,
        children: [
          {
            type: 'link',
            url: data.url,
            children: [
              {
                type: 'text',
                value: data.text
              },
            ],
          },
        ],
      }
    ];

    if (data.shortDescription || data.excerpt) {
      children.push({
        type: 'paragraph',
        children: [
          {
            type: 'text',
            value: data.shortDescription || data.excerpt,
          },
        ],
      });
    }

    return super.structure({
      type: 'htmlContainer',
      tagName: 'div',
      classes: ['fr-col-12'],
      children: children,
    });
  }
}

PageItemHeadingContainerDirective.NAME = 'dsfr-doc-page-item-heading';

export { PageItemHeadingContainerDirective };
