import { ToastContainer } from 'react-toastify-next';
import { keyframes, styled } from '../../styled';
import { NOTIFY_HEIGHT, NOTIFY_HEIGHT_MOBILE, NotificationVariantTypes, notifyClassnames, } from '../constants';
const leaveIn = keyframes `
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0px);
  }
`;
const leaveOut = keyframes `
  from {
    transform: translateX(0px);
  }
  to {
    transform: translateX(100%);
    visibility: hidden;
  }
`;
const leaveInMobile = keyframes `
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0px);
  }
`;
// используем дополнительный враппер,
// потому что styled для ToastContainer не умеет работать с theme внутри
// использовать бэм классы для стилизации пришлось,
// потому что react-toastify не предоставляет,
// достаточно контейнеров для стилизации через styled,
// к примеру добраться до прогресс бара можно только через цсс классы
export const Wrapper = styled('div', {
    shouldForwardProp: (prop) => !['$isBanner'].includes(prop),
}) `
  ${({ theme }) => theme.breakpoints.up('sm')} {
    ${({ $isBanner, theme }) => $isBanner &&
    `
        position: fixed;
        z-index: ${theme.zIndex.snackbar};
        right: 0;
        bottom: 0;
        width: 432px;
      `}
  }

  .Toastify__toast-container {
    ${({ theme }) => theme.breakpoints.down('sm')} {
      padding: ${({ theme }) => theme.spacing(4)};
    }
  }

  .${notifyClassnames.animationIn} {
    animation: ${leaveIn} ease-in-out ${({ theme }) => theme.transitions.duration.standard}ms;
    animation-fill-mode: both;

    ${({ theme }) => theme.breakpoints.down('sm')} {
      animation: ${leaveInMobile} ease-in-out ${({ theme }) => theme.transitions.duration.standard}ms;
      animation-fill-mode: both;
    }
  }

  .${notifyClassnames.animationOut} {
    animation: ${leaveOut} ease-in-out ${({ theme }) => theme.transitions.duration.standard}ms;
    animation-fill-mode: both;
  }

  .${notifyClassnames.root} {
    margin-bottom: ${({ theme }) => theme.spacing(1)};
    padding: 0;

    border-radius: ${({ theme }) => theme.shape.medium};
    box-shadow: ${({ theme }) => theme.elevation[300]};

    &::after {
      content: '';

      position: absolute;
      top: 0;
      left: 0;

      display: block;

      width: 100%;
      height: 3px;
    }
      ${({ theme }) => theme.breakpoints.up('sm')} {
      min-height: ${NOTIFY_HEIGHT};
    }
    ${({ theme }) => theme.breakpoints.down('sm')} {
      min-height: ${NOTIFY_HEIGHT_MOBILE};
    }

    ${({ theme }) => theme.breakpoints.down('sm')} {
      margin-bottom: ${({ theme }) => theme.spacing(3)};
    }

    .Toastify__progress-bar--wrp {
      top: 0;

      height: 3px;
    }
    
    .Toastify__progress-bar {
      opacity: 1;
    }

    &--${NotificationVariantTypes.Info} {
      --toastify-color-progress-light: ${({ theme }) => theme.palette.primary[800]};
    }
    &--${NotificationVariantTypes.Success} {
      --toastify-color-progress-light: ${({ theme }) => theme.palette.success[800]};
    }
    &--${NotificationVariantTypes.Warning} {
      --toastify-color-progress-light: ${({ theme }) => theme.palette.warning[800]};
    }
    &--${NotificationVariantTypes.Error} {
      --toastify-color-progress-light: ${({ theme }) => theme.palette.error[800]};
    }

    &__body {
      margin: 0;
      padding: 0;
    }

    &__progress {
      top: 0;
      bottom: auto;

      height: 3px;
    }
  }
`;
export const Inner = styled(ToastContainer, {
    shouldForwardProp: (prop) => !['$isBanner'].includes(prop),
}) `
  min-width: 400px;
  ${({ theme }) => theme.breakpoints.up('sm')} {
    ${({ $isBanner, theme }) => $isBanner &&
    `
        position: relative !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100%;
        max-width: 432px;
        padding-bottom: 0 !important;
        padding-left: ${theme.spacing(3)} !important;
      `}
  }

  ${({ theme }) => theme.breakpoints.down('sm')} {
    width: 100%;
    min-width: unset;
    max-width: unset;
    padding: ${({ theme }) => theme.spacing(2, 4, 0, 4)};
  }
`;
