/* eslint-disable react/forbid-prop-types */
import React, { useContext } from 'react';
import { Context } from 'gatsby-core-theme/src/context/MainProvider';
import PropTypes from 'prop-types';
import Portrait from '../assets/portrait';
import Name from '../assets/name';
import Socials from '../../../../../atoms/author/socials';
import Expertise from '../assets/expertise';
import Ribbon from '../assets/ribbon';
import { translate } from '~helpers/getters';
import styles from './template-one.module.scss';

export default function TemplateOne({ author, icons, authorTitle }) {
  const { translations } = useContext(Context) || {};
  const {
    pages_count: pagesCount,
    author_title: jobTitle,
    name,
    biography,
    expertise,
    pronouns,
  } = author || null;

  return (
    <div className={styles?.container || ''}>
      <Ribbon
        className={styles?.posts || ''}
        author={author}
        content={`${pagesCount} ${translate(translations, 'posts', 'Posts')}`}
      />
      <Portrait className={styles?.portrait || ''} author={author} />
      <div>
        {jobTitle && <div className={styles?.title || ''}>{jobTitle}</div>}
        <Name
          className={styles?.name || ''}
          name={authorTitle || name}
          icon={icons?.verify}
          pronouns={pronouns || ''}
        />
        <Socials className={styles?.socials || ''} author={author} />
        {biography && (
          <div
            className={styles?.biography || ''}
            // eslint-disable-next-line react/no-danger
            dangerouslySetInnerHTML={{ __html: biography }}
          />
        )}
        <Expertise expertise={expertise} icon={icons?.expertise} />
      </div>
    </div>
  );
}

TemplateOne.propTypes = {
  authorTitle: PropTypes.string,
  author: PropTypes.shape({
    name: PropTypes.string,
    pages_count: PropTypes.number,
    author_title: PropTypes.string,
    biography: PropTypes.string,
    image_alt: PropTypes.string,
    expertise: PropTypes.array,
    icon: PropTypes.object,
    profile_page_path: PropTypes.string,
    facebook_profile: PropTypes.string,
    instagram_profile: PropTypes.string,
    linkedin_profile: PropTypes.string,
    twitter_profile: PropTypes.string,
    tik_tok: PropTypes.string,
    image_object: PropTypes.shape({
      filename: PropTypes.string,
    }),
  }),
  icons: PropTypes.object,
};
