(function(){"use strict";(function(){const c=document.querySelector("trygg-chat"),n=c?c.getAttribute("widget"):null;if(!n){console.error("[tc] Widget ID not found on trygg-chat element");return}const l=new URLSearchParams(window.location.search).get("env");function g(t){return t?t==="test"?"https://test.trygg.chat/api/":t==="stage"?"https://stage.trygg.chat/api/":"https://app.trygg.chat/api/":"https://app.trygg.chat/api/"}const u=g(l);function d(t){try{const e=localStorage.getItem(t);if(!e)return null;const o=JSON.parse(e);return new Date().getTime()>o.expiry?(localStorage.removeItem(t),null):o.value}catch(e){return console.error("[tc] Error reading from localStorage:",e),null}}function h(t,e,o){try{const r=new Date;r.setTime(r.getTime()+o*60*1e3);const p={value:e,expiry:r.getTime()};localStorage.setItem(t,JSON.stringify(p))}catch(r){console.error("[tc] Error writing to localStorage:",r)}}function a(t){const e=document.createElement("script");e.src=t,document.head.appendChild(e)}const i=`tc_script_url_${n}`,s=d(i);s?a(s):fetch(u+"widget/script/"+n,{headers:{"Widget-Domain":window.location.hostname}}).then(t=>t.json()).then(t=>{h(i,t.url,10),a(t.url)}).catch(t=>console.error("[tc] Widget failed to load:",t))})()})();