(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8456,9158,8358],{7403:function(t,e,a){Promise.resolve().then(a.bind(a,7271)),Promise.resolve().then(a.t.bind(a,2972,23))},7271:function(t,e,a){"use strict";a.d(e,{default:function(){return l}});var n=a(7437),s=a(2265),c=a(8706),r=a(2876),i=a(2007);function l(t){let{initialRestaurants:e,totalCount:a,title:l,categoryId:o,businessTypeId:u}=t,d=(0,c.T)(),{location:g}=(0,r.T)(),[f,h]=(0,s.useState)(e),[m,x]=(0,s.useState)(0===a?e.length>0:e.length<a),[p,y]=(0,s.useState)(e.length),[v,w]=(0,s.useState)(!1),j=(0,s.useRef)(null);(0,s.useEffect)(()=>{h(e),y(e.length),x(0===a?e.length>0:e.length<a)},[e,a]);let b=(0,s.useCallback)(async()=>{if(!v&&m){w(!0);try{let t="&latitude=".concat(g.latitude,"&longitude=").concat(g.longitude),e=u?"&businessTypeId=".concat(u):"",a=o?"/api/homepage/marketing-category?categoryId=".concat(o,"&offset=").concat(p,"&limit=").concat(20).concat(t).concat(e):"/api/homepage/businesses?offset=".concat(p,"&limit=").concat(20).concat(t).concat(e),n=await fetch(a),s=await n.json();s.restaurants&&s.restaurants.length>0?(h(t=>{let e=new Set(t.map(t=>t.id)),a=s.restaurants.filter(t=>!e.has(t.id));return[...t,...a]}),y(t=>t+s.restaurants.length),x(s.hasMore)):x(!1)}catch(t){x(!1)}finally{w(!1)}}},[v,m,p,o,u,g.latitude,g.longitude]);(0,s.useEffect)(()=>{let t=j.current;if(!t)return;let e=new IntersectionObserver(t=>{t[0].isIntersecting&&b()},{rootMargin:"200px"});return e.observe(t),()=>e.disconnect()},[b]);let N=""===l?null:l||d("all_restaurants",{defaultValue:"T\xeb gjitha Restorantet"});return(0,n.jsxs)("section",{className:"py-5",children:[N&&(0,n.jsxs)("div",{className:"px-4 mb-4",children:[(0,n.jsx)("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:N}),a>0&&(0,n.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mt-1",children:[f.length," / ",a," ",d("restaurants_lowercase",{defaultValue:"restorante"})]})]}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 px-4",children:f.map((t,e)=>(0,n.jsx)("div",{className:"w-full",children:(0,n.jsx)(i.Z,{restaurant:t,fullWidth:!0})},"".concat(t.id,"-").concat(e)))}),m&&(0,n.jsx)("div",{ref:j,className:"flex justify-center py-8",children:v&&(0,n.jsxs)("div",{className:"flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),(0,n.jsx)("span",{className:"text-sm",children:d("loading_more",{defaultValue:"Duke ngarkuar..."})})]})})]})}},2876:function(t,e,a){"use strict";a.d(e,{LocationProvider:function(){return o},T:function(){return u}});var n=a(7437),s=a(2265),c=a(8685);let r=(0,s.createContext)(void 0),i="baboon-location",l={latitude:c.pH.AL.latitude,longitude:c.pH.AL.longitude,address:"Tiran\xeb, Shqip\xebri",isAutoDetected:!1};function o(t){let{children:e}=t,[a,c]=(0,s.useState)(l),[o,u]=(0,s.useState)(!1),[d,g]=(0,s.useState)(!1),[f,h]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let t=function(){try{let t=localStorage.getItem(i);if(t)return JSON.parse(t)}catch(t){}return null}();t&&c(t),h(!0)},[]),(0,s.useEffect)(()=>{f&&localStorage.setItem(i,JSON.stringify(a))},[a,f]);let m=(0,s.useCallback)((t,e,a)=>{c({latitude:t,longitude:e,address:a,isAutoDetected:!1}),g(!1)},[]),x=(0,s.useCallback)(async()=>{if(navigator.geolocation){u(!0);try{let{latitude:t,longitude:e}=(await new Promise((t,e)=>{navigator.geolocation.getCurrentPosition(t,e,{enableHighAccuracy:!0,timeout:1e4,maximumAge:3e5})})).coords;try{let a=await fetch("https://nominatim.openstreetmap.org/reverse?format=json&lat=".concat(t,"&lon=").concat(e,"&accept-language=sq")),n=await a.json(),s=n.display_name?n.display_name.split(",").slice(0,3).join(",").trim():"".concat(t.toFixed(4),", ").concat(e.toFixed(4));c({latitude:t,longitude:e,address:s,isAutoDetected:!0})}catch(a){c({latitude:t,longitude:e,address:"".concat(t.toFixed(4),", ").concat(e.toFixed(4)),isAutoDetected:!0})}g(!1)}catch(t){}finally{u(!1)}}},[]);return(0,n.jsx)(r.Provider,{value:{location:a,setLocation:m,detectLocation:x,isDetecting:o,showLocationPicker:d,setShowLocationPicker:g},children:e})}function u(){let t=(0,s.useContext)(r);if(!t)throw Error("useLocation must be used within LocationProvider");return t}}},function(t){t.O(0,[8706,3557,2972,5878,6992,4448,2971,2117,1744],function(){return t(t.s=7403)}),_N_E=t.O()}]);