import{i as e,l as n,_ as i,c as t,g as o,a as d,b as l,d as s,e as a,F as u,h as c,f as v,j as f,E as m,s as g,k as h,m as y,n as p}from"./_auto-entry_vgv2-CiA_x9nb.js";export{r as replaceAdsWithFinnBlink}from"./_auto-entry_vgv2-CiA_x9nb.js";import{xandrAdLoaded as k,finnBlinkLoaded as b}from"./events-D4avzv0d.js";import"react/jsx-runtime";e('.advertory-finn-blink-wrapper{height:100%;display:flex !important;align-items:center;justify-content:center}.advertory-finn-blink-wrapper:not(.brandboard-container){width:100%;margin-inline:auto}.advertory-finn-blink{width:100%;height:500px;max-width:580px;display:flex !important;align-items:center;justify-content:center}.advertory-finn-blink::before{content:"" !important}.advertory-finn-blink iframe{max-width:100%}');const I={get:e=>{try{const n=sessionStorage.getItem(e);return n?JSON.parse(n):null}catch(e){return n(`sessionStorageClient.get: Error during getting data from sessionStorage: ${e}`),null}},set:(e,i)=>{try{sessionStorage.setItem(e,JSON.stringify(i))}catch(e){n(`sessionStorageClient.set: Error during saving data to sessionStorage: ${e}`)}},remove:e=>{try{sessionStorage.removeItem(e)}catch(e){n(`sessionStorageClient.remove: Error during remove data from sessionStorage: ${e}`)}}},w="finn_blink_id",S=e=>i(void 0,void 0,void 0,function*(){const{userId:n,id:i,hashed_email:t,theme:r}=e,o=v(e,["userId","id","hashed_email","theme"]),d=window[m.Blink];if(!d)return;const l=new d({remote:f,id:i,hashed_email:t,theme:r});yield l.inject(Object.assign({},o))}),$=e=>i(void 0,void 0,void 0,function*(){const{userId:n,theme:i}=e,t=v(e,["userId","theme"]),r=window[m.Blink];if(!r)return;const o=new r({remote:f,userId:n,theme:i});yield o.inject(Object.assign({},t))}),_=e=>{var n,i;const t=document.querySelector(`[id^="${e}"]`);return null!==(i=null===(n=null==t?void 0:t.dataset)||void 0===n?void 0:n.finnBlinkId)&&void 0!==i?i:e},j=(e,n)=>{const{finnBlink:{enabled:i}={}}=t.get(),r=(null==n?void 0:n.enabled)||(e=>{var n;const i=document.querySelector(`[id^="${e}"]`);return!!(null===(n=null==i?void 0:i.dataset)||void 0===n?void 0:n.noBidAd)})(e);if(!r||!i)return null;const{limit:o,height:d,requireImage:l,theme:s,rec:a,distributionTypes:u,position:c,offset:v}=(null==n?void 0:n.sdkPayload)||{};return{selector:`#${_(e)}`,enabled:r,position:null!=c?c:e,distributionTypes:null!=u?u:[],limit:null!=o?o:100,height:null!=d?d:100,offset:null!=v?v:200,requireImage:l,rec:a,theme:"dark"===s?"dark":"light",advertoryTheme:null==n?void 0:n.advertoryTheme}},x=(e,r,v)=>i(void 0,void 0,void 0,function*(){var f;const{placements:m,pageContext:{deviceType:g}}=t.get();n(`rendering finn blink ad for ${e}`);const h=o(e),y=m[g].find(e=>e.targetId===h),p=j(e,null==y?void 0:y.finnBlink);if(!(null==p?void 0:p.enabled))return n(`Finn blink is not enabled on placement: ${e}`),v&&v(e),void k(e);if((e=>{var n;const i=_(e),t=document.querySelector(`[id^="${i}"]`);return!!(null===(n=null==t?void 0:t.classList)||void 0===n?void 0:n.contains("finn"))})(e))return void n(`Finn blink already loaded ${e}`);const{publisher:x,countryCode:B,finnBlink:C}=r,{sdkPayload:{userId:T,uuid:q,channel:F,theme:O}={}}=null!=C?C:{},E=null!=F?F:`${x}.${B}`,A=(e=>{if(!e){const e=s();return null!=e?e:""}return e})(T),N="dark"===O?"dark":"light",J=yield i(void 0,void 0,void 0,function*(){const{finnBlink:{identifierUrl:e}={}}=t.get(),n=I.get(w),i=a(u);if(!e||i)return"";if(!n){const n=yield c.get(e,{credentials:"include"}),{finn_blink_id:i}=n;if(!i)throw new Error("getFinnBlinkIdentifier: No finn_blink_id found");return I.set(w,i),i}return n}),P=yield d(),L=(null===(f=null==y?void 0:y.finnBlink)||void 0===f?void 0:f.useNewConstructor)?$:S;try{yield L(Object.assign(Object.assign({},p),{channel:E,id:A,userId:P,hashed_email:J,theme:N,uuid:q})).then(()=>{b(p.selector.replace("#",""),p.advertoryTheme)})}catch(i){n(`Finn blink error ${i}`),v&&v(e),!v&&l(e),k(e)}}),B=(e,r,o,d)=>i(void 0,void 0,void 0,function*(){const{pageContext:{isMobileApp:i}}=t.get();if(n(`loadFinnBlinkAd: loading finn blink ad for ${e}`),!(yield g())||i)return o&&o(e),k(e),void(!o&&l(e));try{yield h(y)}catch(e){console.error(e)}yield x(e,r,o),d&&d()}),C=e=>document.querySelector(`#${e}`),T=e=>i(void 0,void 0,void 0,function*(){if(!e.length)return;const{appearanceConfig:n,pageContext:{deviceType:i}}=t.get(),r=null==n?void 0:n.defaultThreshold[i];for(const n of e){const{requestThreshold:e,targetId:i}=n,t=C(i);t&&(yield p(t,null!=e?e:r))}});export{T as handleFinnBlinkOnlyPlacements,B as loadFinnBlinkAd};
