${(0,i.__)("No matching representatives for this district","representative-search")}
`)};h.onclick=function(){l.classList.toggle("active")};const x=e=>{f.innerHTML=''+e+"
"},$=()=>{(e=>{fetch("https://www.googleapis.com/civicinfo/v2/representatives?includeOffices=false&levels=country&levels=administrativeArea1&roles=legislatorLowerBody&roles=legislatorUpperBody&address="+encodeURI(e)+"&key="+o).then((e=>e.json())).then((t=>{t.error?x(t.error.message):""===t.normalizedInput.line1?x((0,i.__)("Please enter your full address","representative-search")):"CA"!==t.normalizedInput.state?x((0,i.__)("Please enter a valid CA address","representative-search")):(S(t),f.innerHTML="",B(Object.keys(t.divisions)),j("sldl")&&j("sldu")||N(e),y.style.display="block",p.value="sldl",R("sldl"))}))})(new FormData(c).get("rs-address"))},N=e=>{var t="https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates",r=new URLSearchParams;r.append("SingleLine",e),r.append("forStorage","false"),r.append("f","pjson"),r.append("w","300"),t+=`?${r.toString()}`,fetch(t).then((e=>e.json())).then((e=>{S("fallbackAddressSearch",e),e.candidates&&e.candidates[0].location&&e.candidates[0].location.x&&e.spatialReference?L(JSON.stringify(e.spatialReference),e.candidates[0].location.x,e.candidates[0].location.y):x((0,i.__)("We could not find the representative for the provided address. Please go to the https://findyourrep.legislature.ca.gov/ to locate ypur representatives","representative-search"))}))},L=(e,t,r)=>{var n="https://services5.arcgis.com/0CGHmi5SBMvfD65u/arcgis/rest/services/AD_SD_2011_2021_Union/FeatureServer/4/query",s=new URLSearchParams;s.append("f","json"),s.append("returnGeometry","false"),s.append("spatialRel","esriSpatialRelIntersects"),s.append("geometry",`{"x":${t},"y":${r},"spatialReference":${e}}`),s.append("geometryType","esriGeometryPoint"),s.append("outFields","AD_2011,SD_2011,AD_2021,SD_2021"),n+=`?${s.toString()}`,fetch(n).then((e=>e.json())).then((e=>{if(S("fallbackGetDistrict",e),e.features&&e.features[0].attributes){let t=P(j("sldu"));if(!t){const r=parseInt(e.features[0].attributes.SD_2011,10),n=parseInt(e.features[0].attributes.SD_2021,10);t=r%2!=0?r:n,console.log("senateDistrict",t)}let r=P(j("sldl"));r||(r=parseInt(e.features[0].attributes.AD_2021,10)),B([`ocd-division/country:us/state:ca/sldl:${r}`,`ocd-division/country:us/state:ca/sldu:${t}`])}else x((0,i.__)("We could not find the representative for the provided address. Please go to the https://findyourrep.legislature.ca.gov/ to locate ypur representatives","representative-search"))}))},B=e=>{M(),sessionStorage.setItem("rs-user-districts",JSON.stringify(e))},P=e=>{if(void 0!==e)return e.replace(/\D/g,"")},j=e=>{var t=sessionStorage.getItem("rs-user-districts");if(t)return(t=JSON.parse(t)).find((function(t){return t.replace("ocd-division/country:us/state:ca/","").includes(e)}))},D=(e,t,r)=>{var n={name:t.name,website:Array.isArray(t.urls)&&t.urls.length>0?t.urls[0]:"",party:t.party,photo:t.hasOwnProperty("photoUrl")?t.photoUrl.replace(/^http:\/\//i,"https://"):null,district:r};sessionStorage.setItem(e,JSON.stringify(n)),window.dispatchEvent(new Event("new-rep"))},R=e=>{if(sessionStorage.getItem("rs-"+e))window.dispatchEvent(new Event("new-rep"));else{var t=j(e);if(t){var r="https://www.googleapis.com/civicinfo/v2/representatives/"+encodeURIComponent(t);fetch(r+"?key="+o).then((e=>e.json())).then((r=>{S("getRepsByLevel",r),D("rs-"+e,r.officials[0],P(t))}))}else console.error("Failed to find district for level",e)}};p.addEventListener("change",(function(e){R(e.target.value)}),!1),window.addEventListener("new-rep",(function(e){var t=p.value;""!==b.value?(E(t),O(t)):(E(t=g.value,document.getElementById(t+"-districts").value),O(t))}));const M=()=>{sessionStorage.removeItem("rs-sldl"),sessionStorage.removeItem("rs-sldu"),sessionStorage.removeItem("rs-cd")},T=(e,t)=>new Promise(((r,n)=>{S("getRepContent",e.name,e.district,t);let i=RS.root+"wp/v2/rs-representatives?api-title="+encodeURIComponent(e.name)+"&api-district="+encodeURIComponent(e.district)+"&api-level="+encodeURIComponent(t);e.hasOwnProperty("location")&&e.location&&(i+="&api-location="+encodeURIComponent(e.location)),S("fetchURL",i),fetch(i,{headers:{"Content-Type":"application/json","X-WP-Nonce":RS.nonce}}).then((e=>{S("getRepContent resp",e);let t=e.json();return 200===e.status?t:t.then(Promise.reject.bind(Promise))})).then((t=>{S("getRepContent data",t,e);var n={...e};if(0