var e={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,n="~";function o(){}function s(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function r(e,t,o,r,i){if("function"!=typeof o)throw new TypeError("The listener must be a function");var a=new s(o,r||e,i),c=n?n+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function i(e,t){0==--e._eventsCount?e._events=new o:delete e._events[t]}function a(){this._events=new o,this._eventsCount=0}Object.create&&(o.prototype=Object.create(null),(new o).__proto__||(n=!1)),a.prototype.eventNames=function(){var e,o,s=[];if(0===this._eventsCount)return s;for(o in e=this._events)t.call(e,o)&&s.push(n?o.slice(1):o);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s},a.prototype.listeners=function(e){var t=n?n+e:e,o=this._events[t];if(!o)return[];if(o.fn)return[o.fn];for(var s=0,r=o.length,i=new Array(r);s<r;s++)i[s]=o[s].fn;return i},a.prototype.listenerCount=function(e){var t=n?n+e:e,o=this._events[t];return o?o.fn?1:o.length:0},a.prototype.emit=function(e,t,o,s,r,i){var a=n?n+e:e;if(!this._events[a])return!1;var c,l,u=this._events[a],d=arguments.length;if(u.fn){switch(u.once&&this.removeListener(e,u.fn,void 0,!0),d){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,t),!0;case 3:return u.fn.call(u.context,t,o),!0;case 4:return u.fn.call(u.context,t,o,s),!0;case 5:return u.fn.call(u.context,t,o,s,r),!0;case 6:return u.fn.call(u.context,t,o,s,r,i),!0}for(l=1,c=new Array(d-1);l<d;l++)c[l-1]=arguments[l];u.fn.apply(u.context,c)}else{var h,p=u.length;for(l=0;l<p;l++)switch(u[l].once&&this.removeListener(e,u[l].fn,void 0,!0),d){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,t);break;case 3:u[l].fn.call(u[l].context,t,o);break;case 4:u[l].fn.call(u[l].context,t,o,s);break;default:if(!c)for(h=1,c=new Array(d-1);h<d;h++)c[h-1]=arguments[h];u[l].fn.apply(u[l].context,c)}}return!0},a.prototype.on=function(e,t,n){return r(this,e,t,n,!1)},a.prototype.once=function(e,t,n){return r(this,e,t,n,!0)},a.prototype.removeListener=function(e,t,o,s){var r=n?n+e:e;if(!this._events[r])return this;if(!t)return i(this,r),this;var a=this._events[r];if(a.fn)a.fn!==t||s&&!a.once||o&&a.context!==o||i(this,r);else{for(var c=0,l=[],u=a.length;c<u;c++)(a[c].fn!==t||s&&!a[c].once||o&&a[c].context!==o)&&l.push(a[c]);l.length?this._events[r]=1===l.length?l[0]:l:i(this,r)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&i(this,t)):(this._events=new o,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,e.exports=a}(e);var t=e.exports;function n(e,t){return`${e}:${t}`}class o{constructor(e,t,n){this.channel=e,this.topic=t,this.payload=n}toKey(){return n(this.channel,this.topic)}}class s{constructor(e=10){this.maxSize=e,this.array=[]}push(e){this.array.length>=this.maxSize&&this.array.pop(),this.array.unshift(e)}peek(){return this.array[0]}toArray(){return this.array.slice()}}class r{constructor(){this.map=new Map}getQueue(e,t){return this.map.get(n(e,t))||new s}push(e){const t=this.getQueue(e.channel,e.topic);t.push(e),this.map.set(e.toKey(),t)}peek(e,t){return this.getQueue(e,t).peek()}log(e,t){return this.getQueue(e,t).toArray()}}function i(){if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}class a{constructor(){const{ee:e,sink:n}=function(){let e=i()["@podium"];return e||(e={},e.ee=new t,e.sink=new r,i()["@podium"]=e),e}();this.ee=e,this.sink=n}log(e,t){return this.sink.log(e,t)}peek(e,t){return this.sink.peek(e,t)}publish(e,t,n){const s=new o(e,t,n);return this.ee.emit(s.toKey(),s),this.sink.push(s),s}subscribe(e,t,o){this.ee.on(n(e,t),o)}unsubscribe(e,t,o){this.ee.off(n(e,t),o)}}function c(e,t){const n=t.querySelector("#top-bar_notifications-link"),o=t.querySelector("#top-bar_notifications-count-bubble");e&&(e.hasNotifications||e.count>0)?(e.count>0?n.setAttribute("aria-label",`Varslinger (${e})`):n.setAttribute("aria-label","Varslinger (nye)"),o.innerHTML='<span id="notifications-bubble" style="background-color: #FF5844;" class="absolute sm:right-auto sm:mr-16 md:left-20 md:ml-4 top-12 rounded-full w-12 h-12 border-2 border-white" />'):(n.setAttribute("aria-label","Varslinger"),o.innerHTML="")}function l(e){const t=window.sessionStorage;e&&"0"!==e?t.setItem("notificationsUnreadCount",e):t.removeItem("notificationsUnreadCount")}function u(e){const t=window.sessionStorage;e&&"0"!==e?t.setItem("messagesUnreadCount",e):t.removeItem("messagesUnreadCount")}function d(e){const t=window.sessionStorage;e?t.setItem("profileImageURL",e):t.removeItem("profileImageURL")}function h(e,t){const n=t.querySelector("#top-bar_messages-link"),o=t.querySelector("#top-bar_messages-count-bubble");e&&"0"!==e?(!function(e){const{title:t}=window.document,n=t.match(/(\(.*\))\s/);window.document.title=n?t.replace(n[1],`(${e})`):`(${e}) ${t}`}(e),n.setAttribute("aria-label",`Meldinger (${e})`),o.innerHTML='<span id="messages-bubble" style="background-color: #FF5844;" class="absolute sm:right-auto sm:mr-16 md:left-20 md:ml-8 top-12 rounded-full w-12 h-12 border-2 border-white" />'):(window.document.title=window.document.title.replace(/\(.*\)\s/,""),n.setAttribute("aria-label","Meldinger"),o.innerHTML="")}function p(e,t){const n=t.querySelector("#topbar_profile-image");e&&(n.innerHTML=`<img src="${e}" class="top-bar__menu-item__profile-picture rounded-full" alt="Mitt profilbilde" width="28" height="28" >`)}window.headerLoaded=!0;class f extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML+=`\n            <link\n                rel="stylesheet"\n                type="text/css"\n                href="https://assets.finn.no/pkg/@fabric-ds/css/v1/fabric.min.css"\n                onload="(function(){ const event = new Event('header-load'); document.dispatchEvent(event); })(this)"\n            />\n            <style>\n                :host {\n                    display: block;\n                }\n                @media print {\n                    header { position: static !important; }\n                }\n            </style>\n            ${this.innerHTML}\n        `,this.innerHTML="",this.setup()}setup(){const{dataset:{spidId:e,loginId:t,apiUrl:n,env:o,distractionFree:s}}=this.shadowRoot.querySelector("#topbar_api-url"),r={clientId:`finn${"prod"===o?"":"Staging"}`,userIdDomain:"spid.no"};if(window.pulse2opt=window.pulse2opt||r,window.pulse2opt.userId=e,window.finnUserId=t,!e||!t)return;if("true"===s)return;const i=window.sessionStorage,f=i.getItem("notificationsUnreadCount"),m=i.getItem("messagesUnreadCount"),w=i.getItem("profileImageURL");f&&t&&e&&c(f,this.shadowRoot),m&&t&&e&&h(m,this.shadowRoot),w&&t&&e&&p(w,this.shadowRoot),fetch(new URL(n),{credentials:"include"}).then((e=>{e.ok?e.json().then((e=>{const{notificationsUnreadCount:t,messagesUnreadCount:n,profileImage:o}=e;f!==t&&(c(t,this.shadowRoot),l(t)),m!==n&&(h(n,this.shadowRoot),u(n)),w!==o&&(p(o,this.shadowRoot),d(o))})).catch((()=>{})):401===e.status&&(c(0,this.shadowRoot),l(0),h(0,this.shadowRoot),u(0),p(null,this.shadowRoot),d(null));(new a).subscribe("notifications","allWereViewed",(()=>{if("undefined"!=typeof window){const e=this.shadowRoot.querySelector("#notifications-bubble");e&&e.remove()}}))})).catch((()=>{}))}}customElements.define("finn-topbar",f),document.addEventListener("DOMContentLoaded",(()=>{try{const e=document.querySelector("#broadcast");if(!e)return;if(!document.querySelector(['header[data-browser-warning="true"]']))return;if(window.CSS&&window.CSS.supports("color","var(--detect)"))return;const t="dismissedBrowserVersionWarning";if("true"===window.sessionStorage.getItem(t))return;const n=document.createElement("section");n.className="broadcast",n.setAttribute("aria-label","Viktig melding");const o=document.createElement("div");o.className="broadcast__content",o.innerHTML='\n            <p>Hei! Vi ser at du bruker en eldre nettleser. Det kan derfor hende at FINN ikke fungerer optimalt for deg.</p>\n            <p>Fra 1. januar 2021 kan det hende at FINN ikke vil fungere for deg i det hele tatt, ettersom vi ikke lenger kommer til å støtte gamle versjoner av nettlesere.</p>\n            <p>Vi anbefaler at du oppdaterer nettleseren eller enheten din til siste versjon. Eller hva med å teste en ny nettleser? Vi har noen forslag \n                <a class="u-display-block u-mt16" href="https://www.google.com/intl/no/chrome/">Google Chrome</a>\n                <a class="u-display-block u-mt8" href="https://www.microsoft.com/nb-no/edge">Microsoft Edge</a>\n                <a class="u-display-block u-mt8" href="https://www.mozilla.org/nb-NO/firefox/new/">Mozilla Firefox</a>\n            </p>\n                ',n.appendChild(o);const s=document.createElement("span");s.className="icon icon--cross";const r=document.createElement("button");r.className="button button--pill button--small button--has-icon broadcast__dismiss",r.type="button",r.setAttribute("aria-label","Lukk");const i=()=>{n.remove(),r.removeEventListener("click",i),window.sessionStorage.setItem(t,!0)};r.addEventListener("click",i),r.appendChild(s),n.appendChild(r),e.appendChild(n)}catch(e){}}));
//# sourceMappingURL=index.js.map
