(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[173],{1795:(e,t,a)=>{Promise.resolve().then(a.bind(a,2514))},2514:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>m});var n=a(5155),r=a(2115),s=a(2801),c=a(5695),o=a(6874),i=a.n(o);let l="https://api-arsipkl.dimasp.app";function m(){let{token:e,loading:t}=(0,s.A)(),[a,o]=(0,r.useState)([]),m=(0,c.useRouter)();(0,r.useEffect)(()=>{if(!e)return;let t=async()=>{try{await fetch("".concat(l,"/api/notifications/mark-read"),{method:"POST",headers:{Authorization:"Bearer ".concat(e)}})}catch(e){console.error("Gagal menandai notifikasi:",e)}};(async()=>{try{let t=await fetch("".concat(l,"/api/notifications"),{headers:{Authorization:"Bearer ".concat(e)}}),a=await t.json();t.ok&&o(a)}catch(e){console.error("Gagal memuat notifikasi:",e)}})(),t()},[e]);let u=[],d=new Map;return(a.forEach(e=>{if("like"===e.type){let t="".concat(e.actor_username,"_").concat(e.post_id);(!d.has(t)||new Date(e.created_at)>new Date(d.get(t).created_at))&&d.set(t,e)}else u.push(e)}),u.push(...Array.from(d.values())),u.sort((e,t)=>new Date(t.created_at)-new Date(e.created_at)),t)?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center p-10",children:[(0,n.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500 mb-3"}),(0,n.jsx)("p",{className:"text-blue-600 font-semibold",children:"Memuat..."})]}):(0,n.jsxs)("div",{className:"container mx-auto max-w-2xl py-10 px-4",children:[(0,n.jsxs)("button",{onClick:()=>m.back(),className:"mb-4 bg-transparent flex items-center gap-2 cursor-pointer",style:{border:"none"},children:[(0,n.jsx)("span",{style:{fontSize:"1.2em"},children:"←"}),(0,n.jsx)("span",{children:"Kembali"})]}),(0,n.jsx)("h1",{className:"text-3xl font-bold mb-6",children:"Notifikasi"}),(0,n.jsx)("div",{className:"bg-white p-4 rounded-lg shadow-md space-y-2",children:u.length>0?u.map(e=>(0,n.jsx)(i(),{href:("like"===e.type||"comment"===e.type)&&e.post_slug?"/p/".concat(e.post_slug):"/profil/".concat(e.actor_username),className:"block",children:(0,n.jsxs)("div",{className:"p-3 rounded-md flex items-center justify-between space-x-4 ".concat(e.is_read?"":"bg-blue-50"," hover:bg-gray-50 transition"),children:[(0,n.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,n.jsx)("img",{src:"".concat(l).concat(e.actor_avatar),alt:e.actor_username,className:"w-10 h-10 rounded-full object-cover flex-shrink-0 cursor-pointer",onClick:t=>{t.stopPropagation(),window.location.href="/profil/".concat(e.actor_username)}}),(0,n.jsxs)("p",{className:"text-sm",children:[(0,n.jsx)("span",{className:"font-bold cursor-pointer",onClick:t=>{t.stopPropagation(),window.location.href="/profil/".concat(e.actor_username)},children:e.actor_username})," ",(e=>{switch(e.type){case"like":return(0,n.jsx)(n.Fragment,{children:"menyukai postingan Anda."});case"comment":return(0,n.jsx)(n.Fragment,{children:"mengomentari postingan Anda."});case"follow":return(0,n.jsx)(n.Fragment,{children:"mulai mengikuti Anda."});default:return(0,n.jsx)(n.Fragment,{children:"berinteraksi dengan Anda."})}})(e),(0,n.jsx)("span",{className:"text-xs text-gray-500 block mt-1",children:new Date(e.created_at).toLocaleString("id-ID",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})})]})]}),("like"===e.type||"comment"===e.type)&&e.post_image_url&&(0,n.jsx)("img",{src:"".concat(l).concat(e.post_image_url),alt:"Gambar Postingan",className:"w-14 h-14 rounded-md object-cover ml-2"})]})},e.id)):(0,n.jsx)("p",{className:"text-center text-gray-500 py-8",children:"Tidak ada notifikasi."})})]})}},2801:(e,t,a)=>{"use strict";a.d(t,{A:()=>i,AuthProvider:()=>o});var n=a(5155),r=a(2115),s=a(9159);let c=(0,r.createContext)(null);function o(e){let{children:t}=e,[a,o]=(0,r.useState)(null),[i,l]=(0,r.useState)(null),[m,u]=(0,r.useState)(!0);async function d(e,t){if(e&&t)try{let a=await fetch("".concat("https://api-arsipkl.dimasp.app","/api/users/").concat(e),{headers:{Authorization:"Bearer ".concat(t)}});if(a.ok){let e=await a.json();o(t=>({...t,...e.user}))}}catch(e){}}(0,r.useEffect)(()=>{let e=localStorage.getItem("token");if(e)try{let t=(0,s.s)(e);o(t),l(e),d(t.username,e)}catch(e){localStorage.removeItem("token"),o(null),l(null)}u(!1)},[]);let p=async e=>{if(e){localStorage.setItem("token",e);try{let t=(0,s.s)(e);o(t),l(e),await d(t.username,e)}catch(e){o(null),l(null),localStorage.removeItem("token")}}};return(0,n.jsx)(c.Provider,{value:{user:a,token:i,loginUser:p,logout:()=>{localStorage.removeItem("token"),o(null),l(null)},loading:m},children:t})}let i=()=>(0,r.useContext)(c)}},e=>{e.O(0,[556,441,964,358],()=>e(e.s=1795)),_N_E=e.O()}]);