import React from 'react';
import CopyrightContainer from '@digigov/react-core/CopyrightContainer';
import { useTranslation } from '@digigov/ui/i18n';
import Link from '@digigov/ui/navigation/Link';

export const getCopyright = () => {
  const year = new Date().getFullYear();
  return `© Copyright ${year} - `;
};

export interface CopyrightProps {
  copyright?: string;
  createdBy?: React.ReactNode;
  minDigitalCopyright?: boolean;
  children?: React.ReactNode;
}
export const Copyright: React.FC<CopyrightProps> = ({
  copyright,
  createdBy,
  minDigitalCopyright,
  children,
  ...props
}) => {
  const { t } = useTranslation();
  const copyrightInfo = minDigitalCopyright
    ? {
        url: 'https://mindigital.gr',
        label: t('footer.mindigital'),
      }
    : {
        url: 'https://grnet.gr',
        label: t('footer.grnet'),
      };

  return (
    <CopyrightContainer {...props}>
      {children ? (
        children
      ) : (
        <>
          {copyright}
          {createdBy || (
            <>
              {`${t('footer.created_by')} `}
              <Link
                href={copyrightInfo.url}
                target="_blank"
                rel="noopener noreferrer"
              >
                {`${copyrightInfo.label}`}
              </Link>
              {!minDigitalCopyright && (
                <>
                  {` ${t('footer.created_for')} `}
                  <Link
                    href="https://mindigital.gr"
                    target="_blank"
                    rel="noopener noreferrer"
                  >
                    {`${t('footer.mindigital')}`}
                  </Link>
                </>
              )}
            </>
          )}
        </>
      )}
    </CopyrightContainer>
  );
};

export { CopyrightContainer };

export default Copyright;
