import storyTeaserTextTwig from './node.story.teaser-text.twig';
import storyTeaserTextData from './node.story.teaser-text.yml';
import './node.story.teaser-text.js';

import linkTwig from '@ui-base/link/_link.twig';

/**
 * Storybook Definition.
 */
export default {
  title: 'Content Types/Story/Teaser Text',
};

export const teaserText = (args) => {
  // Create deep copy of data and merge args.
  let data = JSON.parse(JSON.stringify(storyTeaserTextData ?? {}));
  data = Object.assign(data, args);

  let topicLinks = [];

  data.node_teaser_topics.forEach(topic => {
    topicLinks.push(linkTwig({
      link_text: topic,
    }));
  });

  return storyTeaserTextTwig({
    ...data,
    node_teaser_label_as_link: linkTwig({ link_text: data.node_teaser_label_as_link }),
    node_teaser_topics: topicLinks.join(''),
  });
}
teaserText.args = storyTeaserTextData;
