new-site/site/public/_astro/hoisted.aBLqmOPy.js
justin 5d9b378e55 Scroll to results anchor when search result is clicked
Immediate scroll before the FCC lookup starts, so the user sees
the loading spinner even when the search results list is long.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-28 04:58:59 -05:00

22 lines
6.8 KiB
JavaScript

import"./hoisted.yFz1BYXO.js";const k=window.__PW_API||"https://api.performancewest.net",t=e=>document.getElementById(e),f=t("frn-input"),l=t("btn-check"),b=new URLSearchParams(window.location.search),v=b.get("frn"),g=b.get("entity");v?(f.value=v.replace(/\D/g,"").padStart(10,"0"),setTimeout(()=>m(),500)):g&&fetch(`${k}/api/v1/entities/telecom/${g}`).then(e=>e.json()).then(e=>{e.frn?(f.value=e.frn,setTimeout(()=>m(),300)):h(`Entity "${e.legal_name||g}" has no FRN on file. Add an FRN to run compliance checks.`)}).catch(()=>h("Could not load entity."));l.addEventListener("click",m);f.addEventListener("keydown",e=>{e.key==="Enter"&&m()});const w=t("search-input"),p=t("btn-search");p.addEventListener("click",y);w.addEventListener("keydown",e=>{e.key==="Enter"&&y()});async function y(){const e=w.value.trim();if(!(!e||e.length<2)){p.disabled=!0,p.textContent="Searching...";try{const r=/^\d+$/.test(e),o=new URLSearchParams;r&&e.length===10?o.set("frn",e):r&&e.length<10?o.set("filer_id",e):o.set("q",e);const c=await(await fetch(`${k}/api/v1/fcc/search?${o}`)).json(),x=t("search-results"),n=t("search-list"),a=t("search-count");if(x.classList.remove("hidden"),n.innerHTML="",!c.results||c.results.length===0){a.textContent="No results found. Try a different search or enter the FRN directly below.";return}a.textContent=`${c.count} result${c.count!==1?"s":""} found — click to check:`;for(const s of c.results){const i=document.createElement("button");i.type="button";const u=s.removed_from_rmd?' <span class="text-red-600 font-bold text-xs">REMOVED</span>':"",C=s.source==="rmd"?"RMD":"499 Filer";i.className="w-full text-left px-3 py-2 rounded-lg border border-gray-200 hover:border-pw-400 hover:bg-pw-50 transition-colors text-sm cursor-pointer",i.innerHTML=`
<span class="font-medium text-gray-900">${s.business_name||"Unknown"}${u}</span>
${s.frn?`<span class="text-xs text-gray-500 ml-2">FRN: ${s.frn}</span>`:""}
${s.filer_id?`<span class="text-xs text-gray-500 ml-2">Filer ID: ${s.filer_id}</span>`:""}
<span class="text-xs text-gray-400 ml-2">(${C})</span>
`,i.addEventListener("click",()=>{s.frn?(f.value=s.frn,document.getElementById("pw-results-anchor")?.scrollIntoView({behavior:"smooth",block:"start"}),m()):h("This record has no FRN. Enter an FRN manually to run a compliance check.")}),n.appendChild(i)}}catch{t("search-count").textContent="Search failed. Please try again.",t("search-results")?.classList.remove("hidden")}finally{p.disabled=!1,p.textContent="Search"}}}async function m(){const e=f.value.replace(/\D/g,"").padStart(10,"0");if(e.length!==10||e==="0000000000"){h("Please enter a valid 10-digit FRN.");return}const r=new URL(window.location.href);r.searchParams.set("frn",e),history.replaceState(null,"",r.toString()),t("loading")?.classList.remove("hidden"),t("results")?.classList.add("hidden"),t("error-box")?.classList.add("hidden"),l.disabled=!0,l.textContent="Checking...";try{const o=await fetch(`${k}/api/v1/fcc/lookup?frn=${e}`),d=await o.json();if(!o.ok){h(d.error||"Lookup failed. Please try again.");return}$(d)}catch{h("Could not reach the compliance checker. Please try again.")}finally{t("loading")?.classList.add("hidden"),l.disabled=!1,l.textContent="Check Compliance"}}function h(e){const r=t("error-box"),o=t("error-msg");o.textContent=e,r.classList.remove("hidden"),t("loading")?.classList.add("hidden"),l.disabled=!1,l.textContent="Check Compliance"}function $(e){t("entity-name").textContent=e.entity_name||"Unknown Entity",t("entity-frn").textContent=e.frn;const r=e.cores;r.address?t("entity-address").textContent=[r.address,r.city,r.state,r.zip].filter(Boolean).join(", "):t("entity-address").textContent="Address not available from CORES";const o=t("checks-container");o.innerHTML="";for(const n of e.checks){const a={green:{bg:"bg-green-50",border:"border-green-200",icon:"text-green-600",text:"text-green-800"},yellow:{bg:"bg-amber-50",border:"border-amber-200",icon:"text-amber-600",text:"text-amber-800"},red:{bg:"bg-red-50",border:"border-red-200",icon:"text-red-600",text:"text-red-800"},unknown:{bg:"bg-gray-50",border:"border-gray-200",icon:"text-gray-400",text:"text-gray-600"}},s=a[n.status]||a.unknown,i={green:'<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/></svg>',yellow:'<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z"/></svg>',red:'<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>',unknown:'<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9 5.25h.008v.008H12v-.008z"/></svg>'},u=document.createElement("div");u.className=`${s.bg} ${s.border} border rounded-xl p-4 flex items-start gap-3`,u.innerHTML=`
<span class="${s.icon} shrink-0 mt-0.5">${i[n.status]||i.unknown}</span>
<div class="flex-1 min-w-0">
<div class="flex items-center justify-between gap-2">
<p class="text-sm font-semibold ${s.text}">${n.label}</p>
${n.due_date?`<span class="text-xs text-gray-500 shrink-0">Due: ${n.due_date}</span>`:""}
</div>
<p class="text-xs ${s.text} mt-1">${n.detail}</p>
${n.action_url?`<a href="${n.action_url}" target="_blank" class="inline-block text-xs text-pw-600 underline mt-2 hover:text-pw-800">Open portal &rarr;</a>`:""}
</div>
`,o.appendChild(u)}const d=e.checks.filter(n=>n.status==="red"),c=t("catchup-section"),x=t("catchup-items");if(d.length>0){c.classList.remove("hidden"),x.innerHTML="";for(const n of d){const a=document.createElement("div");a.className="flex items-start gap-2",a.innerHTML=`
<svg class="w-4 h-4 text-amber-600 shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126z"/></svg>
<div>
<p class="text-sm font-medium text-amber-900">${n.label}</p>
<p class="text-xs text-amber-800">${n.detail}</p>
</div>
`,x.appendChild(a)}}else c.classList.add("hidden");t("checked-at").textContent=`Checked at ${new Date(e.checked_at).toLocaleString()}`,t("results")?.classList.remove("hidden")}