{"version":3,"sources":["webpack://nada.org/./themes/custom/nada/js/components/capitol-rep-finder.js"],"names":["capitolRepFinder","document","querySelector","capitolReps","storedReps","JSON","parse","localStorage","getItem","addRepCard","rep","container","template","card","content","cloneNode","repName","repPhoto","congressSeal","senateSeal","houseSeal","textContent","name","urls","sealPhoto","includes","photoUrl","setAttribute","appendChild","revealRepCards","cards","querySelectorAll","Array","prototype","forEach","call","i","classList","remove","hideRepCards","add","getCapitolReps","form","setItem","innerHTML","apiKey","civicsURL","address","value","zipcode","fetch","then","response","json","data","officials","push","stringify","addressForm","addEventListener","e","preventDefault","input","autocomplete","google","maps","places","Autocomplete","setFields"],"mappings":";;;;;;;;AAAA,IAAIA,gBAAgB,GAAGC,QAAQ,CAACC,aAAT,CAAuB,mBAAvB,CAAvB;AACA,IAAIC,WAAW,GAAG,EAAlB;AACA,IAAIC,UAAU,GAAGC,IAAI,CAACC,KAAL,CAAWC,YAAY,CAACC,OAAb,CAAqB,aAArB,CAAX,CAAjB;;AAEA,SAASC,UAAT,CAAoBC,GAApB,EAAyB;AACvB,MAAIC,SAAS,GAAGV,QAAQ,CAACC,aAAT,CAAuB,eAAvB,CAAhB;AACA,MAAIU,QAAQ,GAAGX,QAAQ,CAACC,aAAT,CAAuB,iBAAvB,CAAf;AAEA,MAAIW,IAAI,GAAGD,QAAQ,CAACE,OAAT,CAAiBC,SAAjB,CAA2B,IAA3B,CAAX;AACA,MAAIC,OAAO,GAAGH,IAAI,CAACX,aAAL,CAAmB,UAAnB,CAAd;AACA,MAAIe,QAAQ,GAAGJ,IAAI,CAACX,aAAL,CAAmB,WAAnB,CAAf;AACA,MAAIgB,YAAY,GAAG,mEAAnB;AACA,MAAIC,UAAU,GAAG,iEAAjB;AACA,MAAIC,SAAS,GAAG,mFAAhB;AAEAJ,SAAO,CAACK,WAAR,GAAsBX,GAAG,CAACY,IAA1B;;AAEA,MAAIZ,GAAG,CAACa,IAAR,EAAc;AACZ,QAAIC,SAAS,GAAGd,GAAG,CAAC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7B,kBAAc;AACf,GAJD,EAZoB,CAkBpB;;AACA5B,UAAQ,CAAC0D,gBAAT,CAA0B,kBAA1B,EAA8C,MAAM;AAClD,QAAIG,KAAK,GAAG7D,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAZ;AACA,QAAI6D,YAAY,GAAG,IAAIC,MAAM,CAACC,IAAP,CAAYC,MAAZ,CAAmBC,YAAvB,CAAoCL,KAApC,CAAnB;AACAC,gBAAY,CAACK,SAAb,CAAuB,CAAC,aAAD,CAAvB;AACD,GAJD;AAKD,C","file":"webpack-chunks/chunk.themes_custom_nada_js_components_capitol-rep-finder_js.ef168ffc80ea385e2028.js","sourcesContent":["let capitolRepFinder = document.querySelector(\"#capitolRepFinder\");\nlet capitolReps = [];\nlet storedReps = JSON.parse(localStorage.getItem(\"capitolReps\"));\n\nfunction addRepCard(rep) {\n var container = document.querySelector(\".capitol-reps\");\n var template = document.querySelector('#capitolRepCard');\n\n var card = template.content.cloneNode(true);\n var repName = card.querySelector(\".repName\");\n var repPhoto = card.querySelector(\".repPhoto\");\n var congressSeal = '/themes/custom/nada/images/Seal_of_the_United_States_Congress.svg';\n var senateSeal = '/themes/custom/nada/images/Seal_of_the_United_States_Senate.svg';\n var houseSeal = '/themes/custom/nada/images/Seal_of_the_United_States_House_of_Representatives.svg';\n\n repName.textContent = rep.name;\n\n if (rep.urls) {\n var sealPhoto = rep.urls[0].includes('house') ? houseSeal : senateSeal;\n rep.photoUrl ? repPhoto.setAttribute('src', rep.photoUrl) : repPhoto.setAttribute('src', sealPhoto);\n } else {\n rep.photoUrl ? repPhoto.setAttribute('src', rep.photoUrl) : repPhoto.setAttribute('src', congressSeal);\n }\n\n container.appendChild(card);\n}\n\nfunction revealRepCards() {\n let cards = document.querySelectorAll('.capitol-rep');\n Array.prototype.forEach.call(cards, function (card, i) {\n card.classList.remove('opacity-0');\n });\n}\n\nfunction hideRepCards() {\n let cards = document.querySelectorAll('.capitol-rep');\n Array.prototype.forEach.call(cards, function (card, i) {\n card.classList.add('opacity-0');\n });\n}\n\nfunction getCapitolReps(form) {\n // Clear existing capitol reps before getting new ones\n hideRepCards();\n capitolReps = [];\n localStorage.setItem(\"capitolReps\", '');\n document.querySelector('.capitol-reps').innerHTML = '';\n\n let apiKey = 'AIzaSyDl3PSvyzoaV8C8Qpg84OO1WR9aNAkQ9js';\n let civicsURL = 'https://www.googleapis.com/civicinfo/v2/representatives';\n let address = form.address.value;\n let zipcode = form.zipcode.value;\n\n // Fetch reps from Google Civics API https://developers.google.com/civic-information/docs/v2\n fetch(civicsURL + '?address=' + address + ' ' + zipcode + '&levels=country&roles=legislatorLowerBody&roles=legislatorUpperBody&key=' + apiKey)\n .then(response => response.json())\n .then(data => {\n Array.prototype.forEach.call(data.officials, function (rep, i) {\n capitolReps.push(rep);\n addRepCard(rep);\n });\n localStorage.setItem(\"capitolReps\", JSON.stringify(capitolReps));\n });\n}\n\n// Only do something if the page has the capitol rep finder block\nif (capitolRepFinder) {\n\n // Load any locally stored reps first\n if (storedReps) {\n Array.prototype.forEach.call(storedReps, function (rep, i) {\n addRepCard(rep);\n });\n revealRepCards();\n }\n\n // Get the address form and listen for an address update\n let addressForm = capitolRepFinder.querySelector('#addressForm');\n addressForm.addEventListener('submit', function (e) {\n e.preventDefault();\n getCapitolReps(addressForm);\n revealRepCards();\n })\n\n // Wait for the page to finish loading, then attach Places Autocomplete Search\n document.addEventListener('DOMContentLoaded', () => {\n let input = document.querySelector('#address');\n let autocomplete = new google.maps.places.Autocomplete(input);\n autocomplete.setFields([\"adr_address\"]);\n })\n}\n"],"sourceRoot":""}