1 line
9.7 KiB
JavaScript
1 line
9.7 KiB
JavaScript
import{n as e,r as t,t as n}from"./x-BDEl80Ev.js";import{t as r}from"./plus-8GVzNLn4.js";import{a as i,m as a,o,s,t as c,u as l}from"./index-Cw6Vy2ED.js";import{t as u}from"./proxy-D2DvKtgS.js";import{t as d}from"./AnimatePresence-K0yVRmqs.js";var f=a(l(),1),p=c(),m=async(e,t={})=>{let n=sessionStorage.getItem(`counterToken`),r={"Content-Type":`application/json`,...t.headers||{},...n?{Authorization:`Bearer ${n}`}:{}},i=e.replace(/^http:\/\/[^:/]+:8080\/api/,`https://cmsapi.rit-services.in/api`),a=await fetch(i,{...t,headers:r});return(a.status===401||a.status===403)&&(sessionStorage.removeItem(`isCounterLoggedIn`),sessionStorage.removeItem(`counterToken`),window.location.href=`/login`),a},h=()=>{let[a,c]=(0,f.useState)([]),[l,h]=(0,f.useState)(!0),[_,v]=(0,f.useState)(``),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(null),C=async()=>{h(!0);try{let e=window.location.hostname,t=await(await m(`http://${e}:8080/api/base-items`)).json();c(Array.isArray(t)?t:t.content||[])}catch(e){console.error(`Error fetching categories:`,e)}finally{h(!1)}};(0,f.useEffect)(()=>{C()},[]);let w=async e=>{e.preventDefault();let t=window.location.hostname,n=x?.id?`http://${t}:8080/api/base-items/${x.id}`:`http://${t}:8080/api/base-items`,r=x?.id?`PUT`:`POST`;try{(await m(n,{method:r,headers:{"Content-Type":`application/json`},body:JSON.stringify(x)})).ok&&(b(!1),C())}catch(e){console.error(`Error saving category:`,e)}},T=a.filter(e=>e.name.toLowerCase().includes(_.toLowerCase()));return(0,p.jsxs)(`div`,{className:`p-8 space-y-8 h-full overflow-y-auto custom-scrollbar bg-slate-50`,children:[(0,p.jsxs)(`div`,{className:`flex flex-col md:flex-row md:items-center justify-between gap-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`h1`,{className:`text-4xl font-black text-slate-900 tracking-tight`,children:`Food Categories`}),(0,p.jsx)(`p`,{className:`text-slate-400 text-xs font-bold uppercase tracking-[0.2em] mt-2`,children:`Manage your menu structure`})]}),(0,p.jsxs)(`button`,{onClick:()=>{S({name:``,description:``,active:!0}),b(!0)},className:`bg-primary text-white px-10 py-4 rounded-2xl font-black text-xs uppercase tracking-widest flex items-center gap-3 shadow-2xl shadow-primary/30 hover:scale-[1.02] active:scale-95 transition-all`,children:[(0,p.jsx)(r,{size:18}),` Add Category`]})]}),(0,p.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8`,children:[(0,p.jsx)(g,{icon:s,label:`Active Categories`,value:a.filter(e=>e.active).length,color:`bg-primary/5 text-primary`}),(0,p.jsx)(g,{icon:o,label:`Total Structure`,value:a.length,color:`bg-emerald-50 text-emerald-500`})]}),(0,p.jsxs)(`div`,{className:`bg-white p-4 rounded-[3rem] shadow-xl shadow-slate-200/50 border border-slate-100 overflow-hidden`,children:[(0,p.jsxs)(`div`,{className:`p-6 relative group`,children:[(0,p.jsx)(i,{className:`absolute left-12 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-primary transition-colors`,size:24}),(0,p.jsx)(`input`,{type:`text`,placeholder:`Search categories by name...`,value:_,onChange:e=>v(e.target.value),className:`w-full bg-slate-50 border border-slate-100/50 rounded-2xl py-6 pl-16 pr-8 text-sm font-semibold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all shadow-inner`})]}),(0,p.jsx)(`div`,{className:`p-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-8`,children:(0,p.jsx)(d,{children:l?(0,p.jsx)(`div`,{className:`col-span-full h-40 flex items-center justify-center`,children:(0,p.jsx)(`div`,{className:`w-10 h-10 border-4 border-primary/20 border-t-primary rounded-full animate-spin`})}):T.map(t=>(0,p.jsxs)(u.div,{layout:!0,initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:`bg-white p-8 rounded-[2.8rem] border border-slate-100 shadow-sm hover:shadow-2xl transition-all group flex flex-col gap-8 relative overflow-hidden`,children:[(0,p.jsx)(`div`,{className:`absolute top-0 right-0 w-32 h-32 -mr-16 -mt-16 rounded-full opacity-[0.03] transition-transform duration-700 group-hover:scale-150 ${t.active?`bg-emerald-500`:`bg-slate-500`}`}),(0,p.jsxs)(`div`,{className:`flex items-center justify-between relative z-10`,children:[(0,p.jsx)(`div`,{className:`w-16 h-16 rounded-2xl flex items-center justify-center transition-all ${t.active?`bg-primary/5 text-primary`:`bg-slate-100 text-slate-400`} group-hover:bg-primary group-hover:text-white`,children:(0,p.jsx)(s,{size:32})}),(0,p.jsxs)(`div`,{className:`flex gap-2 opacity-0 group-hover:opacity-100 transition-all transform translate-x-4 group-hover:translate-x-0`,children:[(0,p.jsx)(`button`,{onClick:()=>window.location.href=`/products?category=${t.name}`,className:`w-10 h-10 bg-white border border-slate-100 rounded-xl flex items-center justify-center text-slate-400 hover:text-emerald-500 hover:border-emerald-500/30 shadow-sm transition-all`,title:`View Products`,children:(0,p.jsx)(o,{size:16})}),(0,p.jsx)(`button`,{onClick:()=>{S(t),b(!0)},className:`w-10 h-10 bg-white border border-slate-100 rounded-xl flex items-center justify-center text-slate-400 hover:text-primary hover:border-primary/30 shadow-sm transition-all`,title:`Edit Category`,children:(0,p.jsx)(e,{size:16})})]})]}),(0,p.jsxs)(`div`,{className:`relative z-10`,children:[(0,p.jsx)(`h3`,{className:`text-xl font-black text-slate-800 uppercase tracking-tight leading-none mb-3`,children:t.name}),(0,p.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,p.jsx)(`span`,{className:`w-2 h-2 rounded-full ${t.active?`bg-emerald-500 animate-pulse`:`bg-slate-300`}`}),(0,p.jsx)(`p`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-[0.2em]`,children:t.active?`Active`:`Inactive`})]})]})]},t.id))})})]}),y&&(0,p.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,p.jsx)(u.div,{initial:{opacity:0},animate:{opacity:1},onClick:()=>b(!1),className:`absolute inset-0 bg-slate-900/60 backdrop-blur-md`}),(0,p.jsxs)(u.div,{initial:{opacity:0,scale:.9,y:20},animate:{opacity:1,scale:1,y:0},className:`relative bg-white w-full max-w-lg rounded-[3rem] shadow-2xl overflow-hidden`,children:[(0,p.jsxs)(`div`,{className:`p-10 border-b border-slate-100 flex items-center justify-between bg-white`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`h2`,{className:`text-2xl font-black text-slate-900`,children:x?.id?`Edit Category`:`New Category`}),(0,p.jsx)(`p`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-widest mt-1`,children:`Configure category properties`})]}),(0,p.jsx)(`button`,{onClick:()=>b(!1),className:`w-12 h-12 bg-slate-50 rounded-2xl flex items-center justify-center text-slate-400 hover:text-rose-500 transition-all`,children:(0,p.jsx)(n,{size:24})})]}),(0,p.jsxs)(`form`,{onSubmit:w,className:`p-10 space-y-8`,children:[(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsx)(`label`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-[0.2em] ml-2`,children:`Category Name`}),(0,p.jsx)(`input`,{autoFocus:!0,required:!0,type:`text`,value:x?.name||``,onChange:e=>S({...x,name:e.target.value}),className:`w-full bg-slate-50 border border-slate-100 rounded-2xl py-5 px-8 text-sm font-semibold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all`,placeholder:`e.g. FAST FOOD`})]}),(0,p.jsxs)(`div`,{className:`space-y-4`,children:[(0,p.jsx)(`label`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-[0.2em] ml-2`,children:`Description`}),(0,p.jsx)(`textarea`,{value:x?.description||``,onChange:e=>S({...x,description:e.target.value}),className:`w-full bg-slate-50 border border-slate-100 rounded-2xl py-5 px-8 text-sm font-semibold outline-none focus:bg-white focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all h-32 resize-none`,placeholder:`Tell us more about this category...`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-4 bg-slate-50 p-6 rounded-3xl border border-slate-100`,children:[(0,p.jsxs)(`div`,{className:`flex-1`,children:[(0,p.jsx)(`p`,{className:`text-sm font-black text-slate-800`,children:`Status`}),(0,p.jsx)(`p`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-widest`,children:`Enable or disable category visibility`})]}),(0,p.jsx)(`button`,{type:`button`,onClick:()=>S({...x,active:!x.active}),className:`w-16 h-8 rounded-full transition-all relative ${x?.active?`bg-primary`:`bg-slate-300`}`,children:(0,p.jsx)(`div`,{className:`absolute top-1 w-6 h-6 bg-white rounded-full transition-all ${x?.active?`right-1`:`left-1`}`})})]}),(0,p.jsxs)(`div`,{className:`flex gap-4 pt-4`,children:[(0,p.jsx)(`button`,{type:`button`,onClick:()=>b(!1),className:`flex-1 py-5 rounded-2xl font-black text-xs uppercase tracking-widest text-slate-400 hover:bg-slate-50 transition-all border border-transparent hover:border-slate-100`,children:`Cancel`}),(0,p.jsxs)(`button`,{type:`submit`,className:`flex-1 bg-primary text-white py-5 rounded-2xl font-black text-xs uppercase tracking-widest shadow-xl shadow-primary/20 hover:scale-[1.02] active:scale-95 transition-all flex items-center justify-center gap-2`,children:[(0,p.jsx)(t,{size:18}),` `,x?.id?`Update Category`:`Save Category`]})]})]})]})]})]})},g=({icon:e,label:t,value:n,color:r})=>(0,p.jsxs)(`div`,{className:`bg-white p-8 rounded-[2.8rem] border border-slate-100 shadow-sm flex items-center gap-8 group hover:shadow-2xl transition-all`,children:[(0,p.jsx)(`div`,{className:`w-16 h-16 rounded-[1.5rem] flex items-center justify-center group-hover:bg-primary group-hover:text-white transition-all ${r.split(` `)[0]} ${r.split(` `)[1]}`,children:(0,p.jsx)(e,{size:32})}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`p`,{className:`text-3xl font-black text-slate-900 tracking-tighter`,children:n}),(0,p.jsx)(`p`,{className:`text-[10px] font-black text-slate-400 uppercase tracking-[0.2em]`,children:t})]})]});export{h as default}; |