PageSourceSearch

https://crypto-vault-insight.lovable.app/assets/SurveysAdmin-hYb1ScCb.js

js crypto-vault-insight.lovable.app collected 2026-10-03 05:33:21 UTC 11,706 bytes, 1 lines download raw bytes

1import{r as d,u as P,j as e,a2 as Y,aW as Z,B as g,Q as _,br as I,a3 as ee,a4 as se,a5 as te,I as k,C as T,d as V,e as q,a1 as L,g as O,s as b,bf as z,k as ae,l as ie,aV as re,S as le,bq as ne,H as ce}from"./index-D4T1ghJH.js";import{S as de}from"./switch-DXP2CWSP.js";import{A as oe,a as xe,b as me,c as he,d as je,e as ue,f as ge,g as pe,h as fe}from"./alert-dialog-DS2R-y_8.js";import{T as ve}from"./textarea-pDjx8h1t.js";import{L as u}from"./label-BeVhvnkf.js";import{S as F,a as E,b as H,c as $,d as C}from"./select-Cc7pUdUd.js";import{A as Ne}from"./AdminPageShell-DfAcDwIo.js";import"./index-Dg9XYgQE.js";function B({survey:n,onSurveyUpdated:D,disabled:y}){const[A,h]=d.useState(!1),[o,x]=d.useState(n?.title||""),[m,w]=d.useState(n?.description||""),[c,p]=d.useState(n?.questions||[]),[s,l]=d.useState(n?.language||"ar"),[f,Q]=d.useState(!1),{toast:S}=P(),j=!n,U=()=>{const t={id:Date.now().toString(),type:"text",question:"",required:!1};p([...c,t])},N=(t,i,a)=>{p(c.map(r=>r.id===t?{...r,[i]:a}:r))},M=t=>{p(c.filter(i=>i.id!==t))},R=t=>{const i=c.find(a=>a.id===t);if(i){const a=i.options||[];N(t,"options",[...a,""])}},W=(t,i,a)=>{const r=c.find(v=>v.id===t);if(r&&r.options){const v=[...r.options];v[i]=a,N(t,"options",v)}},X=(t,i)=>{const a=c.find(r=>r.id===t);if(a&&a.options){const r=a.options.filter((v,K)=>K!==i);N(t,"options",r)}},G=async()=>{if(!o.trim()){S({variant:"destructive",title:"خطأ",description:"عنوان الاستبيان مطلوب"});return}if(c.filter(i=>!i.question.trim()).length>0){S({variant:"destructive",title:"خطأ",description:"يجب إدخال نص لجميع الأسئلة"});return}Q(!0);try{if(j){const{data:i}=await b.auth.getUser(),{error:a}=await b.from("surveys").insert({title:o.trim(),description:m.trim()||null,questions:c,is_active:!1,language:s,created_by:i.user?.id});if(a)throw a;S({title:"تم الإنشاء",description:"تم إنشاء الاستبيان بنجاح"})}else{const{error:i}=await b.from("surveys").update({title:o.trim(),description:m.trim()||null,questions:c,language:s,updated_at:new Date().toISOString()}).eq("id",n.id);if(i)throw i;S({title:"تم الحفظ",description:"تم تحديث الاستبيان بنجاح"})}h(!1),await D()}catch{S({variant:"destructive",title:"خطأ",description:j?"فشل في إنشاء الاستبيان":"فشل في تحديث الاستبيان"})}finally{Q(!1)}},J=t=>{t&&(n?(x(n.title),w(n.description||""),p(n.questions||[]),l(n.language||"ar")):(x(""),w(""),p([]),l("ar"))),h(t)};return e.jsxs(Y,{open:A,onOpenChange:J,children:[e.jsx(Z,{asChild:!0,children:e.jsxs(g,{variant:j?"default":"outline",size:"sm",disabled:y,children:[j?e.jsx(_,{className:"h-4 w-4 mr-2"}):e.jsx(I,{className:"h-4 w-4 mr-2"}),j?"إنشاء استبيان جديد":"تحرير"]})}),e.jsxs(ee,{className:`max-w-4xl max-h-[90vh] overflow-y-auto ${s==="ar"?"arabic-content":""}`,children:[e.jsx(se,{children:e.jsx(te,{children:j?"إنشاء استبيان جديد":"تحرير الاستبيان"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{htmlFor:"title",children:"عنوان الاستبيان *"}),e.jsx(k,{id:"title",value:o,onChange:t=>x(t.target.value),placeholder:"أدخل عنوان الاستبيان",className:s==="ar"?"arabic-text text-right":"text-left",dir:s==="ar"?"rtl":"ltr"})]}),e.jsxs("div",{children:[e.jsx(u,{htmlFor:"description",children:"الوصف"}),e.jsx(k,{id:"description",value:m,onChange:t=>w(t.target.value),placeholder:"أدخل وصف الاستبيان",className:s==="ar"?"arabic-text text-right":"text-left",dir:s==="ar"?"rtl":"ltr"})]}),e.jsxs("div",{children:[e.jsx(u,{htmlFor:"language",children:"اللغة / Language"}),e.jsxs(F,{value:s,onValueChange:t=>l(t),children:[e.jsx(E,{children:e.jsx(H,{})}),e.jsxs($,{children:[e.jsx(C,{value:"ar",children:"العربية"}),e.jsx(C,{value:"en",children:"English"})]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(u,{className:"text-lg font-semibold",children:"الأسئلة"}),e.jsxs(g,{onClick:U,size:"sm",children:[e.jsx(_,{className:"h-4 w-4 mr-2"}),"إضافة سؤال"]})]}),c.map((t,i)=>e.jsxs(T,{children:[e.jsx(V,{className:"pb-3",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs(q,{className:"text-base",children:["سؤال ",i+1]}),e.jsx(g,{variant:"outline",size:"sm",onClick:()=>M(t.id),children:e.jsx(L,{className:"h-4 w-4"})})]})}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(u,{children:"نص السؤال *"}),e.jsx(ve,{value:t.question,onChange:a=>N(t.id,"question",a.target.value),placeholder:"أدخل نص السؤال",rows:2,className:s==="ar"?"arabic-text text-right":"text-left",dir:s==="ar"?"rtl":"ltr"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"نوع السؤال"}),e.jsxs(F,{value:t.type,onValueChange:a=>N(t.id,"type",a),children:[e.jsx(E,{children:e.jsx(H,{})}),e.jsxs($,{children:[e.jsx(C,{value:"text",children:"نص مفتوح"}),e.jsx(C,{value:"multiple_choice",children:"اختيار متعدد"}),e.jsx(C,{value:"rating",children:"تقييم"})]})]})]})]}),t.type==="multiple_choice"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx(u,{children:"الخيارات"}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>R(t.id),children:[e.jsx(_,{className:"h-4 w-4 mr-2"}),"إضافة خيار"]})]}),t.options?.map((a,r)=>
1e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{value:a,onChange:v=>W(t.id,r,v.target.value),placeholder:`الخيار ${r+1}`,className:s==="ar"?"arabic-text text-right":"text-left",dir:s==="ar"?"rtl":"ltr"}),e.jsx(g,{size:"sm",variant:"outline",onClick:()=>X(t.id,r),children:e.jsx(L,{className:"h-4 w-4"})})]},r))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:`required-${t.id}`,checked:t.required,onChange:a=>N(t.id,"required",a.target.checked),className:"rounded"}),e.jsx(u,{htmlFor:`required-${t.id}`,children:"سؤال مطلوب"})]})]})]},t.id))]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(g,{variant:"outline",onClick:()=>h(!1),disabled:f,children:"إلغاء"}),e.jsx(g,{onClick:G,disabled:f,children:f?j?"جاري الإنشاء...":"جاري الحفظ...":j?"إنشاء":"حفظ"})]})]})]})]})}function be(){const[n,D]=d.useState([]),[y,A]=d.useState(!0),[h,o]=d.useState(null),{toast:x}=P();d.useEffect(()=>{m()},[]);const m=async()=>{try{const{data:s,error:l}=await b.from("surveys").select("*").order("created_at",{ascending:!1});if(l)throw l;D(s||[])}catch{x({variant:"destructive",title:"خطأ",description:"فشل في تحميل الاستبيانات"})}finally{A(!1)}},w=async(s,l)=>{o(s);try{const{error:f}=await b.from("surveys").update({is_active:l,updated_at:new Date().toISOString()}).eq("id",s);if(f)throw f;x({title:"تم التحديث",description:`تم ${l?"تفعيل":"إلغاء تفعيل"} الاستبيان بنجاح`}),await m()}catch{x({variant:"destructive",title:"خطأ",description:"فشل في تحديث حالة الاستبيان"})}finally{o(null)}},c=async s=>{o(s);try{const{error:l}=await b.from("surveys").delete().eq("id",s);if(l)throw l;x({title:"تم الحذف",description:"تم حذف الاستبيان بنجاح"}),await m()}catch{x({variant:"destructive",title:"خطأ",description:"فشل في حذف الاستبيان"})}finally{o(null)}},p=s=>s?"bg-success/10 text-success border-success/20":"bg-muted/10 text-muted-foreground border-muted/20";return y?e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"إدارة الاستبيانات"}),e.jsx("p",{className:"text-muted-foreground",children:"إدارة وتحرير الاستبيانات"})]}),e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary mx-auto"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"جاري التحميل..."})]})]}):e.jsxs("div",{className:"p-6 max-w-7xl mx-auto",children:[e.jsx("div",{className:"mb-6",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"إدارة الاستبيانات"}),e.jsx("p",{className:"text-muted-foreground",children:"إدارة وتحرير الاستبيانات"})]}),e.jsx(B,{onSurveyUpdated:m})]})}),e.jsx("div",{className:"grid gap-4",children:n.length===0?e.jsx(T,{children:e.jsxs(O,{className:"text-center py-8",children:[e.jsx(z,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"لا توجد استبيانات"})]})}):n.map(s=>e.jsxs(T,{className:"hover:shadow-md transition-shadow",children:[e.jsx(V,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx(q,{className:"text-lg",children:s.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:new Date(s.created_at).toLocaleDateString("ar-SA")})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ae,{variant:"outline",className:p(s.is_active),children:e.jsxs("div",{className:"flex items-center gap-1",children:[s.is_active?e.jsx(ie,{className:"h-3 w-3"}):e.jsx(re,{className:"h-3 w-3"}),s.is_active?"نشط":"معطل"]})}),e.jsx(de,{checked:s.is_active,onCheckedChange:l=>w(s.id,l),disabled:h===s.id})]})]})}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-1",children:"الوصف"}),e.jsx("p",{className:"text-sm",children:s.description||"لا يوجد وصف"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-1",children:"عدد الأسئلة"}),e.jsxs("p",{className:"text-sm font-medium",children:[Array.isArray(s.questions)?s.questions.length:0," سؤال"]})]}),e.jsx(le,{}),e.jsxs("div",{className:"flex gap-2 justify-between items-center",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{survey:s,onSurveyUpdated:m,disabled:h===s.id}),e.jsxs(oe,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs(g,{variant:"destructive",size:"sm",disabled:h===s.id,children:[e.jsx(L,{className:"h-4 w-4 mr-2"}),"حذف"]})}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(je,{children:"حذف الاستبيان"}),e.jsxs(ue,{children:['هل أنت متأكد من حذف الاستبيان "',s.title,'"؟ هذا الإجراء لا يمكن التراجع عنه.']})]}),e.jsxs(ge,{children:[e.jsx(pe,{children:"إلغاء"}),e.jsx(fe,{onClick:()=>c(s.id),disabled:h===s.id,className:"bg-destructive hover:bg-destructive/90",children:"حذف الاستبيان"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ne,{className:"h-4 w-4"}),"آخر تحديث: ",new Date(s.updated_at).toLocaleDateString("ar-SA")]})]})]})]},s.id))})]})}const Te=()=>e.jsxs(e.Fragment,{children:[e.jsxs(ce,{children:[e.jsx("title",{children:"إدارة الاستبيانات - لوحة التحكم"}),e.jsx("meta",{name:"description",content:"إدارة وتحرير الاستبيانات"})]}),e.jsx(Ne,{children:e.jsx(be,{})})]});
1export{Te as default};

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.