import React, {useEffect} from 'react';
import { styled, keyframes } from '@mui/system';

const flameFlicker = keyframes`
  0% { transform: scaleY(1); opacity: 1; }
  50% { transform: scaleY(1.5); opacity: 0.8; }
  100% { transform: scaleY(1); opacity: 1; }
`;

const FlamesWrapper = styled('div')`
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background: black;
  overflow: hidden;
`;

const Flame = styled('div')`
  position: absolute;
  bottom: 0;
  width: 20px;
  height: 100px;
  background: linear-gradient(to top, orange, transparent);
  animation: ${flameFlicker} 0.5s infinite;
  border-radius: 50%;
`;

const FlamesBackground = ({ children }) => {
  useEffect(() => {
    const flamesWrapper = document.getElementById('flamesWrapper');
    for (let i = 0; i < 30; i++) {
      const flame = document.createElement('div');
      flame.className = Flame.styledComponentId;
      flame.style.left = `${Math.random() * 100}%`;
      flame.style.animationDuration = `${Math.random() * 0.5 + 0.5}s`;
      flamesWrapper.appendChild(flame);
    }
  }, []);

  return <FlamesWrapper id="flamesWrapper">{children}</FlamesWrapper>;
};

export default FlamesBackground;
