PageSourceSearch

https://www.wfg26.com/assets/admin.map-categories-DGrx0YTE.js

js wfg26.com collected 2026-10-02 00:37:14 UTC 7,498 bytes, 1 lines download raw bytes

1import{c as R,bi as D,bj as L,r as n,j as e,c6 as F,v as I,b as M,d3 as q,x as l,d6 as P,d5 as B,d4 as T}from"./index-BGXoFh6q.js";import{A as z,a as i,b as u}from"./AdminFormShell-D7q8Gibv.js";import{I as O}from"./ImagePicker-jGqKLeKl.js";import{u as U}from"./audit-Bw_Hh5De.js";import{E as V}from"./eye-DgTf4wSM.js";import{E as Y}from"./eye-off-Dc5RdcvL.js";import{P as H}from"./pencil-CMQzqPW9.js";import{T as W}from"./trash-2-CxUJJUsq.js";import"./UnifiedImagePicker-C1Lfj-GM.js";import"./dialog-OOpYJOVM.js";import"./media-admin.functions-CfW62fzC.js";import"./search-Y2d20jtb.js";import"./funnel-DoLeRiD_.js";import"./image-Z-2XyIiY.js";import"./upload-BXXdBojH.js";import"./folder-open-Vu_44seL.js";import"./link-2-BS8CxlMT.js";import"./circle-alert-CjI1P3js.js";const $=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],G=R("tag",$),N={slug:"",name_en:"",name_ar:"",color:"#FF6B35",marker_icon:"",display_order:0,is_visible:!0};function v(d){return d.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)}function xe(){const{t:d}=D(),{can:h}=L(),x=U(),w=h("write","map_categories"),_=h("delete","map_categories"),[p,b]=n.useState([]),[k,f]=n.useState(!0),[c,j]=n.useState(null),[t,r]=n.useState(N),[C,m]=n.useState(!1),[E,y]=n.useState(!1),g=async()=>{f(!0);try{const s=await q({data:{table:"map_categories",orderBy:[{column:"display_order",ascending:!0},{column:"name_en",ascending:!0}],limit:5e3}});b(s.rows??[])}catch(s){l.error(s instanceof Error?s.message:"Load failed"),b([])}finally{f(!1)}};n.useEffect(()=>{g()},[]);const S=async()=>{if(!w){l.error("You don't have permission to edit map categories");return}if(!t.name_en||!t.name_ar){l.error("Name (EN + AR) required");return}y(!0);try{const s={...t,slug:v(t.slug||t.name_en),marker_icon:t.marker_icon||null};if(c){const a=c,o=await B({data:{table:"map_categories",id:c.id,patch:s}});x("update","map_categories",c.id,a,o.row??null,"Updated map category"),l.success("Category updated")}else{const o=(await T({data:{table:"map_categories",values:s}})).row;x("insert","map_categories",o?.id??null,null,o??null,"Created map category"),l.success("Category created")}m(!1),await g()}catch(s){l.error(s instanceof Error?s.message:"Save failed")}finally{y(!1)}},A=async s=>{if(!_){l.error("You don't have permission to delete map categories");return}if(!confirm("Delete this category? Existing pins keep the slug but lose the icon."))return;const a=p.find(o=>o.id===s)??null;try{await P({data:{table:"map_categories",id:s}})}catch(o){return l.error(o instanceof Error?o.message:"Delete failed")}x("delete","map_categories",s,a,null,"Deleted map category"),l.success("Deleted"),g()};return e.jsxs("div",{children:[e.jsxs("header",{className:"mb-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-extrabold text-foreground",children:d("pg.mapCats")}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:d("pg.mapCatsSub")})]}),e.jsxs("button",{onClick:()=>{j(null),r(N),m(!0)},className:"inline-flex items-center gap-2 rounded-md bg-brand-red px-4 py-2 text-sm font-semibold text-brand-off hover:bg-brand-red/90",children:[e.jsx(F,{className:"h-4 w-4"})," New category"]})]}),e.jsx("div",{className:"overflow-hidden rounded-2xl border border-border bg-card shadow-sm",children:k?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(I,{className:"h-6 w-6 animate-spin text-brand-red"})}):p.length===0?e.jsx("p",{className:"py-16 text-center text-sm text-muted-foreground",children:"No categories yet."}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"border-b border-border bg-muted/40 text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"Marker"}),e.jsx("th",{className:"px-4 py-3",children:"Name"}),e.jsx("th",{className:"px-4 py-3",children:"Slug"}),e.jsx("th",{className:"px-4 py-3",children:"Color"}),e.jsx("th",{className:"px-4 py-3",children:"Order"}),e.jsx("th",{className:"px-4 py-3",children:"Visible"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:p.map(s=>e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-muted/20",children:[e.jsx("td",{className:"px-4 py-3",children:s.marker_icon?e.jsx("img",{src:M(s.marker_icon)??void 0,alt:"",className:"h-10 w-10 rounded object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded",style:{background:s.
1color},children:e.jsx(G,{className:"h-4 w-4 text-white"})})}),e.jsxs("td",{className:"px-4 py-3 font-medium text-foreground",children:[s.name_en,e.jsx("div",{className:"text-xs text-muted-foreground",dir:"rtl",children:s.name_ar})]}),e.jsx("td",{className:"px-4 py-3 font-mono text-xs text-muted-foreground",children:s.slug}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("span",{className:"inline-flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"h-4 w-4 rounded",style:{background:s.color}}),s.color]})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:s.display_order}),e.jsx("td",{className:"px-4 py-3",children:s.is_visible?e.jsx(V,{className:"h-4 w-4 text-emerald-600"}):e.jsx(Y,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("td",{className:"px-4 py-3 text-right",children:[e.jsxs("button",{onClick:()=>{j(s),r({...s}),m(!0)},className:"mr-2 inline-flex items-center gap-1 rounded-md border border-border px-2.5 py-1 text-xs hover:bg-muted",children:[e.jsx(H,{className:"h-3.5 w-3.5"})," Edit"]}),e.jsxs("button",{onClick:()=>A(s.id),className:"inline-flex items-center gap-1 rounded-md border border-destructive/30 px-2.5 py-1 text-xs text-destructive hover:bg-destructive/10",children:[e.jsx(W,{className:"h-3.5 w-3.5"})," Delete"]})]})]},s.id))})]})}),C&&e.jsxs(z,{title:c?"Edit category":"New category",onClose:()=>m(!1),onSave:S,saving:E,children:[e.jsx(i,{label:"Name (English)",required:!0,children:e.jsx("input",{value:t.name_en,onChange:s=>r(a=>({...a,name_en:s.target.value,slug:c?a.slug:v(s.target.value)})),className:u})}),e.jsx(i,{label:"Name (Arabic)",required:!0,children:e.jsx("input",{dir:"rtl",value:t.name_ar,onChange:s=>r(a=>({...a,name_ar:s.target.value})),className:u})}),e.jsx(i,{label:"Slug",children:e.jsx("input",{value:t.slug,onChange:s=>r(a=>({...a,slug:s.target.value})),className:u,placeholder:"venue"})}),e.jsx(i,{label:"Color",children:e.jsx("input",{type:"color",value:t.color,onChange:s=>r(a=>({...a,color:s.target.value})),className:"h-10 w-full rounded-md border border-border"})}),e.jsx(i,{label:"Marker image (used on the map)",full:!0,children:e.jsx(O,{value:t.marker_icon,onChange:s=>r(a=>({...a,marker_icon:s??""})),folder:"map-markers",label:""})}),e.jsx(i,{label:"Display order",children:e.jsx("input",{type:"number",value:t.display_order,onChange:s=>r(a=>({...a,display_order:Number(s.target.value)})),className:u})}),e.jsx(i,{label:"Visible",children:e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:t.is_visible,onChange:s=>r(a=>({...a,is_visible:s.target.checked}))}),e.jsx("span",{children:"Show in public legend"})]})})]})]})}export{xe as component};

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.