1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5711],{4913:(e,t,a)=>{a.d(t,{O:()=>c,d:()=>m});var n=a(37876),s=a(24708),r=a(47137),i=a(14232),l=a(8291);let d=(0,r.F)((0,l.cn)("inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium cursor-pointer uppercase tracking-wide transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring","disabled:pointer-events-none disabled:opacity-50"),{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-sm"},size:{default:"h-11 min-h-11 px-3",sm:"h-9 min-h-9 px-2",lg:"h-13 min-h-13 px-5"},tone:{default:"hover:bg-muted hover:text-muted-foreground data-[state=on]:bg-muted data-[state=on]:text-foreground",buy:"text-green-700 data-[state=on]:bg-green-50 data-[state=off]:bg-white",sell:"text-red-600 data-[state=on]:bg-red-50 data-[state=off]:bg-white"}},defaultVariants:{variant:"default",size:"default",tone:"default"}}),o=i.createContext({size:"default",variant:"default"}),c=i.forwardRef((e,t)=>{let{className:a,variant:r,size:i,children:d,...c}=e,m="string"==typeof c.value?c.value:void 0;return(0,n.jsx)(s.bL,{ref:t,className:(0,l.cn)("flex w-full items-center justify-center rounded-xl border border-input",a),...c,children:(0,n.jsx)(o.Provider,{value:{variant:r,size:i,activeValue:m},children:d})})});c.displayName=s.bL.displayName;let m=i.forwardRef((e,t)=>{var a;let{className:r,variant:c,size:m,tone:u,...x}=e,p=i.useContext(o),g=null!=(a=null!=u?u:p.tone)?a:"default",f="buy"===g||"sell"===g,h=p.activeValue,v="sell"===g?"border border-red-600 border-r-0":"buy"===g?(0,l.cn)("border border-green-700 -ml-px","sell"===h?"border-l-red-600":"border-l-green-700"):"";return(0,n.jsx)(s.q7,{ref:t,className:(0,l.cn)(d({variant:p.variant||c,size:p.size||m,tone:g}),"flex-1",f?(0,l.cn)("rounded-none first:rounded-l-xl last:rounded-r-xl",v):"rounded-none border-none first:rounded-l-xl last:rounded-r-xl",r),...x})});m.displayName=s.q7.displayName},5989:(e,t,a)=>{a.d(t,{T:()=>i});var n=a(37876),s=a(14232),r=a(8291);let i=s.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,n.jsx)("textarea",{className:(0,r.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-white px-3 py-2 text-sm text-gray-700 shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",a),ref:t,...s})});i.displayName="Textarea"},10739:(e,t,a)=>{a.d(t,{A:()=>r});var n=a(37876),s=a(8291);function r(e){let{tabs:t,active:a,onChange:r,className:i}=e;return(0,n.jsx)("div",{className:(0,s.cn)("flex flex-wrap gap-1 border-b border-[var(--admin-border)]",i),children:t.map(e=>{let t=a===e.id;return(0,n.jsxs)("button",{type:"button",className:(0,s.cn)("-mb-px inline-flex items-center gap-1.5 border-b-2 px-4 py-2 text-sm font-medium transition-colors",t?"border-[var(--admin-accent)] text-[var(--admin-accent)]":"border-transparent text-[var(--admin-text-muted)] hover:text-[var(--admin-text)]"),onClick:()=>r(e.id),children:[e.label,null!=e.count?(0,n.jsx)("span",{className:"rounded-full bg-[var(--admin-accent-muted)] px-1.5 py-0.5 text-[10px] font-semibold text-[var(--admin-accent-hover)]",children:e.count}):null]},e.id)})})}},14099:(e,t,a)=>{a.d(t,{J:()=>o});var n=a(37876),s=a(59773),r=a(47137),i=a(14232),l=a(8291);let d=(0,r.F)("text-xs font-semibold uppercase tracking-wide leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),o=i.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,n.jsx)(s.b,{ref:t,className:(0,l.cn)(d(),a),...r})});o.displayName=s.b.displayName},15074:(e,t,a)=>{a.d(t,{A:()=>r});var n=a(37876),s=a(8291);function r(e){let{children:t,className:a,maxWidth:r="6xl"}=e;return(0,n.jsx)("div",{className:(0,s.cn)("mx-auto px-4 py-6 sm:px-6","5xl"===r?"max-w-5xl":"max-w-6xl",a),children:t})}},25711:(e,t,a)=>{a.r(t),a.d(t,{default:()=>Z});var n=a(37876),s=a(14232),r=a(67745),i=a(54719),l=a(15074),d=a(83373),o=a(10739),c=a(66553),m=a(72047),u=a(26283),x=a(91725),p=a(26625);let g=(0,s.createContext)(null);function f(){let e=(0,s.useContext)(g);if(!e)throw Error("useFaqCategories must be used within a FaqCategoriesProvider");return e}function h(e){let{children:t}
1=e,[a,r]=(0,s.useState)([]),[i,l]=(0,s.useState)(!0),[d,o]=(0,s.useState)(null),c=(0,s.useCallback)(async()=>{try{l(!0),o(null);let e=await fetch("/api/admin/faq-categories"),t=await e.json();t.success?r(t.items||[]):o(t.message||"Failed to load FAQ categories")}catch(e){o("Failed to load FAQ categories")}finally{l(!1)}},[]);(0,s.useEffect)(()=>{c()},[c]);let m=(0,s.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"en",n=a.find(t=>t.id===e);return n&&(("ar"===t?n.name.ar:n.name.en)||n.name.en)||e},[a]),u=(0,s.useCallback)(e=>{r(t=>{let a=t.findIndex(t=>t.id===e.id);if(-1===a)return[...t,e];let n=[...t];return n[a]=e,n})},[]),x=(0,s.useCallback)(e=>{r(t=>t.filter(t=>t.id!==e))},[]),p=(0,s.useMemo)(()=>({categories:a,loading:i,error:d,refresh:c,getCategoryLabel:m,upsertCategory:u,removeCategory:x}),[a,i,d,c,m,u,x]);return(0,n.jsx)(g.Provider,{value:p,children:t})}var v=a(12050),b=a(26921),y=a(80892),j=a(35265),w=a(55637),N=a(45973);let C="fxgrow-faq-bundle",A=w.vk(e=>"string"==typeof e?{en:e,ar:""}:e&&"object"==typeof e&&!Array.isArray(e)?{en:"string"==typeof e.en?e.en:"",ar:"string"==typeof e.ar?e.ar:""}:{en:"",ar:""},w.Ik({en:w.Yj(),ar:w.Yj()})),q=w.Yj().refine(e=>{let t=e.trim();return!t||!t.startsWith("{")||(0,N.Hz)(t)},"Answer must be HTML or valid Editor.js JSON"),S=w.Ik({id:w.Yj().min(1).optional(),name:A}),k=w.Ik({id:w.Yj().min(1).optional(),category:w.Yj().min(1),question:A,answer:w.Ik({en:q,ar:q})}),F=w.Ik({categories:w.YO(S).optional().default([]),items:w.YO(k)}),I=w.Ik({version:w.eu(1),type:w.eu(C),exportedAt:w.Yj().optional(),categories:w.YO(S).optional().default([]),items:w.YO(k)});function E(e,t){let a=new Blob(["".concat(JSON.stringify(t,null,2),"\n")],{type:"application/json"}),n=URL.createObjectURL(a),s=document.createElement("a");s.href=n,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(n)}w.KC([I,F]);var O=a(88992),Q=a(61357),R=a(69759),U=a(14099);let T=e=>{var t,a,n;return{id:null!=(t=null==e?void 0:e.id)?t:"",nameEn:null!=(a=null==e?void 0:e.name.en)?a:"",nameAr:null!=(n=null==e?void 0:e.name.ar)?n:""}};function J(e){let{open:t,onOpenChange:a,editingItem:r,onSuccess:i}=e,{upsertCategory:l}=f(),{register:d,handleSubmit:o,reset:m,formState:{errors:u,isSubmitting:x}}=(0,O.mN)({defaultValues:T(null)}),[g,h]=(0,s.useState)("en");(0,s.useEffect)(()=>{t&&(m(T(r)),h("en"))},[t,r,m]);let v=async e=>{let t=r?"/api/admin/faq-categories?id=".concat(r.id):"/api/admin/faq-categories",n=r?"PUT":"POST",s=r?"update":"create",d=r?{name:{en:e.nameEn,ar:e.nameAr}}:{id:e.id.trim()||void 0,name:{en:e.nameEn,ar:e.nameAr}};try{let e=await fetch(t,{method:n,headers:{"Content-Type":"application/json","X-Admin-Username":sessionStorage.getItem("adminUsername")||""},body:JSON.stringify(d)}),r=await e.json();r.success&&r.item?(l(r.item),(0,b.wU)(r.message,s),i(),a(!1)):(0,b.pi)(r,s)}catch(e){(0,b.jK)("Failed to save FAQ category",s)}},y="en"===g,j="ar"===g;return(0,n.jsx)(R.A,{open:t,onOpenChange:a,title:r?"Edit Category":"Add Category",formId:"faq-category-form",submitLabel:r?"Save Changes":"Add Category",isSubmitting:x,children:(0,n.jsxs)("form",{id:"faq-category-form",onSubmit:o(v),className:"space-y-4",children:[r?(0,n.jsxs)("div",{children:[(0,n.jsx)(U.J,{className:"mb-1 block normal-case",children:"ID / Slug"}),(0,n.jsx)(p.p,{type:"text",value:r.id,disabled:!0,readOnly:!0})]}):(0,n.jsxs)("div",{children:[(0,n.jsx)(U.J,{htmlFor:"faq-cat-id",className:"mb-1 block normal-case",children:"ID / Slug"}),(0,n.jsx)("p",{className:"".concat(c.wH," mt-0 mb-1"),children:"Optional â auto from English name"}),(0,n.jsx)(p.p,{id:"faq-cat-id",type:"text",placeholder:"e.g. account-opening",...d("id")})]}),(0,n.jsx)(Q.A,{value:g,onChange:h}),(0,n.jsxs)("div",{style:{display:y?"block":"none"},children:[(0,n.jsx)(U.J,{htmlFor:"faq-cat-name-en",className:"mb-1 block normal-case",children:"Name (EN) *"}),(0,n.jsx)(p.p,{id:"faq-cat-name-en",type:"text",placeholder:"e.g. Account Opening",...d("nameEn",{required:"English name is required"})}),u.nameEn?(0,n.jsx)("span",{className:c.A2,children:u.nameEn.message}):null]}),(0,n.jsxs)("div",{style:{display:j?"block":"none"},dir:"rtl",children:[(0,n.jsx)(U.J,{htmlFor:"faq-cat-name-ar",className:"mb-1 block normal-case",children:"Ø§ÙØ§Ø³Ù
(AR)"}),(0,n.jsx)(p.p,{id:"faq-cat-name-ar",type:"text",placeholder:"Ù
ثاÙ: ÙØªØ Ø§ÙØØ³Ø§Ø¨",className:"text-right",...d("nameAr")})]})]})})}function D(){let{categories:e,loading:t,error:a,removeCategory:r,refresh:i}
1=f(),[l,d]=(0,s.useState)(!1),[o,p]=(0,s.useState)(null),g=(0,s.useCallback)(async e=>{if(confirm('Delete category "'.concat(e.name.en,'"?\n\nThis cannot be undone. Categories still used by FAQ questions cannot be deleted.')))try{let t=await fetch("/api/admin/faq-categories?id=".concat(e.id),{method:"DELETE",headers:{"X-Admin-Username":sessionStorage.getItem("adminUsername")||""}}),a=await t.json();a.success?(r(e.id),(0,b.wU)(a.message,"delete")):(0,b.pi)(a,"delete")}catch(e){(0,b.jK)("Failed to delete FAQ category","delete")}},[r]);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-3",children:[(0,n.jsx)("p",{className:"m-0 max-w-2xl text-sm text-[var(--admin-text-muted)]",children:"Manage FAQ categories for this domain. Changes appear immediately in the FAQ question form."}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,n.jsx)(u.$,{type:"button",variant:"outline",onClick:()=>void i(),children:"Refresh"}),(0,n.jsx)(u.$,{type:"button",onClick:()=>{p(null),d(!0)},children:"+ Add Category"})]})]}),a&&!l?(0,n.jsx)(m.Fc,{variant:"destructive",className:"mb-4",children:(0,n.jsx)(m.TN,{children:a})}):null,t?(0,n.jsx)("div",{className:"text-sm text-[var(--admin-text-muted)]",children:"Loading categoriesâ¦"}):0===e.length?(0,n.jsx)("div",{className:c.s1,children:"No categories yet. Click âAdd Categoryâ to create one."}):(0,n.jsx)("div",{className:"space-y-3",children:e.map(e=>(0,n.jsxs)(x.Zp,{className:"border-[var(--admin-border)] bg-[var(--admin-surface)] p-4 shadow-sm",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"m-0 font-semibold text-[var(--admin-text)]",children:e.name.en}),e.name.ar?(0,n.jsx)("p",{className:"mt-1 text-sm text-[var(--admin-text-muted)]",dir:"rtl",children:e.name.ar}):null,(0,n.jsx)("code",{className:"mt-1 inline-block rounded bg-[var(--admin-bg)] px-1.5 py-0.5 text-xs text-[var(--admin-text-muted)]",children:e.id})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)(u.$,{type:"button",variant:"outline",size:"xs",onClick:()=>{p(e),d(!0)},children:"Edit"}),(0,n.jsx)(u.$,{type:"button",variant:"destructive",size:"xs",onClick:()=>void g(e),children:"Delete"})]})]}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-[var(--admin-text-muted)]",children:["Updated ",new Date(e.updatedAt).toLocaleDateString()]})]},e.id))}),(0,n.jsx)(J,{open:l,onOpenChange:e=>{d(e),e||p(null)},editingItem:o,onSuccess:()=>{d(!1),p(null)}})]})}var L=a(83528),z=a(5989);function $(e){var t;let{open:a,onOpenChange:r,editingItem:i,onSuccess:l}=e,{categories:d}=f(),o=e=>{var t,a,n;return{questionEn:null!=(a=null==e?void 0:e.question.en)?a:"",questionAr:null!=(n=null==e?void 0:e.question.ar)?n:"",category:(null==e?void 0:e.category)||(null==(t=d[0])?void 0:t.id)||""}},{register:u,handleSubmit:x,reset:p,formState:{errors:g,isSubmitting:h}}=(0,O.mN)({defaultValues:o(null)}),[v,j]=(0,s.useState)("en"),[w,C]=(0,s.useState)(""),[A,q]=(0,s.useState)(""),[S,k]=(0,s.useState)(""),F="".concat(null!=(t=null==i?void 0:i.id)?t:"new","-").concat(a?"open":"closed");(0,s.useEffect)(()=>{var e,t;a&&(p(o(i)),j("en"),C(""),q((0,N.SZ)(null!=(e=null==i?void 0:i.answer.en)?e:"")),k((0,N.SZ)(null!=(t=null==i?void 0:i.answer.ar)?t:"")))},[a,i,p]),(0,s.useEffect)(()=>{var e,t;if(!a||0===d.length)return;let n=null==i?void 0:i.category,s=null!=(t=null==(e=d[0])?void 0:e.id)?t:"",r=n&&d.some(e=>e.id===n)?n:s;p(e=>({...e,category:r}))},[a,d,i,p]);let I=async e=>{if(C(""),!e.category||0===d.length)return void C("Add at least one category before saving an FAQ");if(!(0,y.Q)(A)){C("English answer is required"),j("en");return}let t=i?"/api/admin/faq?id=".concat(i.id):"/api/admin/faq",a=i?"PUT":"POST",n={question:{en:e.questionEn,ar:e.questionAr},answer:{en:A,ar:S},category:e.category},s=i?"update":"create";try{let e=await fetch(t,{method:a,headers:{"Content-Type":"application/json","X-Admin-Username":sessionStorage.getItem("adminUsername")||""},body:JSON.stringify(n)}),i=await e.json();i.success?((0,b.wU)(i.message,s),l(),r(!1)):(0,b.pi)(i,s)}catch(e){(0,b.jK)("Failed to save FAQ item",s)}},E="en"===v,T="ar"===v;return(0,n.jsxs)(R.A,{open:a,onOpenChange:r,title:i?"Edit FAQ":"Add FAQ",formId:"faq-form",submitLabel:i?"Save Changes":"Add Question",isSubmitting:h,contentClassName:"sm:max-w-4xl",children:[w?(0,n.jsx)(m.Fc,{variant:"destructive",className:"mb-4",children:(0,n.jsx)(m.TN,{children:w})}):null,(0,n.jsxs)("form",{id:"faq-form",onSubmit:x(I),children:[(0,n.jsx)("div",{className:"mb-4",children:(0,n.jsx)(Q.A,{value:v,onCh
1ange:j})}),(0,n.jsxs)("div",{style:{display:E?"block":"none"},className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(U.J,{htmlFor:"faq-question-en",className:"mb-1 block normal-case",children:"Question (EN) *"}),(0,n.jsx)(z.T,{id:"faq-question-en",rows:3,placeholder:"e.g. How do I start trading Forex?",...u("questionEn",{required:"English question is required"})}),g.questionEn?(0,n.jsx)("span",{className:c.A2,children:g.questionEn.message}):null]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(U.J,{className:"mb-1 block normal-case",children:"Answer (EN) *"}),(0,n.jsx)(L.s,{value:A,onChange:q,fullToolbar:!0,placeholder:"Write the FAQ answer..."},"faq-en-".concat(F))]})]}),(0,n.jsxs)("div",{style:{display:T?"block":"none"},dir:"rtl",className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(U.J,{htmlFor:"faq-question-ar",className:"mb-1 block normal-case",children:"Ø§ÙØ³Ø¤Ø§Ù (AR)"}),(0,n.jsx)(z.T,{id:"faq-question-ar",rows:3,placeholder:"Ù
ثاÙ: ÙÙ٠أبدأ تداÙ٠اÙÙÙØ±ÙسØ",...u("questionAr")})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(U.J,{className:"mb-1 block normal-case",children:"Ø§ÙØ¥Ø¬Ø§Ø¨Ø© (AR)"}),(0,n.jsx)(L.s,{value:S,onChange:k,fullToolbar:!0,placeholder:"Ø§ÙØªØ¨ إجابة Ø§ÙØ³Ø¤Ø§Ù..."},"faq-ar-".concat(F))]})]}),(0,n.jsxs)("div",{className:"mt-4",children:[(0,n.jsx)(U.J,{htmlFor:"faq-category",className:"mb-1 block normal-case",children:"Category *"}),0===d.length?(0,n.jsx)("p",{className:c.A2,children:"No categories available. Add one under the Categories tab first."}):(0,n.jsx)("select",{id:"faq-category",className:"h-9 w-full cursor-pointer rounded-md border border-input bg-white px-3 text-sm text-[var(--admin-text)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",...u("category",{required:"Category is required"}),children:d.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name.en},e.id))}),g.category?(0,n.jsx)("span",{className:c.A2,children:g.category.message}):null]})]})]})}function Y(e){let{onImported:t}=e,a=(0,s.useRef)(null),[r,l]=(0,s.useState)(!1),[d,o]=(0,s.useState)(""),[x,p]=(0,s.use
1State)(null),[g,f]=(0,s.useState)(null),[h,v]=(0,s.useState)("replace"),y=()=>{p(null),f(null),o(""),v("replace"),a.current&&(a.current.value="")},j=async e=>{l(!0),o("");try{let t=await fetch("/api/admin/faq-import",{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Username":sessionStorage.getItem("adminUsername")||""},body:JSON.stringify({payload:e,dryRun:!0})}),a=await t.json();if(!a.success){o(a.message||"Invalid FAQ JSON"),f(null);return}p(e),f({modeSuggested:a.modeSuggested,categoryCount:a.categoryCount,itemCount:a.itemCount,existingItemCount:a.existingItemCount,matchingIdCount:a.matchingIdCount,newItemCount:a.newItemCount,newCategoryCount:a.newCategoryCount,unknownCategoryIds:a.unknownCategoryIds||[],warnings:a.warnings||[]}),v("merge"===a.modeSuggested?"merge":"replace")}catch(e){o(e instanceof Error?e.message:"Failed to validate import file"),f(null)}finally{l(!1)}},w=async e=>{var t;let n=null==(t=e.target.files)?void 0:t[0];if(n)try{let e=await n.text(),t=JSON.parse(e);await j(t)}catch(e){o("File must be valid JSON"),f(null),a.current&&(a.current.value="")}},N=async()=>{if(x&&g&&confirm("replace"===h?"Replace all ".concat(g.existingItemCount," existing FAQ question").concat(1===g.existingItemCount?"":"s"," with ").concat(g.itemCount," from this file? Categories in the file will be created or updated. Categories not in the file are kept."):"Merge ".concat(g.itemCount," FAQ question").concat(1===g.itemCount?"":"s"," into the current list? ").concat(g.matchingIdCount," matching id").concat(1===g.matchingIdCount?"":"s"," will be updated; ").concat(g.newItemCount," new question").concat(1===g.newItemCount?"":"s"," will be added. Existing questions not in the file are kept."))){l(!0),o("");try{let e=await fetch("/api/admin/faq-import",{method:"POST",headers:{"Content-Type":"application/json","X-Admin-Username":sessionStorage.getItem("adminUsername")||""},body:JSON.stringify({payload:x,dryRun:!1,mode:h})}),a=await e.json();if(!a.success){(0,b.pi)(a,"save"),o(a.message||"Import failed");return}let n=Array.isArray(a.warnings)&&a.warnings.length>0?" (".concat(a.warnings.slice(0,3).join("; "),")"):"";(0,b.wU)((a.message||"Import completed")+n,"save"),y(),t()}catch(e){(0,b.jK)(e instanceof Error?e.message:"Import failed","save")}finally{l(!1)}}};return(0,n.jsxs)("div",{className:"mb-5 rounded-lg border border-[var(--admin-border)] bg-[var(--admin-surface)] p-4",children:[(0,n.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,n.jsx)(u.$,{type:"button",variant:"outline",onClick:()=>{var e;return null==(e=a.current)?void 0:e.click()},disabled:r,children:r?"Validatingâ¦":"Import JSON"}),(0,n.jsxs)(u.$,{type:"button",variant:"outline",onClick:()=>{E("faq-template.json",{version:1,type:C,exportedAt:new Date().toISOString(),categories:[{id:"account-opening",name:{en:"Account Opening",ar:""}}],items:[{id:"who-can-open-a-trading-account",category:"account-opening",question:{en:"Who can open a trading account?",ar:""},answer:{en:"<p>Replace this English answer. Arabic may stay empty and be filled in admin.</p>",ar:""}}]}),(0,b.wU)("Template downloaded","save")},disabled:r,children:[(0,n.jsx)(i.R2D,{"aria-hidden":!0}),"Download Template"]}),(0,n.jsx)("input",{ref:a,type:"file",accept:"application/json,.json",className:"hidden",onChange:e=>void w(e)})]}),(0,n.jsxs)("ul",{className:"".concat(c.wH," m-0 list-disc space-y-1 pl-5"),children:[(0,n.jsx)("li",{children:"Import a FAQ bundle JSON (categories + questions) for this domain only."}),(0,n.jsx)("li",{children:"Replace overwrites all questions. Merge updates matching ids and adds new ones."}),(0,n.jsx)("li",{children:"Arabic may be empty â those items are flagged as needing translation."}),(0,n.jsx)("li",{children:"Invalid JSON is rejected before any write."})]}),d?(0,n.jsx)(m.Fc,{variant:"destructive",className:"mt-3",children:(0,n.jsx)(m.TN,{children:d})}):null,g?(0,n.jsxs)("div",{className:"mt-4 space-y-3 rounded-md border border-[var(--admin-border)] bg-[var(--admin-bg)] p-3",children:[(0,n.jsxs)("div",{className:"text-sm text-[var(--admin-text)]",children:[(0,n.jsxs)("div",{className:"font-semibold",children:[g.itemCount," question",1===g.itemCount?"":"s"," \xb7"," ",g.categoryCount," categor",1===g.categoryCount?"y":"ies"," in file"]}),(0,n.jsxs)("div",{className:"text-[var(--admin-text-muted)]",children:["Existing on this domain: ",g.existingItemCount," \xb7 matching ids:"," ",g.matchingIdCount," \xb7 new: ",g.newItemCount,g.newCategoryCount>0?" \xb7 new categories: ".concat(g.newCategoryCount):""]})]}),g.warnings.length>0?(0,n.jsx)("ul",{className:"m-0 list-disc space-y-1 pl-5 text-xs text-[var(--admin-text-muted)]",children:g.warnings.map(e=>(0,n.jsx)("li",{children:e},e))}):null,(0,n.jsxs)("fieldset",{className:"space-y-2",children:[(0,n.jsx)("legend",{className:"text-sm font-semibold text-[var(--admin-text)]",children:"Import mode"}),(0,n.jsxs)("label",{className:"flex items-start gap-2 text-sm text-[var(--admin-text)]",children:[(0,n.jsx)("input",{type:"radio",name:"faq-import-mode",checked:"replace"===h,disabled:r,onChange:()=>v("replace")}),(0,n.jsxs)("span",{children:["Replace all questions",g.existingItemCount>0?" (removes ".concat(g.existingItemCount," existing)"):""]})]}),(0,n.jsxs)("label",{className:"flex items-start gap-2 text-sm text-[var(--admin-text)]",children:[(0,n.jsx)("input",{type:"radio",name:"faq-import-mode",checked:"merge"===h,disabled:r,onChange:()=>v("merge")}),(0,n.jsx)("span",{children:"Merge (update matching ids, add new, keep the rest)"})]})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,n.jsx)(u.$,{type:"button",onClick:()=>void N(),disabled:r,children:r?"Importingâ¦":"Confirm Import"}),(0,n.jsx)(u.$,{type:"button",variant:"outline",onClick:y,disabled:r,children:"Cancel"})]})]}):null]})}let P=[{id:"questions",label:"Questions"},{id:"categories",label:"Categories"}];function V(){let{getCategoryLabel:e,refresh:t}
1=f(),[a,i]=(0,s.useState)([]),[l,d]=(0,s.useState)(!0),[o,g]=(0,s.useState)(""),[h,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(null),[N,C]=(0,s.useState)("");(0,s.useEffect)(()=>{A()},[]);let A=async()=>{try{d(!0);let e=await fetch("/api/admin/faq"),t=await e.json();t.success?i(t.items||[]):g(t.message||"Failed to fetch FAQ items")}catch(e){g("Failed to fetch FAQ items")}finally{d(!1)}},q=(0,s.useCallback)(async e=>{if(confirm('Delete this FAQ question?\n\n"'.concat(e.question.en,'"\n\nThis action cannot be undone.')))try{let t=await fetch("/api/admin/faq?id=".concat(e.id),{method:"DELETE",headers:{"X-Admin-Username":sessionStorage.getItem("adminUsername")||""}}),a=await t.json();a.success?((0,b.wU)(a.message,"delete"),A()):(0,b.pi)(a,"delete")}catch(e){(0,b.jK)("Failed to delete FAQ item","delete")}},[]),S=(0,s.useMemo)(()=>a.filter(t=>(function(e,t,a){let n=t.trim().toLowerCase();return!n||[e.question.en,e.question.ar,a(e.category),e.category].some(e=>(null!=e?e:"").toLowerCase().includes(n))})(t,N,e)),[a,N,e]),k=N.trim().length>0;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Y,{onImported:()=>{A(),t()}}),(0,n.jsxs)("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-3",children:[(0,n.jsx)("p",{className:"m-0 max-w-2xl text-sm text-[var(--admin-text-muted)]",children:"Add and edit FAQ questions. Choose a category from the managed categories list."}),(0,n.jsx)(u.$,{type:"button",onClick:()=>{w(null),v(!0),g("")},children:"+ Add Question"})]}),o&&!h?(0,n.jsx)(m.Fc,{variant:"destructive",className:"mb-4",children:(0,n.jsx)(m.TN,{children:o})}):null,l?(0,n.jsx)("div",{className:"text-sm text-[var(--admin-text-muted)]",children:"Loading FAQ itemsâ¦"}):0===a.length?(0,n.jsx)("div",{className:c.s1,children:"No FAQ items yet. Click âAdd Questionâ to get started."}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"mb-4 flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsx)(r.A,{className:"pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--admin-text-muted)]","aria-hidden":!0}),(0,n.jsx)(p.p,{type:"search",autoFocus:!0,value:N,onChange:e=>C(e.target.value),placeholder:"Search by question, answer, or category (EN / AR)â¦","aria-label":"Search FAQ questions",className:"h-9 rounded-md pl-9"})]}),(0,n.jsxs)("span",{className:"shrink-0 text-xs text-[var(--admin-text-muted)]",children:[S.length," of ",a.length]})]}),0===S.length?(0,n.jsx)("div",{className:c.s1,children:k?"No FAQ items match â".concat(N.trim(),"â."):"No FAQ items yet."}):(0,n.jsx)("div",{className:"space-y-3",children:S.map(t=>{var a;return(0,n.jsxs)(x.Zp,{className:"border-[var(--admin-border)] bg-[var(--admin-surface)] p-4 shadow-sm",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[(0,n.jsx)("p",{className:"m-0 font-semibold text-[var(--admin-text)]",children:t.question.en}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)(u.$,{type:"button",variant:"outline",size:"xs",onClick:()=>{w(t),v(!0),g("")},children:"Edit"}),(0,n.jsx)(u.$,{type:"button",variant:"destructive",size:"xs",onClick:()=>void q(t),children:"Delete"})]})]}),(0,n.jsxs)("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs text-[var(--admin-text-muted)]",children:[(0,n.jsx)("span",{className:"rounded-full bg-[var(--admin-accent-muted)] px-2 py-0.5 font-medium text-[var(--admin-accent-hover)]",children:e(t.category)}),(0,n.jsxs)("span",{children:["Updated ",new Date(t.updatedAt).toLocaleDateString()]})]}),(0,n.jsx)("p",{className:"mt-2 line-clamp-2 text-sm text-[var(--admin-text-muted)]",children:(0,y.Q)(t.answer.en)}),(null==(a=t.needsTranslation)?void 0:a.ar)?(0,n.jsx)("span",{className:"mt-2 inline-block rounded bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-800",children:"Needs Arabic translation"}):null]},t.id)})})]}),(0,n.jsx)($,{open:h,onOpenChange:e=>{v(e),e||w(null)},editingItem:j,onSuccess:()=>{v(!1),w(null),A()}})]})}
1function K(){let e=(0,j.sn)(),[t,a]=(0,s.useState)("questions"),r=(0,s.useCallback)(async()=>{try{var t,a;let[n,s]=await Promise.all([fetch("/api/admin/faq"),fetch("/api/admin/faq-categories")]),r=await n.json(),i=await s.json();if(!r.success)return void(0,b.pi)(r,"save");if(!i.success)return void(0,b.pi)(i,"save");let l=new Date().toISOString().slice(0,10),d=(0,v.K7)(e.id).replace("fxgrow-","");E("faqs-".concat(d,"-").concat(l,".json"),(t=i.items||[],a=r.items||[],{version:1,type:C,exportedAt:new Date().toISOString(),categories:t.map(e=>({id:e.id,name:{en:e.name.en,ar:e.name.ar}})),items:a.map(e=>({id:e.id,category:e.category,question:{en:e.question.en,ar:e.question.ar},answer:{en:e.answer.en,ar:e.answer.ar}}))})),(0,b.wU)("FAQs exported as JSON","save")}catch(e){(0,b.jK)(e instanceof Error?e.message:"Failed to export FAQs","save")}},[e.id]);return(0,n.jsxs)(l.A,{children:[(0,n.jsx)(d.A,{title:"FAQ Management",actions:(0,n.jsxs)(u.$,{type:"button",variant:"export",onClick:()=>void r(),children:[(0,n.jsx)(i.R2D,{"aria-hidden":!0}),"Export"]})}),(0,n.jsx)(o.A,{tabs:[...P],active:t,onChange:e=>a(e),className:"mb-6"}),"questions"===t?(0,n.jsx)(V,{}):(0,n.jsx)(D,{})]})}function Z(){return(0,n.jsx)(h,{children:(0,n.jsx)(K,{})})}},26921:(e,t,a)=>{a.d(t,{jK:()=>d,pi:()=>o,wU:()=>l});var n=a(94184);let s={create:"Created successfully",update:"Updated successfully",delete:"Deleted successfully",save:"Saved successfully"},r={create:"Failed to create",update:"Failed to update",delete:"Failed to delete",save:"Failed to save"};function i(e,t){return("string"==typeof e?e.trim():"")||t}function l(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"save";n.oR.success({description:i(e,s[t])})}function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"save";n.oR.error({description:i(e,r[t])})}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"save";d(function(e){if(!e)return;let t="string"==typeof e.message?e.message.trim():"";return t||("string"==typeof e.error?e.error.trim():"")||void 0}(e),t)}},30615:(e,t,a)=>{a.d(t,{Cf:()=>m,Es:()=>x,L3:()=>p,c7:()=>u,lG:()=>d,rr:()=>g});var n=a(37876),s=a(26303),r=a(71637),i=a(14232),l=a(8291);let d=s.bL;s.l9;let o=s.ZL;s.bm;let c=i.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,n.jsx)(s.hJ,{ref:t,className:(0,l.cn)("fixed inset-0 z-50 bg-black/70 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",a),...r})});c.displayName=s.hJ.displayName;let m=i.forwardRef((e,t)=>{let{className:a,children:i,...d}=e;return(0,n.jsxs)(o,{children:[(0,n.jsx)(c,{}),(0,n.jsxs)(s.UC,{ref:t,className:(0,l.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-gray-200 bg-white p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-xl",a),...d,children:[i,(0,n.jsxs)(s.bm,{className:"absolute right-4 top-4 roun
1ded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,n.jsx)(r.A,{className:"h-4 w-4"}),(0,n.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});m.displayName=s.UC.displayName;let u=e=>{let{className:t,...a}=e;return(0,n.jsx)("div",{className:(0,l.cn)("flex flex-col space-y-1.5 text-center sm:text-left",t),...a})};u.displayName="DialogHeader";let x=e=>{let{className:t,...a}=e;return(0,n.jsx)("div",{className:(0,l.cn)("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...a})};x.displayName="DialogFooter";let p=i.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,n.jsx)(s.hE,{ref:t,className:(0,l.cn)("text-lg font-semibold leading-none tracking-tight text-gray-900",a),...r})});p.displayName=s.hE.displayName;let g=i.forwardRef((e,t)=>{let{className:a,...r}=e;return(0,n.jsx)(s.VY,{ref:t,className:(0,l.cn)("text-sm text-gray-500",a),...r})});g.displayName=s.VY.displayName},61357:(e,t,a)=>{a.d(t,{A:()=>i});var n=a(37876),s=a(4913),r=a(8291);function i(e){let{value:t,onChange:a,className:i}=e;return(0,n.jsxs)(s.O,{type:"single",value:t,onValueChange:e=>{("en"===e||"ar"===e)&&a(e)},className:(0,r.cn)("h-9 w-50 shrink-0",i),children:[(0,n.jsx)(s.d,{value:"en",size:"sm",className:"text-xs data-[state=on]:bg-red-500 data-[state=on]:text-white data-[state=on]:hover:bg-red-600 data-[state=on]:hover:text-white",children:"English"}),(0,n.jsx)(s.d,{value:"ar",size:"sm",className:"text-xs data-[state=on]:bg-red-500 data-[state=on]:text-white data-[state=on]:hover:bg-red-600 data-[state=on]:hover:text-white",children:"Ø§ÙØ¹Ø±Ø¨ÙØ©"})]})}},66553:(e,t,a)=>{a.d(t,{$B:()=>C,A2:()=>s,D_:()=>q,EG:()=>d,F9:()=>i,IZ:()=>A,LJ:()=>c,Lr:()=>p,Nf:()=>g,S6:()=>b,Uo:()=>m,Vf:()=>v,W9:()=>N,Wc:()=>y,Zi:()=>j,i6:()=>x,qO:()=>h,s1:()=>r,sm:()=>o,v8:()=>l,vd:()=>f,wH:()=>n,wl:()=>u,zs:()=>w});let n="mt-2 text-xs text-[var(--admin-text-muted)]",s="mt-1 block text-xs text-[var(--admin-danger)]",r="rounded-xl border border-[var(--admin-border)] bg-[var(--admin-surface)] p-6 text-sm text-[var(--admin-text-muted)]",i="mt-auto flex justify-end gap-2 border-t border-[var(--admin-border)] bg-[var(--admin-bg)] px-4 py-3",l="mb-5",d="font-normal text-[var(--admin-text-muted)]",o="cursor-pointer rounded-lg border-2 border-dashed border-[var(--admin-border)] p-6 text-center transition-colors hover:border-[var(--admin-accent)]",c="mx-auto mb-3 max-h-[220px] max-w-full rounded-md object-cover",m="m-0 text-sm text-[var(--admin-accent)]",u="mb-5 grid gap-4 sm:grid-cols-2",x="mb-5 grid gap-4 sm:grid-cols-2",p="h-9 w-full cursor-pointer rounded-md border border-input bg-white px-3 text-sm text-[var(--admin-text)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",g="min-h-[80px] w-full rounded-md border border-input bg-white px-3 py-2 text-sm text-[var(--admin-text)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",f="mb-3 grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-3",h="relative aspect-square overflow-visible",v="h-full w-full rounded-md border-2 border-[var(--admin-border)] object-cover",b="absolute -right-2 -top-2 flex h-[22px] w-[22px] cursor-pointer items-center justify-center rounded-full border-none bg-[var(--admin-danger)] text-[0.7rem] leading-none text-white transition-colors hover:bg-red-700",y="mb-4 overflow-hidden rounded-xl border border-[var(--admin-border)] bg-[var(--admin-surface)] shadow-sm transition-colors hover:border-[var(--admin-border-strong)]",j="opacity-60",w="flex cursor-pointer select-none items-center gap-2.5 px-4 py-3.5",N="border-t border-[var(--admin-border)] px-4 pb-4",C="inline-flex overflow-hidden rounded-lg border border-[var(--admin-border)]",A="cursor-pointer border-none bg-[var(--admin-surface)] px-3.5 py-1.5 text-[0.82rem] font-semibold text-[var(--admin-text-muted)] transition-colors first:border-r first:border-[var(--admin-border)]",q="bg-[var(--admin-accent)] text-[var(--admin-text-inverse)]"},69759:(e,t,a)=>{a.d(t,{A:()=>l});var n=a(37876),s=a(26283),r=a(30615),i=a(8291);function l(e){let{open:t,onOpenChange:a,title:l,description:d,formId:o,submitLabel:c,cancelLabel:m="Cancel",isSubmitting:u=!1,submitDisabled:x=!1,contentClassName:p,size:g="default",children:f}=e,h="full"===g;return(0,n.jsx)(r.lG,{open:t,onOpenChange:a,children:(0,n.jsxs)(r.Cf,{className:(0,i.cn)(h?"flex h-[min(96vh,100dvh)] w-[min(98vw,1200px)] max-w-none flex-col gap-0 overflow-hidden p-0 sm:max-w-none sm:rounded-lg":"max-h-[90vh] overflow-y-auto sm:max-w-lg",p),children:[(0,n.jsxs)(r.c7,{className:(0,i.cn)(h&&"shrink-0 space-y-1 border-b border-gray-200 px-6 py-4 pr-12 text-left"),children:[(0,n.jsx)(r.L3,{children:l}),d?(0,n.jsx)(r.rr,{children:d}):null]}),(0,n.jsx)("div",{className:(0,i.cn)(h&&"min-h-0 flex-1 overflow-y-auto px-6 py-4"),children:f}),(0,n.jsxs)(r.Es,{className:(0,i.cn)("gap-2 border-t border-gray-200 pt-4",h&&"shrink-0 px-6 py-4"),children:[(0,n.jsx)(s.$,{type:"button",variant:"outline",size:"sm",onClick:()=>a(!1),disabled:u,children:m}),(0,n.jsx)(s.$,{type:"submit",form:o,size:"sm",disabled:u||x,children:u?"Savingâ¦":c})]})]})})}},72047:(e,t,a)=>{a.d(t,{Fc:()=>d,TN:()=>o});var n=a(37876),s=a(47137),r=a(14232),i=a(8291);let l=(0,s.F)("relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",success:"border-green-200 bg-green-50 text-green-800",warning:"border-amber-200 bg-amber-50 text-amber-900"}},defaultVariants:{variant:"default"}}),d=r.forwardRef((e,t)=>
1{let{className:a,variant:s,...r}=e;return(0,n.jsx)("div",{ref:t,role:"alert",className:(0,i.cn)(l({variant:s}),a),...r})});d.displayName="Alert",r.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,n.jsx)("h5",{ref:t,className:(0,i.cn)("mb-1 font-medium leading-none tracking-tight",a),...s})}).displayName="AlertTitle";let o=r.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,n.jsx)("div",{ref:t,className:(0,i.cn)("text-sm [&_p]:leading-relaxed",a),...s})});o.displayName="AlertDescription"},80892:(e,t,a)=>{a.d(t,{Q:()=>s});var n=a(45973);function s(e){return e?(0,n.SZ)(e).replace(/<[^>]+>/g," ").replace(/ /gi," ").replace(/&/gi,"&").replace(/</gi,"<").replace(/>/gi,">").replace(/"/gi,'"').replace(/'/gi,"'").replace(/\s+/g," ").trim():""}},83373:(e,t,a)=>{a.d(t,{A:()=>s});var n=a(37876);function s(e){let{title:t,description:a,actions:s}=e;return(0,n.jsxs)("div",{className:"mb-6 flex flex-wrap items-start justify-between gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h1",{className:"m-0 text-2xl font-bold text-[var(--admin-text)]",children:t}),a?(0,n.jsx)("p",{className:"mt-1 text-sm text-[var(--admin-text-muted)]",children:a}):null]}),s?(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:s}):null]})}},83528:(e,t,a)=>{a.d(t,{s:()=>n.s});var n=a(70110)},91725:(e,t,a)=>{a.d(t,{Wu:()=>d,Zp:()=>i,aR:()=>l});var n=a(37876),s=a(14232),r=a(8291);let i=s.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,n.jsx)("div",{ref:t,className:(0,r.cn)("rounded-xl border border-input bg-gray-50 text-card-foreground shadow-xs",a),...s})});i.displayName="Card";let l=s.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,n.jsx)("div",{ref:t,className:(0,r.cn)("flex flex-col space-y-1.5 p-4",a),...s})});l.displayName="CardHeader";let d=s.forwardRef((e,t)=>{let{className:a,...s}=e;return(0,n.jsx)("div",{ref:t,className:(0,r.cn)("p-4 pt-0",a),...s})});d.displayName="CardContent"}}]);
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.