import{removeBloomQuickPanels as y}from"./panel.js-Sp61DuG0.js";import{createTradingPanel as d}from"./panel-new.js-BnOGaXq1.js";import"./utils.js-CCIONsCi.js";const b="dexscreener";window.platform=b;let u="#00ff95",i="#00563180";function p(){document.querySelectorAll(".bloom-buy-qt-btn").forEach(e=>{e.style.color=u,e.style.backgroundColor=i,e.style.borderColor=`${i}${i.length===7?"80":""}`;const s=e.querySelector("svg");s&&s.setAttribute("fill",u),e.onmouseover=function(){e.style.backgroundColor=i.slice(0,7)+"CC"},e.onmouseout=function(){e.style.backgroundColor=i}})}chrome.storage.onChanged.addListener(t=>{if(t["bloom.quickBuyButton"]){const e=t["bloom.quickBuyButton"].newValue||{};u=e?.color||"#00ff95",i=e?.backgroundColor||"#00563180",p()}});async function w(){const t=[...document.getElementsByClassName("chakra-text")].find(e=>e.innerText==="Pair")?.getAttribute("title");return t||showToast("Pool ID not found!")}window.getPoolId=w;async function x(){const t=[...document.getElementsByClassName("chakra-text")].find(n=>n.innerText==="Pair");if(!t)return showToast("Token mint not found!");const e=t.parentElement;if(!e)return showToast("Token mint not found!");const s=[e.nextSibling.nextSibling,e.nextSibling.nextSibling.nextSibling];let o="";for(const n of s){const r=n.firstChild;if(r.innerText!=="SOL"){o=r.getAttribute("title");break}}return o||showToast("Failed to get token mint!")}window.getTokenMint=x;let m,f;chrome.runtime.onMessage.addListener(async function(t){if(f=t.tabId,window.__BLOOM_TAB_ID__=f,t.message==="txUpdate")return showSwapToast(t);t.shouldWarnAboutUpdate&&showToast("A new version of the Bloom Extension is available! Check out how to install it <a href='https://docs.bloombot.app/extension/setup/download-chrome/.zip-file' target='_blank' style='text-decoration: underline; color: #EEA7ED;'>here</a>","top-center");const e=(await chrome.storage.local.get("bloom.sitePreferences"))?.["bloom.sitePreferences"]||{};if(y(),e[b]===!1)return;const s=(await chrome.storage.local.get("bloom.quickBuyButton"))?.["bloom.quickBuyButton"]||{};if(u=s?.color||"#00ff95",i=s?.backgroundColor||"#00563180",t.message==="dexscreener-token"){const o=await C();o&&(g(o.container,o.hasMetadata),d());const n=document.querySelector("main");new MutationObserver(async c=>{for(const a of c)if(a.removedNodes.length>0&&Array.from(a.removedNodes).find(l=>l.nodeName.toLowerCase()==="div"&&!l.classList?.contains("bloom-buy-qt-btn-div"))&&!a.target?.classList?.contains("chakra-stack")){const l=await C();l&&g(l.container,l.hasMetadata)}}).observe(n,{childList:!0,subtree:!0})}else t.message==="reset"&&m==="dexscreener-token"?d():t.message!=="quickBuyAmount"&&(m="other")});async function C(t=1e4){for(let e=0;e<t/500;e++){const s=[document.querySelector('div[style="overflow-anchor: none;"]'),document.querySelector('div[style="overflow-anchor:none"]')].find(Boolean);if(s){const o=Array.from(s.children).filter(l=>Array.from(l.classList).every(h=>!h.includes("bloom"))),r=o.some(l=>l.innerHTML.includes("Embed this chart"))?8:7,c=o.length===r,a=c?o[2]:o[1];if(a)return{container:a,hasMetadata:c}}await new Promise(o=>setTimeout(o,500))}return null}function g(t,e){try{const s=document.querySelector(".bloom-buy-qt-btn"),o=document.querySelector(".bloom-buy-qt-btn-div");s&&s.remove(),o&&o.remove();const n=document.createElement("div");n.classList.add("bloom-buy-qt-btn-div"),n.style.display="flex",n.style.justifyContent="center",n.style.alignItems="center",n.style.gap="4px",n.style.width="100%",n.style.marginTop=e?"24px":"12px";const r=document.createElement("button");r.innerHTML=`
      <svg style="flex-shrink: 0; width: 14px; height: 14px;" viewBox="0 0 40 40" fill="${u}" xmlns="http://www.w3.org/2000/svg">
        <path d="M37.0146 17.925C41.1031 22.5236 41.0995 29.1627 36.3408 32.01C35.2744 32.6581 34.0458 32.9768 32.8037 32.9768C31.5618 32.977 30.5089 34.0174 30.5088 35.2981V39.6702C24.1963 41.066 18.8553 37.8804 16.4795 33.0657C14.631 29.3229 14.5746 24.5943 17.2432 20.2678C17.3623 23.7545 20.1462 30.1369 26.083 31.4612C26.362 31.5204 26.638 31.5657 26.9121 31.5969C30.0776 31.9714 32.7697 30.65 32.7334 30.2053C32.6804 29.9881 32.1081 29.8967 31.3809 29.7815C30.8308 29.6941 30.192 29.5933 29.6221 29.4124C28.5833 29.0831 27.7736 28.4905 28.1436 27.2395C28.7538 26.2922 29.7681 26.1742 30.9062 26.0422C31.2816 25.9988 31.6712 25.953 32.0635 25.8762C34.093 25.4752 36.2101 24.2221 37.0146 17.925ZM11.8262 9.27563C16.235 9.24781 20.7146 11.5628 23.2471 16.3704C20.201 14.7307 13.3434 13.9774 9.24121 18.5149C7.90955 20.0187 7.22894 21.7821 6.96191 23.0872C6.7501 24.1287 6.80045 24.8758 6.99316 24.967C7.1 25.0175 7.25384 24.908 7.44336 24.7024C7.60309 24.532 7.78937 24.2954 7.99707 24.0315C8.76841 23.0513 9.83908 21.6907 10.9736 21.9143C12.6629 22.4111 12.0929 23.8403 11.46 25.429C11.1403 26.2311 10.8047 27.0745 10.7354 27.8586C10.6734 28.5137 10.7669 29.2842 11.1631 30.1711C11.7472 31.4725 12.9875 33.0302 15.3662 34.8577C9.38443 36.1383 3.70042 32.8175 3.64355 27.2258C3.64355 27.2066 3.64398 27.1868 3.64355 27.1672C3.64313 27.1477 3.64258 27.1278 3.64258 27.1086C3.64265 25.8925 3.98005 24.6986 4.58301 23.6428C5.21675 22.5329 4.83945 21.1152 3.74219 20.4739L0 18.2883C1.85727 12.3899 6.79708 9.30872 11.8262 9.27563ZM11.6943 7.42896C13.5878 1.54994 19.2745 -1.76803 24.0898 0.977783C25.177 1.58593 26.0664 2.50275 26.6885 3.59009C27.3225 4.70006 28.7247 5.08192 29.8223 4.44067L33.5654 2.25513C38.5807 7.82595 37.7402 15.305 33.3848 19.7659C31.0263 22.1844 27.6343 23.7147 23.584 23.5754C26.5111 21.7283 30.5836 16.0981 28.749 10.2366C28.6698 9.99261 28.583 9.75684 28.4863 9.52856C27.2373 6.5142 24.712 4.78065 24.3486 5.04028C24.1719 5.16619 24.3772 5.69334 24.6445 6.37915C24.773 6.70945 24.9167 7.07676 25.0381 7.45337C25.3464 8.4045 25.5164 9.41848 24.9727 10.051C23.7025 11.2845 22.7625 10.0702 21.7188 8.72095C21.1921 8.04027 20.6384 7.32551 20.0029 6.87329C19.7997 6.72699 19.5708 6.59274 19.3125 6.47778C17.9032 5.84351 15.6051 5.76851 11.6943 7.42896Z" fill="currentColor"/>
      </svg>
      <span style="white-space: nowrap; font-size: 14px; font-weight: 500;">Bloom</span>
    `,r.type="button",r.classList.add("bloom-buy-qt-btn"),Object.assign(r.style,{display:"flex",alignItems:"center",justifyContent:"center",gap:"4px",padding:"2px",borderRadius:"6px",margin:"auto",width:"50%",border:"1px solid",borderColor:`${i}${i.length===7?"80":""}`,color:u,backgroundColor:i,cursor:"pointer",transition:"background-color 0.2s ease"}),r.onmouseover=function(){r.style.backgroundColor=i.slice(0,7)+"CC"},r.onmouseout=function(){r.style.backgroundColor=i},n.appendChild(r);const c=[...document.getElementsByClassName("chakra-text")].find(a=>a.innerText==="Pair")?.getAttribute("title");if(!c)return;r.onclick=function(a){a.preventDefault(),a.stopPropagation(),chrome.runtime.sendMessage({message:"openTab",url:`https://t.me/BloomSolana_bot?start=ref_QT_ca_${c}`})},insertBefore(t,n)}catch(s){console.error("Failed to add Dexscreener token buttons:",s)}}
