import React, { useEffect } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import styled from 'styled-components';
import ParticleBackground from '../../components/ParticleBackground/ParticleBackground';
import { AnalyticsEvents, trackEvent } from '../../utils/analytics';

const PageContainer = styled.div`
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  color: #fff;
  font-family: 'Inter', sans-serif;
`;

const ContentWrapper = styled.div`
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 5;
  padding: 2rem;
`;

const GlassCard = styled.div`
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  padding: 3rem;
  width: 100%;
  max-width: 450px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
`;

const CardTitle = styled.h2`
  font-size: 2rem;
  margin-bottom: 1rem;
  color: #fff;
`;

const BodyText = styled.p`
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 1.5rem;
  line-height: 1.5;
`;

const PrimaryButton = styled.button`
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 0.5rem;
  color: #fff;
  padding: 1rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-bottom: 1rem;

  &:hover {
    transform: translateY(-2px);
  }
`;

const NavLink = styled(Link)`
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  text-decoration: none;

  &:hover {
    color: #fff;
    text-decoration: underline;
  }
`;

const BillingCancel = (): JSX.Element => {
  const navigate = useNavigate();

  useEffect(() => {
    trackEvent(AnalyticsEvents.PAYMENT_CANCELED);
  }, []);

  return (
    <PageContainer>
      <ParticleBackground />
      <ContentWrapper>
        <GlassCard>
          <CardTitle>Checkout canceled</CardTitle>
          <BodyText>
            No charge was made. Your account may already exist — sign in and open billing again, or
            return to sign up to retry Stripe Checkout.
          </BodyText>
          <PrimaryButton type="button" onClick={() => navigate('/signup/')}>
            Retry sign up
          </PrimaryButton>
          <NavLink to="/signin/">Back to sign in</NavLink>
        </GlassCard>
      </ContentWrapper>
    </PageContainer>
  );
};

export default BillingCancel;
