Spaces:
Running

File size: 10,191 Bytes
ce65d97
8fd5d73
ce65d97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fd5d73
ce65d97
 
 
 
 
8fd5d73
 
 
 
 
 
 
 
 
ce65d97
 
 
b8040c3
ce65d97
 
 
8fd5d73
ce65d97
 
 
 
 
 
8fd5d73
ce65d97
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, {useEffect, useId, useRef, useState} from 'react';
import {ArrowDownRight, ArrowRight, ChevronDown, ChevronUp, Flame, Pause, Play, RotateCcw, Sun, Volume2, VolumeX, Zap} from 'lucide-react';
import './intro.css';

function EnergyField() {
  const uid=useId().replaceAll(':','');
  return <svg className="energy-field" viewBox="0 0 1200 520" fill="none" aria-hidden="true" focusable="false" preserveAspectRatio="xMidYMid slice">
    <defs>
      <linearGradient id={`${uid}-current`} x1="70" y1="460" x2="1130" y2="40" gradientUnits="userSpaceOnUse"><stop stopColor="#c8f58d" stopOpacity="0"/><stop offset=".48" stopColor="#c8f58d" stopOpacity=".8"/><stop offset="1" stopColor="#c8f58d" stopOpacity="0"/></linearGradient>
      <radialGradient id={`${uid}-glow`}><stop stopColor="#a5ce67" stopOpacity=".16"/><stop offset="1" stopColor="#a5ce67" stopOpacity="0"/></radialGradient>
    </defs>
    <circle cx="900" cy="220" r="330" fill={`url(#${uid}-glow)`}/>
    <g className="energy-orbit" transform="translate(700 255)" stroke="#a8cc8e" strokeOpacity=".13">
      <ellipse rx="370" ry="147" transform="rotate(-34)"/><ellipse rx="353" ry="157" transform="rotate(-30)"/><ellipse rx="336" ry="167" transform="rotate(-26)"/>
    </g>
    <g stroke={`url(#${uid}-current)`} strokeWidth="1">
      <path d="M-90 445C205 532 318 388 519 402S806 505 970 339 1230 130 1290 178"/>
      <path d="M-90 460C205 547 318 403 519 417S806 520 970 354 1230 145 1290 193" opacity=".45"/>
      <path className="energy-current" d="M-90 445C205 532 318 388 519 402S806 505 970 339 1230 130 1290 178" stroke="#d4ff9e" strokeWidth="2" strokeDasharray="32 1260"/>
      <path className="energy-current energy-current-late" d="M-90 460C205 547 318 403 519 417S806 520 970 354 1230 145 1290 193" stroke="#d4ff9e" strokeWidth="2" strokeDasharray="18 1274"/>
    </g>
    <g className="energy-atom" transform="translate(1133 76)" stroke="#c8f58d" strokeWidth=".8" opacity=".7">
      <g className="energy-atom-spin"><ellipse rx="32" ry="11"/><ellipse rx="32" ry="11" transform="rotate(60)"/><ellipse rx="32" ry="11" transform="rotate(120)"/><circle cx="30" cy="4" r="2.7" fill="#d4ff9e" stroke="none"/></g><circle r="3" fill="#d4ff9e" stroke="none"/>
    </g>
    <g fill="#c8f58d" opacity=".38"><circle cx="610" cy="101" r="2"/><circle cx="730" cy="440" r="2"/><circle cx="1085" cy="392" r="2"/><path d="M566 459h10m-5-5v10M1042 45h10m-5-5v10" stroke="#c8f58d"/></g>
  </svg>;
}

