import homepageHeroTwig from './paragraph.homepage-hero.twig';
import homepageHeroData from './paragraph.homepage-hero.yml';
import './paragraph.homepage-hero.js';

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

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

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

  data.paragraph = setPublishedStatus(data.paragraph_is_published);

  return homepageHeroTwig({
    ...data,
    paragraph_field_link: linkTwig({
      link_text: data.paragraph_field_link,
    }),
    paragraph_field_body: formatParagraphCKEditor(data.paragraph_field_body),
    paragraph_field_subtitle: formatParagraphCKEditor(data.paragraph_field_subtitle),
  });
}
homepageHero.args = homepageHeroData;
