1const STORAGE_KEY="vo:favoriteStore",SYNCED_KEY="vo:favoriteStoreSynced",RECENT_PICK_MS=6e4,CHANGE_EVENT="store-favorite:changed",STORE_PAGE_PATH="/pages/centri-ottici/",APPOINTMENT_FORM_PATH="/pages/richiesta-appuntamento?store=";export function getFavorite(){try{const raw=localStorage.getItem(STORAGE_KEY);if(!raw)return null;const parsed=JSON.parse(raw);return!parsed||typeof parsed.handle!="string"||!parsed.handle?null:{handle:parsed.handle,name:parsed.name||"",url:parsed.url||"",appointmentUrl:parsed.appointmentUrl||"",id:parsed.id||"",address:parsed.address||"",pickedAt:typeof parsed.pickedAt=="number"?parsed.pickedAt:0}}catch{return null}}export function setFavorite(favorite,{sync=!0}={}){if(!favorite||!favorite.handle)return;const record={handle:favorite.handle,name:favorite.name||"",url:favorite.url||"",appointmentUrl:favorite.appointmentUrl||"",id:favorite.id||"",address:favorite.address||"",pickedAt:sync?Date.now():0};try{localStorage.setItem(STORAGE_KEY,JSON.stringify(record))}catch{}notify(record),sync&&pushRemote(record.handle)}export function clearFavorite({sync=!0}={}){try{localStorage.removeItem(STORAGE_KEY)}catch{}notify(null),sync&&deleteRemote()}export function isFavorite(handle){if(!handle)return!1;const favorite=getFavorite();return favorite!=null&&favorite.handle===handle}export function favoriteStoreUrl(favorite){return!favorite||!favorite.handle?"":favorite.url||`${STORE_PAGE_PATH}${encodeURIComponent(favorite.handle)}`}export function favoriteAppointmentUrl(favorite){return!favorite||!favorite.handle?"":favorite.appointmentUrl||`${APPOINTMENT_FORM_PATH}${encodeURIComponent(favorite.handle)}`}function notify(favorite){window.dispatchEvent(new CustomEvent(CHANGE_EVENT,{detail:{favorite}}))}function syncConfig(){const element=document.querySelector("[data-store-favorite-sync-config]");if(!element)return null;try{const parsed=JSON.parse(element.textContent);return parsed&&typeof parsed.endpoint=="string"?parsed:null}catch{return null}}function getSynced(){try{return localStorage.getItem(SYNCED_KEY)||null}catch{return null}}function setSynced(handle){try{handle?localStorage.setItem(SYNCED_KEY,handle):localStorage.removeItem(SYNCED_KEY)}catch{}}function pushRemote(handle){const config=syncConfig();config&&fetch(config.endpoint,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({handle})}).then(response=>{response.ok&&setSynced(handle)}).catch(()=>{})}function deleteRemote(){const config=syncConfig();config&&fetch(config.endpoint,{method:"DELETE"}).then(response=>{response.ok&&setSynced(null)}).catch(()=>{})}function reconcile(){const config=syncConfig();if(!config)return;const local=getFavorite(),account=config.account&&config.account.handle?config.account:null,synced=getSynced();if(local?.handle===account?.handle){setSynced(account?account.handle:null);return}local&&local.handle===synced?local.pickedAt&&Date.now()-local.pickedAt<6e4?pushRemote(local.handle):account?(setFavorite(account,{sync:!1}),setSynced(account.handle)):(clearFavorite({sync:!1}),setSynced(null)):!local&&account&&account.handle===synced?deleteRemote():local?pushRemote(local.handle):account&&(setFavorite(account,{sync:!1}),setSynced(account.handle))}reconcile();class StoreFavoriteToggle extends HTMLElement{connectedCallback(){this.handle=this.dataset.storeHandle||"",this.storeName=this.dataset.storeName||"",this.url=this.dataset.storeUrl||"",this.appointmentUrl=this.dataset.storeAppointmentUrl||"",this.storeId=this.dataset.storeId||"",this.address=this.dataset.storeAddress||"",this.input=this.querySelector("[data-favorite-toggle]"),this.#reflect(),this.input&&this.input.addEventListener("change",this.#onChange),window.addEventListener(CHANGE_EVENT,this.#reflect),window.addEventListener("storage",this.#onStorage)}disconnectedCallback(){this.input&&this.input.removeEventListener("change",this.#onChange),window.removeEventListener(CHANGE_EVENT,this.#reflect),window.removeEventListener("storage",this.#onStorage)}#onChange=()=>{this.input.checked?setFavorite({handle:this.handle,name:this.storeName,url:this.url,appointmentUrl:this.appointmentUrl,id:this.storeId,address:this.address}):clearFavorite()};#onStorage=event=>{event.key===STORAGE_KEY&&this.#reflect()};#reflect=()=>{this.input&&(this.input.checked=isFavorite(this.handle))}}customElements.get("store-favorite-toggle")||customElements.define("store-favorite-toggle",StoreFavoriteToggle); 2//# sourceMappingURL=/cdn/shop/t/173/assets/store-favorites.js.map?v=147896348990608646371789978108
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.