(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,17053,e=>{"use strict";var t=e.i(86909);function a(){return"https://api.banglayon.com/api".replace(/\/+$/,"")}function i(){let e=a();if(!e)throw{status:0,message:"API Base URL সেট করা নেই। `nextjsadmin/.env.local` এ NEXT_PUBLIC_API_BASE_URL দিন (example দেখুন), তারপর dev server restart করুন।"};return e}function n(e){let a=(0,t.getAdminApiKey)(),i=new Headers(e?.headers);return a&&i.set("x-admin-key",a),{...e,headers:i}}async function s(e){return await e.json().catch(()=>null)}async function r(e){let t=await s(e),a=(()=>{if(t&&"object"==typeof t&&"message"in t){let e=t.message;if(null!=e)return String(e)}return`Request failed (${e.status})`})();return{status:e.status,message:a}}async function l(e,t){let a=new URL(`${i()}${e}`);t&&Object.entries(t).forEach(([e,t])=>a.searchParams.set(e,t));let l=await fetch(a.toString(),n({method:"GET"}));if(!l.ok)throw await r(l);let d=await s(l);return d?.data??d}async function d(e,t){let a=await fetch(`${i()}${e}`,n({method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(t)}));if(!a.ok)throw await r(a);let l=await s(a);return l?.data??l}async function o(e,t){let a=await fetch(`${i()}${e}`,n({method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(t)}));if(!a.ok)throw await r(a);let l=await s(a);return l?.data??l}async function c(e){let t=await fetch(`${i()}${e}`,n({method:"DELETE"}));if(!t.ok)throw await r(t);return!0}async function u(e){let t=`${i()}/admin/books`,a=new Headers;a.set("x-admin-key",e.trim());let n=await fetch(t,{method:"GET",headers:a});if(401===n.status)throw{status:401,message:"ভুল Admin API Key। সঠিক key দিন।"};if(!n.ok)throw await r(n)}async function m(e,t,a){let l=new FormData;for(let[e,t]of Object.entries(a))l.set(e,t);l.set("file",t,t.name);let d=await fetch(`${i()}${e}`,n({method:"POST",body:l}));if(!d.ok)throw await r(d);let o=await s(d);return o?.data??o}async function x(e,t,a=!1){let l=new FormData;l.set("file",t,t.name);let d=await fetch(`${i()}/admin/contents/${e}/file${a?"?keepName=true":""}`,n({method:"PUT",body:l}));if(!d.ok)throw await r(d);let o=await s(d);return o?.data??o}e.s(["apiDelete",0,c,"apiGet",0,l,"apiPost",0,o,"apiPut",0,d,"apiReplacePdf",0,x,"apiUploadPdf",0,m,"getApiBaseUrl",0,a,"validateAdminKey",0,u])},76504,e=>{"use strict";var t=e.i(43476),a=e.i(71645),i=e.i(17053);function n({book:e,existing:s,onClose:r,onSaved:l}){let d=String(e.bookId),o=String(e?.title?.bn??d),[c,u]=(0,a.useState)(()=>{let e=s?.delta?.bn;return Array.isArray(e)?e.map(e=>"string"==typeof e?.insert?e.insert:"").join(""):""}),[m,x]=(0,a.useState)(!1),[b,h]=(0,a.useState)(null);function f(e){return[{insert:e.endsWith("\n")?e:`${e}
`}]}async function p(){h(null),x(!0);try{await (0,i.apiPut)(`/admin/guides/${d}`,{title:{bn:`${o} — গাইড`,en:`${String(e?.title?.en??o)} — Guide`,ar:`${String(e?.title?.ar??o)} — دليل`},delta:{bn:f(c),en:f(c),ar:f(c)},isPublished:!0}),await l()}catch(e){h(e?.message??String(e)),x(!1)}}return(0,t.jsx)("div",{className:"fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4",children:(0,t.jsxs)("div",{className:"w-full max-w-[760px] rounded-3xl border border-zinc-800 bg-zinc-950 shadow-2xl",children:[(0,t.jsxs)("div",{className:"px-6 py-4 border-b border-zinc-800 flex items-center gap-3",children:[(0,t.jsxs)("div",{className:"text-base font-semibold",children:[o," — গাইড"]}),(0,t.jsx)("div",{className:"flex-1"}),(0,t.jsx)("button",{onClick:r,className:"px-3 py-2 rounded-lg border border-zinc-800 hover:border-zinc-700 text-sm",children:"Close"})]}),(0,t.jsxs)("div",{className:"p-6 space-y-3",children:[(0,t.jsx)("div",{className:"text-xs text-zinc-300",children:"Guide text (BN) — simple editor"}),(0,t.jsx)("textarea",{value:c,onChange:e=>u(e.target.value),className:"w-full rounded-xl bg-black/40 border border-zinc-800 px-4 py-3 outline-none focus:border-[#D4AF37]/60 min-h-[360px]"}),b?(0,t.jsx)("div",{className:"text-sm text-red-300",children:b}):null,(0,t.jsx)("div",{className:"flex gap-2 pt-2",children:(0,t.jsx)("button",{type:"button",onClick:()=>void p(),disabled:m,className:"px-4 py-2 rounded-xl bg-[#D4AF37] text-zinc-950 font-semibold text-sm disabled:opacity-40",children:m?"Saving…":"Save Guide"})})]})]})})}e.s(["default",0,function(){let[e,s]=(0,a.useState)([]),[r,l]=(0,a.useState)([]),[d,o]=(0,a.useState)([]),[c,u]=(0,a.useState)("all"),[m,x]=(0,a.useState)(!0),[b,h]=(0,a.useState)(null),[f,p]=(0,a.useState)(null);async function g(){x(!0),h(null);try{let[e,t,a]=await Promise.all([(0,i.apiGet)("/admin/books"),(0,i.apiGet)("/admin/categories"),(0,i.apiGet)("/admin/guides")]),n=(e??[]).filter(e=>e?.showOnHome!==!1&&e?.hasGuide!==!1).sort((e,t)=>Number(e?.sortOrder??e?.number??0)-Number(t?.sortOrder??t?.number??0));s(n),l(t??[]),o(a??[])}catch(e){h(e?.message??String(e))}finally{x(!1)}}(0,a.useEffect)(()=>{g()},[]);let y=(0,a.useMemo)(()=>[{id:"all",label:"সকল কিতাব"},...r.map(e=>({id:String(e.categoryId),label:String(e?.title?.bn??e.categoryId)}))],[r]),w=(0,a.useMemo)(()=>"all"===c?e:e.filter(e=>String(e?.category??"")===c),[e,c]);return(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)("div",{className:"flex items-start gap-4",children:[(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("div",{className:"text-xl font-semibold",children:"Teaching Guides"}),(0,t.jsx)("div",{className:"text-sm text-zinc-400",children:"প্রতিটি book card এর জন্য আলাদা গাইড"})]}),(0,t.jsx)("button",{onClick:()=>void g(),className:"px-3 py-2 rounded-lg border border-zinc-800 hover:border-zinc-700 text-sm",children:"Refresh"})]}),m?null:(0,t.jsx)("div",{className:"flex gap-2 overflow-x-auto pb-1",children:y.map(a=>{let i=c===a.id,n="all"===a.id?e.length:e.filter(e=>String(e?.category??"")===a.id).length;return(0,t.jsxs)("button",{onClick:()=>u(a.id),className:["shrink-0 rounded-full border px-4 py-2 text-sm flex items-center gap-2",i?"bg-[#D4AF37] text-zinc-950 border-[#D4AF37]":"border-zinc-800 text-zinc-200 hover:bg-zinc-900/50"].join(" "),children:[(0,t.jsx)("span",{className:"truncate max-w-[200px]",children:a.label}),(0,t.jsx)("span",{className:["text-xs rounded-full px-2 py-0.5 font-medium",i?"count-badge-selected":"count-badge"].join(" "),children:n})]},a.id)})}),m?(0,t.jsx)("div",{className:"py-10 text-center text-zinc-300 text-sm",children:"Loading…"}):0===w.length?(0,t.jsx)("div",{className:"py-10 text-center text-zinc-300 text-sm",children:"No guide-enabled books"}):(0,t.jsx)("div",{className:"space-y-2",children:w.map(e=>{let a=String(e.bookId),n=d.find(e=>String(e.bookId)===a)??null,s=String(e?.title?.bn??a);return(0,t.jsxs)("div",{className:"rounded-2xl border border-zinc-800 bg-black/40 p-4 flex items-start gap-4",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("div",{className:"font-semibold truncate",children:s}),(0,t.jsx)("div",{className:"text-sm text-zinc-400 truncate",children:n?"Guide saved":"Not set"})]}),(0,t.jsx)("button",{className:"px-3 py-2 rounded-lg border border-zinc-800 hover:border-zinc-700 text-sm",onClick:()=>p({book:e,guide:n}),children:"Edit"}),n?(0,t.jsx)("button",{className:"px-3 py-2 rounded-lg border border-red-900/60 text-red-200 hover:border-red-800 text-sm",onClick:async()=>{if(confirm("Delete guide?"))try{await (0,i.apiDelete)(`/admin/guides/${a}`),await g()}catch(e){h(e?.message??String(e))}},children:"Delete"}):null]},a)})}),b?(0,t.jsx)("div",{className:"text-sm text-red-300",children:b}):null,f?(0,t.jsx)(n,{book:f.book,existing:f.guide,onClose:()=>p(null),onSaved:async()=>{p(null),await g()}}):null]})}])}]);