PageSourceSearch

https://anaweenbooks.org/assets/AdminAwardShortlist-pFdmxSyd.js

js anaweenbooks.org collected 2026-10-08 01:59:23 UTC 5,768 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-motion-BT5tO7Mj.js";import{r as a}from"./vendor-react-4hOqMNFt.js";import{j as l,X as S,e as g,q as i}from"./index-DpO05to_.js";import{A as E}from"./AdminLayout-Ztu7cQWe.js";import{P as z}from"./plus-BjbhKe6L.js";import{P}from"./pencil-CE66Swml.js";import{T as A}from"./trash-2-RI38zWxG.js";import"./vendor-ui-BGjhACF7.js";import"./vendor-query-DklQPRCh.js";import"./vendor-supabase-CJJS8yeL.js";import"./truck-CTb-lJWP.js";import"./users-Jperj5AZ.js";import"./sparkles-BYY_jMka.js";import"./external-link-Cb-5V2_U.js";const M=()=>{const[h,f]=a.useState([]),[c,b]=a.useState([]),[j,_]=a.useState(!0),[m,u]=a.useState(null),[v,n]=a.useState(!1),[t,o]=a.useState({edition_id:"",novel_title:"",author_name:"",is_printed:!1,book_slug:"",sort_order:0}),[x,p]=a.useState(!1),d=a.useCallback(async()=>{const[s,r]=await Promise.all([l.from("award_shortlist").select("*").order("sort_order",{ascending:!0}),l.from("award_editions").select("*").order("sort_order",{ascending:!0})]);f(s.data||[]),b(r.data||[]),_(!1)},[]);a.useEffect(()=>{d()},[d]);const N=async()=>{p(!0);const s={...t,book_slug:t.book_slug||null};if(m){const{error:r}=await l.from("award_shortlist").update(s).eq("id",m.id);r?i.error(r.message):i.success("تم التحديث")}else{const{error:r}=await l.from("award_shortlist").insert(s);r?i.error(r.message):i.success("تمت الإضافة")}p(!1),n(!1),u(null),d()},y=async s=>{confirm("هل أنت متأكد؟")&&(await l.from("award_shortlist").delete().eq("id",s),i.success("تم الحذف"),d())},k=s=>{u(s),o({edition_id:s.edition_id,novel_title:s.novel_title,author_name:s.author_name,is_printed:s.is_printed,book_slug:s.book_slug||"",sort_order:s.sort_order}),n(!0)},w=s=>{const r=c.find(C=>C.id===s);return r?`${r.year} – ${r.title}`:""};return e.jsx(E,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-bold",children:"إدارة القائمة القصيرة"}),e.jsxs("button",{onClick:()=>{var s;u(null),o({edition_id:((s=c[0])==null?void 0:s.id)||"",novel_title:"",author_name:"",is_printed:!1,book_slug:"",sort_order:0}),n(!0)},className:"flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground",children:[e.jsx(z,{size:16})," إضافة عمل"]})]}),v&&e.jsxs("div",{className:"rounded-xl border bg-card p-4 space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"font-bold",children:m?"تعديل":"إضافة"}),e.jsx("button",{onClick:()=>n(!1),children:e.jsx(S,{size:18})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"الدورة"}),e.jsxs("select",{value:t.edition_id,onChange:s=>o({...t,edition_id:s.target.value}),className:"w-full rounded-lg border bg-background px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"اختر الدورة"}),c.map(s=>e.jsxs("option",{value:s.id,children:[s.year," – ",s.title]},s.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"اسم الرواية"}),e.jsx("input",{value:t.novel_title,onChange:s=>o({...t,novel_title:s.target.value}),className:"w-full rounded-lg border bg-background px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"اسم الكاتب"}),e.jsx("input",{value:t.author_name,onChange:s=>o({...t,author_name:s.target.value}),className:"w-full rounded-lg border bg-background px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"رابط الكتاب (slug)"}),e.jsx("input",{value:t.book_slug,onChange:s=>o({...t,book_slug:s.target.value}),className:"w-full rounded-lg border bg-background px-3 py-2 text-sm",placeholder:"اتركه فارغاً إن لم يُطبع"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"ترتيب العرض"}),e.jsx("input",{type:"number",value:t.sort_order,onChange:s=>o({...t,sort_order:+s.target.value}),className:"w-full rounded-lg border bg-background px-3 py-2 text-sm"})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-6",children:[e.jsx("input",{type:"checkbox",checked:t.is_printed,onChange:s=>o({...t,is_printed:s.target.checked})}),e.jsx("label",{className:"text-sm",children:"تمت الطباعة"})]})]}),e.jsx("button",{onClick:N,disabled:x,className:"rounded-lg bg-primary px-6 py-2 text-sm font-medium text-primary-foreground disabled:opacity-50",children:x?e.jsx(g,{size:16,className:"animate-spin"}):"حفظ"})]}),j?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(g,{className:"animate-spin",size:24})}):e.jsx("div",{className:"space-y-2",children:h.map(s=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-card p-4",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-bold text-foreground",children:["«",s.novel_title,"»"]}),e.jsx("span",{className:"text-muted-foreground text-sm mx-2",children:s.author_name}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",w(s.edition_id),")"]}),s.is_printed&&e.jsx("span",{className:"mr-2 text-xs bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400 px-2 py-0.5 rounded-full",children:"مطبوع"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>k(s),className:"rounded p-1.5 hover:bg-secondary",children:e.jsx(P,{size:16})}),e.jsx("button",{onClick:()=>y(s.id),className:"rounded p-1.5 hover:bg-destructive/10 text-destructive",children:e.jsx(A,{size:16})})]})]},s.id))})]})})};export{M 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.