(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[222],{2801:(e,t,a)=>{"use strict";a.d(t,{A:()=>o,AuthProvider:()=>i});var r=a(5155),s=a(2115),l=a(9159);let n=(0,s.createContext)(null);function i(e){let{children:t}=e,[a,i]=(0,s.useState)(null),[o,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(!0);async function h(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();i(t=>({...t,...e.user}))}}catch(e){}}(0,s.useEffect)(()=>{let e=localStorage.getItem("token");if(e)try{let t=(0,l.s)(e);i(t),c(e),h(t.username,e)}catch(e){localStorage.removeItem("token"),i(null),c(null)}u(!1)},[]);let p=async e=>{if(e){localStorage.setItem("token",e);try{let t=(0,l.s)(e);i(t),c(e),await h(t.username,e)}catch(e){i(null),c(null),localStorage.removeItem("token")}}};return(0,r.jsx)(n.Provider,{value:{user:a,token:o,loginUser:p,logout:()=>{localStorage.removeItem("token"),i(null),c(null)},loading:d},children:t})}let o=()=>(0,s.useContext)(n)},7347:(e,t,a)=>{Promise.resolve().then(a.bind(a,7743))},7743:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>n});var r=a(5155),s=a(2115),l=a(2801);function n(){let{user:e,token:t,loading:a}=(0,l.A)(),[n,i]=(0,s.useState)(""),[o,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(null),[h,p]=(0,s.useState)(""),[m,g]=(0,s.useState)(""),[f,x]=(0,s.useState)(!1),b=async e=>{if(e.preventDefault(),p(""),g(""),!n||!o||!d)return void g("Semua kolom wajib diisi.");x(!0);let a=new FormData;a.append("title",n),a.append("artist",o),a.append("audioFile",d);try{let r=await fetch("".concat("https://api-arsipkl.dimasp.app","/api/songs/upload"),{method:"POST",headers:{Authorization:"Bearer ".concat(t)},body:a}),s=await r.json();if(!r.ok)throw Error(s.message);p("Lagu berhasil diunggah!"),i(""),c(""),e.target.reset()}catch(e){g(e.message)}x(!1)};return e&&"admin"===e.role?(0,r.jsxs)("div",{className:"container mx-auto max-w-lg py-10",children:[(0,r.jsx)("h1",{className:"text-3xl font-bold mb-6",children:"Unggah Lagu Baru"}),(0,r.jsxs)("form",{onSubmit:b,className:"bg-white p-8 rounded-lg shadow-md space-y-4",children:[h&&(0,r.jsx)("p",{className:"text-green-600",children:h}),m&&(0,r.jsx)("p",{className:"text-red-600",children:m}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{htmlFor:"title",children:"Judul Lagu"}),(0,r.jsx)("input",{type:"text",id:"title",value:n,onChange:e=>i(e.target.value),className:"w-full mt-1 p-2 border rounded"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{htmlFor:"artist",children:"Nama Artis/Penyanyi"}),(0,r.jsx)("input",{type:"text",id:"artist",value:o,onChange:e=>c(e.target.value),className:"w-full mt-1 p-2 border rounded"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{htmlFor:"audioFile",children:"File Audio (MP3)"}),(0,r.jsx)("input",{type:"file",id:"audioFile",accept:"audio/mpeg",onChange:e=>u(e.target.files[0]),className:"w-full mt-1"})]}),(0,r.jsx)("button",{type:"submit",className:"w-full bg-blue-500 text-white py-2 rounded",disabled:f,children:f?"Memproses...":"Unggah"})]})]}):(0,r.jsxs)("div",{className:"container mx-auto max-w-lg py-10 text-center",children:[(0,r.jsx)("h1",{className:"text-2xl font-bold text-red-600",children:"Akses Ditolak"}),(0,r.jsx)("p",{className:"mt-2 text-gray-600",children:"Halaman ini hanya dapat diakses oleh Administrator."})]})}},9159:(e,t,a)=>{"use strict";a.d(t,{s:()=>s});class r extends Error{}function s(e,t){let a;if("string"!=typeof e)throw new r("Invalid token specified: must be a string");t||(t={});let s=+(!0!==t.header),l=e.split(".")[s];if("string"!=typeof l)throw new r(`Invalid token specified: missing part #${s+1}`);try{a=function(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw Error("base64 string is not of the correct length")}try{var a;return a=t,decodeURIComponent(atob(a).replace(/(.)/g,(e,t)=>{let a=t.charCodeAt(0).toString(16).toUpperCase();return a.length<2&&(a="0"+a),"%"+a}))}catch(e){return atob(t)}}(l)}catch(e){throw new r(`Invalid token specified: invalid base64 for part #${s+1} (${e.message})`)}try{return JSON.parse(a)}catch(e){throw new r(`Invalid token specified: invalid json for part #${s+1} (${e.message})`)}}r.prototype.name="InvalidTokenError"}},e=>{e.O(0,[441,964,358],()=>e(e.s=7347)),_N_E=e.O()}]);