import storyFullTwig from './node.story.full.twig';
import storyFullData from './node.story.full.yml';
import './node.story.full.js';

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

import { setPublishedStatus, formatParagraphCKEditor } from '.storybook/utils';
import { oneColumn } from '@ui-layouts/layouts.stories.js';

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

export const full = (args) => {
  // Create deep copy of data and merge args.
  let data = JSON.parse(JSON.stringify(storyFullData ?? {}));
  data = Object.assign(data, args);
  data.node = setPublishedStatus(data.node_is_published);

  let authorLinks = [];
  let topicLinks = [];

  data.node_field_ern_related_people.forEach(author => {
    authorLinks.push(linkTwig({
      link_text: author,
      link_url: '#',
    }))
  });

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

  return storyFullTwig({
    ...data,
    node_field_ern_related_people: authorLinks,
    node_field_summary: formatParagraphCKEditor(data.node_field_summary),
    node_topics: topicLinks.join('')
  });
}
full.args = storyFullData;
