1import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{X as t,v as n}from"./components-LX1YoyU2.js";import{k as r,o as i}from"./AnchorLink-3N_4Fkow.js";import{t as a}from"./jsx-runtime-B74pBk57.js";import{G as o,N as s,X as c,Z as l,at as u,h as d,mt as f,nt as p,ut as m}from"./Spacing-xZeuy1vj.js";import{t as h}from"./graphql-CEOT6iX6.js";import{s as g,t as _}from"./analytics-CucLn3Xn.js";import{i as v,n as y,t as b}from"./calls-DfS8GebN.js";import{_ as x,f as S,g as C,l as w,r as T,t as E,v as D,w as O}from"./constants-CiPe0TnI.js";import{a as k,c as A,d as j,f as ee,i as te,l as M,n as N,o as ne,r as P,s as F,t as re}from"./addressSearchController-2AVkJXvC.js";import{n as ie}from"./FiberOrderProvider-BODAr-RN.js";import{t as ae}from"./SlideUpDownContent-BLGy0OV7.js";var I=a(),L=e(t());function R(e,t){let n=(0,L.useRef)(e),r=(0,L.useRef)(null);return(0,L.useEffect)(()=>{n.current=e},[e]),(0,L.useCallback)((...e)=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{n.current(...e)},t)},[t])}var z={dar
1kWrapper:`_darkWrapper_i0yn4_1`,fields:`_fields_i0yn4_7`,intro:`_intro_i0yn4_11`,helpText:`_helpText_i0yn4_17`};function B(e){let t=n();return e.variant?e.variant===`all-products`&&!(e.hasResult&&e.hasRun)?(0,I.jsxs)(`div`,{className:z.helpText,children:[`Her kan du se`,` `,(0,I.jsx)(r,{to:`${S.start}/alle-produkter`,children:`alle våre produkter`})]}):e.variant===`cta-to-results`&&e.hasResult?(0,I.jsx)(d,{className:`mt-3`,onClick:()=>{t(S.start,{viewTransition:!0})},children:`Se produktene du kan få`}):null:null}var V={wrap:`_wrap_1f0o9_1`,searchClear:`_searchClear_1f0o9_8`,dropdown:`_dropdown_1f0o9_24`},H=(0,L.forwardRef)(function({id:e=`combobox`,name:t=`combobox`,options:n,setOptions:r,label:i,placeholder:a=`Gateveien 32, 1234 Poststedet`,value:s,defaultValue:u,required:d=!1,error:f,setError:p,onSearch:m,onSelect:h,onClear:g,onBlur:_,dropdown:v=!1,hiddenLabel:y=!1,searching:b=!1,setIsActive:x},S){let[C,w]=(0,L.useState)(-1),[T,E]=(0,L.useState)(s??u??``),[D,O]=(0,L.useState)(!1),k=(0,L.useRef)(n?.length??0),A=(0,L.useRef)([]),j=(0,L.useRef)(null),ee=U({inputRef:S,searching:b,options:n,value:s}),te=R(async e=>{p&&p(null),w(-1);let t=e.trim();if(!t||t?.length===0){M();return}t.length<3||(m&&m(t),O(!0))},500),M=()=>{S.current.value=``,p&&p(``),E(``),O(!1),r?.(null),g&&g()};function N(e){w(e),A.current[e]?.scrollIntoView({block:`nearest`})}function ne(e){let t=n?.length??0;if(e.key===`ArrowDown`){if(e.preventDefault(),t===0)return;v&&O(!0),N(C<t-1?C+1:0)}else if(e.key===`ArrowUp`){if(e.preventDefault(),t===0)return;v&&O(!0),N(C>0?C-1:t-1)}else e.key===`Enter`?C>=0&&(e.preventDefault(),P(n?.[C]??``)):e.key===`Escape`&&(w(-1),v&&O(!1))}function P(e){s===void 0?(E(e),w(-1),h?.(e)):h?.(e),x&&x(!1),r&&r([])}(0,L.useEffect)(()=>{s!==void 0&&E(s),s===void 0&&u!==void 0&&E(u??``)},[s,u]),(0,L.useEffect)(()=>{if(!v)return;let e=n?.length??0,t=k.current===0;k.current=e,e>0&&t&&O(!0)},[v,n?.length]),(0,L.useEffect)(()=>{let e=e=>{j.current&&!j.current.contains(e.target)&&(O(!1),x&&x(!1))},t=e=>{e.key===`Escape`&&(O(!1),x&&x(!1),w(-1))};return document.addEventListener(`keydown`,t),document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`keydown`,t),document.removeEventListener(`mousedown`,e)}},[]);let F=!!(D&&n?.length);return(0,I.jsxs)(`div`,{id:e,className:`combobox ${V?.wrap}`,ref:j,children:[y?(0,I.jsx)(l,{id:`${e}-label`,children:i}):(0,I.jsx)(`label`,{id:`${e}-label`,htmlFor:`${e}-input`,children:i}),(0,I.jsx)(o,{id:`${e}-input`,name:`${t}-input`,ref:S,type:`text`,autoComplete:`off`,placeholder:a,value:T,required:d,loading:b,error:typeof f==`string`?f:void 0,role:`combobox`,"aria-haspopup":`listbox`,"aria-labelledby":`${e}-label`,"aria-expanded":F,"aria-controls":F?`${e}-listbox`:void 0,"aria-invalid":f?!0:void 0,"aria-describedby":f?`${e}-error`:void 0,"aria-activedescendant":C>=0?`${e}-option-${C}`:void 0,onChange:e=>{E(e.target.value),te(e.target.value)},onKeyDown:ne,onFocus:()=>{p&&p(``),x&&x(!0),v&&n?.length!==0&&O(!0)},onBlur:()=>{setTimeout(()=>{let t=document.getElementById(e);t&&document.activeElement&&t.contains(document.activeElement)||(x&&x(!1),v&&O(!1))},0),_&&_()},className:V?.input,icon:T?void 0:`fa-regular fa-magnifying-glass`,clear:T&&!f&&(0,I.jsx)(`button`,{type:`button`,className:V.searchClear,onClick:M,title:`Klikk for å tømme søket`,children:(0,I.jsx)(`i`,{className:`fa-regular fa-circle-xmark`})})||void 0}),D&&n?.length!==0&&(0,I.jsx)(`ul`,{id:`${e}-listbox`,role:`listbox`,tabIndex:-1,"aria-labelledby":`${e}-label`,"aria-label":i,className:V.dropdown,children:n?.map((t,n)=>(0,I.jsx)(`li`,{id:`${e}-option-${n}`,role:`option`,"aria-selected":C===n,tabIndex:-1,ref:e=>{A.current[n]=e},onClick:()=>{P(t)},onMouseDown:()=>{P(t)},onTouchStart:()=>{P(t)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),P(t))},children:t},t))}),typeof f!=`string`&&(0,I.jsx)(c,{variant:`error`,children:f}),f&&(0,I.jsx)(l,{id:`${e}-error`,children:f}),ee]})});function U({inputRef:e,searching:t=!1,options:n,value:r,optionType:i=`adresse`}
1){let[a,o]=(0,L.useState)(null);return(0,L.useEffect)(()=>{if(t)return;let a=null;e&&typeof e!=`function`&&`current`in e&&(a=e.current),a&&(n&&n.length>0?o(`Listen viser ${n.length} treff på ${i}, bruk opp eller ned pil for navigasjon. Trykk eller bruk Enter for å velge.`):a.value!==``&&!r?o(`Fant ingen ${i} som tilsvarer søket ditt, ${a.value}. Skriv på nytt eller gå videre.`):o(r?`Valgte ${i} ${r}.`:null))},[t,n?.length,r,e,i]),a?(0,I.jsx)(l,{"aria-live":`polite`,children:a}):null}function W({suggestions:e,setSuggestions:t,inputRef:n,searching:r,loading:i,contextLoading:a,error:o,...s}){let c=typeof o==`string`?o:o?.text??null;return(0,I.jsx)(H,{...s,ref:n,label:`Adresse`,dropdown:!0,hiddenLabel:!0,options:e?.map(e=>e?.result||``)||[],setOptions:e=>{(!e||e.length===0)&&t([])},placeholder:`Skriv inn din adresse`,error:c,searching:!!(r||i||a)})}var G={unitsDropdown:`_unitsDropdown_1szdn_1`,helpText:`_help-text_1szdn_7`};function K({setError:e,setLoading:t,...n}){let{setData:r,order:i,setOrder:a,loading:o}=ie(),[c,l]=(0,L.useState)(!1);async function d(n){try{let o=n.target?.textContent?.trim();if(!o)return;if(o===`Mitt bruksenhetsnummer står ikke på listen`){r({result:w.LEAD,code:`users-dwelling-unit-not-in-list`,hasRun:!0,servicepoint_id:null,dwelling_unit:null}),a({address:{...i.address,dwelling_unit:null}});return}let s=i?.address?.units?.find(e=>e?.unit_id===o);if(!s?.unit_id){console.error(`Selected unit not found: ${o}`),e(T.SELECTED_UNIT_NOT_FOUND);return}if(!s?.servicepoint_id){console.error(`No servicepoint_id found in selected unit`),e(T.NO_DWELLING_UNIT);return}l(!0),t(!0),r({hasRun:!1});let c=(await h(v,{id:s.servicepoint_id}))?.getServicepointData;if(!c){r({result:w.LEAD,code:C.NO_INFO,hasRun:!0});return}a({address:{...i.address,dwelling_unit:s.unit_id},adresse:i.adresse}),r({...c,hasRun:!0})}catch{r({result:w.LEAD,code:C.NO_INFO,hasRun:!0})}finally{l(!1),t(!1)}}return(0,I.jsx)(ae,{id:`fiber-address-servicepoint-select`,"data-cy":`fiber-address-servicepoint-select`,collapsedHeight:0,show:i?.address?.units?.length>1&&!o,children:(0,I.jsxs)(`div`,{className:G.unitsDropdown,children:[(0,I.jsx)(`p`,{className:`mb-2`,children:`Det ser ut som det er flere enheter på denne adressen. Se om du finner din her:`}),(0,I.jsx)(u,{id:`dwelling_unit`,name:`place`,placeholder:`Velg enhet`,label:`Velg enhet`,options:n?.options?.length?n.options.map(e=>({value:e.value,label:e.label})):[],value:n?.value,onClick:d,loading:n?.loading||c,required:!0}),(0,I.jsx)(s,{className:`mt-2`,children:(0,I.jsx)(f,{href:`https://www.kartverket.no/eiendom/adressering/finn-bruksenhetsnummer-bolignummer`,target:`_blank`,children:`Slik finner du ditt bruksenhetsnummer`})})]})})}function oe(e,t){if(t&&e?.units?.length)return e.units.find(e=>String(e?.servicepoint_id||``)===String(t))}function q({products:e,productTypes:t,filter:n,typeMap:r}){if(!n||n===x.ALL||(t?.length??0)<2)return e||[];let i=r[n];return i?(e||[]).filter(e=>e?.type===i):e||[]}function se(e,t){if(!e||new URLSearchParams(e).get(`se`)!==x.ALL)return;t(x.ALL);let n=document.getElementById(`fiber-delivery-result`);n&&setTimeout(()=>{i(n,80)},150)}function ce(e,t){let n=e?.result||[e?.street,e?.zip,e?.city].filter(Boolean).join(` `).trim()||t?.result||``;return{resolvedAddressResult:n,resolvedAddress:{...t,...e,result:n}}}
1function le(e,t){let[n,r]=(0,L.useState)(void 0),[i,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),[c,l]=(0,L.useState)(void 0),[u,d]=(0,L.useState)(!1);return(0,L.useEffect)(()=>{if(!e||e.length<3){a(!1),s(null),r(void 0);return}let t=!0;return a(!0),s(null),h(b,{keyword:e}).then(e=>{t&&(r(e),a(!1))}).catch(e=>{t&&(s(e instanceof Error?e:Error(String(e))),a(!1))}),()=>{t=!1}},[e]),(0,L.useEffect)(()=>{if(!t){d(!1),l(void 0);return}let e=!0;return l(void 0),d(!0),h(y,{id:t}).then(t=>{e&&(l(t),d(!1))}).catch(()=>{e&&(l(null),d(!1))}),()=>{e=!1}},[t]),{addresses:n,isLoadingAddresses:i,errorAddresses:o,addressData:c,isLoadingAddressData:u,resetAddressData:(0,L.useCallback)(()=>l(void 0),[])}}function J({url:e,pageSettingsSearch:t,doDeliveryCheck:r,setLoading:i,setError:a}){let o=n(),{data:s,setData:c,order:l,setOrder:u,clearAddress:d,resetForServicePoint:f,setView:p,flushContext:m,loading:h}=ie(),[v,y]=(0,L.useState)([]),[b,x]=(0,L.useState)(!1),[ae,I]=(0,L.useState)(``),R=(0,L.useRef)(null),z=(0,L.useRef)(!1),B=(0,L.useRef)(``),V=(0,L.useRef)(``),H=(0,L.useRef)(null),U=r?s?.searchKeyword:ae,W=U?.length||0,G=k(e),K=ne(G),q=F(G),J=M(G),Y=q||l?.address?.id,{addresses:X,isLoadingAddresses:Z,errorAddresses:Q,addressData:$,isLoadingAddressData:ue,resetAddressData:de}=le(U,r?Y:void 0),fe=()=>{a(null),d(),i(!1),c({result:null,hasRun:!1}),de(),x(!1),setTimeout(()=>{m(),R?.current?.focus()},500)},pe=(0,L.useCallback)(e=>{if(a(null),!e||e.length===0){r?(d(),i(!1),c({result:null,hasRun:!1}),de()):(I(``),y([])),x(!1);return}x(!0),r?c({searchKeyword:e?.trim()}):I(e?.trim())},[r,a,d,i,c,x]);return(0,L.useEffect)(()=>{if(!r)return;if((K||q)&&j(),q){B.current=``,V.current=``,z.current=!1,y([]),R.current&&(R.current.value=``),f();return}let e=K?.trim()||``;if(e&&H.current!==e){if(e.length<3){H.current=e,x(!1);return}H.current=e,a(null),B.current=``,V.current=``,z.current=!1,y([]),u({address:{result:e},adresse:e}),c({searchKeyword:e,hasRun:!1,result:null,code:void 0,servicepoint_id:void 0}),x(!0)}},[r,K,q,f,c,a,u]),(0,L.useEffect)(()=>{q&&r&&(s?.hasRun||(x(!0),i(!0)))},[s?.hasRun,r,q,i]),(0,L.useEffect)(()=>{if(r&&s?.hasRun&&s?.result){y([]);return}if(!re({isLoadingAddresses:Z,searchKeywordLength:W,addresses:X}))return;let e=X?.getAddresses||[],t=te(U,e);if(B.current===t){b&&x(!1);return}if(B.current=t,e.length===0){console.error(`No addresses found`),y([]),a(T.NO_ADDRESSES),x(!1);return}if(a(null),!r){y(r?[...e,E]:e),x(!1);return}let n=N(e,U||``);if(n){y([]),R.current&&(R.current.value=n.result);let e={...n,dwelling_unit:null,units:[]};u({address:e,adresse:e?.result}),c({result:null,hasRun:!1}),i(!0)}else y([...e,E]),setTimeout(()=>{R.current?.focus()},0);x(!1)},[X,U,s?.hasRun,s?.result,Z,W,b,a,i,r]),(0,L.useEffect)(()=>{Q&&!Z&&(console.error(`Error fetching addresses:`,Q),a(T.FETCH_ADDRESSES_ERROR),x(!1))},[Q,Z,a]),(0,L.useEffect)(()=>{if($===void 0||ue||!r||!Y)return;let e=$?.getAddressData;if(!e){console.error(`No getAddressData payload found`),a(T.NO_ADDRESS_DATA),x(!1),i(!1);return}let t=P(Y,e);if(V.current===t){if(!s?.hasRun)V.current=``;else{x(!1),i(!1);return}}V.current=t;let n=l?.address||{},{resolvedAddressResult:d,resolvedAddress:f}=ce(e?.address||{},n),p={...f,units:e?.units||n?.units||[]},m=oe(e,q);if(m?.unit_id){if(n?.dwelling_unit!==m.unit_id||String(s?.servicepoint_id||``)!==String(m?.servicepoint_id||``)||String(n?.result||``)!==String(d||``)){R.current&&d&&(R.current.value=d),u({address:{...f,units:e?.units||n?.units||[],dwelling_unit:m.unit_id},adresse:d});let t=typeof m?.result==`string`;c({...m,result:t?m.result:w.LEAD,code:t?m.code:C.NO_INFO,hasRun:!0})}window.location.pathname!==S.start&&o(S.start,{viewTransition:!0}),x(!1),i(!1);return}ee(n,d,p,e)&&u({address:p,adresse:d}),z.current||(z.current=!0,g(_.ADDRESS_SEARCHED,{landing_page:e?.deliverable?.landing_page,query:s?.searchKeyword,reason:e?.code?O[e?.code]:``})),c({...e,hasRun:!0}),window.location.pathname!==S.start&&o(S.start,{viewTransition:!0}),x(!1),i(!1)},[$,Y,r,ue,o,a,i]),(0,L.useEffect)(()=>{t&&(l?.address?.result&&R.current&&(R.current.value=l.address.result),se(t,p))},[t]),(0,L.useEffect)(()=>{J&&p(J)},[]),{data:s,order:l,contextLoading:h,suggestions:v,setSuggestions:y,searching:b,inputRef:R,onSearch:pe,onAddressSelect:e=>{let t=v.find(t=>t?.result===e);if(!t){console.error(`Selected address not found in suggestions`),a(T.ADDRESS_NOT_FOUND);return}if(!t.id){console.error(`Selected address has no ID`),a(T.NO_SERVICEPOINT_ID);return}if(t.id===T?.ADDRESS_NOT_FOUND_IN_LIST?.id){a(T.ADDRESS_NOT_FOUND_IN_LIST),i(!1),x(!1);return}i(!0),V.current=``,R.current&&(R.current.value=t.result);let n={...t,dwelling_unit:null,units:[]};u({address:n,adresse:n?.result}),c({result:null,hasRun:!1})},clearSearch:fe,unitOptions:A(l?.address?.units,D)}}function Y({id:e=`fiber-delivery-address-input`,name:t=`fiber-delivery-address-input`,loading:n,setLoading:r,error:i,setError:a,defaultValue:o,doDeliveryCheck:s=!0,helpTextVariant:c=`all-products`,required:l=!1,onSelect:u,onClear:d,...f}){let{data:h,order:g,contextLoading:_,suggestions:v,setSuggestions:y,searching:b,inputRef:x,onSearch:S,onAddressSelect:C,clearSearch:T,unitOptions:E}=J({url:f?.url,pageSettingsSearch:f?.pageSettings?.search,doDeliveryCheck:s,setLoading:r,setError:a}),D={id:e,name:t,inputRef:x,suggestions:v,setSuggestions:y,searching:b,loading:n,contextLoading:_,onSearch:S},O=h?.result===w.UNIT_SELECTION&&!h?.hasRun;return s?(0,I.jsxs)(m,{children:[(0,I.jsx)(p,{level:f?.headingLevel||3,className:`h3 mb-2`,children:`Sjekk om du kan få fiber`}),(0,I.jsxs)(`div`,{className:z.fields,children:[(0,I.jsx)(`p`,{className:z.intro,children:`Fyll inn adressen din og se hvilke produkter og priser vi kan tilby deg`}),(0,I.jsx)(W,{...D,value:g?.address?.result||``,error:i,onSelect:C,onClear:T}),(0,I.jsx)(K,{value:g?.address?.dwelling_unit||void 0,options:E,loading:!1,setLoading:r,setError:a,...f}),!O&&(0,I.jsx)(B,{variant:c,hasResult:!!h?.result,hasRun:!!h?.hasRun})]})]}):(0,I.jsx)(W,{...D,required:l,defaultValue:o,error:i,onSelect:u||(()=>{}),onClear:d})}export{R as i,q as n,z as r,Y as t};
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.