text: "use strict";const formComplete=document.querySelector(".complete__form"),formObject={name:document.querySelector(".js-form-input-name"),job:document.querySelector(".js-form-input-job"),email:document.querySelector(".js-form-input-email"),tel:document.querySelector(".js-form-input-tel"),linkedin:document.querySelector(".js-form-input-linkedin"),github:document.querySelector(".js-form-input-github"),palette:document.querySelectorAll(".js-input-color")};formComplete.addEventListener("keyup",ensureData);const cardObject={name:document.querySelector(".js-card-title-first"),job:document.querySelector(".js-card-title-second"),tel:document.querySelector(".js-a-mobile"),email:document.querySelector(".js-a-mail"),linkedin:document.querySelector(".js-a-linkedin"),github:document.querySelector(".js-a-github"),image:document.querySelector(".js-card-img"),palette:document.querySelectorAll(".js-input-color")};let photo,card=document.querySelector(".js-card");function setLocalStorage(){const e={};for(const t in formObject)e[t]=formObject[t].value;localStorage.setItem("data",JSON.stringify(e))}function getLocalStorage(){localStorage.getItem("datapalette")&&(card.classList=localStorage.getItem("datapalette"));const e=JSON.parse(localStorage.getItem("data"));if(null!==e)for(const t in formObject)formObject[t].value=e[t];ensureData()}function ensureData(){cardObject.name.innerHTML=formObject.name.value||"Nombre Apellido",cardObject.job.innerHTML=formObject.job.value||"Puesto de trabajo",cardObject.tel.href="tel:"+formObject.tel.value,cardObject.email.href="mailto:"+formObject.email.value,cardObject.linkedin.href=formObject.linkedin.value,cardObject.github.href=formObject.github.value,setLocalStorage()}getLocalStorage();let palette=document.querySelector(".design__form");function changePalette(e){"green"===e.target.value?card.classList="card js-card card--theme1":"red"===e.target.value?card.classList="card js-card card--theme2":card.classList="card js-card card--theme3",localStorage.setItem("datapalette",card.classList)}palette.addEventListener("change",changePalette);const btnReset=document.querySelector(".js-btn-reset");function reset(){for(const e in formObject)formObject[e].value="";ensureData()}btnReset.addEventListener("click",reset);const shareButtonDiv=document.querySelector(".js-share__button"),button=document.querySelector(".js-button"),divList=document.querySelectorAll(".js-title-collapse"),myCard=document.querySelector(".js-share__card");function unCollapse(){shareButtonDiv.classList.toggle("hidden")}function createCard(){const e={palette:getRadioValue(),name:document.querySelector(".js-form-input-name").value,job:document.querySelector(".js-form-input-job").value,tel:document.querySelector(".js-form-input-tel").value,email:document.querySelector(".js-form-input-email").value,linkedin:document.querySelector(".js-form-input-linkedin").value,github:document.querySelector(".js-form-input-github").value,photo:photo};console.log(e),fetch("https://us-central1-awesome-cards-cf6f0.cloudfunctions.net/card/",{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then((function(e){return e.json()})).then((function(e){showURL(e)})).catch((function(e){console.log(e)}))}function showURL(e){let t=e.cardURL;console.log(t);const o=document.querySelector(".js-share-button"),r=document.querySelector(".js-share-link");r.innerHTML=t,r.href=t,o.href=`https://twitter.com/intent/tweet?text=Mi+tarjeta+se+ha+creado+${t}`,button.classList.remove("share__button__enabled"),button.classList.add("share__button__unabled"),myCard.classList.remove("hidden")}divList[2].addEventListener("click",unCollapse),button.addEventListener("click",createCard);const invisibleInput=document.querySelector(".js-input-invisible");function previewFile(){var e=document.querySelector(".js-img"),t=document.querySelector(".js-input-invisible").files[0],o=new FileReader;o.onloadend=function(){e.src=o.result,photo=o.result,cardObject.image.src=e.src},t?o.readAsDataURL(t):e.src=""}function toggleBtnStyle(){document.querySelector(".complete__form__image-fields__image-button-label").classList.toggle("hover")}function getRadioValue(){let e=document.getElementsByName("color");for(let t of e)if(t.checked)return"green"===t.value?1:"red"===t.value?2:3;return 1}invisibleInput.addEventListener("onchange",previewFile),invisibleInput.addEventListener("mouseover",toggleBtnStyle),invisibleInput.addEventListener("mouseout",toggleBtnStyle);