import linkListTwig from './paragraph.link-list.twig';
import linkListData from './paragraph.link-list.yml';
import './paragraph.link-list.js';

import linkTwig from '@ui-base/link/_link.twig';
import { setPublishedStatus } from '.storybook/utils';

/**
 * Storybook Definition.
 */
export default {
  title: 'Layout Components/Link List',
};

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

  data.paragraph = setPublishedStatus(data.paragraph_is_published);

  let links = [];

  data.paragraph_field_links.forEach(link => {
    links.push(linkTwig({ link_text: link }));
  });

  return linkListTwig({
    ...data,
    paragraph_field_links: links
  });
};
linkList.args = linkListData;
