1import{a as e}from"./rolldown-runtime-DkW27tQK.js";import{$ as t,B as n,Kt as r,Qt as i,T as a,U as o,W as s,X as c,Z as l,b as u,bt as d,dt as f,f as p,ft as m,k as h,m as g,pt as _,s as v,v as y}from"./BuilderType.context-BFA6N7DT.js";import{d as b,o as x,r as S,s as C}from"./Customer.context-Cmo3IL78.js";import{h as w,l as T}from"./GetCurrency.util-DdfKARlw.js";import{t as E}from"./TextInput.view-MM2nAGuF.js";import{t as D}from"./Order.dao-COov5G9n.js";import{t as O}from"./UseTimeout.util-CYY1BpaV.js";import{c as k,f as A}from"./Cart.provider-D-xRRw2W.js";import{t as j}from"./UseForm.provider-c1cnZB3V.js";var M=e(i(),1),N=d(),P=(0,M.createContext)(null);P.displayName=`PreviousOrdersContext`;var F=e=>{let{i18n:n,t:i}=t(),{categoriesById:a,optionGroups:o}=T(),s=n.language,c=(0,M.useRef)(!1),[u,d]=(0,M.useState)(null),[f,m]=(0,M.useState)(!0),[h,g]=(0,M.useState)(0),[_,v]=(0,M.useState)([]),[y,b]=(0,M.useState)(0),[x,S]=(0,M.useState)([]),[C,w]=(0,M.useState)(null),[E,O]=(0,M.useState)(!1),[k,A]=(0,M.useState)(!1),j=e=>{e&&!c.current||c.current&&!e||(e&&(y>0&&b(0),h>0&&b(0)),c.current=!0,Promise.all([D.loadLastSuccededOrder(s),D.loadOrderItems(0),D.loadCustomerOrders(0,s)]).then(([e,t,n])=>{w(e),S(t),v(n)}).catch(e=>d(e)).finally(()=>m(!1)))},F=function(){var e=r(function*(e){if(!a[e.product_category.id])return`NO_CAT`;try{return yield new Promise((t,n)=>{var r;let i=(((r=a[e.product_category.id])==null?void 0:r.products)||[]).find(t=>t.id===e.product.id);if(i){let r=i.subproducts.find(t=>t.id===e.subproduct.id);if(r){let i=o[r.id]||[];for(let t of e.item_options){let e=!1;groupLoop:for(let n of i)for(let r of n.options)if(r.id===t.option_id){e=!0;break groupLoop}e||n(`NO_OPTION`)}t(`OK`)}else n(`NO_SUB`)}else n(`NO_PROD`)})}catch(e){return e}});return function(t){return e.apply(this,arguments)}}();return l(()=>{m({reason:i(`loading_prev_items`),promise:D.loadOrderItems(h).then(e=>{e.length===4?O(!1):O(!0),S(x.concat(e))}).catch(e=>d(e)).finally(()=>m(!1))})},[h]),l(()=>{m({reason:i(`loading_prev_orders`),promise:D.loadCustomerOrders(y,s).then(e=>{e.length===5?A(!1):A(!0),v(_.concat(e))}).catch(e=>d(e)).finally(()=>m(!1))})},[y]),(0,N.jsxs)(P.Provider,{value:{asyncCheckPrevOrderItemData:F,checkPrevOrderItemData:(e,t,n)=>{t(F(e).then(e=>n(e)).catch(e=>n(e)))},disableOrderLoadMore:k,disableItemLoadMore:E,setPrevOrdersPage:b,setPrevItemsPage:g,prevOrdersPage:y,prevItemsPage:h,prevOrders:_,prevItems:x,lastOrder:C,loading:f,init:j},children:[e.children,(0,N.jsx)(p,{error:u,resetError:()=>d(null)})]})},I=()=>(0,M.useContext)(P),L=(e,t)=>{e.stopPropagation(),e.preventDefault(),t.onChange(t.id,``,null)},R=[`value`,`isOpen`,`search`,`onClose`,`uniqueKey`,`optionRefs`,`localOptions`,`contextMenuSelected`,`setContextMenuSelected`],z=e=>{let{value:t,isOpen:n,search:r,onClose:i,uniqueKey:a,optionRefs:o,localOptions:s,contextMenuSelected:l,setContextMenuSelected:u}=e,d=c(e,R),f=d.idAccessor||`id`,p=e=>{if(e.key===`ArrowDown`){if(e.preventDefault(),e.stopPropagation(),!n)return d.setIsOpen(!0);u(e=>{var t;let n=e+1,r=n;return n>=s.length&&(r=e),(t=o.current[r])==null||t.scrollIntoView({block:`end`,inline:`end`}),r})}if(e.key===`ArrowUp`){if(e.preventDefault(),e.stopPropagation(),!n)return;u(e=>{var t;let n=e-1;return n<0?(i(),e):((t=o.current[n])==null||t.scrollIntoView({block:`end`,inline:`end`}),n)})}if(e.key===`Escape`){if(!n)return;e.preventDefault(),e.stopPropagation(),i()}if(e.key===`Enter`){if(!n)return;e.preventDefault(),e.stopPropagation();let t=s[l];if(!t)return i();let r=t[f];d.onChange(d.id,r,t),i()}},m=e=>{let t=e.composedPath();for(let e of t)if((e==null?void 0:e.id)===a)return;i()};return(0,M.useEffect)(()=>(window.addEventListener(`mouseup`,m,{passive:!0}),()=>window.removeEventListener(`mouseup`,m)),[n,r,s,t]),(0,M.useEffect)(()=>{u(-1)},[s.length]),{handleClick:m,handleKeyPress:p}},B=e=>{let t=null,n=w(e.search),r=[],i=e.idAccessor||`id`,a=e.nameAccessor||`name`;for(let o in e.options){let s=e.options[o];if(s[i]===e.value&&(t=s),e.isOpen){if(e.search){(e.requireTransform?w(s[a]):s[e.searchAccessor]).indexOf(n)>-1&&r.push(s);continue}r.push(s)}}return{options:r,selectedValue:t}};m();var V=e=>{let{t:r}=t(),{config:i,app:c}=v(),[d,p]=(0,M.useState)(``),[m,h]=(0,M.useState)(!1),[g,_]=(0,M.useState)(!1),[b,x]=(0,M.useState)(-1),S=(0,M.useRef)({}),C=u(i||c),w=e.id,T=[`wrapper`,`select`],E=`${w}-menu`,D=e.idAccessor||`id`,O=e.nameAccessor||`name`,k=!e.searchAccessor,A=(0,M.createRef)(),j=()=>{h(!1),p(``),x(-1)},{options:P,selectedValue:F}=(0,M.useMemo)(()=>B(f(f({},e),{},{isOpen:m,search:d,requireTransform:k})),[m,d,k,e]),{handleKeyPress:I}=z(f({isOpen:m,search:d,onClose:j,uniqueKey:E,setIsOpen:h,optionRefs:S,contextMenuSelected:b,localOptions:P,setContextMenuSelected:x},e));l(()=>{j()},[e.value]),e.className&&T.push(e.className),e.isDisabled&&T.push(`
1select-disabled`),C.isRounded&&T.push(`global__rounded-corners`);let R={backgroundColor:C.backgroundColor,color:C.color};return(0,N.jsxs)(`div`,{className:T.join(` `),children:[!e.noLabel&&(0,N.jsxs)(`label`,{htmlFor:w,className:`input-label`,children:[r(e.labelText||w),e.required?`*`:null]}),(0,N.jsx)(`select`,{required:e.required,className:`hidden-select-input`,id:`${w}-hidden-select-field`,onChange:()=>{},autoComplete:`off`,value:e.value,autoSave:`off`,children:e.required?e.value?(0,N.jsx)(`option`,{value:e.value}):null:(0,N.jsx)(`option`,{value:e.value})}),(0,N.jsxs)(`div`,{className:`select-input`,onMouseUp:()=>{e.isDisabled||h(!0)},id:E,children:[(0,N.jsx)(`input`,{id:w,name:w,type:`text`,ref:A,autoSave:`off`,autoComplete:`off`,onKeyDown:I,disabled:e.isDisabled,className:`select-input__search`,placeholder:m?e.openSearchPlaceholder||r(`search`):e.placeholder,onChange:t=>{p(t.target.value),e.onSearchChange&&(_(!0),e.onSearchChange(t.target.value,_))},value:m?d:(F==null?void 0:F[O])||``}),(0,N.jsxs)(`div`,{className:`select-input__controls`,children:[e.isClearable&&(0,N.jsx)(n,{size:20,className:`select-input__controls--icon`,onMouseUp:t=>L(t,e)}),(0,N.jsx)(`span`,{className:`select-input__controls--separator`,children:`|`}),m?(0,N.jsx)(s,{size:24,className:`multi-select-input__controls--icon`,onMouseUp:e=>{e.stopPropagation(),h(!1)}}):(0,N.jsx)(o,{size:24,className:`multi-select-input__controls--icon`,onMouseUp:t=>{t.stopPropagation(),!e.isDisabled&&(h(!0),A.current&&A.current.focus())}})]}),m&&(0,N.jsx)(`div`,{className:`select-input__list`,children:(0,N.jsxs)(`div`,{className:`select-input__list--scrollable`,children:[g?(0,N.jsxs)(`div`,{className:`select-input__list--loading`,children:[(0,N.jsx)(a,{}),(0,N.jsx)(`span`,{className:`search-loading-text`,children:r(e.searchLoadingText||``)})]}):null,g?null:(0,N.jsxs)(N.Fragment,{children:[e.onSearchChange&&P.length>0&&(0,N.jsx)(`div`,{className:`select-input__list--last-search-results`,children:r(`last_search_results`)}),P.map((t,n)=>{let i=[`select-input__list--item`],a=t[D],o=a===e.value;return a===e.value&&i.push(`--selected`),n===b&&i.push(`--active`),(0,N.jsx)(`div`,{className:i.join(` `),ref:e=>S.current[n]=e,style:o?R:void 0,onMouseUp:()=>{e.isDisabled||(e.onChange(e.id,a,t),j())},children:e.useTranslationOnName?r(t[O]):t[O]},`${n}-${w}-${t[D]}`)})]})]})})]}),e.errors&&(0,N.jsx)(y,{id:e.id,errors:e.errors})]})},H=e=>{let{t:n}=t(),{regions:r,streets:i,loadStreets:a}=A(),{form:o,onSaveAddress:s}=J(),{restaurant:c}=v(),{setTm:l}=O(),{show_country_field:u}=k();if((0,M.useEffect)(()=>{c.delivery_method===`priced_street_based`&&o.editor&&o.editor.street&&a(o.editor.delivery_region_id,o.editor.street)},[]),!o.editor)return null;let d=c.delivery_method===`gps_based`;return(0,N.jsxs)(`form`,{className:`profile__addresses--form`,onSubmit:o.handleSubmit(s),children:[(0,N.jsxs)(`div`,{className:`profile__addresses--form--disabled-text`,children:[o.editor.country,`, `,o.editor.state_province_county,`,`,` `,o.editor.toAddress(n,!1,!0)]}),u&&(0,N.jsx)(E,{required:!0,id:`country`,className:`country`,value:o.editor.country,errors:o.fieldErrors,onChange:o.handleChange,placeholder:`Magyarország`}),d?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(E,{id:`zipcode`,required:!0,className:`zipcode`,errors:o.fieldErrors,value:o.editor.zipcode,onChange:o.handleChange,placeholder:n(`example_zipcode`)}),(0,N.jsx)(E,{required:!0,id:`city`,className:`city`,value:o.editor.city,errors:o.fieldErrors,onChange:o.handleChange,placeholder:n(`example_city`)})]}):(0,N.jsx)(V,{required:!0,options:r,id:`delivery_region_id`,onChange:o.handleChange,className:`delivery_region_id`,value:o.editor.delivery_region_id,placeholder:n(`select_region`)}),c.delivery_method===`priced_street_based`?(0,N.jsx)(V,{required:!0,isClearable:!0,id:`street_id`,options:i,className:`street_id`,searchLoadingText:`searching_in_street_list`,onSearchChange:(e,t)=>
1{l(()=>{a(o.editor.delivery_region_id,e).then(()=>t(!1))},600,`street-fetcher`)},onChange:o.handleChange,value:o.editor.street_id,errors:o.fieldErrors,isDisabled:!o.editor.delivery_region_id}):(0,N.jsx)(E,{required:!0,id:`street`,className:`street`,value:o.editor.street,errors:o.fieldErrors,onChange:o.handleChange,placeholder:n(`example_street`)}),(0,N.jsx)(E,{required:!0,id:`house_number`,errors:o.fieldErrors,onChange:o.handleChange,value:o.editor.house_number,placeholder:n(`example_house_number`)}),(0,N.jsx)(E,{id:`floor`,onChange:o.handleChange,value:o.editor.floor,placeholder:n(`example_floor`)}),(0,N.jsx)(E,{id:`door`,onChange:o.handleChange,value:o.editor.door,placeholder:n(`example_door`)}),(0,N.jsx)(E,{id:`doorbell`,onChange:o.handleChange,value:o.editor.doorbell,placeholder:n(`example_bell`)}),(0,N.jsx)(E,{required:!0,id:`address_name`,className:`address_name`,labelText:`address_name`,onChange:o.handleChange,value:o.editor.address_name,placeholder:n(`address_name_placeholder`)}),(0,N.jsx)(E,{id:`address_notes`,className:`address_notes`,onChange:o.handleChange,value:o.editor.address_notes,placeholder:n(`address_note_placeholder`)}),(0,N.jsx)(`button`,{type:`submit`,style:{display:`none`}})]})},U=e=>{let{t:n}=t(),{form:r,onSaveAddress:i,loading:o}=J();return r.editor?(0,N.jsx)(g,{size:`SM`,isSubmitDisabled:!r.isDirty,onClose:()=>r.setEditor(null),onSubmit:r.handleSubmit(i),heading:n(r.editor.id?`edit`:`new_address`),submitIcon:o?(0,N.jsx)(a,{isAlternate:!0}):h,children:(0,N.jsx)(H,{})}):null},W=_(),G=[`customer`],K=(0,M.createContext)(null);K.displayName=`AddressContext`;var q=e=>{let t=S(),{customer:n}=t,i=c(t,G),{setStreets:a}=A(),{restaurant:o,startPage:s,setSelectableRestaurants:u}=v(),[d,f]=(0,M.useState)(i.addresses),[m,h]=(0,M.useState)(!1),[g,_]=(0,M.useState)(null),y=o.delivery_method===`gps_based`,w=j({editor:null,initialRules:{city:y,zipcode:y,street:y||o.delivery_method===`region_based`,delivery_region_id:!y,street_id:o.delivery_method===`priced_street_based`,house_number:!0,address_name:!0},fieldHooks:{delivery_region_id:(e,t,n)=>(a([]),e.city=n.name,e.street_id=``,e.street=``,e),street_id:(e,t,n)=>(e.street=n?n.name:``,e)}});return l(()=>{f((0,W.cloneDeep)(i.addresses))},[i.addresses]),(0,N.jsxs)(K.Provider,{value:{form:w,loading:m,addresses:d,onNewAddress:()=>{w.setEditor(new C({country:o.country,state_province_county:o.state_province_county,city:o.city,customer_id:n==null?void 0:n.id,address_name:`#${d.length+1}`}))},onSaveAddress:()=>{if(w.editor){h(!0);try{r(function*(){s&&o.delivery_method===`gps_based`&&(yield b(o.id,w.editor,u))===`INVALID`||(yield w.editor.id?x.updateAddress(w.editor.id,w.editor.JSON):x.saveAddress(w.editor.JSON),i.loadAddresses(),w.setEditor(null),w.setIsDirty(!1),h(!1))})()}catch(e){h(!1),_(e)}}},onDeleteAddress:e=>{h(x.removeAddress(e).then(()=>{f(t=>{let n=(0,W.cloneDeep)(t);for(let t in n)n[t].id===e&&n.splice(parseInt(t),1);return i.setAddresses(n),n})}).catch(e=>_(e)).finally(()=>h(!1)))}},children:[(0,N.jsx)(U,{}),(0,N.jsx)(p,{error:g,resetError:()=>_(null)}),e.children]})},J=()=>(0,M.useContext)(K);export{I as a,F as i,J as n,V as r,q 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.