PageSourceSearch

https://www.supernoty.cz/assets/AdminDiscountRulesPage-D4Plsfnk.js

js supernoty.cz collected 2026-10-02 22:52:19 UTC 29,121 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/adminLog-DJf5O5-H.js","assets/index-BVx_WpMX.js","assets/query-C5nF0jqi.js","assets/vendor-CMDGo4EK.js","assets/firebase-A3MA2iqO.js","assets/sentry-BlyCWhjt.js","assets/icons-DHW7FPWn.js","assets/index-CdBlW4zP.css"])))=>i.map(i=>d[i]);
2import{$ as Ee,x as W,ax as Re,at as Ke,c as _,d as B,u as Ue,H as Me,_ as q,z as P,h as Be,f as Ve,w as ue}from"./index-BVx_WpMX.js";import{j as e,u as qe,a as Fe}from"./query-C5nF0jqi.js";import{a as i}from"./vendor-CMDGo4EK.js";import{g as he,q as ge,c as ae,o as ve,u as fe,d as Y,f as Oe,T as Q,j as He,l as Qe}from"./firebase-A3MA2iqO.js";import{A as Ze}from"./AdminLoader-Cp60miV3.js";import{S as Je,b as Xe,a as Ge,c as We,F as Ye,d as et,e as tt,Q as st,D as at,L as rt,f as Z,g as K,N as J,h as nt,i as ot}from"./helpers-f4ZrqV-z.js";import{X as be,g as pe,a3 as ct,bz as lt,bA as it,J as xe,d as dt,aU as ye,an as je,Q as we,h as Ne,T as ke,s as mt,bo as ut,q as pt,aK as xt,ay as ht,bB as gt,bC as vt,f as ft,aC as bt,aH as yt,au as jt}from"./icons-DHW7FPWn.js";import"./sentry-BlyCWhjt.js";const wt={score:{icon:e.jsx(dt,{size:11}),placeholder:"Přidat notu…",accent:"text-blue-600",chipBg:"bg-blue-50",chipBorder:"border-blue-500/25",chipText:"text-blue-700"},composer:{icon:e.jsx(xe,{size:11}),placeholder:"Přidat skladatele…",accent:"text-purple-600",chipBg:"bg-purple-50",chipBorder:"border-purple-500/25",chipText:"text-purple-700"},artist:{icon:e.jsx(xe,{size:11}),placeholder:"Přidat interpreta…",accent:"text-purple-600",chipBg:"bg-purple-50",chipBorder:"border-purple-500/25",chipText:"text-purple-700"},category:{icon:e.jsx(it,{size:11}),placeholder:"Přidat kategorii…",accent:"text-emerald-600",chipBg:"bg-emerald-50",chipBorder:"border-emerald-500/25",chipText:"text-emerald-700"},instrument:{icon:e.jsx(lt,{size:11}),placeholder:"Přidat nástroj…",accent:"text-amber-600",chipBg:"bg-amber-50",chipBorder:"border-amber-500/25",chipText:"text-amber-700"}};let X=null;async function Nt(t,u){if(!X)try{X=(await he(ge(ae(B,"categories"),ve("order")))).docs.map(w=>{const m=w.data();return{id:m.slug||w.id,label:m.name||m.label||m.slug||w.id,sub:m.type?`Typ: ${m.type}`:void 0}})}catch{X=[]}const y=X.filter(d=>!u.has(d.id));if(!t.trim())return y.slice(0,8);const f=t.toLowerCase();return y.filter(d=>d.label.toLowerCase().includes(f)||d.id.toLowerCase().includes(f)).slice(0,8)}const kt=[{id:"piano",label:"Klavír"},{id:"guitar",label:"Kytara"},{id:"violin",label:"Housle"},{id:"flute",label:"Flétna"},{id:"trumpet",label:"Trubka"},{id:"saxophone",label:"Saxofon"},{id:"clarinet",label:"Klarinet"},{id:"accordion",label:"Akordeon"},{id:"voice",label:"Zpěv"},{id:"drums",label:"Bicí"}];function St({kind:t,values:u,onChange:y,placeholder:f,max:d,invalid:w}){const[m,z]=i.useState(""),[n,L]=i.useState([]),[v,U]=i.useState(!1),[j,$]=i.useState(!1),[b,s]=i.useState(-1),p=i.useRef(null),o=i.useRef(null);i.useEffect(()=>{const a=l=>{p.current&&!p.current.contains(l.target)&&$(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]),i.useEffect(()=>{const a=t==="score"||t==="composer"||t==="artist"?2:0;if(!j)return;if(m.length<a&&!(t==="category"||t==="instrument")){L([]);return}let l=!1;const D=new Set(u.map(A=>A.id)),M=setTimeout(async()=>{U(!0);try{let A=[];if(t==="score")A=(await Ee({query:m,limit:8})).data.hits.filter(c=>!D.has(c.id)).map(c=>({id:c.id,label:c.title,sub:`${c.composer||""}${c.price!==void 0?` · ${W(c.price)}`:""}`.trim().replace(/^·\s*/,"")}));else if(t==="composer")A=(await Re({query:m,limit:8})).data.hits.filter(c=>!D.has(c.slug||c.id)).map(c=>({id:c.slug||c.id,label:c.name,sub:`${c.scoreCount??0} not`}));else if(t==="artist")A=(await Ke({query:m,limit:8})).data.hits.filter(c=>!D.has(c.slug||c.id)).map(c=>({id:c.slug||c.id,label:c.name,sub:`${c.scoreCount??0} not`}));else if(t==="category")A=await Nt(m,D);else if(t==="instrument"){const C=kt.filter(c=>!D.has(c.id));if(!m.trim())A=C.slice(0,8);else{const c=m.toLowerCase();A=C.filter(N=>N.label.toLowerCase().includes(c)||N.id.toLowerCase().includes(c))}}l||(L(A),s(-1))}catch{l||L([])}finally{l||U(!1)}},250);return()=>
2{l=!0,clearTimeout(M)}},[m,t,j,u]);const x=wt[t],k=!!d&&u.length>=d,S=a=>{var l;k||u.some(D=>D.id===a.id)||(y([...u,{id:a.id,label:a.label}]),z(""),(l=o.current)==null||l.focus())},h=a=>{y(u.filter(l=>l.id!==a))};return e.jsxs("div",{ref:p,className:"relative",children:[e.jsxs("div",{className:_("flex flex-wrap items-center gap-1.5 rounded-lg border bg-white p-1.5 transition-colors min-h-[42px]",w?"border-red-500/60 ring-1 ring-red-500/20":"border-warm-lightest focus-within:border-wine/50 focus-within:ring-2 focus-within:ring-wine/15"),onClick:()=>{var a;return(a=o.current)==null?void 0:a.focus()},children:[u.map(a=>e.jsxs("span",{className:_("inline-flex items-center gap-1.5 pl-2 pr-1 py-1 rounded-md border text-xs",x.chipBg,x.chipBorder,x.chipText),children:[e.jsx("span",{className:x.accent,children:x.icon}),e.jsx("span",{className:"max-w-[180px] truncate",children:a.label}),e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),h(a.id)},className:"p-0.5 rounded hover:bg-charcoal/5 text-current/70 hover:text-charcoal transition-colors",children:e.jsx(be,{size:10})})]},a.id)),!k&&e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-[120px]",children:[e.jsx("span",{className:_("pl-1 shrink-0",x.accent),children:v?e.jsx(pe,{size:11,className:"animate-spin"}):e.jsx(ct,{size:11})}),e.jsx("input",{ref:o,type:"text",value:m,placeholder:u.length===0?f||x.placeholder:"Přidat další…",onChange:a=>{z(a.target.value),$(!0)},onFocus:()=>$(!0),onKeyDown:a=>{if(a.key==="Backspace"&&m===""&&u.length>0){a.preventDefault();const l=u[u.length-1];l&&h(l.id);return}j&&(a.key==="ArrowDown"?(a.preventDefault(),s(l=>Math.min(l+1,n.length-1))):a.key==="ArrowUp"?(a.preventDefault(),s(l=>Math.max(l-1,-1))):a.key==="Enter"&&b>=0&&n[b]?(a.preventDefault(),S(n[b])):a.key==="Escape"&&$(!1))},className:"flex-1 bg-transparent px-1 py-1 text-sm text-charcoal placeholder:text-warm-light focus:outline-none min-w-[80px]"})]})]}),j&&!k&&(n.length>0||v||m.trim().length>0)&&e.jsxs("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white border border-warm-lightest rounded-lg shadow-2xl z-50 max-h-64 overflow-y-auto animate-[fadeInDown_0.12s_ease-out]",children:[v&&n.length===0&&e.jsxs("div",{className:"px-3 py-4 text-xs text-warm-gray text-center inline-flex items-center gap-2 w-full justify-center",children:[e.jsx(pe,{size:12,className:"animate-spin"})," Hledám…"]}),n.map((a,l)=>e.jsxs("button",{type:"button",onMouseDown:D=>{D.preventDefault(),S(a)},onMouseEnter:()=>s(l),className:_("w-full flex items-center gap-2.5 px-3 py-2 text-left transition-colors border-b border-warm-lightest last:border-0",l===b?"bg-wine/15":"hover:bg-charcoal/5"),children:[e.jsx("span",{className:_("shrink-0",x.accent),children:x.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-charcoal truncate font-medium",children:a.label}),a.sub&&e.jsx("p",{className:"text-[10px] text-warm-gray truncate",children:a.sub})]}),e.jsx("span",{className:"text-[9px] text-warm-light font-mono shrink-0",children:a.id.slice(0,12)})]},a.id)),!v&&n.length===0&&m.trim().length>0&&e.jsx("div",{className:"px-3 py-3 text-xs text-warm-gray text-center",children:"Nic nenalezeno"})]}),k&&e.jsxs("p",{className:"text-[10px] text-amber-600 mt-1",children:["Maximum dosaženo (",d," ",d===1?"položka":d<5?"položky":"položek",")"]})]})}function G(t){switch(t){case"all":return"all";case"category":case"genre":case"instrument":return t==="instrument"?"instrument":"category";case"score":case"specific":return"score";case"artist":return"interpret";case"composer":return"composer";default:return"all"}}function At(t){switch(t){case"category":return"category";case"score":return"score";case"composer":return"composer";case"artist":return"artist";default:return null}}function Dt(t){var y,f;const u=(y=t.targetLabels)!=null&&y.length?` · ${t.targetLabels.slice(0,2).join(", ")}${t.targetLabels.length>2?"…":""}`:(f=t.targetValues)!=null&&f.length?` · ${t.targetValues.slice(0,2).join(", ")}${t.targetValues.length>2?"…":""}`:"";switch(t.appliesTo){case"all":return"Vše";case"category":case"genre":case"instrument":return`Kategorie${u}`;case"score":case"specific":return`Konkrétní nota${u}`;case"artist":return`Interpret${u}`;case"composer":return`Skladatel${u}`;default:return String(t.appliesTo)}}function Kt(){const t=qe(),{user:u}=Ue(),[y,f]=i.useState(!1),[d,w]=i.useState(null),[m,z]=i.useState(null),{data:n,isLoading:L}=Fe({queryKey:["admin","discountRules"],queryFn:async()=>{const s=ge(ae(B,"discountRules"),ve("createdAt","desc"),Qe(200));return(await he(s)).docs.map(o=>({id:o.id,...o.data()}))},staleTime:3e4}),v=i.useMemo(()=>
2{if(!n)return{total:0,active:0,expired:0,avgPercent:0,scopes:0};const s=Date.now(),p=n.filter(h=>{var a;return h.isActive&&(!((a=h.validUntil)!=null&&a.toMillis)||h.validUntil.toMillis()>s)}),o=n.filter(h=>{var a;return((a=h.validUntil)==null?void 0:a.toMillis)&&h.validUntil.toMillis()<=s}),x=n.filter(h=>(h.type??"percent")==="percent").map(h=>h.discountPercent||0),k=x.length?Math.round(x.reduce((h,a)=>h+a,0)/x.length):0,S=new Set(n.map(h=>h.appliesTo));return{total:n.length,active:p.length,expired:o.length,avgPercent:k,scopes:S.size}},[n]),U=async s=>{await fe(Y(B,"discountRules",s.id),{isActive:!s.isActive});try{const{logAdmin:p}=await q(async()=>{const{logAdmin:o}=await import("./adminLog-DJf5O5-H.js");return{logAdmin:o}},__vite__mapDeps([0,1,2,3,4,5,6,7]));p({action:s.isActive?"discount.deactivate":"discount.activate",category:"discount",targetId:s.id,targetType:"discountRule",summary:`${s.isActive?"Deaktivoval":"Aktivoval"} slevu „${s.name}"`,before:{isActive:s.isActive},after:{isActive:!s.isActive}})}catch{}P.success(s.isActive?"Deaktivováno":"Aktivováno"),t.invalidateQueries({queryKey:["admin","discountRules"]})},j=async s=>{if(confirm(`Smazat „${s.name}"?`))try{await Oe(Y(B,"discountRules",s.id)),t.setQueryData(["admin","discountRules"],p=>(p||[]).filter(o=>o.id!==s.id));try{const{logAdmin:p}=await q(async()=>{const{logAdmin:o}=await import("./adminLog-DJf5O5-H.js");return{logAdmin:o}},__vite__mapDeps([0,1,2,3,4,5,6,7]));p({action:"discount.delete",category:"discount",targetId:s.id,targetType:"discountRule",summary:`Smazal slevu „${s.name}"`,before:{name:s.name,type:s.type,discountPercent:s.discountPercent}})}catch{}P.success("Smazáno"),t.invalidateQueries({queryKey:["admin","discountRules"]})}catch(p){const o=(p==null?void 0:p.code)||(p==null?void 0:p.message)||"unknown";o!=="permission-denied"&&o!=="unavailable"&&q(()=>import("./index-BVx_WpMX.js").then(x=>x.bq),__vite__mapDeps([1,2,3,4,5,6,7])).then(x=>x.captureError(p,{feature:"discount.delete",ruleId:s.id,code:o})).catch(()=>{}),P.error("Nepodařilo se smazat. Zkus znovu nebo obnov stránku.")}},$=s=>{z({...s,id:"",name:`${s.name} (kopie)`,isActive:!1}),w(null),f(!0)},b=()=>{f(!1),w(null),z(null),t.invalidateQueries({queryKey:["admin","discountRules"]})};return e.jsxs(e.Fragment,{children:[e.jsx(Me,{children:e.jsx("title",{children:"Slevy | Admin | SuperNoty.cz"})}),e.jsxs("div",{className:"flex items-start justify-between mb-5 gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-charcoal flex items-center gap-2",children:[e.jsx(ye,{size:20,className:"text-wine-light"})," Slevy"]}),e.jsxs("p",{className:"text-xs text-warm-gray mt-1",children:["Automatické slevy aplikované v košíku. Nevyžadují kód — pro slevové kódy použij"," ",e.jsx("a",{href:"/admin/kupony",className:"text-wine-light hover:underline",children:"Kupóny"}),"."]})]}),e.jsxs("button",{onClick:()=>{f(!y),w(null),z(null)},className:"inline-flex items-center gap-1.5 bg-wine text-white px-4 py-2 rounded-lg text-sm font-semibold hover:bg-wine-light transition-colors shrink-0 shadow-[0_2px_8px_-2px_rgba(139,26,43,0.5)]",children:[y?e.jsx(be,{size:16}):e.jsx(je,{size:16}),y?"Zrušit":"Nová sleva"]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-5 gap-3 mb-5",children:[e.jsx(V,{icon:e.jsx(we,{size:14}),label:"Pravidla (celkem)",value:v.total,color:"text-charcoal"}),e.jsx(V,{icon:e.jsx(Ne,{size:14}),label:"Aktivních",value:v.active,color:"text-emerald-600"}),e.jsx(V,{icon:e.jsx(ke,{size:14}),label:"Expirovaných",value:v.expired,color:"text-red-600"}),e.jsx(V,{icon:e.jsx(mt,{size:14}),label:"Ø % sleva",value:`${v.avgPercent}%`,color:"text-wine-light"}),e.jsx(V,{icon:e.jsx(ut,{size:14}),label:"Rozsahy",value:v.scopes,color:"text-blue-600"})]}),e.jsxs("div",{className:"space-y-5",children:[(y||d)&&e.jsx(zt,{initial:d||m,createdBy:(u==null?void 0:u.id)||"",onSaved:b,onCancel:()=>{f(!1),w(null),z(null)}},(d==null?void 0:d.id)||(m==null?void 0:m.name)||"new"),e.jsxs("div",{className:"bg-white rounded-xl border border-white/5 overflow-hidden",children:[e.jsxs("div",{className:"hidden md:grid grid-cols-12 gap-3 px-5 py-2.5 border-b border-white/5 text-[10px] text-warm-gray font-medium uppercase tracking-wider bg-charcoal/[0.02]",children:[e.jsx("div",{className:"col-span-3",children:"Název"}),e.jsx("div",{className:"col-span-1",children:"Typ"}),e.jsx("div",{className:"col-span-1",children:"Hodnota"}),e.jsx("div",{className:"col-span-2",children:"Rozsah"}),e.jsx("div",{className:"col-span-2",children:"Platnost"}),e.jsx("div",{className:"col-span-1",children:"Priorita"}),e.jsx("div",{className:"col-span-1",children:"Stav"}),e.jsx("div",{className:"col-span-1 text-right",children:"Akce"})]}),L?e.jsx(Ze,{text:"Načítání…",center:!0,padding:"p-8"}):!n||n.length===0?e.jsx(Pt,{onCreate:()=>{f(!0),w(null)}}):e.jsx("div",{className:"divide-y divide-white/[0.04]",children:n.map(s=>{var x,k,S,h,a;const p=((k=(x=s.validUntil)==null?void 0:x.toDate)==null?void 0:k.call(x))&&s.validUntil.toDate()<new Date,o=s.type||"percent";return e.jsxs("div",{className:_("grid grid-cols-1 md:grid-cols-12 gap-2 md:gap-3 px-5 py-3 hover:bg-charcoal/[0.02] transition-colors items-center",p&&"opacity-60"),children:[e.jsxs("div",{className:"md:col-span-3 min-w-0",children:[e.jsx("p",{className:"text-sm text-charcoal font-medium truncate",children:s.name}),s.description&&e.jsx("p",{className:"text-[10px] text-warm-gray truncate",children:s.description})]}),e.jsx("div",{className:"md:col-span-1 text-xs text-warm-gray",children:o==="fixed_amount"?"Kč":"%"}),e.jsx("div",{className:"md:col-span-1 text-sm text-wine-light font-bold",children:o==="fixed_amount"?W(s.discountAmount||0):`${s.discountPercent}%`}),e.jsx("div",{className:"md:col-span-2 text-xs text-warm-gray truncate",children:Dt(s)}),e.jsxs("div",{className:"md:col-span-2 text-xs text-warm-gray inline-flex items-center gap-1",children:[e.jsx(pt,{size:10,
2className:"opacity-60"}),((a=(h=(S=s.validUntil)==null?void 0:S.toDate)==null?void 0:h.call(S))==null?void 0:a.toLocaleDateString("cs-CZ"))||"∞"]}),e.jsx("div",{className:"md:col-span-1 text-xs text-warm-light",children:s.priority??0}),e.jsx("div",{className:"md:col-span-1",children:e.jsx(Je,{variant:p?"expired":s.isActive?"active":"inactive"})}),e.jsxs("div",{className:"md:col-span-1 flex justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>$(s),className:"p-1.5 rounded text-warm-gray hover:text-blue-600 hover:bg-blue-500/10 transition-colors",title:"Klonovat",children:e.jsx(xt,{size:13})}),e.jsx("button",{onClick:()=>{w(s),f(!1),z(null)},className:"p-1.5 rounded text-warm-gray hover:text-wine-light hover:bg-wine/10 transition-colors",title:"Upravit",children:e.jsx(ht,{size:13})}),e.jsx("button",{onClick:()=>U(s),className:_("p-1.5 rounded transition-colors",s.isActive?"text-warm-gray hover:text-red-600":"text-warm-gray hover:text-emerald-600"),title:s.isActive?"Deaktivovat":"Aktivovat",children:s.isActive?e.jsx(gt,{size:13}):e.jsx(vt,{size:13})}),e.jsx("button",{onClick:()=>j(s),className:"p-1.5 rounded text-warm-gray hover:text-red-600 hover:bg-red-500/10 transition-colors",title:"Smazat",children:e.jsx(ft,{size:13})})]})]},s.id)})})]})]})]})}function V({icon:t,label:u,value:y,color:f}){return e.jsxs("div",{className:"bg-white border border-white/5 rounded-xl p-3 hover:bg-charcoal/[0.02] transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-warm-gray uppercase tracking-wider mb-1",children:[e.jsx("span",{className:f,children:t}),e.jsx("span",{children:u})]}),e.jsx("p",{className:_("text-xl font-bold",f),children:y})]})}function Pt({onCreate:t}){return e.jsxs("div",{className:"p-12 text-center",children:[e.jsx("div",{className:"inline-flex h-14 w-14 items-center justify-center rounded-full bg-wine/10 border border-wine/20 mb-4",children:e.jsx(ye,{size:22,className:"text-wine-light"})}),e.jsx("h3",{className:"text-sm font-semibold text-charcoal mb-1",children:"Zatím žádná slevová pravidla"}),e.jsx("p",{className:"text-xs text-warm-gray mb-4 max-w-sm mx-auto",children:'Automatické slevy se aplikují v košíku bez kódu. Například „Sleva 20 % na klavír do konce dubna".'}),e.jsxs("button",{onClick:t,className:"inline-flex items-center gap-1.5 bg-wine text-white px-4 py-2 rounded-lg text-sm font-semibold hover:bg-wine-light transition-colors",children:[e.jsx(je,{size:14})," Vytvořit první slevu"]})]})}function zt({initial:t,createdBy:u,onSaved:y,onCancel:f}){var F,ie,O,de;const[d,w]=i.useState((t==null?void 0:t.name)??""),[m,z]=i.useState((t==null?void 0:t.description)??""),[n,L]=i.useState((t==null?void 0:t.type)??"percent"),[v,U]=i.useState((t==null?void 0:t.discountPercent)??10),[j,$]=i.useState((t==null?void 0:t.discountAmount)??50),[b,s]=i.useState((t==null?void 0:t.appliesTo)||"all"),p=(()=>{const r=(t==null?void 0:t.targetValues)||[],g=(t==null?void 0:t.targetLabels)||[];return r.map((T,E)=>({id:T,label:g[E]||T}))})(),[o,x]=i.useState(p),[k,S]=i.useState((t==null?void 0:t.priority)??0),[h,a]=i.useState((t==null?void 0:t.maxDiscountPercent)??50),[l,D]=i.useState((t==null?void 0:t.isActive)??!0),[M,A]=i.useState(((ie=(F=t==null?void 0:t.validFrom)==null?void 0:F.toDate)==null?void 0:ie.call(F).toISOString().slice(0,10))||new Date().toISOString().slice(0,10)),[C,c]=i.useState(((de=(O=t==null?void 0:t.validUntil)==null?void 0:O.toDate)==null?void 0:de.call(O).toISOString().slice(0,10))||new Date(Date.now()+30*864e5).toISOString().slice(0,10)),[N,Se]=i.useState(null),[Ae,re]=i.useState(!1),[De,ne]=i.useState(!1),[Pe,oe]=i.useState({name:!1}),ce=At(b),ee=b!=="all",le=Pe.name&&!d.trim(),te=ee&&o.length===0,ze=Xe({scope:G(b),targetLabels:o.map(r=>r.label)}),Ce=Ge({validFrom:M,validUntil:C}),Te=We({type:n,value:n==="percent"?v??0:j??0,scope:G(b),targetLabels:o.map(r=>r.label),validFrom:M,validUntil:C,maxDiscountPercent:h??0}),_e=r=>{const g=r.patch;if(g.name&&w(g.name),g.type&&L(g.type),g.discountPercent!==void 0&&U(g.discountPercent),g.discountAmount!==void 0&&$(g.discountAmount),g.maxDiscountPercent!==void 0&&a(g.maxDiscountPercent),g.priority!==void 0&&S(g.priority),g.appliesTo&&s(g.appliesTo),g.durationDays!==void 0){const T=new Date;A(T.toISOString().slice(0,10));const E=new Date(T);E.setDate(E.getDate()+g.durationDays),c(E.toISOString().slice(0,10))}
2P.success(`Použita šablona: ${r.label}`)},$e=async()=>{re(!0);try{const r=G(b),g=r==="all"?[]:o.map(H=>H.id),T=n==="percent"?v??0:j??0,I=await Be(Ve,"adminDiscountPreview")({scope:r,targets:g,type:n,value:T,maxDiscountPercent:h??0});Se(I.data),P.success(`Náhled: ${I.data.matchedCount} not by dostalo slevu`)}catch(r){ue(r,{feature:"admin.discount.preview",code:r==null?void 0:r.code}),P.error((r==null?void 0:r.message)||"Náhled selhal")}finally{re(!1)}},Ie=async()=>{if(oe({name:!0}),!d.trim()){P.error("Zadej název");return}if(ee&&o.length===0){P.error("Přidej alespoň jeden cíl (nota / skladatel / kategorie)");return}ne(!0);try{const r=Q.fromDate(new Date(M)),g=Q.fromDate(new Date(C+"T23:59:59")),T=o.map(R=>R.id),E=o.map(R=>R.label),I=G(b),H=m.trim(),me={name:d.trim(),...H?{description:H}:{},type:n,appliesTo:b,scope:I,targets:I==="all"?[]:T,value:n==="percent"?v??0:j??0,maxDiscountPercent:h??0,targetValues:I==="all"?[]:T,targetLabels:I==="all"?[]:E,discountPercent:n==="percent"?v??0:0,discountAmount:n==="fixed_amount"?j??0:0,priority:k??0,validFrom:r,validUntil:g,isActive:l,updatedAt:Q.now()};if(t&&t.id){await fe(Y(B,"discountRules",t.id),me);try{const{logAdmin:R}=await q(async()=>{const{logAdmin:se}=await import("./adminLog-DJf5O5-H.js");return{logAdmin:se}},__vite__mapDeps([0,1,2,3,4,5,6,7]));R({action:"discount.update",category:"discount",targetId:t.id,targetType:"discountRule",summary:`Upravil slevu „${d}" (${n==="percent"?`−${v||0}%`:`−${j||0} Kč`})`,after:{name:d,type:n,isActive:l,scope:I,discountPercent:v,discountAmount:j}})}catch{}P.success("Uloženo")}else{const R=Y(ae(B,"discountRules"));await He(R,{...me,createdAt:Q.now(),createdBy:u});try{const{logAdmin:se}=await q(async()=>{const{logAdmin:Le}=await import("./adminLog-DJf5O5-H.js");return{logAdmin:Le}},__vite__mapDeps([0,1,2,3,4,5,6,7]));se({action:"discount.create",category:"discount",targetId:R.id,targetType:"discountRule",summary:`Vytvořil slevu „${d}" (${n==="percent"?`−${v||0}%`:`−${j||0} Kč`})`,after:{name:d,type:n,isActive:l,scope:I,discountPercent:v,discountAmount:j}})}catch{}P.success("Sleva vytvořena")}y()}catch(r){ue(r,{feature:"admin.discount.save",mode:t&&t.id?"update":"create",ruleId:t==null?void 0:t.id,code:r==null?void 0:r.code}),P.error((r==null?void 0:r.message)||"Chyba")}finally{ne(!1)}};return e.jsxs(Ye,{children:[e.jsx(et,{icon:e.jsx(we,{size:15}),title:t&&t.id?"Upravit slevu":"Nová sleva",subtitle:t&&t.id?`ID: ${t.id}`:"Automatická sleva bez kódu — platí v košíku",onClose:f}),e.jsxs(tt,{children:[(!t||!t.id)&&e.jsx(st,{templates:at,onApply:_e}),e.jsx(rt,{kind:"discount",name:d,type:n,percent:v??0,amount:j??0,scopeSummary:ze,dateSummary:Ce||void 0,isActive:l}),e.jsxs("div",{className:"rounded-lg border border-white/5 bg-charcoal/[0.02] px-4 py-2.5 text-xs text-warm-light leading-relaxed",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-[0.08em] text-wine-light mr-2",children:"Souhrn"}),Te]}),e.jsx(Z,{title:"Základní informace",accent:"wine",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(K,{label:"Název",required:!0,error:le?"Název je povinný":void 0,className:"sm:col-span-2",children:e.jsx("input",{value:d,onChange:r=>w(r.target.value),onBlur:()=>oe(r=>({...r,name:!0})),placeholder:"Např. Vánoční sleva na klavír",className:_("w-full px-3 py-2 rounded-lg bg-white border text-charcoal text-sm placeholder:text-warm-gray/50 transition-colors focus:ring-2 focus:outline-none",le?"border-red-500/60 focus:border-red-500/80 focus:ring-red-500/15":"border-white/10 focus:border-wine/50 focus:ring-wine/15")})}),e.jsx(K,{label:"Priorita",hint:"Vyšší má přednost při střetu",children:e.jsx(J,{value:k,onChange:S,min:0,max:100,allowEmpty:!1})}),e.jsx(K,{label:"Popis (volitelný)",className:"sm:col-span-3",children:e.jsx("input",{value:m,onChange:r=>z(r.target.value),placeholder:"Krátký interní popis, co sleva řeší",className:"w-full px-3 py-2 rounded-lg bg-white border border-white/10 text-charcoal text-sm placeholder:text-warm-gray/50 focus:border-wine/50 focus:ring-2 focus:ring-wine/15 focus:outline-none transition-colors"})})]})}),e.jsx(Z,{title:"Hodnota slevy",accent:"emerald",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsx(K,{label:"Typ slevy",children:e.jsxs("select",{value:n,onChange:r=>L(r.target.value),className:"w-full px-3 py-2 rounded-lg bg-white border border-white/10 text-charcoal text-sm focus:border-wine/50 focus:ring-2 focus:ring-wine/15 focus:outline-none transition-colors",children:[e.jsx("option",{value:"percent",children:"Procentuální (%)"}),e.jsx("option",{value:"fixed_amount",children:"Pevná částka (Kč)"})]})}),e.jsx(K,{label:`Hodnota ${n==="percent"?"(%)":"(Kč)"}
2`,required:!0,children:n==="percent"?e.jsx(J,{value:v,onChange:U,min:1,max:100,suffix:"%",allowEmpty:!1}):e.jsx(J,{value:j,onChange:$,min:1,suffix:"Kč",allowEmpty:!1})}),e.jsx(K,{label:"Max sleva (% cap)",hint:"0 = bez stropu, 50 = nikdy víc než 50 %",children:e.jsx(J,{value:h,onChange:a,min:0,max:100,suffix:"%"})})]})}),e.jsx(Z,{title:"Rozsah a cíle",hint:"Vybere, na které položky se sleva aplikuje",accent:"blue",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-5 gap-3",children:[e.jsx(K,{label:"Rozsah",className:"sm:col-span-2",children:e.jsxs("select",{value:b,onChange:r=>{const g=r.target.value;s(g),x([])},className:"w-full px-3 py-2 rounded-lg bg-white border border-white/10 text-charcoal text-sm focus:border-wine/50 focus:ring-2 focus:ring-wine/15 focus:outline-none transition-colors",children:[e.jsx("option",{value:"all",children:"🌍 Všechno v katalogu"}),e.jsx("option",{value:"category",children:"📁 Kategorie / nástroj"}),e.jsx("option",{value:"score",children:"🎼 Konkrétní nota"}),e.jsx("option",{value:"composer",children:"✍️ Skladatel"}),e.jsx("option",{value:"artist",children:"🎤 Interpret"})]})}),b!=="all"&&ce&&e.jsx(K,{label:`Cíle — ${b==="category"?"kategorie":b==="score"?"noty":b==="composer"?"skladatelé":"interpreti"}`,className:"sm:col-span-3",error:te?"Přidej alespoň jeden cíl":void 0,hint:te?void 0:"Začni psát název — výsledky se hledají v katalogu",children:e.jsx(St,{kind:ce,values:o,onChange:x,invalid:te,max:50})})]})}),e.jsx(Z,{title:"Platnost",accent:"amber",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx("div",{className:"sm:col-span-2",children:e.jsx(nt,{from:M,until:C,onFromChange:A,onUntilChange:c})}),e.jsx("div",{children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none px-3 py-2 rounded-lg bg-charcoal/[0.03] border border-white/5 hover:bg-charcoal/5 transition-colors w-fit",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:r=>D(r.target.checked),className:"accent-wine w-4 h-4"}),e.jsx("span",{className:"text-xs font-medium text-charcoal",children:"Aktivní"}),l&&e.jsx(Ne,{size:12,className:"text-emerald-600"})]})})]})}),N&&e.jsxs("div",{className:"rounded-xl border border-emerald-500/20 bg-gradient-to-br from-emerald-500/5 to-transparent p-4 text-xs space-y-2 animate-[fadeInUp_0.2s_ease-out]",children:[e.jsxs("div",{className:"flex items-center gap-2 text-emerald-600 font-semibold",children:[e.jsx(bt,{size:14})," Dopad na katalog"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] uppercase tracking-wider text-warm-gray",children:"Odpovídá"}),e.jsx("p",{className:"text-lg font-bold text-charcoal",children:N.matchedCount}),e.jsxs("p",{className:"text-[10px] text-warm-gray",children:["z ",N.scannedCount," not"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] uppercase tracking-wider text-warm-gray",children:"Celková sleva"}),e.jsx("p",{className:"text-lg font-bold text-emerald-600",children:W(N.totalSavings)}),e.jsx("p",{className:"text-[10px] text-warm-gray",children:"potenciální dopad"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] uppercase tracking-wider text-warm-gray",children:"Konfliktů"}),e.jsx("p",{className:_("text-lg font-bold",N.overlaps.length>0?"text-amber-600":"text-emerald-600"),children:N.overlaps.length}),e.jsx("p",{className:"text-[10px] text-warm-gray",children:"překrývajících se pravidel"})]})]}),N.sampleMatches.length>0&&e.jsxs("div",{className:"text-warm-gray pt-2 border-t border-white/5",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wider text-warm-gray",children:"Příklady:"})," ",N.sampleMatches.map(r=>`${r.title} (−${W(r.saving)})`).join(" · "),N.matchedCount>N.sampleMatches.length&&"…"]}),N.overlaps.length>0&&e.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-amber-600 font-semibold mb-1",children:[e.jsx(ke,{size:12})," Možný konflikt s existujícími pravidly"]}),e.jsx("ul",{className:"text-warm-gray space-y-0.5",children:N.overlaps.map(r=>e.jsxs("li",{children:["• ",e.jsx("span",{className:"text-charcoal",children:r.name})," ",e.jsxs("span",{className:"text-warm-gray/70",children:["(",r.scope,": ",r.overlap,")"]})]},r.id))}),e.jsx("p",{className:"text-[10px] text-warm-gray/70 mt-1.5",children:"Vyhraje pravidlo s vyšší prioritou; při shodě to s větší efektivní slevou."})]})]})]}),e.jsx(ot,{onCancel:f,onSave:Ie,onPreview:$e,saving:De,previewing:Ae,saveIcon:e.jsx(jt,{size:14}),saveLabel:t&&t.id?"Uložit změny":"Vytvořit slevu",extra:e.jsxs("div",{className:"text-[10px] text-warm-gray inline-flex items-center gap-1.5",children:[e.jsx(yt,{size:11,className:"text-wine-light/60"}),o.length>0?`${o.length} ${o.length===1?"cíl":o.length<5?"cíle":"cílů"}`:ee?"Bez cíle (nutno vybrat)":"Platí na celý katalog"]})})]})}export{Kt 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.