import { useFormContext } from 'react-hook-form';

import { InformationRow } from 'src/pages/dashboard/Learning/common/components/InformationRow';
import { RevisionAccordion } from 'src/pages/dashboard/Learning/common/components/RevisionAccordion';
import { PathSteps } from 'src/pages/dashboard/Learning/Paths/constants';
import { newPathFields } from 'src/pages/dashboard/Learning/Paths/New/form';
import { type NewPathFormValues } from 'src/pages/dashboard/Learning/Paths/types';
import { getNotificationChannelLabelKey } from 'src/pages/dashboard/Learning/Paths/utils';
import { useLokaliseTranslation } from 'src/utils/i18n';

const RevisionPathConfiguration = () => {
  const { t } = useLokaliseTranslation(['learning', 'notifications_center']);
  const { getValues } = useFormContext<NewPathFormValues>();
  const pathConfiguration = getValues(newPathFields.configuration.all());

  const {
    isObligatory,
    isSequential,
    sendPushNotification,
    sendEmailNotification,
    dueDate,
    issueCertificate,
  } = pathConfiguration;

  const data = [
    {
      title: t(`common.type`),
      description: isObligatory
        ? t(`path.required.title`)
        : t(`course.optional`),
    },
    {
      title: t(`common.order`),
      description: isSequential
        ? t(`common.sequential`)
        : t(`common.no_sequential`),
    },
    {
      title: t(`common.deadline`),
      description: dueDate
        ? t(`common.days_from_assignment`, {
            count: Number(dueDate),
          })
        : t(`common.no_deadline`),
    },
    {
      title: t(`common.certificate`),
      description: issueCertificate
        ? t(`common.completion_certificate`)
        : t(`common.no_certificate`),
    },
    {
      title: t(`common.notifications`),
      description: t(
        getNotificationChannelLabelKey(
          sendPushNotification,
          sendEmailNotification,
        ),
      ),
    },
  ];

  return (
    <RevisionAccordion step={PathSteps.CONFIGURATION}>
      {data.map(item => (
        <InformationRow
          key={item.title}
          title={item.title}
          description={item.description}
        />
      ))}
    </RevisionAccordion>
  );
};

export default RevisionPathConfiguration;