export default function EnergyIntro({active=true,onStart}) {
  const [expanded,setExpanded]=useState(true);
  const [motionPaused,setMotionPaused]=useState(()=>typeof window!=='undefined'&&window.matchMedia('(prefers-reduced-motion: reduce)').matches);
  const [visible,setVisible]=useState(true),[pageVisible,setPageVisible]=useState(()=>typeof document==='undefined'||!document.hidden);
  const [playing,setPlaying]=useState(false),[muted,setMuted]=useState(true),[ended,setEnded]=useState(false),[progress,setProgress]=useState(0),[mediaError,setMediaError]=useState('');
  const root=useRef(null), video=useRef(null), resumeVideo=useRef(false), showControl=useRef(null), hideControl=useRef(null);
  const moving=active&&expanded&&visible&&pageVisible&&!motionPaused;

  useEffect(()=>{
    const preference=window.matchMedia('(prefers-reduced-motion: reduce)');
    const reduce=event=>{if(event.matches){setMotionPaused(true);video.current?.pause();resumeVideo.current=false;}};
    preference.addEventListener('change',reduce);
    const visibility=()=>{setPageVisible(!document.hidden);if(document.hidden){video.current?.pause();resumeVideo.current=false;}};
    document.addEventListener('visibilitychange',visibility);
    return()=>{preference.removeEventListener('change',reduce);document.removeEventListener('visibilitychange',visibility);};
  },[]);
  useEffect(()=>{
    if(!root.current||!('IntersectionObserver' in window))return;
    const observer=new IntersectionObserver(([entry])=>{setVisible(entry.isIntersecting);if(!entry.isIntersecting){video.current?.pause();resumeVideo.current=false;}},{threshold:.08});
    observer.observe(root.current);return()=>observer.disconnect();
  },[expanded]);
  useEffect(()=>{if(!active||!expanded){video.current?.pause();resumeVideo.current=false;}},[active,expanded]);

  const playFilm=async()=>{
    if(!video.current)return;
    setMediaError('');setMotionPaused(false);
    if(video.current.ended)video.current.currentTime=0;
    try {await video.current.play();} catch {setMediaError('Playback is unavailable. You can still start your analysis.');}
  };
  const toggleFilm=()=>{if(playing)video.current?.pause();else playFilm();};
  const toggleMotion=()=>{
    if(!motionPaused){resumeVideo.current=!!video.current&&!video.current.paused;video.current?.pause();setMotionPaused(true);}
    else {setMotionPaused(false);if(resumeVideo.current){resumeVideo.current=false;playFilm();}}
  };
  const collapse=(restoreFocus=true)=>{video.current?.pause();resumeVideo.current=false;setPlaying(false);setEnded(false);setProgress(0);setMediaError('');setExpanded(false);if(restoreFocus)requestAnimationFrame(()=>showControl.current?.focus({preventScroll:true}));};
  const expand=()=>{setExpanded(true);requestAnimationFrame(()=>hideControl.current?.focus({preventScroll:true}));};
  const start=()=>{collapse(false);onStart?.();};
  const replay=()=>{if(video.current)video.current.currentTime=0;setEnded(false);setProgress(0);playFilm();};

  if(!expanded)return <section ref={root} className="energy-intro-collapsed" aria-label="Right to Energy introduction"><span><Zap size={17}/><strong>Right to Energy.</strong><small>Fair bills. Fair returns.</small></span><button ref={showControl} type="button" onClick={expand}>Show intro <ChevronDown size={15}/></button></section>;

  return <section ref={root} className="energy-intro" data-motion={moving?'running':'paused'} aria-labelledby="energy-intro-title">
    <EnergyField/>
    <div className="energy-intro-top"><span className="energy-edition"><i/>XENOWATTZ PRESENTS <span>/</span> RIGHT TO ENERGY</span><button ref={hideControl} type="button" className="energy-hide" onClick={()=>collapse()} aria-label="Hide introduction">Hide intro <ChevronUp size={14}/></button></div>
    <div className="energy-intro-body">
      <div className="energy-intro-copy">
        <p className="energy-audience">FOR HOUSEHOLDS. NGOs. SMALL BUSINESSES.</p>
        <h2 id="energy-intro-title">Right to<br/><span>Energy.</span><svg viewBox="0 0 70 70" aria-hidden="true" focusable="false"><path d="M18 15h37v37M55 15L15 55"/></svg></h2>
        <p className="energy-promise">Fair bills. Fair returns.</p>
        <ul className="energy-focus" aria-label="Our mission"><li><Zap size={13} aria-hidden="true"/>Electricity</li><li><Flame size={13} aria-hidden="true"/>Gas</li><li><Sun size={13} aria-hidden="true"/>Solar returns</li></ul>
        <p className="energy-mission">What you pay. What your roof earns. Put supplier prices, network costs, policy charges and taxes under scrutiny.</p>
        <button className="energy-start" type="button" onClick={start}>Analyse electricity <ArrowRight size={18}/></button>
        <p className="energy-caption">Electricity tools live now. Your data. A fresh forecast.</p>
      </div>
      <div className="energy-film-column">
        <div className="energy-film-label"><span><i/>MEET BHOR BOHR</span><span>THE INTRO <span className="energy-slash">/</span> 10 SEC</span></div>
        <div className={`energy-film${playing?' is-playing':''}`}>
          <video ref={video} playsInline muted={muted} preload="none" poster="/brand/right-to-energy-poster.jpg" aria-label="Bhor Bohr in a wall of glowing CRT televisions, with electrical sparks and green digital effects" onCanPlay={()=>setMediaError('')} onPlay={()=>{setPlaying(true);setEnded(false);}} onPause={()=>setPlaying(false)} onEnded={()=>{setPlaying(false);setEnded(true);setProgress(1);}} onTimeUpdate={event=>{const el=event.currentTarget;setProgress(el.duration?Math.min(el.currentTime/el.duration,1):0);}} onError={event=>{if(event.target===event.currentTarget&&event.currentTarget.error)setMediaError('The intro could not load. Your analysis is still available.');}}>
            <source src="/brand/right-to-energy-intro-mobile.mp4" type="video/mp4" media="(max-width: 640px)"/>
            <source src="/brand/right-to-energy-intro.mp4" type="video/mp4"/>
          </video>
          {!playing&&<button type="button" className="energy-film-play" onClick={toggleFilm} aria-label={ended?'Replay Bhor Bohr intro':'Play Bhor Bohr intro'}><span>{ended?<RotateCcw size={24}/>:<Play size={24} fill="currentColor"/>}</span><strong>{ended?'Once more?':'Every bill deserves a question.'}</strong><small>{ended?'Replay the intro':'Press play. Then follow the numbers.'}</small></button>}
          <div className="energy-film-controls"><button type="button" onClick={toggleFilm} aria-label={playing?'Pause intro':'Play intro'}>{playing?<Pause size={16}/>:<Play size={16}/>}<span>{playing?'Pause':ended?'Replay':'Play'}</span></button><span className="energy-film-progress" aria-hidden="true"><i style={{transform:`scaleX(${progress})`}}/></span><button type="button" onClick={()=>setMuted(previous=>!previous)} aria-label={muted?'Turn intro sound on':'Mute intro sound'} aria-pressed={!muted}>{muted?<VolumeX size={17}/>:<Volume2 size={17}/>}</button><button type="button" onClick={replay} aria-label="Restart intro"><RotateCcw size={15}/></button></div>
        </div>
        <div className="energy-character-line"><span className="energy-quote-mark">“</span><p>Even Bhor Bohr has bills to pay.</p><span className="energy-character-credit">BHOR BOHR<br/><b>RESIDENT ENERGY REBEL</b></span></div>
        {mediaError&&<p className="energy-media-error" role="status">{mediaError}</p>}
      </div>
    </div>
    <div className="energy-intro-bottom"><span><ArrowDownRight size={16}/> AFFORDABILITY. ACCOUNTABILITY. BALANCE.</span><button type="button" onClick={toggleMotion} aria-pressed={motionPaused}>{motionPaused?<Play size={12}/>:<Pause size={12}/>} {motionPaused?'Resume motion':'Pause motion'}</button></div>
  </section>;
}