1import{j as e}from"./vendor-radix-08a60bdd.js";import{r as a}from"./vendor-react-9016e4a2.js";import{s as t,B as s}from"./index-06245da3.js";import{S as r,a as i,b as n,c as l,d}from"./select-aef99edf.js";import{b as c}from"./bundleUtils-05c817e4.js";import{ai as m,R as o,aB as x,z as p,aG as u,a6 as h,f as b}from"./vendor-icons-f2656d21.js";import{f as j}from"./vendor-date-f65bd227.js";import"./vendor-supabase-36eb0853.js";import"./vendor-capacitor-43d743f6.js";import"./vendor-motion-a26fe6c4.js";const f=/kampanj|tarjou|kampanya|campaign/i,y=["Pz","Pt","Sa","Ãa","Pe","Cu","Ct"],g=e=>{if(!e.is_active)return"pasif";const a=new Date;return e.start_date&&new Date(e.start_date)>a?"planlı":e.end_date&&new Date(e.end_date)<a?"süresi doldu":"aktif"},v={aktif:"bg-emerald-950 text-emerald-300",pasif:"bg-zinc-800 text-zinc-400","planlı":"bg-sky-950 text-sky-300","süresi doldu":"bg-amber-950 text-amber-300"},_={percentage:{label:"İndirim %",Icon:x,cls:"bg-red-950 text-red-300"},fixed:{label:"İndirim â¬",Icon:b,cls:"bg-red-950 text-red-300"},bundle:{label:"Paket",Icon:p,cls:"bg-violet-950 text-violet-300"},gift:{label:"Hediyeli",Icon:u,cls:"bg-pink-950 text-pink-300"},item:{label:"Kampanya ürünü",Icon:m,cls:"bg-zinc-800 text-zinc-300"}};function N(){const[b,N]=a.useState([]),[w,z]=a.useState([]),[k,I]=a.useState(!0),[S,A]=a.useState(null),[$,D]=a.useState("all"),[M,C]=a.useState("all"),[P,K]=a.useState("all"),T=a.useCallback(async()=>{I(!0),A(null);try{const[e,a,s]=await Promise.all([t.from("restaurants").select("id, name").order("name"),t.from("campaigns").select("*").order("created_at",{ascending:!1}).limit(1e3),t.from("categories").select("id, name, restaurant_id")]);if(e.error)throw e.error;if(a.error)throw a.error;if(s.error)throw s.error;const r=new Map((e.data||[]).map(e=>[e.id,e.name]));z(e.data||[]);const i=(s.data||[]).filter(e=>f.test(e?.name||""));let n=[];if(i.length>0){const{data:e,error:a}=await t.from("menu_items").select("id, name, base_price, restaurant_id, category_id, is_active, is_available, bundle_items, created_at").in("category_id",i.map(e=>e.id)).order("created_at",{ascending:!1}).limit(1e3);if(a)throw a;n=e||[]}const l=(a.data||[]).map(e=>({key:`c-${e.id}`,restaurantId:e.restaurant_id,restaurant:r.get(e.restaurant_id)||`#${e.restaurant_id}`,type:"fixed"===e.discount_type?"fixed":"percentage",name:e.name,value:"fixed"===e.discount_type?`ââ¬${Number(e.discount_value).toFixed(2)}`:`â%${Number(e.discount_value)}`,status:g(e),timing:[e.start_date?j(new Date(e.start_date),"dd.MM.yy"):null,e.end_date?`â ${j(new Date(e.end_date),"dd.MM.yy")}`:null,e.start_time&&e.end_time?`${String(e.start_time).slice(0,5)}â${String(e.end_time).slice(0,5)}`:null,Array.isArray(e.valid_days)&&e.valid_days.length>0&&e.valid_days.length<7?e.valid_days.map(e=>y[e]??e).join(","):null].filter(Boolean).join(" ")||"sürekli",createdAt:e.created_at})),d=n.map(e=>({key:`m-${e.id}`,restaurantId:e.restaurant_id,restaurant:r.get(e.restaurant_id)||`#${e.restaurant_id}`,type:c(e.bundle_items)?"gift":Array.isArray(e.bundle_items)?"bundle":"item",name:e.name,value:`â¬${Number(e.base_price||0).toFixed(2)}`,status:e.is_active&&!1!==e.is_available?"aktif":"pasif",timing:"sürekli",createdAt:e.created_at}));N([...l,...d].sort((e,a)=>(a.createdAt||"").localeCompare(e.createdAt||"")))}catch(e){A(e.message)}finally{I(!1)}},[]);a.useEffect(()=>{T()},[T]);const B=a.useMemo(()=>b.filter(e=>!("all"!==$&&String(e.restaurantId)!==$||"all"!==M&&e.type!==M||"all"!==P&&e.status!==P)),[b,$,M,P]),O=a.useMemo(()=>({activeDiscounts:b.filter(e=>("percentage"===e.type||"fixed"===e.type)&&"aktif"===e.status).length,bundles:b.filter(e=>"bundle"===e.type&&"aktif"===e.status).length,gifts:b.filter(e=>"gift"===e.type&&"aktif"===e.status).length,restaurants:new Set(b.filter(e=>"aktif"===e.status).map(e=>e.restaurantId)).size}),[b]);return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold text-zinc-100 flex items-center gap-2",children:[e.jsx(m,{className:"w-5 h-5 text-orange-400"})," Kampanyalar"]}),e.jsx("p",{className:"text-sm text-zinc-500 mt-0.5",children:"Tüm restoranların kampanya envanteri â indirimler, paketler, hediyeli kampanyalar"})]}),e.jsx(s,{variant:"outline",size:"sm",onClick:T,disabled:k,className:"h-8 border-zinc-700 text-zinc-400 hover:text-zinc-100 hover:bg-zinc-800",children:e.jsx(o,{className:"h-3.5 w-3.5 "+(k?"animate-spin":"")})})]}),S&&e.jsx("div",{className:"text-sm text-red-400 bg-red-950/30 border border-red-900/50 rounded-lg p-3",children:S}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[{label:"Aktif İndirim",value:O.activeDiscounts,Icon:x},{label:"Aktif Paket",value:O.bundles,Icon:p},{label:"Aktif Hediyeli",value:O.gifts,Icon:u},{label:"Kampanyalı Restoran",value:O.restaurants,Icon:h}].map(({label:a,value:t,Icon:s})=>e.jsxs("div",{className:"bg-zinc-900 border border-zinc-800 rounded-xl p-4",children:[e.jsxs("div",{className:"text-[11px] text-zinc-500 uppercase tracking-widest mb-1 flex items-center gap-1",children:[e.jsx(s,{className:"w-3 h-3"})," ",a]}),e.jsx("div",{className:"text-xl font-bold text-zinc-100",children:t})]},a))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(r,{value:$,onValueChange:D,children:[e.jsx(i,{className:"w-[200px] h-9 bg-zinc-900 border-zinc-700 text-zinc-200",children:e.jsx(n,{})}),e.jsxs(l,{children:[e.jsx(d,{value:"all",children:"Tüm restoranlar"}),w.map(a=>e.jsx(d,{value:String(a.id),children:a.name},a.id))]})]}),e.jsxs(r,{value:M,onValueChange:C,children:[e.jsx(i,{className:"w-[170px] h-9 bg-zinc-900 border-zinc-700 text-zinc-200",children:e.jsx(n,{})}),e.jsxs(l,{children:[e.jsx(d,{value:"all",children:"Tüm tipler"}),Object.entries(_).map(([a,t])=>e.jsx(d,{value:a,children:t.label},a))]})]}),e.jsxs(r,{value:P,onValueChange:K,children:[e.jsx(i,{className:"w-[160px] h-9 bg-zinc-900 border-zinc-700 text-zinc-200",children:e.jsx(n,{})}),e.jsxs(l,{children:[e.jsx(d,{value:"all",children:"Tüm durumlar"}),Object.keys(v).map(a=>e.jsx(d,{value:a,children:a},a))]})]})]}),e.jsx("div",{className:"bg-zinc-900 border border-zinc-800 rounded-xl overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[11px] uppercase tracking-wider text-zinc-500 border-b border-zinc-800",children:[e.jsx("th",{className:"px-4 py-2.5",children:"Restoran"}),e.jsx("th",{className:"px-4 py-2.5",children:"Tip"}),e.jsx("th",{className:"px-4 py-2.5",children:"Kampanya"}),e.jsx("th",{className:"px-4 py-2.5",children:"DeÄer"}),e.jsx("th",{className:"px-4 py-2.5",children:"Durum"}),e.jsx("th",{className:"px-4 py-2.5",children:"Zamanlama"}),e.jsx("th",{className:"px-4 py-2.5",children:"OluÅturma"})]})}),e.jsxs("tbody",{children:[B.map(a=>{const t=_[a.type]||_.item;return e.jsxs("tr",{className:"border-b border-zinc-800/60 text-zinc-300",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium text-zinc-100 whitespace-nowrap",children:a.restaurant}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] uppercase font-semibold ${t.cls}`,children:[e.jsx(t.Icon,{className:"w-3 h-3"})," ",t.label]})}),e.jsx("td",{className:"px-4 py-2.5 max-w-[320px] truncate",title:a.name,children:a.name}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums whitespace-nowrap",children:a.value}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] uppercase ${v[a.status]||v.pasif}`,children:a.status})}),e.jsx("td",{className:"px-4 py-2.5 text-xs whitespace-nowrap",children:a.timing}),e.jsx("td",{className:"px-4 py-2.5 text-xs whitespace-nowrap",children:a.createdAt?j(new Date(a.createdAt),"dd.MM.yyyy"):"â"})]},a.key)}),!k&&0===B.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-8 text-center text-zinc-500",children:"Kampanya bulunamadı"})})]})]})})})]})}export{N 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.