import personFullData from './node.person.full.yml';
import personFullTwig from './node.person.full.twig';
import './node.person.full.js';

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

import { icon } from '@ui-component/icon/icon.stories.js';

import { setPublishedStatus, formatParagraphCKEditor } from '.storybook/utils';

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

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

  data.node = setPublishedStatus(data.node_is_published);

  let socialLinks = [];

  data.node_field_social_links.forEach(socialLink => {
    socialLinks.push(linkTwig({
      link_text: icon({icon: socialLink.toLowerCase()}),
      link_url: '#',
    }))
  });

  return personFullTwig({
    ...data,
    node_field_erm_headshot: imgTwig({ image_src: data.node_field_erm_headshot }),
    node_field_erm_page_image: (data.showPageImage)
      ? imgTwig({ image_src: data.node_field_erm_page_image })
      : '',
    node_field_email: linkTwig({ link_text: 'Say Hello!', link_url: '#' }),
    node_field_bio: formatParagraphCKEditor(data.node_field_bio),
    node_field_summary: formatParagraphCKEditor(data.node_field_summary),
    node_field_social_links: socialLinks.join('')
  });
}
full.args = {
  ...personFullData,
  showPageImage: true
};
full.argTypes = {
  showPageImage: {
    control: 'boolean'
  }
}
