PageSourceSearch

https://atcom.ro/assets/Comenzi-DuJirg9q.js

js atcom.ro collected 2026-10-10 01:31:36 UTC 156,710 bytes, 28 lines download raw bytes

1import{J as ss,G as is,q as h,f as k,o as e,L as ns,e as Ie,A as or,v as V}from"./index-CHGZ0aK0.js";import{u as ls}from"./useAdminTheme-LebxE6DH.js";import{u as cs,C as os}from"./ConfirmCloseBar-BQ_xSSND.js";import{a as ds,F as ms}from"./FisaCumparare-DPCKeoKb.js";import{c as sa}from"./clientNume-CcVQ_9Um.js";import{C as us}from"./CalendarAtelierPopup-DjAz0FmJ.js";import{I as We}from"./InfoBtn-DBLXJRIK.js";const dr={latime:"Lățime (mm)",material:"Material",culoare_aur:"Culoare aur",finisaj:"Finisaj",forma_interior:"Formă interior",forma_exterior:"Formă exterior",pietre:"Pietre",caracteristici_piatra:"Caracteristici piatră",gravura_font:"Font gravură",gravura_simbol:"Simbol gravură",marime:"Mărime",marime_deget:"Mărime deget",greutate:"Greutate (g)",diametru:"Diametru (mm)",culoare:"Culoare",inaltime:"Înălțime (mm)",grosime:"Grosime (mm)",model:"Model",tip:"Tip",stil:"Stil",lungime:"Lungime (cm)",cifra:"Cifră",litera:"Literă",text_gravura:"Text gravură",proba:"Probă aur",marcare:"Marcare",executie:"Execuție",ambalaj:"Ambalaj",gravura:"Gravură",text:"Text",marime_dama:"Mărime damă",marime_barbat:"Mărime bărbat",font:"Font",simbol:"Simbol",simboluri:"Simboluri",zodie:"Zodie",adauga_detalii_suplimentare:"Detalii suplimentare"},ps=new Set(["culoare_aur","culoare","latime","material","marime_deget","marime","greutate"]);function Ba(b){return String(b).includes("::")?String(b).split("::").map(Ba).join(" · "):dr[b]?dr[b]:b.charAt(0).toUpperCase()+b.slice(1).replace(/_/g," ")}function hs(b){if(!b||typeof b!="object")return[];const _=b.sel;if(!_||typeof _!="object")return[];const A=Array.isArray(b.activeItems)?b.activeItems:[],p={};A.forEach($=>{$&&$.key&&(p[$.key]=$.label||$.key)});const D=["_global","_single"],F=A.length?[...A.map($=>$.key).filter($=>_[$]),...Object.keys(_).filter($=>D.includes($)&&!A.some(z=>z.key===$))]:Object.keys(_),pe=[];for(const $ of F){const z=_[$];if(!z||typeof z!="object")continue;const L=[];for(const[q,Z]of Object.entries(z)){const M=Array.isArray(Z)?Z.join(", "):Z;M===""||M==null||M===!1||L.push({label:Ba(q),value:String(M)})}if(L.length){const q=$==="_global"||$==="_single"?"General":p[$]||$;pe.push({label:q,rows:L})}}return pe}function gs(b){if(!b||typeof b!="object")return null;const _=b.sel;if(!_||typeof _!="object")return null;const A=Array.isArray(b.activeItems)?b.activeItems:[],p=A.map(z=>z.key).filter(z=>_[z]&&typeof _[z]=="object");if(p.length<2)return null;const D=p.map(z=>A.find(L=>L.key===z)?.label||z),F=[];p.forEach(z=>Object.keys(_[z]).forEach(L=>{F.includes(L)||F.push(L)}));const pe=F.map(z=>{const L={};p.forEach((M,Da)=>{const Ae=_[M][z],he=Array.isArray(Ae)?Ae.join(", "):Ae;L[D[Da]]=he===""||he==null||he===!1?"":String(he)});const q=D.map(M=>L[M]),Z=new Set(q).size===1;return{label:Ba(z),key:z,important:ps.has(z),byItem:L,same:Z,value:Z?q[0]:""}}).filter(z=>Object.values(z.byItem).some(L=>L!=="")),$=[];return["_global","_single"].forEach(z=>{_[z]&&typeof _[z]=="object"&&Object.entries(_[z]).forEach(([L,q])=>{const Z=Array.isArray(q)?q.join(", "):q;Z!==""&&Z!=null&&Z!==!1&&$.push({label:Ba(L),value:String(Z)})})}),{items:D,attributes:pe,general:$}}const mt=()=>e.jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{verticalAlign:"-2px"},"aria-hidden":"true",children:[e.jsx("circle",{cx:"9",cy:"7",r:"3.1"}),e.jsx("path",{d:"M3.6 20a5.6 5.6 0 0 1 9.3-4"}),e.jsx("circle",{cx:"17.5",cy:"17.5",r:"4.2"}),e.jsx("path",{d:"M17.5 15.7v1.8l1.4.9"})]}),Oa=({size:b=22,color:_="#b08820"})=>e.jsxs("svg",{viewBox:"0 0 24 24",width:b,height:b,fill:"none",stroke:_,strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 4.2v15"}),e.jsx("path",{d:"M8.4 19.2h7.2"}),e.jsx("path",{d:"M4 7.6h16"}),e.jsx("circle",{cx:"12",cy:"6",r:"1.5",fill:_,stroke:"none"}),e.jsx("path",{d:"M4 7.6 1.8 13.4h4.4L4 7.6Z"}),e.jsx("path",{d:"M20 7.6l-2.2 5.8h4.4L20 7.6Z"})]}),xs=()=>e.jsxs("svg",{viewBox:"0 0 24 24",width:"13",height:"13",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{verticalAlign:"-2px"},"aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M12 7.5v5l3.2 2"})]}),ve={plasata:"#78909c",preluata:"#1565c0",la_atelier:"#163a5f",la_bijutier:"#e65100",la_tintuit:"#f9a825",la_finisat:"#00695c",la_gravat:"#6d4c41",terminata:"#2e7d32",la_magazin:"#6a1b9a",eliberata:"#0097a7",trimisa:"#0277bd",platita:"#c9a84c",completa:"#1b5e20",anulata:"#bf360c",returnata:"#b71c1c"},fs=["anulata","returnata"],bs={numarComanda:"",client:"",telefon:"",email:"",produs:"",sku:"",configuratie:{},pret:0,avans:0,status:"plasata",observatii:""};function re(b){return b?new Date(b).toLocaleDateString("ro-RO",{day:"2-digit",month:"2-digit",year:"numeric"}):"—"}
1function ye(b){return b?new Date(b).toLocaleString("ro-RO",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"—"}function js(b){const _=Array.isArray(b?.randuri)?b.randuri.filter(p=>Number(p.grame)>0):[];if(!_.length)return"";const A=[...new Set(_.map(p=>Number(p.karat)||14))];return A.length===1?` ${A[0]}kt`:" (mix)"}function vs(b){const _=(Array.isArray(b?.plati)?b.plati.filter(A=>A.metoda==="aur_schimb"):[]).length+1;return`${b?.numarComanda||"ATC"}-F${_} / ${new Date().toLocaleDateString("ro-RO")}`}function Ms(){const{can:b}=ss(),_=is(),A=ls()==="light",p={txt:A?"#2b2118":"#e8e0d0",dim:A?"#7a6d58":"#9c9484",dim2:A?"#6b5d49":"#cfc7b4",gold:A?"#8a6a1e":"#d8c178",green:A?"#2e7d32":"#9ae6a0",red:A?"#c0392b":"#e07a7a",redBig:A?"#c0392b":"#ff9090",errTxt:A?"#b02a22":"#f0a098",warn:A?"#a86a00":"#e0a020",softBg:A?"rgba(0,0,0,.03)":"rgba(255,255,255,.03)",softBd:A?"rgba(0,0,0,.12)":"rgba(255,255,255,.1)",amber:A?"#8a5e12":"#e0b060",noteBg:A?"#ffffff":"#1c1a16",noteBd:A?"#e8e3d8":"#33302a",noteTxt:A?"#444444":"#ddd6c8",infoBg:A?"#ffffff":"#241a1a",infoBd:A?"#f0c9c9":"#7a3b3b",infoTxt:A?"#7a2a2a":"#f0c0c0",infoStrong:A?"#b23b3b":"#f08a8a"},[D,F]=h.useState([]),[pe,$]=h.useState({}),[z,L]=h.useState(0),[q,Z]=h.useState([]),[M,Da]=h.useState({}),[Ae,he]=h.useState(null),[ia,mr]=h.useState({}),[ys,ur]=h.useState({}),[ce,pr]=h.useState([]),[Ea,Ia]=h.useState(!1),Wa=h.useRef(null);h.useEffect(()=>{if(!Ea)return;const a=t=>{Wa.current&&!Wa.current.contains(t.target)&&Ia(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[Ea]);const[na,ut]=h.useState([]),[la,Ga]=h.useState([]),[ge,Ua]=h.useState(""),[pt,hr]=h.useState(!1),[Ge,ca]=h.useState({service:"Standard",plata:"achitat",ramburs:0,rambursMod:"cont",livrare:"adresa",fanbox:"",uit:"",optiuni:["A se contacta telefonic"]}),[oa,da]=h.useState({}),[W,ze]=h.useState({female:"",male:"",pair:""}),[ma,ua]=h.useState(!1),[pa,ha]=h.useState(""),[Ns,gr]=h.useState({metoda:"",suma:""}),[Va,xr]=h.useState({}),[Ue,ga]=h.useState(!1),[oe,_e]=h.useState(!1),[de,ht]=h.useState(null),[Ve,xa]=h.useState(""),[fr,fa]=h.useState(!1),gt=[{k:"faza_bijutier",l:"🔧 Bijutier"},{k:"faza_tintuit",l:"💎 Țintuit"},{k:"faza_finisat",l:"✨ Finisat"},{k:"faza_gravat",l:"✒️ Gravură"}],[br,xt]=h.useState(!0),[J,ft]=h.useState(""),[X,qe]=h.useState(""),[xe,qa]=h.useState(""),[bt,jr]=h.useState("termen"),[se,me]=h.useState(""),[ie,ue]=h.useState(""),[Ha,vr]=h.useState(()=>localStorage.getItem("com_calbar")==="1"),yr=()=>vr(a=>{const t=!a;return localStorage.setItem("com_calbar",t?"1":"0"),t});h.useEffect(()=>{const a=new URLSearchParams(window.location.search),t=a.get("status"),s=a.get("termen");t&&qe(t),s&&qa(s)},[]);const[Y,fe]=h.useState(null),[i,O]=h.useState({...bs}),[Re,ba]=h.useState("general"),[jt,vt]=h.useState(!1),[yt,$e]=h.useState(""),[ja,Nt]=h.useState(""),[He,Ka]=h.useState(null),[St,wt]=h.useState(null),[Nr,Xa]=h.useState(!1),[Ct,kt]=h.useState({}),[At,zt]=h.useState(""),[Ya,_t]=h.useState(!1),[g,Te]=h.useState(null),[Ke,va]=h.useState(null),[G,Fe]=h.useState(""),[Sr,Xe]=h.useState(""),[Ye,Me]=h.useState(""),[Ss,Ne]=h.useState(!1),[ya,Ze]=h.useState(!1),[Rt,Za]=h.useState({}),[Na,Ja]=h.useState({}),[$t,Tt]=h.useState(!0),[wr,Cr]=h.useState(!0),[Ft,Sa]=h.useState({}),Pe={la_bijutier:"Bijutier",la_tintuit:"Țintuitor",la_finisat:"Finisor",la_gravat:"Gravor",terminata:"CTC",eliberata:"Vânzător",trimisa:"Vânzător"},Mt=a=>(a||"").toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,"");function Je(a){const t=Mt(a),s=new Map;return Object.entries(Ft).forEach(([r,n])=>{Mt(r).includes(t)&&(n||[]).forEach(o=>s.set(o.id,o))}),[...s.values()]}const Pt=["platita","completa","anulata","returnata"],Qa=["la_bijutier","la_tintuit","la_finisat","la_gravat"],Lt={completa:"Status intern — NU trimite email clientului. Se pune de un user superior (ex. Stefan / Lavinia), după ce verifică că toate etapele comenzii sunt corecte. Marchează comanda ca închisă complet în sistem."};function Ot(){const a=new Map;return Object.values(Ft).forEach(t=>
1(t||[]).forEach(s=>a.set(s.id,s))),[...a.values()].sort((t,s)=>(t.name||"").localeCompare(s.name||""))}const wa={la_atelier:{faza:"",label:"🛠 Atelier (comasat)"},la_bijutier:{faza:"bijutier",label:"🔧 Bijutier"},la_tintuit:{faza:"tintuit",label:"💎 Țintuit"},la_finisat:{faza:"finisat",label:"✨ Finisare"},la_gravat:{faza:"gravat",label:"✒️ Gravură"},terminata:{faza:"ctc",label:"✓ CTC"}},et=[{k:"bijutier",l:"🔧 Bijutier"},{k:"tintuit",l:"💎 Țintuit"},{k:"finisat",l:"✨ Finisare"},{k:"gravat",l:"✒️ Gravură"}],at=["la_bijutier","la_tintuit","la_finisat","la_gravat"],kr=a=>{const t=a&&a.configuratie||{},s=t.sel||{};for(const n of Object.values(s))if(n&&typeof n=="object"){for(const[o,l]of Object.entries(n))if(/detali/i.test(o)&&l&&String(l).trim())return String(l).trim()}const r=(t._lines||[]).find(n=>/detali/i.test(n));if(r){const n=String(r).indexOf(":");return n>-1?r.slice(n+1).trim():String(r).trim()}return""},[Ca,Bt]=h.useState(null),[ee,Ar]=h.useState({}),[zr,_r]=h.useState({}),[ws,Cs]=h.useState(null),[Dt,Et]=h.useState(null),[C,H]=h.useState({suma:"",metoda:"numerar",aurDesc:"",aurValoare:"",corectieSuma:"",corectieDesc:"",returMotiv:"",returScadenta:"",returMod:"",returRambMetoda:"cash",returRambSuma:""}),[Le,Oe]=h.useState(!1),[Rr,ka]=h.useState(!1),[ks,It]=h.useState(null),[Be,tt]=h.useState(""),[be,rt]=h.useState([]),Qe=ds(be),$r=be.reduce((a,t)=>a+(Number(t.grame)||0),0),Se=cs(()=>fe(null));h.useCallback(()=>wt(null),[]),h.useEffect(()=>{if(!St)return;const a=t=>{t.target.closest(".com-dropdown-wrap")||wt(null)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[St]),h.useEffect(()=>{ne()},[X]);const[ea,Tr]=h.useState([]),[Wt,Gt]=h.useState(null),[Aa,Ut]=h.useState(""),[st,Vt]=h.useState(!1),[we,qt]=h.useState(""),[Ht,Kt]=h.useState(""),[za,Xt]=h.useState(!1);h.useEffect(()=>{k.get("/api/admin/firme/factura-config").then(a=>Tr(a.data.firme||[])).catch(()=>{})},[]);const Fr=a=>{if(!a||a.sursa==="emag")return null;const t=ea.find(r=>String(r.id)===String(a.firmaId))||(ea.length===1?ea[0]:ea.find(r=>r.principala));if(!t||!t.factura_interna_activ)return null;const s=Array.isArray(t.factura_interna_statusuri)?t.factura_interna_statusuri:[];return s.length&&!s.includes(a.status)?null:t};h.useEffect(()=>{k.get("/api/orders/atribuiri/useri").then(a=>Sa(a.data.map||{})).catch(()=>Sa({}))},[]),h.useEffect(()=>{k.get("/api/public/fan-judete").then(a=>ut(a.data?.judete||[])).catch(()=>ut([])),k.get("/api/public/setari").then(a=>{xr(a.data?.preturi||{}),Cr(a.data?.urgentaFisaImplicita!==!1)}).catch(()=>{})},[]),h.useEffect(()=>{function a(t){if(t.key!=="atcom_reconfig_done"||!t.newValue)return;let s;try{s=JSON.parse(t.newValue)}catch{return}const r=s?.id;r&&k.get(`/api/orders/${r}`).then(n=>{const o=n.data?.comanda;o&&(F(l=>l.map(u=>String(u.id)===String(o.id)?o:u)),O(l=>l&&String(l.id)===String(o.id)?o:l))}).catch(()=>{})}return window.addEventListener("storage",a),()=>window.removeEventListener("storage",a)},[]);const Yt=h.useRef(!1);h.useEffect(()=>{if(Yt.current)return;const a=new URLSearchParams(window.location.search),t=a.get("scan");if(!t)return;Yt.current=!0;const s=a.get("do")||"view";try{window.history.replaceState({},"","/admin/comenzi")}catch{}k.get(`/api/orders/${t}`).then(r=>{const n=r.data?.comanda;if(!n){y("⚠ Comanda scanată nu a fost găsită.");return}if(s==="avans")nt(n),ba("plati"),setTimeout(()=>{try{document.querySelector(".com-plati-newpay")?.scrollIntoView({behavior:"smooth",block:"center"})}catch{}},160);else if(s==="eliberare"){Te(n),Fe(""),Xe(""),Me(""),Ne(!1),Ze(!1),Za(n.detaliiFaze||{}),Ja({bijutier:n.atribuiri?.la_bijutier||"",tintuit:n.atribuiri?.la_tintuit||"",finisat:n.atribuiri?.la_finisat||"",gravat:n.atribuiri?.la_gravat||""}),k.get("/api/orders/atribuiri/useri").then(l=>Sa(l.data.map||{})).catch(()=>{});const o=(l=0)=>{const u=document.querySelector("#status-acc-eliberata .com-status-row");u?(u.closest(".com-status-item--open")||u.click(),setTimeout(()=>{try{document.getElementById("status-acc-eliberata")?.scrollIntoView({behavior:"smooth",block:"start"})}catch{}},90)):(l===0&&Ze(!0),l<10&&setTimeout(()=>
1o(l+1),70))};setTimeout(()=>o(0),100)}else ar(n)}).catch(()=>y("⚠ Comanda scanată nu a fost găsită."))},[]),h.useEffect(()=>{const a=i?.adresa?.judet;if(i?.livrareMod==="international"||!a||!String(a).trim()){Ga([]);return}let t=!0;return k.get("/api/public/fan-localitati",{params:{judet:a}}).then(s=>{t&&Ga(s.data?.localitati||[])}).catch(()=>{t&&Ga([])}),()=>{t=!1}},[i?.adresa?.judet,i?.livrareMod]);const[_a,Mr]=h.useState(!1),[U,Zt]=h.useState(()=>{try{return JSON.parse(localStorage.getItem("comGramajCols")||"[]")}catch{return[]}}),[Pr,it]=h.useState(!1),Lr=a=>Zt(t=>{const s=t.includes(a)?t.filter(r=>r!==a):[...t,a];try{localStorage.setItem("comGramajCols",JSON.stringify(s))}catch{}return s}),Ra=a=>{if(a==null)return 0;if(typeof a=="number")return a;if(typeof a=="string"){const t=parseFloat(a.replace(",","."));return isNaN(t)?0:t}return typeof a=="object"?a.pair!=null&&a.pair!==""?Number(a.pair)||0:(Number(a.female)||0)+(Number(a.male)||0):0},$a=a=>a>0?`${(Math.round(a*100)/100).toLocaleString("ro-RO")} g`:"—",De=a=>`${(Number(a)||0).toLocaleString("ro-RO")} lei`,Jt=a=>Number(a.avans)||0,Qt=a=>a.cardDiscountApplied&&Number(a.cardDiscount)||0,[er,Or]=h.useState([]);h.useEffect(()=>{k.get("/api/admin/plati").then(a=>Or(a.data.plata_metode||[])).catch(()=>{})},[]);const Ce=er.filter(a=>a.activ&&a.id!=="card_online"&&a.id!=="ramburs").filter(a=>a.vizibil==="admin"||a.vizibil==="toti"||!a.vizibil).filter(a=>!a.permisiune||b(a.permisiune)).sort((a,t)=>(a.ordine||0)-(t.ordine||0));h.useEffect(()=>{Ce.length&&!Ce.some(a=>a.id===C.metoda)&&H(a=>({...a,metoda:Ce[0].id}))},[er]);async function ne(a,t){const s=t!==void 0?t:X,r=a!==void 0?a:J;xt(!0);try{const n={};s&&(n.status=s),r&&(n.search=r);const o=await k.get("/api/orders",{params:n});F(o.data.comenzi||[]),$(o.data.counts||{}),L(o.data.totalActive??(o.data.comenzi||[]).length),Z(o.data.statusuri||[]),Da(o.data.labels||{}),mr(o.data.statusFlux||{}),ur(o.data.statusPlaceholders||{}),pr(o.data.curieri||[])}catch(n){console.error(n)}finally{xt(!1)}}function y(a){Nt(a),setTimeout(()=>Nt(""),3e3)}function ae(a,t){O(s=>({...s,[a]:t}))}function je(a,t){O(s=>({...s,adresa:{...s.adresa||{},[a]:t}}))}function nt(a){Se.reset(),O({...a}),ba("general"),$e(""),fe("edit")}function ar(a){O({...a}),fe("view")}async function Br(){if(!i.client?.trim()){$e("Numele clientului este obligatoriu.");return}vt(!0),$e("");try{if(Y==="create"){const a=await k.post("/api/orders",i);F(t=>[a.data.comanda,...t]),fe(null),y("Comandă creată!")}else{const{configuratie:a,revizii:t,versiune:s,breakdown:r,...n}=i,o=await k.put(`/api/orders/${i.id}`,n);F(l=>l.map(u=>u.id===i.id?o.data.comanda:u)),O(o.data.comanda),y(o.data.autoEmail?"Salvat! ✉ Email status trimis automat":"Salvat!")}}catch(a){$e(a.response?.data?.error||"Eroare la salvare.")}finally{vt(!1)}}async function lt(a,t,s={}){if(a.awb&&["la_magazin","anulata","returnata"].includes(t)&&await Ie({title:`Comanda are AWB ${a.awb}`,icon:"🚚",tone:"danger",msg:a.pickupOrderId?'O treci înapoi din „Trimisă curier". Anulez și AWB-ul + comanda de ridicare la curier (să nu vină degeaba)?':'O treci înapoi din „Trimisă curier". Anulez și AWB-ul la curier?',okText:"Da, anulează AWB-ul",cancelText:"Nu, păstrează AWB-ul"}))try{const n=await k.post(`/api/orders/${a.id}/awb-cancel`);n.data.ok?(a={...a,awb:"",trackingUrl:"",pickupOrderId:""},y(n.data.pickupAnulat?"🗑 AWB + ridicare anulate la curier":"🗑 AWB anulat la curier")):V("Nu s-a putut anula AWB-ul — schimb doar statusul.")}catch{V("Eroare la anularea AWB — schimb doar statusul.")}try{const r={status:t,statusNota:s.nota||"",statusAssignee:s.assignee||"",resend:!!s.resend};s.curier!==void 0&&(r.curier=s.curier),s.curierLogo!==void 0&&(r.curierLogo=s.curierLogo),s.curierOpt!==void 0&&(r.curierOpt=s.curierOpt),s.ctcChecks!==void 0&&(r.ctcChecks=s.ctcChecks),s.gramajReal!==void 0&&(r.gramajReal=s.gramajReal),s.corectieMod!==void 0&&(r.corectieMod=s.corectieMod),s.corectieSuma!==void 0&&(r.corectieSuma=s.corectieSuma);const n=await k.put(`/api/orders/${a.id}`,r);F(l=>l.map(u=>u.id===a.id?n.data.comanda:u)),(Y==="edit"||Y==="view")&&O(n.data.comanda);const o=n.data.autoEmail?`✉ Status: ${M[t]||t} · Email trimis automat`:`Status: ${M[t]||t}`;y(o);try{window.dispatchEvent(new Event("atcom-notif-refresh"))}catch{}}catch(r){const n=r.response?.data?.error;n?V({title:"Status blocat",icon:"🔒",tone:"danger",msg:n}):y("Eroare la schimbat status.")}}async function Dr(a){try{const t=await k.post(`/api/orders/${a.id}/corectie-refund/platit`);t.data.order&&(O(s=>s&&{...s,...t.data.order}),F(s=>s.map(r=>r.id===a.id?{...r,...t.data.order}:r)),y("✓ Rambursare marcată ca dată"))}catch{y("Eroare la marcarea rambursării")}}function tr(a){const t=a&&a.sel||{},r=(Array.isArray(a?.activeItems)&&a.activeItems.length?a.activeItems:Object.keys(t)).map(o=>o&&typeof o=="object"?o.key||o.id||o.value||"":o).filter(o=>o&&o!=="_global"&&o!=="_single");if(!r.length)return[{key:"_single",label:"Gravură"}];const n=o=>{const l=(a.activeItems||[]).find(u=>u&&typeof u=="object"&&u.key===o);return l&&l.label||(o==="dama"?"Damă":o==="barbat"?"Bărbat":o)};return r.map(o=>({key:o,label:n(o)}))}function Er(a,t){const s=a&&a.sel||{};return String(t==="_single"?s.gravura||s._single&&s._single.gravura||"":s[t]&&s[t].gravura||"")}function Ir(a){const t=a&&a.sel||{},s=t._global&&typeof t._global=="object"?t._global:t._single&&typeof t._single=="object"?t._single:{};return String(s.adauga_detalii_suplimentare||"")}function Wr(){const a=typeof i.configuratie=="object"&&i.configuratie||{},t={};
1tr(a).forEach(s=>{t[s.key]=Er(a,s.key)}),kt(t),zt(Ir(a)),Xa(!0)}async function Gr(){_t(!0),$e("");try{const a=await k.put(`/api/orders/${i.id}/gravura-detalii`,{gravura:Ct,detalii:At});F(t=>t.map(s=>s.id===i.id?a.data.comanda:s)),O(a.data.comanda),Xa(!1),y("✓ Gravură & detalii salvate — se propagă peste tot")}catch(a){$e(a.response?.data?.error||"Eroare la salvarea gravurii.")}finally{_t(!1)}}async function rr(){if(!g||!G)return;if(G==="terminata"){const t=Array.isArray(g.configuratie?.activeItems)?g.configuratie.activeItems:[];{const r=t.length>=2,n=String(g.configuratie?.sel?.dama?.material||""),o=String(g.configuratie?.sel?.barbat?.material||""),l=r&&!!n&&!!o&&n!==o,u=Number(W.female)||0,d=Number(W.male)||0,v=Number(W.pair)||0;if(r?l?!(u>0&&d>0):!(u>0&&d>0||v>0):!(v>0)){_e(!0),V({title:"Gramaj real lipsă",icon:"⚖️",tone:"danger",msg:r?l?`Titluri diferite (${t[0]?.label||"damă"} ${n} · ${t[1]?.label||"bărbat"} ${o}) — pune gramajul real de pe cântar la AMBELE piese, separat. Un total al perechii n-are cum fi convertit corect în gestiune.`:`Pune gramajul real de pe cântar: fie la ambele piese (${t[0]?.label||"damă"} ȘI ${t[1]?.label||"bărbat"}), fie doar totalul perechii. Fără el, gestiunea de aur nu scade corect, iar certificatul de garanție iese greșit.`:"Pune gramajul real de pe cântar. Fără el, stocul de aur nu scade corect, iar certificatul de garanție iese greșit."}),setTimeout(()=>{try{document.getElementById("gramaj-box")?.scrollIntoView({behavior:"smooth",block:"center"})}catch{}},30);return}}if(![...gt.map(r=>r.k),...t.length>=2?t.map((r,n)=>`item_${n}`):[]].every(r=>oa[r])){ga(!0),y("⚠ Bifează toate verificările CTC (zona roșie) ca să poți salva"),setTimeout(()=>{try{document.getElementById("ctc-box")?.scrollIntoView({behavior:"smooth",block:"center"})}catch{}},30);return}}{const t=Pe[G],s=Pt.includes(G),r=t?Je(t):s?Ot():[];if(Qa.includes(G)&&r.length>0&&!Ye){Ne(!0),y(`⚠ Alege ${t?t.toLowerCase():"userul"} care a făcut operația (obligatoriu, pentru istoric)`),setTimeout(()=>{try{document.getElementById("assignee-box")?.scrollIntoView({behavior:"smooth",block:"center"})}catch{}},30);return}}if(G==="la_atelier"){const t=et.find(s=>Je(Pe["la_"+s.k]).length>=2&&!Na[s.k]);if(t){Ne(!0),y(`⚠ Alege ${(Pe["la_"+t.k]||"").toLowerCase()} la „${t.l}" (obligatoriu — pentru răspundere)`),setTimeout(()=>{try{document.getElementById("detfaza-"+t.k)?.scrollIntoView({behavior:"smooth",block:"center"})}catch{}},30);return}}const a={nota:Sr,assignee:Ye,resend:G===g.status};if(G==="trimisa"){const t=D.find(l=>l.id===g.id)||g,s=Array.isArray(t.breakdown)?t.breakdown.find(l=>l.total):null,r=(Array.isArray(t.corectii)?t.corectii:[]).reduce((l,u)=>l+(Number(u.suma)||0),0),n=t.sursa==="emag"?0:Math.max(0,(s&&s.val?s.val+r:t.pret||0)-(t.avans||0));if(n>0&&Ge.plata!=="ramburs"){V({title:"Expediere blocată",icon:"🔒",tone:"danger",msg:`Mai are de plătit ${n.toLocaleString("ro-RO")} lei și nu e pe ramburs. Ori încasezi restul acum (aur / cash / card / transfer) sau îl aduci la 0 printr-o corecție, ori pui Plata pe „Ramburs (încasează la livrare)" — atunci curierul îi ia banii clientului la livrare.`});return}const o=ce.find(l=>l.label===ge);a.curier=ge||"",a.curierLogo=o?.logo||"",a.curierOpt={...Ge,ramburs:Ge.plata==="ramburs"?n:0}}if(G==="terminata"){a.ctcChecks=oa;const t=W;a.gramajReal={...t.female!==""?{female:parseFloat(t.female)||0}:{},...t.male!==""?{male:parseFloat(t.male)||0}:{},...t.pair!==""?{pair:parseFloat(t.pair)||0}:{}},a.corectieMod=ma?"pastreaza":pa!==""?"manual":"auto",pa!==""&&(a.corectieSuma=parseFloat(pa)||0)}{const t={};if(G==="preluata"&&(t.termenEliberare=Ve||null),["la_atelier","la_bijutier","la_tintuit","la_finisat","la_gravat"].includes(G)){const s={};if(Object.entries(Rt||{}).forEach(([r,n])=>{n&&String(n).trim()&&(s[r]=String(n).trim())}),t.detaliiFaze=s,/urgen/i.test(JSON.stringify(g.configuratie||{}))&&(t.urgentFisa=$t),G==="la_atelier"){const r={};et.forEach(n=>{const o=Je(Pe["la_"+n.k]),l=Na[n.k]||(o.length===1?o[0].name:"");l&&(r["la_"+n.k]=l)}),Object.keys(r).length&&(t.atribuiriPerFaza=r)}}if(Object.keys(t).length)try{await k.put(`/api/orders/${g.id}`,t),F(s=>s.map(r=>r.id===g.id?{...r,...t}:r))}catch{}}if(Te(null),Fe(""),Xe(""),Me(""),Ne(!1),Ua(""),ca({service:"Standard",plata:"achitat",ramburs:0,rambursMod:"cont",livrare:"adresa",fanbox:"",uit:"",optiuni:["A se contacta telefonic"]}),da({}),ze({female:"",male:"",pair:""}),_e(!1),ua(!1),ha(""),G==="anulata"){Ka({comanda:g,newStatus:G,meta:a});return}await lt(g,G,a)}async function aa(a){const t=window.open("","_blank");
1if(!t){y("Permite pop-up-urile pentru acest site ca să se deschidă documentul.");return}try{const s=localStorage.getItem("atcom_token"),r=await fetch(a,{headers:{Authorization:`Bearer ${s}`}});if(!r.ok){try{t.close()}catch{}y("Eroare la deschiderea documentului");return}const n=r.headers.get("content-type")||"";if(/pdf/i.test(n)){const o=URL.createObjectURL(await r.blob());t.location.href=o,setTimeout(()=>URL.revokeObjectURL(o),6e4)}else{const o=await r.text();t.document.open(),t.document.write(o),t.document.close()}}catch{try{t.close()}catch{}y("Eroare la deschiderea documentului")}}function Ta(a,t,s){const r=t==="atelier"&&!!s,n=[t?`tip=${t}`:"",s?`faza=${s}`:"",r?"format=pdf":""].filter(Boolean).join("&");aa(`/api/orders/${a}/pdf-html${n?`?${n}`:""}`)}async function sr(a,t){Bt(t);try{const s=await k.post(`/api/orders/${a}/email-${t}`);y(`Email trimis la ${s.data.to}`)}catch(s){y(s.response?.data?.error||"Eroare la trimitere email")}Bt(null)}async function Ur(a,t){if(window.confirm(`Reface factura în SmartBill pentru această plată?
2
3• Dacă factura EXISTĂ deja în SmartBill → o marchează ÎNCASATĂ.
4• Dacă LIPSEȘTE din SmartBill → o reemite și o încasează.
5
6⚠ Verifică întâi în SmartBill să NU fie deja încasată/dublată.`)){Et(t);try{const r=await k.post(`/api/orders/${a}/plata/${encodeURIComponent(t)}/reface-factura`);r.data.facturi&&(O(n=>n&&{...n,facturi:r.data.facturi}),F(n=>n.map(o=>o.id===a?{...o,facturi:r.data.facturi}:o))),y(r.data.already?"Factura era deja încasată în SmartBill.":r.data.reemis?"✓ Factură reemisă + încasată în SmartBill":"✓ Factură încasată în SmartBill")}catch(r){y(r.response?.data?.error||"Eroare la refacerea facturii")}Et(null)}}async function Vr(a){try{const t=await k.post(`/api/orders/${a}/factura-interna`);t.data.facturi&&O(s=>s&&{...s,facturi:t.data.facturi}),F(s=>s.map(r=>r.id===a?{...r,facturi:t.data.facturi}:r)),y(t.data.already?"Factura internă există deja.":`Factură internă emisă: ${t.data.doc.serie}-${t.data.doc.numar}`),t.data.doc&&!t.data.already&&ta(a,t.data.doc.numar)}catch(t){y(t.response?.data?.error||"Eroare la emitere factură internă")}}async function qr(a,t){Gt(t);try{const s=await k.post(`/api/orders/${a}/factura-interna/${encodeURIComponent(t)}/email`);y(`Factură trimisă pe email: ${s.data.to}`)}catch(s){y(s.response?.data?.error||"Eroare la trimiterea pe email")}finally{Gt(null)}}async function Hr(a){if(!Aa){y("Alege firma pe care migrezi.");return}if(await Ie({title:"Migrezi comanda pe altă firmă?",msg:"Comanda curentă se rectifică la avansul încasat și se închide (doar financiar). Restul pleacă pe firma aleasă ca o comandă NOUĂ, cu tot fluxul de producție. Avansul nu se dublează.",okText:"Da, migrează"})){Vt(!0);try{const s=await k.post(`/api/orders/${a}/migreaza`,{firmaId:Aa});y(`✓ ${s.data.a.numarComanda} închisă la ${(s.data.a.pret||0).toLocaleString("ro-RO")} lei → comandă nouă ${s.data.b.numarComanda} pe firma aleasă.`),Ut(""),await ne(J,X),O(r=>r&&String(r.id)===String(a)?{...r,...s.data.a}:r)}catch(s){y(s.response?.data?.error||"Eroare la migrare.")}finally{Vt(!1)}}}function ta(a,t){aa(`/api/orders/${a}/factura/${encodeURIComponent(t)}/pdf`)}function ir(a,t){aa(`/api/orders/${a}/plata/${encodeURIComponent(t)}/fisa-print`)}function ct(a){aa(`/api/admin/comenzi/${a.id}/certificat`)}async function nr(a){if(await Ie({title:`Anulezi AWB-ul ${a.awb}?`,msg:a.curierTest?"Mod test — doar îl golește.":"FAN: anulare reală, în aceeași zi.",okText:"Da, anulează AWB-ul"}))try{(await k.post(`/api/orders/${a.id}/awb-cancel`)).data.ok?(O(s=>({...s,awb:"",trackingUrl:"",curierTest:!1})),ne(J,X)):V("Nu s-a putut anula AWB-ul.")}catch(t){V("Eroare la anulare: "+(t.response?.data?.error||t.message))}}async function Fa(a,t){try{const s=await k.post(`/api/orders/${a.id}/${t}`);V(s.data.ok?s.data.message||"✅ Gata.":"❌ "+(s.data.error||"Eroare."))}catch(s){V("❌ "+(s.response?.data?.error||s.message))}}function Ma(a){if(!a.curierTest){aa(`/api/orders/${a.id}/awb-label`);return}const t=a.adresaLivrare||a.client?.adresa||a.adresa||"",s=a.client?.nume||a.clientNume||a.client?.name||"",r=a.client?.telefon||a.telefon||"",n=window.open("","_blank","width=420,height=620");n&&(n.document.write(`<html><head><title>AWB ${a.awb}</title><style>
7      *{font-family:Arial,sans-serif;box-sizing:border-box}
8      body{margin:0;padding:18px}
9      .lbl{border:2px solid #000;border-radius:8px;padding:16px;width:100%}
10      .top{display:flex;justify-content:space-between;align-items:center;border-bottom:2px solid #000;padding-bottom:8px;margin-bottom:10px}
11      .cur{font-size:20px;font-weight:900}
12      .test{background:#b26a00;color:#fff;font-size:11px;font-weight:700;padding:3px 8px;border-radius:5px}
13      .awb{font-size:26px;font-weight:900;letter-spacing:2px;text-align:center;margin:12px 0;font-family:monospace}
14      .row{margin:6px 0;font-size:14px}
15      .lbl b{display:inline-block;min-width:70px}
16      @media print{button{display:none}}
17    </style></head><body>
18      <div class="lbl">
19        <div class="top"><span class="cur">${a.curier||"Curier"}</span>${a.curierTest?'<span class="test">MOD TEST</span>':""}</div>
20        <div class="awb">${a.awb}</div>
21        <div class="row"><b>Destinatar:</b> ${s}</div>
22        <div class="row"><b>Telefon:</b> ${r}</div>
23        <div class="row"><b>Adresă:</b> ${t}</div>
24        <div class="row"><b>Comandă:</b> #${a.numarComanda||a.id}</div>
25        <div class="row"><b>Expeditor:</b> ATCOM SRL</div>
26      </div>
27      <p style="text-align:center;margin-top:14px"><button onclick="window.print()" style="padding:8px 20px;font-size:14px;cursor:pointer">🖨 Printează</button></p>
28    </body></html>`),n.document.close())}function lr(a){const t=String(Be||"").trim(),s=t&&(a?.plati||[]).some(r=>r.metoda==="aur_schimb"&&String(r.aur?.notaNr||"").trim()===t);(!t||s)&&(rt([]),tt(vs(a)))}async function Kr(a){const t=C.metoda==="aur_schimb",s=t?Qe:parseFloat(C.suma);if(!s||s<=0){y(t?"Completează fișa de cumpărare (rânduri cu valoare)":"Introdu o sumă validă");return}Oe(!0);try{const r=await k.post(`/api/orders/${a}/plata-manuala`,{suma:C.suma,metoda:C.metoda,...t?{aurRows:be,aurNotaNr:Be}:{}});r.data.order&&(O(m=>m&&{...m,...r.data.order}),F(m=>m.map(f=>f.id===a?{...f,...r.data.order}:f))),H({suma:"",metoda:"numerar",aurDesc:"",aurValoare:"",corectieSuma:"",corectieDesc:"",returMotiv:"",returScadenta:"",returMod:"",returRambMetoda:"cash",returRambSuma:""}),rt([]),tt("");const n=r.data.order||{},o=Array.isArray(n.breakdown)?n.breakdown.find(m=>m.total):null,l=(Array.isArray(n.corectii)?n.corectii:[]).reduce((m,f)=>m+(Number(f.suma)||0),0),u=o&&o.val?o.val+l:n.pret||0,d=n.cardDiscountApplied&&n.cardDiscount||0,v=Math.max(0,+(u-d-(n.avans||
280)).toFixed(2)),x=r.data.factura?` + factură ${r.data.factura.serie}-${r.data.factura.numar}`:"";y(v>0?`✓ Plată înregistrată${x}. Mai are de încasat ${v.toLocaleString("ro-RO")} lei — poți închide, dar comanda NU se eliberează până la 0.`:`✓ Achitat integral${x}! Restul e 0 — poți elibera comanda (dacă e finalizată prin „Terminată").`)}catch(r){const n=r.response?.data?.error||"Eroare la înregistrarea plății";r.response?.data?.dejaInregistrata?V({title:"Fișa e deja înregistrată",icon:"✋",tone:"danger",msg:n}):/depășește|depășește|rest de plat|maxim/i.test(n)?V({title:"Plată respinsă",icon:"🔒",tone:"danger",msg:n}):y(n)}Oe(!1)}async function Xr(a){const t=parseFloat(C.corectieSuma);if(!t||t===0){y("Pune o sumă (ex: 200 pentru adăugare, -150 pentru reducere)");return}Oe(!0);try{const s=await k.post(`/api/orders/${a}/corectie-pret`,{suma:t,descriere:C.corectieDesc});s.data.order&&(O(r=>r&&{...r,...s.data.order}),F(r=>r.map(n=>n.id===a?{...n,...s.data.order}:n))),H(r=>({...r,corectieSuma:"",corectieDesc:"",metoda:"numerar"})),y(s.data.factura?`Corecție aplicată + factură ${s.data.factura.serie}-${s.data.factura.numar}`:"Corecție aplicată")}catch(s){y(s.response?.data?.error||"Eroare la corecție")}Oe(!1)}async function Yr(a){const t=parseFloat(we);if(we===""||isNaN(t)||t<0){y("Pune noul total al comenzii (ex: 7500)");return}Xt(!0);try{const s=await k.post(`/api/orders/${a}/total-manual`,{total:t,motiv:Ht});s.data.order&&(O(r=>r&&{...r,...s.data.order}),F(r=>r.map(n=>n.id===a?{...n,...s.data.order}:n))),qt(""),Kt(""),y("Total comandă actualizat")}catch(s){y(s.response?.data?.error||"Eroare la ajustarea totalului")}Xt(!1)}function ot(){const a=new Date;return a.setDate(a.getDate()+15),a.toISOString().slice(0,10)}async function Zr(a){const t=new Date().toISOString().slice(0,10),s=C.returMod||"15",r=s==="azi"?t:s==="15"?ot():C.returScadenta;if(!r){V({title:"Alege întâi data",tone:"danger",icon:"🗓",msg:'Ai bifat „Altă dată", dar n-ai pus-o. Alege din calendar data la care se face rambursarea — sau apasă „Pe loc (azi)" ori „15 zile (standard)".'}),setTimeout(()=>{try{document.querySelector(".com-date-input")?.focus()}catch{}},60);return}const n=r>t,l=s==="azi"&&!!C.returCashPeLoc,u=D.find(m=>m.id===a)||i||{},d=(Array.isArray(u.plati)?u.plati:[]).reduce((m,f)=>m+(Number(f.suma)||0),0),v=Math.min(9999,Math.round(d*100)/100),x={title:"Ai piesa fizic în mână?",msg:e.jsxs(e.Fragment,{children:["Returul se face ",e.jsx("strong",{children:"doar cu piesa la tine"})," — dacă vine prin curier, aștepți coletul. Apeși pe răspunderea ta și ",e.jsx("strong",{children:"rămâne înregistrat pe numele tău"}),".",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{children:"Banii:"})," ",n?e.jsxs(e.Fragment,{children:["se rambursează la ",e.jsx("strong",{children:re(r)})," prin ",e.jsx("strong",{children:"transfer"})," — atunci se emit automat storno + factura cu minus, iar clientul primește email. Până atunci comanda rămâne în starea curentă."]}):l?e.jsxs(e.Fragment,{children:["storno + factura cu minus se emit ",e.jsx("strong",{children:"ACUM"}),", apoi ",e.jsx("strong",{children:"te duce în casierie"})," să dai cash-ul (suma pre-luată din comandă, plafon 9.999). Ce a plătit cu cardul/transferul se întoarce separat pe canalul lui."]}):e.jsxs(e.Fragment,{children:["storno + factura cu minus se emit ",e.jsx("strong",{children:"ACUM"}),". Banii se întorc ",e.jsx("strong",{children:"cum a plătit"})," — card online → auto pe card; altă metodă → primești alertă roșie să rambursezi manual."]})]}),okText:n?"Da, am piesa — programează returul":"Da, am piesa — fă returul"};if(await Ie({...x,tone:"danger",icon:"↩"})){Oe(!0);try{const m={motiv:C.returMotiv,scadenta:r};l&&(m.viaCasierie=!0);const f=await k.post(`/api/orders/${a}/retur`,m);if(f.data.order&&(O(S=>S&&{...S,...f.data.order}),F(S=>S.map(P=>P.id===a?{...P,...f.data.order}:P))),H(S=>({...S,returMotiv:"",returScadenta:"",returMod:"",metoda:"numerar",returRambMetoda:"cash",returRambSuma:"",returCashPeLoc:!1})),g&&g.id===a&&(Te(null),Fe("")),V({title:f.data.programat?"Retur programat":"C
28omandă returnată",tone:f.data.programat?"warn":"ok",icon:"↩",msg:f.data.programat?`La ${new Date(r).toLocaleDateString("ro-RO")} se emit automat storno + factura cu minus, iar clientul primește email. Până atunci comanda rămâne în starea curentă.`:l?`S-a emis storno${f.data.factura?` ${f.data.factura.serie}-${f.data.factura.numar}`:""} + factură cu minus, clientul a primit email. Te-am dus în casierie — confirmă cash-ul (suma e pre-completată din comandă).`:`S-a emis storno${f.data.factura?` ${f.data.factura.serie}-${f.data.factura.numar}`:""} + factura cu minus, clientul a primit email. ${f.data.order?.retur?.returDePlatit?'ATENȚIE: rambursarea NU e automată — dă banii clientului și marchează „Am dat banii".':"Banii se întorc automat pe cardul clientului."}`}),l){const S=f.data.order?.numarComanda||u.numarComanda||"";setTimeout(()=>{try{_(`/admin/registru-casa?retur=${encodeURIComponent(S)}&suma=${v}`)}catch{}},250)}}catch(m){y(m.response?.data?.error||"Eroare la retur")}Oe(!1)}}async function Jr(a){try{const t=await k.post(`/api/orders/${a}/retur/platit`);t.data.order&&(O(s=>s&&{...s,...t.data.order}),F(s=>s.map(r=>r.id===a?{...r,...t.data.order}:r))),y("Rambursare marcată ca efectuată")}catch{y("Eroare")}}async function Qr(a){if(await Ie({title:`Ștergi comanda ${a.numarComanda||`#${a.id}`}?`,msg:e.jsxs(e.Fragment,{children:["Comanda lui ",e.jsx("strong",{children:sa(a.client)})," dispare împreună cu ",e.jsx("strong",{children:"plățile, facturile și mișcările de aur"})," legate de ea.",e.jsx("br",{}),"Acțiunea este ireversibilă."]}),okText:"Șterge definitiv",cancelText:"Renunț",tone:"danger",icon:"🗑"}))try{await k.delete(`/api/orders/${a.id}`),F(s=>s.filter(r=>r.id!==a.id)),y("Comandă ștearsă.")}catch{V({title:"Nu am putut șterge comanda",msg:"Încearcă din nou.",tone:"danger",icon:"🗑"})}}const Pa=(()=>{const a=new Date;return`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,"0")}-${String(a.getDate()).padStart(2,"0")}`})(),La=["terminata","eliberata","la_magazin","trimisa","platita","completa","anulata","returnata"],le=D.filter(a=>{if(xe){const s=a.termenEliberare;if(xe==="cu_termen"&&!s||xe==="intarziate"&&!(s&&s<Pa&&!La.includes(a.status))||xe==="azi"&&!(s&&s===Pa&&!La.includes(a.status)))return!1}if(se||ie){const s=bt==="plasare"?a.createdAt||"":a.termenEliberare||"",r=String(s).slice(0,10);if(!r||se&&r<se||ie&&r>ie)return!1}if(!J)return!0;const t=J.toLowerCase();return a.numarComanda?.toLowerCase().includes(t)||a.client?.toLowerCase().includes(t)||a.telefon?.includes(t)||a.sku?.toLowerCase().includes(t)}),ra=pe&&Object.keys(pe).length?pe:q.reduce((a,t)=>(a[t]=D.filter(s=>s.status===t).length,a),{});if(!b("comenzi.view"))return e.jsx("div",{className:"access-denied",children:"Acces interzis."});const[cr,es]=h.useState(!1),as=a=>{H(t=>({...t,metoda:"numerar"})),(!g||g.id!==a.id)&&(fe(null),Te(a),Xe(""),Me(""),Ne(!1),Ze(!1)),Fe("returnata"),setTimeout(()=>{const t=document.getElementById("status-acc-returnata");t?t.scrollIntoView({behavior:"smooth",block:"center"}):V({title:"Retur indisponibil din starea curentă",tone:"danger",icon:"↩",msg:'Statusul „Returnată" nu e permis din starea în care se află comanda acum. Verifică fluxul de statusuri din Setări sau schimbă întâi starea comenzii.'})},120)},ts=a=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"com-newpay-info",style:{marginTop:10},children:["↩️ Returul se face din statusul ",e.jsx("strong",{children:'„Returnată"'})," — acolo pui motivul și scadența, iar sistemul emite ",e.jsx("strong",{children:"storno + factura cu minus"}),", anunță clientul și programează rambursarea."]}),e.jsx("button",{type:"button",className:"com-fact-btn com-newpay-btn",style:{background:"linear-gradient(180deg,#e57373,#c0392b)",color:"#fff"},onClick:()=>as(a),children:'↩️ Du-mă la „Returnată" — acolo se face returul'})]}),rs=a=>{const t=new Date().toISOString().slice(0,10),s=C.returMod||"15",r=s==="azi",n=s==="15",o=s==="custom",l=r?t:n?ot():C.returScadenta||"",u=D.find(x=>x.id===a)||i||{},d=(Array.isArray(u.plati)?u.plati:[]).reduce((x,m)=>x+(Number(m.suma)||0),0),v=x=>({flex:"1 1 0",padding:"9px 6px",borderRadius:8,cursor:"pointer",fontSize:"0.8rem",fontWeight:x?800:600,textAlign:"center",fontFamily:"inherit",transition:"all .15s",border:x?"1px solid #b8942f":`1px solid ${p.softBd}`,background:x?"linear-gradient(180deg,#e0c068,#c9a84c)":"transparent",color:x?"#1a1a1a":p.dim,boxShadow:x?"0 2px 8px rgba(201,168,76,.35)":"none"});return e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"form-label",style:{marginTop:8},children:[e.jsxs("span",{children:["📅 Scadență retur (rambursare) — ",r?e.jsx("b",{style:{color:p.red,fontWeight:700},children:"se face ACUM"}):n?e.jsxs(e.Fragment,{children:["termenul legal: 15 zile → ",e.jsx("b",{style:{color:p.gold,fontWeight:700},children:re(l)})]}):l?e.jsxs(e.Fragment,{children:["la data aleasă de tine → ",e.jsx("b",{style:{color:p.gold,fontWeight:700},children:re(l)})]}):e.jsx("b",{style:{color:p.amber,fontWeight:700},children:"alege data din calendar ↓"})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{type:"button",style:v(r),onClick:()=>H(x=>({...x,returMod:"azi",returScadenta:t})),children:"⚡ Pe loc (azi)"}),e.jsx("button",{type:"button",style:v(n),onClick:()=>H(x=>({...x,returMod:"15",returScadenta:ot()})),children:"📅 15 zile (standard)"}),e.jsx("button",{type:"button",style:v(o),onClick:()=>H(x=>({...x,returMod:"custom",returScadenta:""})),children:"🗓 Altă dată"})]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"date",className:"com-date-input",style:{marginTop:6}
28,min:t,value:l,onChange:x=>H(m=>({...m,returScadenta:x.target.value}))}),e.jsx("span",{style:{fontSize:"0.8rem",color:p.dim,fontWeight:400},children:"Apasă pe câmp sau pe iconița din dreapta ca să alegi din calendar."})]})]}),e.jsxs("label",{className:"form-label",style:{marginTop:8},children:[e.jsx("span",{children:"Motiv retur (opțional)"}),e.jsx("textarea",{rows:2,value:C.returMotiv,placeholder:"ex: client renunță / produs defect…",onChange:x=>H(m=>({...m,returMotiv:x.target.value}))})]}),r&&d>0&&e.jsxs("label",{className:"form-label",style:{marginTop:8,cursor:"pointer"},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("input",{type:"checkbox",checked:!!C.returCashPeLoc,style:{width:18,height:18,margin:0,cursor:"pointer"},onChange:x=>H(m=>({...m,returCashPeLoc:x.target.checked}))}),e.jsxs("span",{children:["💵 Dau ",e.jsx("b",{children:"cash pe loc"})," din casierie ",e.jsx("b",{style:{color:p.dim,fontWeight:500},children:"(max 9.999 lei)"})]})]}),e.jsxs("span",{style:{fontSize:"0.78rem",color:p.dim,fontWeight:400,marginTop:4},children:["Bifează doar dacă clientul vrea ",e.jsx("b",{children:"cash în mână acum"}),". Te duce în casierie cu suma pre-completată din comandă (o scazi doar dacă dai mai puțin). Altfel banii se întorc ",e.jsx("b",{children:"cum a plătit"})," (card → pe card, transfer → pe cont)."]})]}),e.jsxs("div",{className:"com-newpay-warn",children:["↩️ ",r?C.returCashPeLoc?e.jsxs(e.Fragment,{children:["Se face ",e.jsx("strong",{children:"ACUM"}),": storno + factură cu minus, clientul primește email. Apoi ",e.jsx("strong",{children:"te duce în casierie"})," să dai cash-ul — suma vine pre-luată din comandă, o scazi doar dacă dai mai puțin (plafon 9.999)."]}):e.jsxs(e.Fragment,{children:["Se face ",e.jsx("strong",{children:"ACUM"}),": storno + factură cu minus, clientul primește email. Banii se întorc ",e.jsx("strong",{children:"cum a plătit"})," — card online → auto pe card; restul → transfer/manual."]}):e.jsxs(e.Fragment,{children:["La ",e.jsx("strong",{children:l?re(l):"data scadenței"})," se emit automat ",e.jsx("strong",{children:"storno + factura cu minus"}),", clientul primește email, iar tu primești o ",e.jsx("strong",{children:"alertă roșie"}),' („nu uita rambursarea, a ajuns la termen"). Rambursarea = ',e.jsx("strong",{children:"transfer"}),". Până atunci comanda rămâne în starea curentă."]})]}),e.jsx("button",{type:"button",className:"com-fact-btn com-newpay-btn",disabled:Le,style:{background:"linear-gradient(180deg,#e57373,#c0392b)",color:"#fff"},onClick:()=>Zr(a),children:Le?"Se procesează…":`↩️ Returnează comanda (storno)${r?" — acum":l?` — la ${re(l)}`:""}`})]})},dt=(a,t={})=>{const s=!!t.curier,r=D.find(c=>c.id===a.id)||a,n=Array.isArray(r.plati)?r.plati:[],o=Array.isArray(r.facturi)?r.facturi:[],l=r.cardDiscountApplied&&r.cardDiscount||0,u=Array.isArray(r.breakdown)?r.breakdown.find(c=>c.total):null,d=(Array.isArray(r.corectii)?r.corectii:[]).reduce((c,j)=>c+(Number(j.suma)||0),0),v=u&&u.val?u.val+d:r.pret||0,x=Math.max(0,v-l),m=r.avans||0,f=["returnata","anulata"].includes(r.status),S=f?0:Math.max(0,x-m),P=r.sursa==="emag",T=r.emagPlatit??r.emag?.platit,te=r.emagRamburs??r.emag?.ramburs,Q=r.emagMetodaPlata||r.emag?.plata||(te?"Ramburs":"Card online"),E=n.filter(c=>c.metoda==="aur_schimb");return E.reduce((c,j)=>c+(j.aur?.total??j.suma??0),0),E.reduce((c,j)=>c+(j.aur?.grameTotal??0),0),o.filter(c=>!c.plataRef||!n.some(j=>j.ref===c.plataRef)),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"com-plati-toggle com-plati-rest",style:{cursor:"default"},children:f?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontWeight:700,color:"#e0a020"},children:r.status==="anulata"?"✖ Comandă anulată":"↩ Comandă returnată"}),e.jsx("b",{style:{color:"#e0a020",fontSize:"1.05rem"},children:r.retur?.refundCard?.suma>0?`rambursat ${Number(r.retur.refundCard.suma).toLocaleString("ro-RO")} lei pe card`:"storno emis"})]}):P?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{fontWeight:700,color:T?p.green:"#e0a020"},children:[T?`✅ Plătit la eMAG.ro (${Q})`:`📦 Ramburs eMAG.ro (${Q})`,T?" · achitată":" · la livrare"]}),e.jsxs("b",{style:{color:T?p.green:"#e0a020",fontSize:"1.05rem"}
28,children:[x.toLocaleString("ro-RO")," lei"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{fontWeight:700},children:"💳 Mai are de plătit"}),e.jsx("b",{style:{color:S>0?p.redBig:p.green,fontSize:"1.05rem"},children:S>0?`${S.toLocaleString("ro-RO")} lei`:"achitată ✓"})]})}),r.corectieRefund&&r.corectieRefund.suma>0&&(r.corectieRefund.returPlatit?e.jsxs("div",{style:{margin:"10px 0",padding:"8px 12px",borderRadius:8,background:"rgba(46,125,50,.1)",border:"1px solid rgba(46,125,50,.4)",color:"#9ae6a0",fontSize:".85rem"},children:["✓ Rambursare corecție gramaj dată: ",e.jsxs("strong",{children:[r.corectieRefund.suma.toLocaleString("ro-RO")," lei"]}),r.corectieRefund.metoda==="card_online"?" (automat pe card)":""]}):e.jsxs("div",{style:{margin:"10px 0",padding:"10px 14px",borderRadius:8,background:"rgba(224,90,74,.1)",border:"1px solid #e05a4a"},children:[e.jsxs("div",{style:{color:"#f0a098",fontWeight:700,fontSize:".9rem",marginBottom:6},children:["↩ De returnat clientului: ",r.corectieRefund.suma.toLocaleString("ro-RO")," lei ",e.jsx("span",{style:{fontWeight:500,color:"#c0b89a"},children:"(corecție gramaj)"})]}),e.jsxs("div",{style:{color:"#c0b89a",fontSize:".82rem",marginBottom:r.corectieRefund.metoda==="card_online"&&!r.corectieRefund.bankErr?0:8},children:[r.corectieRefund.metoda==="card_online"?r.corectieRefund.bankErr?`⚠ Refund card eșuat (${r.corectieRefund.bankErr}) — fă-l manual.`:"Se returnează automat pe cardul folosit la plată.":`${{card:"Plătit card POS",numerar:"Plătit cash",transfer:"Plătit transfer"}[r.metodaPlata]||"Plată la magazin"} → dă banii la ridicare (cash sau retur POS).`,r.corectieRefund.status==="programat"&&r.corectieRefund.scadenta&&` · programat: ${new Date(r.corectieRefund.scadenta).toLocaleDateString("ro-RO")}`]}),b("comenzi.edit")&&(r.corectieRefund.metoda!=="card_online"||r.corectieRefund.bankErr)&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Dr(r),children:"✓ Am dat banii"})]})),f&&e.jsxs("div",{className:"com-newpay-info",style:{marginTop:10},children:[r.status==="anulata"?"✖ Comandă anulată":"↩ Comandă returnată",' — nu se mai încasează nimic. Detaliile rambursării sunt în „Plăți & facturi" jos.']}),P&&e.jsxs("div",{className:"com-newpay-info",style:{marginTop:10},children:["✓ ",T?`Plătită la eMAG.ro (${Q})`:`Ramburs eMAG.ro (${Q}) — încasează curierul lor la livrare`," · nu se încasează de la client la magazin."]}),!f&&!P&&b("comenzi.edit")&&e.jsxs("div",{className:"com-plati-newpay",children:[e.jsx("div",{className:"com-plati-h",style:{marginTop:0},children:"➕ Înregistrează plată (la magazin)"}),e.jsxs("div",{className:"com-newpay-grid",children:[e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Metodă de plată"}),e.jsxs("select",{value:C.metoda,onChange:c=>{const j=c.target.value;H(N=>({...N,metoda:j,suma:"",corectieSuma:""})),j==="aur_schimb"&&(lr(r),It(r.id),ka(!0)),j==="transfer"&&V({title:"Transfer bancar — atenție la sumă",tone:"danger",icon:"🏦",msg:"Înregistrează plata DOAR după ce confirmi că banii au intrat în cont. Până atunci comanda rămâne neplătită."})},children:[Ce.length===0?e.jsx("option",{value:"numerar",children:"💵 Numerar"}):Ce.filter(c=>!s||c.id!=="aur_schimb").map(c=>e.jsxs("option",{value:c.id,children:[c.icon?c.icon+" ":"",c.label]},c.id)),e.jsx("option",{value:"corectie",children:"🧮 Corecție preț (+/−)"}),e.jsx("option",{value:"retur",children:"↩️ Retur comandă"})]})]}),C.metoda==="aur_schimb"?e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Valoare totală fișă (lei)"}),e.jsx("input",{type:"text",readOnly:!0,value:Qe?Qe.toLocaleString("ro-RO"):"—",style:{cursor:"default",color:"#c9a84c",fontWeight:700}})]}):C.metoda==="corectie"?e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Sumă corecție (+ / −)"}),e.jsx("input",{type:"number",value:C.corectieSuma,placeholder:"ex: 200 sau -150",onChange:c=>H(j=>({...j,corectieSuma:c.target.value}))})]}):C.metoda==="retur"?e.jsx("span",{}):e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Sumă (lei)"}),e.jsx("input",{type:"number",min:0,value:C.suma,placeholder:`rest: ${S}
28`,onChange:c=>H(j=>({...j,suma:c.target.value}))})]})]}),C.metoda==="aur_schimb"&&e.jsxs("div",{className:"com-aur-summary",children:[e.jsx("span",{children:be.length?`🧾 Fișă ${Be?`nr ${Be} `:""}· ${be.length} ${be.length===1?"articol":"articole"} · ${$r.toLocaleString("ro-RO")} g · total ${Qe.toLocaleString("ro-RO")} lei`:'🧾 Fișa se deschide singură — sau apasă „Deschide fișa"'}),e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>{lr(r),It(r.id),ka(!0)},children:be.length?"✎ Editează fișa":"🧾 Deschide fișa"})]}),C.metoda==="corectie"&&e.jsx(e.Fragment,{children:e.jsxs("label",{className:"form-label",style:{marginTop:8},children:[e.jsxs("span",{children:["Detaliu (opțional) ",e.jsxs(We,{title:"Corecție preț",children:["🧮 ",e.jsx("strong",{children:"Corecție preț (rotunjire / discount final):"})," ajustează totalul comenzii înainte de plată — folosește ",e.jsx("strong",{children:"−"})," pentru a rotunji/scădea (ex: 5.617 → 5.600, nu mai ceri 17 lei la raft), ",e.jsx("strong",{children:"+"})," pentru adăugare. ",e.jsx("strong",{children:"NU emite factură"})," — totalul final (rotunjit) apare pe factura de plată. Restul de plată se recalculează singur."]})]}),e.jsx("input",{value:C.corectieDesc,placeholder:"ex: gramaj final / lucrare suplimentară / reducere",onChange:c=>H(j=>({...j,corectieDesc:c.target.value}))})]})}),C.metoda==="retur"&&ts(r),C.metoda==="corectie"?(()=>{const c=parseFloat(C.corectieSuma),j=!isNaN(c)&&c!==0,N=Math.max(0,Math.round(v+(c||0)));return e.jsx("button",{type:"button",className:"com-fact-btn com-newpay-btn"+(j?"":" com-newpay-btn--dim"),disabled:Le||!j,onClick:()=>Xr(r.id),children:Le?"Se aplică…":j?`🧮 Aplică: ${Math.round(v).toLocaleString("ro-RO")} → ${N.toLocaleString("ro-RO")} lei (${c>0?"+":"−"}${Math.abs(Math.round(c)).toLocaleString("ro-RO")})`:"🧮 Pune suma corecției mai sus ↑"})})():C.metoda==="retur"?null:(()=>{const c=Ce.find(B=>B.id===C.metoda),j=C.metoda==="aur_schimb"?Qe:parseFloat(C.suma)||0,N=c&&c.cond_max_suma>0&&j>c.cond_max_suma;return S<=0?e.jsx("div",{className:"com-newpay-info",style:{marginTop:12,color:p.green,fontWeight:700},children:'✓ Achitată integral — nu mai e nimic de încasat. (Dacă totuși trebuie ajustat ceva, folosește „Corecție preț".)'}):e.jsxs(e.Fragment,{children:[N&&e.jsxs("div",{className:"com-newpay-warn",children:["⚠ ",c.cond_max_mesaj||`Plata „${c.label}" este limitată la ${c.cond_max_suma.toLocaleString("ro-RO")} lei.`]}),(()=>{const B=String(Be||"").trim(),K=C.metoda==="aur_schimb"&&B&&(r?.plati||[]).find(I=>I.metoda==="aur_schimb"&&String(I.aur?.notaNr||"").trim()===B);return e.jsxs(e.Fragment,{children:[K&&e.jsxs("div",{className:"com-newpay-warn",children:["✋ Fișa ",e.jsx("b",{children:B})," e deja înregistrată pe comanda asta (",K.suma," lei · ",new Date(K.data).toLocaleString("ro-RO",{hour:"2-digit",minute:"2-digit"}),"). Nu se poate înregistra de două ori. Dacă clientul a adus aur din nou, deschide fișa și schimbă numărul notei."]}),e.jsx("button",{type:"button",className:"com-fact-btn com-newpay-btn"+(j>0&&!K?"":" com-newpay-btn--dim"),disabled:Le||N||j<=0||!!K,onClick:()=>Kr(r.id),children:Le?"Se înregistrează…":K?"✋ Fișa e deja înregistrată":j>0?`✓ Înregistrează plata ${j.toLocaleString("ro-RO")} lei + emite factură`:C.metoda==="aur_schimb"?"🪙 Completează fișa de cumpărare ↑":"✓ Pune suma încasată mai sus ↑"})]})})()]})})()]}),e.jsxs("button",{type:"button",onClick:()=>es(c=>!c),className:"com-plati-toggle com-plati-toggle--hist",children:[e.jsx("span",{style:{fontWeight:700},children:"📋 Plăți & facturi"}),e.jsx("span",{style:{color:"#9c9484",fontWeight:500,fontSize:"0.8rem"},children:cr?"▾ ascunde":"▸ vezi istoricul"})]}),cr&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"com-plati-ledger",children:[r.metodaPlata&&e.jsxs("div",{className:"com-led-row",children:[e.jsx("span",{children:"Metodă aleasă la comandă"}),e.jsx("span",{style:{color:p.gold,fontWeight:700},children:{card_online:"💳 Card online",card:"💳 Card POS la magazin",numerar:"💵 Numerar",transfer:"🏦 Transfer",aur_schimb:"🪙 Aur la schimb",ramburs:"📦 Ramburs"}[r.metodaPlata]||r.metodaPlata})]}),(Array.isArray(r.breakdown)?r.breakdown:[]).filter(c=>!/corec[țt]ie/i.test(c.label||"")).map((c,j)=>{const N=(Array.isArray(r.breakdown)?r.breakdown:[]).filter(R=>
28/corec[țt]ie/i.test(R.label||"")).reduce((R,ke)=>R+(ke.val||0),0),B=c.total,K=B?(c.val||0)-N-l:c.val||0,I=K<0,Ee=c.display?c.display:`${I?"- ":""}${Math.abs(K).toLocaleString("ro-RO")} lei`,w=e.jsxs("div",{className:"com-led-row"+(B?" com-led-total":""),children:[e.jsx("span",{children:c.label}),e.jsx("span",{style:{color:c.display||I?p.green:B?p.gold:p.txt},children:Ee})]},"r"+j);return B&&l>0?[e.jsxs("div",{className:"com-led-row",children:[e.jsx("span",{children:"🎁 Bonus card aplicat"}),e.jsxs("span",{style:{color:p.green},children:["− ",l.toLocaleString("ro-RO")," lei"]})]},"b"+j),w]:w}),n.map((c,j)=>e.jsxs("div",{className:"com-led-pay",children:[e.jsxs("div",{className:"com-led-row",children:[e.jsxs("span",{children:["Plata ",j+1,c.data?` · ${ye(c.data)}`:""," · ",{numerar:"💵 Numerar",card:"💳 Card POS",card_online:"💳 Card online",transfer:"🏦 Transfer",aur_schimb:"🪙 Aur la schimb"}[c.metoda]||c.metoda]}),e.jsxs("span",{style:{color:p.green,whiteSpace:"nowrap",fontWeight:700},children:["− ",(c.suma||0).toLocaleString("ro-RO")," lei"]})]}),c.metoda==="aur_schimb"&&c.aur&&(c.aur.grameTotal||c.aur.notaNr)&&e.jsxs("div",{className:"com-led-info",children:[c.aur.notaNr?`cf. fișă nr ${String(c.aur.notaNr).trim()}`:"",c.aur.notaNr&&c.aur.grameTotal?" · ":"",c.aur.grameTotal?`${c.aur.grameTotal} g${js(c.aur)}`:""]})]},"p"+j)),(Array.isArray(r.breakdown)?r.breakdown:[]).filter(c=>/corec[țt]ie/i.test(c.label||"")).map((c,j)=>{const N=(c.val||0)<0;return e.jsxs("div",{className:"com-led-row",children:[e.jsx("span",{children:c.label}),e.jsxs("span",{style:{color:N?p.green:p.txt},children:[N?"- ":"",Math.abs(c.val||0).toLocaleString("ro-RO")," lei"]})]},"c"+j)}),e.jsx("div",{className:"com-led-sep"}),m>0&&e.jsxs("div",{className:"com-led-row",children:[e.jsx("span",{style:{color:p.green,fontWeight:700},children:"✓ Achitat până acum"}),e.jsxs("span",{style:{color:p.green,fontWeight:700},children:["− ",m.toLocaleString("ro-RO")," lei"]})]}),d!==0&&e.jsxs("div",{className:"com-led-row",children:[e.jsx("span",{children:"🧮 Corecție aplicată"}),e.jsxs("span",{style:{color:d<0?p.green:p.warn,fontWeight:600},children:[d<0?"− ":"+ ",Math.abs(d).toLocaleString("ro-RO")," lei"]})]}),P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"com-led-row com-led-total",children:[e.jsx("span",{style:{fontWeight:700},children:"Total comandă"}),e.jsxs("span",{style:{color:p.gold,fontWeight:800},children:[x.toLocaleString("ro-RO")," lei"]})]}),e.jsxs("div",{className:"com-led-row",children:[e.jsx("span",{style:{color:T?p.green:"#e0a020",fontWeight:700},children:T?`✓ Achitat prin eMAG.ro · ${Q}`:`📦 Ramburs eMAG.ro · ${Q}`}),e.jsx("span",{style:{color:T?p.green:"#e0a020",fontWeight:700},children:T?`− ${x.toLocaleString("ro-RO")} lei`:"la livrare"})]}),e.jsxs("div",{className:"com-led-row com-led-final",children:[e.jsx("span",{style:{fontWeight:700},children:"💳 Rest de plată"}),e.jsx("span",{style:{color:p.green,fontWeight:800},children:T?"0 lei · achitat ✓":`${x.toLocaleString("ro-RO")} lei · la livrare`})]})]}):e.jsxs("div",{className:"com-led-row com-led-final",children:[e.jsx("span",{style:{fontWeight:700},children:"💳 Mai are de plătit"}),e.jsx("span",{style:{color:S>0?p.redBig:p.green,fontWeight:800},children:S>0?`${S.toLocaleString("ro-RO")} lei`:"achitată ✓"})]})]}),(()=>{if(!b("facturare.view"))return null;const c=Fr(r),j=(Array.isArray(r.facturi)?r.facturi:[]).filter(N=>N&&N.internal);return!c&&!j.length?null:e.jsxs("div",{style:{marginTop:10,padding:"8px 10px",border:`1px dashed ${p.softBd}`,borderRadius:8},children:[e.jsx("div",{style:{fontWeight:700,fontSize:"0.82rem",marginBottom:j.length?6:4},children:"🧾 Factură internă"}),!j.length&&e.jsx("div",{style:{color:p.dim,fontSize:"0.75rem",marginBottom:6},children:"Pentru clientul care cere factură (firmă micro, fără SmartBill)."}),j.map((N,B)=>e.jsxs("span",{style:{display:"inline-flex",gap:4,marginRight:8,marginBottom:4},children:[e.jsxs("button",{type:"button",className:"com-fact-btn",onClick:()=>ta(r.id,N.numar),title:"Deschide / printează factura internă",children:["🖨 ",N.serie,"-",N.numar]}),b("facturare.emit")&&e.jsx("button",{type:"button",className:"com-fact-btn",disabled:Wt===N.numar,onClick:()=>qr(r.id,N.numar),title:"Trimite factura pe email clientului",children:Wt===N.numar?"…":"✉"})]},B)),c&&!j.length&&b("facturare.emit")&&e.jsx("button",{type:"button",className:"com-fact-btn com-fact-btn--emit",onClick:()=>Vr(r.id),children:"+ Emite factură (internă)"})]})})(),e.jsxs("div",{className:"com-plati-h",children:["💳 Plăți & facturi (print) ",e.jsx(We,{title:"Facturi (SmartBill)",children:"🖨 Apasă pe o factură ca s-o deschizi și s-o printezi direct — PDF-ul vine din SmartBill, nu trebuie să intri în SmartBill. (În mod simulator vezi facturi de test.) Facturile se emit pe fiecare plată, în funcție de metoda aleasă."})]}),n.length===0?e.jsx("div",{className:"com-plati-empty",children:"Nicio plată 
28înregistrată încă pentru această comandă."}):e.jsx("div",{className:"com-plati-list",children:n.map((c,j)=>{const N=o.find(ke=>ke.plataRef===c.ref),B=c.metoda==="aur_schimb"&&c.aur,K=c.metoda?` · ${{numerar:"💵 Numerar",card:"💳 Card POS",card_online:"💳 Card online",transfer:"🏦 Transfer",aur_schimb:"🪙 Aur la schimb"}[c.metoda]||c.metoda}`:"",I=b("facturare.emit"),Ee=!N||N.status!=="incasata",w=e.jsxs(e.Fragment,{children:[N&&e.jsxs("button",{type:"button",className:"com-fact-btn",onClick:()=>ta(r.id,N.numar),title:N.status==="incasata"?`Factură ${N.serie}-${N.numar} · Încasată în SmartBill`:"Deschide / printează factura",children:["🖨 ",N.serie,"-",N.numar,N.status==="incasata"?e.jsx("span",{style:{color:"#2e9e52",marginLeft:5,fontWeight:800},title:"Încasată în SmartBill",children:"✓"}):""]}),Ee&&e.jsx("button",{type:"button",className:"com-fact-btn com-fact-btn--sync",disabled:!I||Dt===c.ref,title:I?N?"Marchează factura ca ÎNCASATĂ în SmartBill (dacă lipsește de acolo, o reemite). Verifică întâi să nu fie deja încasată.":"Emite factura în SmartBill și o marchează încasată. Verifică întâi.":'Necesită privilegiul „facturare.emit" — nu poți emite/încasa o factură fără verificare.',onClick:()=>Ur(r.id,c.ref),children:Dt===c.ref?"…":N?"✓ Încasează în SmartBill":"+ Emite în SmartBill"})]}),R=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"com-plati-info",children:["Plata ",j+1,c.data?` · ${ye(c.data)}`:"",K]}),e.jsxs("span",{className:"com-plati-act",children:[e.jsxs("span",{className:"com-plati-suma",children:[(c.suma||0).toLocaleString("ro-RO")," lei"]}),w]})]});return B?e.jsxs("div",{className:"com-plati-item",style:{flexDirection:"column",alignItems:"stretch",gap:6},children:[e.jsx("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:10},children:R}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:10,paddingTop:5,borderTop:`1px dashed ${p.softBd}`},children:[e.jsxs("span",{className:"com-plati-info",style:{color:p.dim,fontSize:"0.75rem"},children:["🪙 ",c.aur.notaNr?`Notă cumpărare nr ${c.aur.notaNr} · `:"",c.aur.descriere||""]}),e.jsx("span",{className:"com-plati-act",children:e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>ir(r.id,c.ref),title:"Print fișă de cumpărare (aurul adus)",children:"🖨 Fișă"})})]})]},j):e.jsx("div",{className:"com-plati-item",children:R},j)})}),Array.isArray(r.corectii)&&r.corectii.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"com-plati-h",children:"🧮 Corecții de preț"}),e.jsx("div",{className:"com-plati-list",children:r.corectii.map((c,j)=>e.jsxs("div",{className:"com-plati-item",children:[e.jsxs("span",{className:"com-plati-info",children:[c.descriere||"Regularizare preț",c.data?` · ${ye(c.data)}`:""]}),e.jsxs("span",{className:"com-plati-suma",style:{color:c.suma<0?"#e05a4a":"#5dc87a"},children:[c.suma>0?"+":"",Number(c.suma).toLocaleString("ro-RO")," lei",c.factura?` · 🧾 ${c.factura}`:""]})]},j))})]}),r.retur&&r.retur.status==="programat"&&e.jsxs("div",{className:"com-newpay-info",style:{marginTop:12},children:["📅 ",e.jsx("strong",{children:"Retur programat"})," pentru ",e.jsx("strong",{children:r.retur.scadenta?new Date(r.retur.scadenta).toLocaleDateString("ro-RO"):"—"}),". La acea dată se emit automat storno + factura cu minus + email client.",r.retur.motiv?` Motiv: ${r.retur.motiv}`:""]}),r.retur&&r.retur.status==="efectuat"&&(r.retur.returPlatit?e.jsxs("div",{className:"com-newpay-info",style:{marginTop:12},children:["✓ ",e.jsx("strong",{children:"Comandă returnată și rambursată"})," · storno ",Number(r.retur.suma).toLocaleString("ro-RO")," lei",r.retur.factura?` · 🧾 ${r.retur.factura}`:""]}):e.jsxs("div",{className:"com-newpay-warn",style:{marginTop:12,display:"flex",justifyContent:"space-between",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsxs("span",{children:["↩️ ",e.jsx("strong",{children:"DE RAMBURSAT"})," — comandă stornată",r.retur.factura?` · 🧾 ${r.retur.factura}
28`:""," · ",Number(r.retur.suma).toLocaleString("ro-RO")," lei. Nu uita rambursarea către client!"]}),b("comenzi.edit")&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Jr(r.id),children:"✓ Marchează rambursat"})]}))]})]})};return e.jsxs("div",{className:"com-page",children:[Ae&&e.jsx("div",{className:"com-photo-lightbox",onClick:()=>he(null),children:e.jsx("img",{src:Ae,alt:"Poză produs — mărită"})}),e.jsx("div",{className:"page-header",children:e.jsxs("div",{children:[e.jsx("h1",{children:"Comenzi"}),e.jsxs("p",{children:["Flux producție bijuterii — ",D.length," comenzi total"]})]})}),ja&&e.jsx("div",{className:"flash-success",children:ja}),e.jsx("div",{className:"com-chips",children:(()=>{const a=(d,v="",x="")=>e.jsxs("button",{className:`com-chip ${v} ${X===d?"com-chip--active":""} ${ra[d]>0?"com-chip--has":""}`,style:{"--cc":ve[d]||"#888"},onClick:()=>{const m=X===d?"":d;qe(m),ne(J,m)},children:[x,M[d]||d,ra[d]>0&&e.jsx("span",{className:"com-chip-n",children:ra[d]})]},d),t=e.jsxs("div",{className:"com-atelier-grp",title:"Mod rapid: comasează cele 4 faze de atelier",children:[a("la_atelier","com-chip--atelier",e.jsxs(e.Fragment,{children:[e.jsxs("svg",{viewBox:"0 0 120 64",fill:"
28currentColor",style:{height:"1.1em",width:"auto",verticalAlign:"-0.18em",marginRight:"4px"},children:[e.jsx("rect",{x:"0",y:"14",width:"26",height:"4.2",rx:"2.1"}),e.jsx("rect",{x:"6",y:"30",width:"30",height:"4.2",rx:"2.1"}),e.jsx("rect",{x:"0",y:"46",width:"22",height:"4.2",rx:"2.1"}),e.jsx("g",{transform:"translate(46,3) scale(0.117)",children:e.jsx("path",{d:"M320 48a48 48 0 1 1 96 0 48 48 0 1 1-96 0zM125.7 175.5c9.9-9.9 23.4-15.5 37.5-15.5 1.9 0 3.8 .1 5.6 .3L137.6 254c-9.3 28 1.7 58.8 26.8 74.5l86.2 53.9-25.4 88.8c-4.9 17 5 34.7 22 39.6s34.7-5 39.6-22l28.7-100.4c5.9-20.6-2.6-42.6-20.7-53.9L238 299l30.9-82.4 5.1 12.3C289 264.7 323.9 288 362.7 288l37.3 0c17.7 0 32-14.3 32-32s-14.3-32-32-32l-37.3 0c-12.9 0-24.6-7.8-29.5-19.7l-6.3-15c-14.6-35-44.1-61.9-80.5-73.1l-48.7-15c-11.1-3.4-22.7-5.2-34.4-5.2-31 0-60.8 12.3-82.7 34.3L57.4 153.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l23-23zM91.2 352L32 352c-17.7 0-32 14.3-32 32s14.3 32 32 32l69.6 0c19 0 36.2-11.2 43.9-28.5L157 361.6l-9.5-6c-17.5-10.9-30.5-26.8-37.9-44.9L91.2 352z"})}),e.jsxs("g",{transform:"translate(92,29) rotate(45)",children:[e.jsx("rect",{x:"-2.2",y:"-11",width:"4.4",height:"17",rx:"2"}),e.jsx("rect",{x:"-8",y:"-15",width:"16",height:"7.5",rx:"2.2"})]})]})," "]})),e.jsx("div",{className:"com-atelier-phases",children:at.map(d=>a(d))})]},"atelier-grp"),s=["anulata","returnata","completa"],r=d=>at.includes(d)?null:d==="la_atelier"?t:a(d),n=q.filter(d=>!["plasata","preluata"].includes(d)&&d!=="la_atelier"&&!at.includes(d)),o=n.filter(d=>!s.includes(d)),l=n.filter(d=>s.includes(d)),u=(d,v,x)=>{const m=d===""?!X:X===d;return e.jsxs("button",{className:`com-chip com-chip--big ${m?"com-chip--active":""} ${x>0?"com-chip--has":""}`,style:d?{"--cc":ve[d]||"#888"}:void 0,onClick:()=>{const f=d===""||X===d?"":d;qe(f),ne(J,f)},children:[e.jsx("span",{className:"com-chip-bign",children:x}),e.jsx("span",{className:"com-chip-biglbl",children:v})]},d||"toate")};return e.jsxs(e.Fragment,{children:[u("","Toate",z),u("plasata",M.plasata||"Plasată",ra.plasata||0),u("preluata",M.preluata||"Preluată",ra.preluata||0),t,(()=>{const d=[...o,...l];return e.jsxs("div",{className:"com-chips-grp--right com-chips-grp--grid",children:[e.jsx("div",{className:"com-chips-row",children:d.slice(0,4).map(r)}),e.jsx("div",{className:"com-chips-row",children:d.slice(4).map(r)})]})})()]})})()}),e.jsxs("div",{className:"com-filters",children:[e.jsx("input",{className:"com-search-inp",placeholder:"Caută nr. comandă, client, telefon, SKU...",value:J,onChange:a=>ft(a.target.value),onKeyDown:a=>a.key==="Enter"&&ne(J,X)}),e.jsx("button",{className:"btn-secondary",onClick:()=>ne(J,X),children:"Caută"}),(J||X||xe||se||ie)&&e.jsxs("button",{className:"btn-secondary com-clear-btn",title:"Șterge filtre",onClick:()=>{ft(""),qe(""),qa(""),me(""),ue(""),ne("","")},children:[e.jsx("span",{className:"com-clear-ico",children:"🗑️"}),e.jsx("span",{className:"com-clear-txt",children:"Șterge"})]}),e.jsxs("button",{type:"button",className:"com-calbar-ico"+(Ha?" open":"")+(xe||se||ie?" pulse":""),onClick:yr,title:"Sortare & calendar",children:[e.jsx("span",{className:"com-calbar-cal",children:"📅"}),e.jsx("span",{className:"com-calbar-arrow"+(Ha?" open":""),children:"▸"})]}),e.jsxs("button",{type:"button",className:"com-rapid-ico"+(U.length?" on":""),onClick:()=>it(!0),title:"Rapid — arată coloane gramaj (estimat / final) direct în listă, fără să intri în comandă",children:["⚖️ Rapid",U.length>0&&e.jsx("span",{className:"com-rapid-n",children:U.length})]})]}),Ha&&e.jsxs("div",{className:"com-date-filter",children:[e.jsx("div",{className:"com-df-chips",children:[{k:"intarziate",l:"⏰ Întârziate",cls:"com-chip--late"},{k:"azi",l:"📅 Termen azi",cls:"com-chip--today"},{k:"cu_termen",l:"🕐 În termen",cls:""}].map(a=>{const t=D.filter(s=>{const r=s.termenEliberare;return a.k==="cu_termen"?!!r:a.k==="intarziate"?r&&r<Pa&&!La.includes(s.status):r&&r===Pa&&!La.includes(s.status)}).length;return e.jsxs("button",{className:`com-chip ${a.cls} ${xe===a.k?"com-chip--active":""} ${t>0?"com-chip--has":""}`,onClick:()=>{const s=xe===a.k?"":a.k;
28qa(s),s&&X&&(qe(""),ne(J,""))},children:[a.l,t>0&&e.jsx("span",{className:"com-chip-n",children:t})]},a.k)})}),e.jsx("span",{className:"com-df-divider"}),e.jsxs("select",{className:"com-df-sel",value:bt,onChange:a=>jr(a.target.value),title:"Filtrează după",children:[e.jsx("option",{value:"termen",children:"termen execuție"}),e.jsx("option",{value:"plasare",children:"data plasării"})]}),e.jsxs("div",{className:"com-df-range",children:[e.jsxs("span",{className:"com-df-datewrap",children:[e.jsx("input",{type:"date",className:"com-df-date"+(se?"":" com-df-date--empty"),value:se,onChange:a=>me(a.target.value),title:"De la"}),!se&&e.jsxs("span",{className:"com-df-hint",children:[e.jsx("span",{className:"com-df-hint-txt",children:"Dată personalizată"}),e.jsx("span",{className:"com-df-hint-ico",children:"📅"})]})]}),e.jsx("span",{className:"com-df-arrow",children:"→"}),e.jsxs("span",{className:"com-df-datewrap",children:[e.jsx("input",{type:"date",className:"com-df-date"+(ie?"":" com-df-date--empty"),value:ie,onChange:a=>ue(a.target.value),title:"Până la"}),!ie&&e.jsxs("span",{className:"com-df-hint",children:[e.jsx("span",{className:"com-df-hint-txt",children:"Dată personalizată"}),e.jsx("span",{className:"com-df-hint-ico",children:"📅"})]})]})]}),(()=>{const a=s=>`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`,t=s=>{if(!s)return;const r=new Date;if(s==="azi"){const n=a(r);me(n),ue(n)}else if(s==="ieri"){const n=new Date(r);n.setDate(n.getDate()-1);const o=a(n);me(o),ue(o)}else if(s==="sapt"){const n=new Date(r),o=(n.getDay()+6)%7;n.setDate(n.getDate()-o);const l=new Date(n);l.setDate(l.getDate()+6),me(a(n)),ue(a(l))}else if(s==="sapt1"){const n=new Date(r),o=(n.getDay()+6)%7;n.setDate(n.getDate()-o+7);const l=new Date(n);l.setDate(l.getDate()+6),me(a(n)),ue(a(l))}else if(s==="sapt2"){const n=new Date(r),o=(n.getDay()+6)%7;n.setDate(n.getDate()-o);const l=new Date(n);l.setDate(l.getDate()+13),me(a(n)),ue(a(l))}else if(s.startsWith("luna")){const n=parseInt(s.slice(4));me(a(new Date(r.getFullYear(),r.getMonth()+n,1))),ue(a(new Date(r.getFullYear(),r.getMonth()+n+1,0)))}};return e.jsxs("div",{className:"com-df-quick",ref:Wa,children:[e.jsxs("button",{type:"button",className:"com-df-quick-btn",onClick:()=>Ia(s=>!s),title:"Perioadă rapidă",children:[e.jsx("span",{children:"⚡ Perioadă…"}),e.jsx("span",{className:"com-df-quick-caret",children:"▾"})]}),Ea&&e.jsx("div",{className:"com-df-quick-menu",role:"listbox",children:[["azi","Azi"],["ieri","Ieri"],["sapt","Săptămâna asta"],["sapt1","Săptămâna viitoare"],["sapt2","2 săptămâni (asta + viitoare)"],["luna0","Luna asta"],["luna1","Luna viitoare"],["luna-1","Luna trecută"]].map(([s,r])=>e.jsx("button",{type:"button",className:"com-df-quick-opt",onClick:()=>{t(s),Ia(!1)},children:r},s))})]})})(),(se||ie)&&e.jsx("button",{type:"button",className:"com-df-clear",onClick:()=>{me(""),ue("")},children:"✕"}),e.jsx(ns,{to:"/admin/calendar",className:"com-cal-link com-cal-link--end",children:"📅 Calendar atelier"})]}),br?e.jsx("div",{className:"com-loading",children:"Se încarcă..."}):e.jsx("div",{className:"com-table-wrap",children:e.jsxs("table",{className:"com-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Nr. Comandă"}),e.jsx("th",{children:"Client"}),e.jsx("th",{children:"Produs / SKU"}),e.jsx("th",{children:"Status"}),U.includes("gramaj")&&e.jsx("th",{className:"com-th-gram",children:"Gramaj"}),U.includes("pret")&&e.jsx("th",{className:"com-th-gram",children:"Preț / Avans"}),e.jsx("th",{children:"Data"}),e.jsx("th",{children:"Print"}),e.jsxs("th",{className:"com-th-actions",children:["Acțiuni",b("comenzi.delete")&&e.jsx("button",{type:"button",className:`com-delcol-toggle${_a?" com-delcol-toggle--on":""}`,onClick:()=>Mr(a=>!a),title:_a?"Ascunde coloana de ștergere":"Arată coloana de ștergere (periculos)",children:_a?"🗑️ ◂":"🗑️ ▸"})]})]})}),e.jsx("tbody",{children:le.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7+(U.includes("gramaj")?1:0)+(U.includes("pret")?1:0),className:"com-empty-row",children:"Nicio comandă găsită."})}):le.map(a=>e.jsxs("tr",{className:`com-row${fs.includes(a.status)?" com-row--danger":""}`,children:[e.jsxs("td",{className:"com-td-nr",children:[e.jsxs("span",{className:"com-nr-top",children:[e.jsx("button",{className:"com-nr-link"+(a.sursa==="emag"?" com-nr-link--emag":""),onClick:()=>ar(a),children:a.sursa==="emag"&&a.emagId?`#${a.emagId}`:a.numarComanda||`#${a.id}`}),a.versiune&&a.versiune!=="A"&&e.jsx("span",{className:"com-rev-badge com-rev-badge--sm",title:`Modificată după plasare — versiunea ${a.versiune}`,children:a.versiune}),a.notaInterna&&e.jsx("span",{title:a.notaInterna,className:"com-nota-dot",children:"📝"}),e.jsx("button",{type:"button",className:"com-prio-star"+(a.prioritar?" on":""),title:a.prioritar?"Urgent — urcă în coada domnului calendar. Click ca să anulezi.":"Marchează urgent (urcă în coada agentului)",onClick:()=>k.put(`/api/orders/${a.id}`,{prioritar:!a.prioritar}).then(()=>ne(J,X)).catch(()=>{}),children:a.prioritar?"⭐":"☆"})]}),(()=>{const t=zr[a.id]||a.sku||ee[a.id]||Array.isArray(a.produse)&&a.produse.length>1,s=a.sursa==="emag";if(!t&&s)return null;const r=!s&&!!(a.vanzator&&(a.vanzator.name||a.vanzator.email)),n=t?ee[a.id]?"Restrânge info comandă":"Extinde info comandă (produse + SKU)":"",o=s?"":r?"Comandă din magazin":"Comandă online (de pe site)";return e.jsxs("button",{type:"button",className:"com-row-toggle com-row-toggle--chan"+(t?"":" com-row-toggle--static")+(s?""
28:r?" com-chan--mag":" com-chan--online"),title:[n,o].filter(Boolean).join(" · "),onClick:()=>{t&&Ar(l=>({...l,[a.id]:!l[a.id]}))},children:[!s&&(r?e.jsxs("svg",{className:"com-chan-ic",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M3 9l1.6-5h14.8L21 9"}),e.jsx("path",{d:"M4 9v10a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1V9"}),e.jsx("path",{d:"M3 9h18"}),e.jsx("path",{d:"M9.5 20v-5.5h5V20"})]}):e.jsxs("svg",{className:"com-chan-ic",viewBox:"0 0 24 24",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M3 12h18"}),e.jsx("path",{d:"M12 3c2.5 2.4 3.9 5.7 3.9 9s-1.4 6.6-3.9 9c-2.5-2.4-3.9-5.7-3.9-9S9.5 5.4 12 3z"})]})),!s&&e.jsx("span",{className:"com-chan-lbl",children:r?"Magazin":"Online"}),t&&e.jsx("span",{className:"com-rt-txt",children:ee[a.id]?"Restrânge":"Extinde"}),t&&e.jsx("span",{className:"com-rt-arrow",children:ee[a.id]?"▲":"▼"})]})})()]}),e.jsx("td",{className:"com-td-client","data-label":"Client",children:e.jsxs("div",{className:"com-expcell-c"+(ee[a.id]?" is-exp":""),children:[a.sursa==="emag"&&(()=>{const t=a.emagPlatit??a.emag?.platit,s=a.emagRamburs??a.emag?.ramburs,r=a.emagMetodaPlata||a.emag?.plata||(s?"Ramburs":"Card online"),n=t?`Plată: achitată (${r})`:s?"Plată: ramburs — se încasează la livrare":`Plată: ${r}`;return e.jsxs("div",{className:"com-emag-row",children:[e.jsxs("span",{className:"com-emag-badge",title:`Comandă eMAG.${a.emagPlatform||"ro"} #${a.emagId}${a.emagStatusLabel?" · "+a.emagStatusLabel:""} · client final: ${sa(a.client)}`,children:[e.jsx("span",{className:"com-emag-e",children:"e"}),"MAG.",a.emagPlatform||"ro"]}),e.jsxs("span",{className:"com-emag-pay com-emag-pay--"+(t?"paid":"ramburs"),title:n,children:[e.jsx("span",{className:"com-emag-dot com-emag-dot--"+(t?"paid":"ramburs")}),t?"achitată":s?"ramburs":r]})]})})(),e.jsx("div",{className:"com-client-name",title:sa(a.client),children:sa(a.client)}),a.telefon&&(a.sursa!=="emag"||ee[a.id])&&e.jsx("div",{className:"com-client-phone",children:a.telefon})]})}),e.jsx("td",{className:"com-td-produs","data-label":"Produs",children:(()=>{const t=Array.isArray(a.produse)?a.produse.filter(n=>n&&(n.name||n.produs)):[],s=t.length>1,r=n=>e.jsx("button",{type:"button",className:"com-sku-copy",title:"Copiază codul (caută-l pe site ca să vezi modelul)",onClick:()=>{try{navigator.clipboard.writeText(n)}catch{}y("Cod copiat: "+n)},children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"11",height:"11",rx:"2"}),e.jsx("path",{d:"M5 15V5a2 2 0 0 1 2-2h10"})]})});return ee[a.id]&&s?e.jsx("div",{className:"com-prod-all",children:t.map((n,o)=>e.jsxs("div",{className:"com-prod-line",children:[e.jsxs("span",{className:"com-prod-nm",children:[e.jsxs("b",{children:[o+1,"."]}
28)," ",n.name||n.produs]}),n.sku&&e.jsxs("span",{className:"com-sku-wrap",children:[e.jsx("code",{className:"com-sku-code",children:n.sku}),r(n.sku)]})]},o))}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"com-prod-collapsed",children:[e.jsx("div",{ref:n=>{if(n){const o=n.scrollHeight>n.clientHeight+1;_r(l=>l[a.id]===o?l:{...l,[a.id]:o})}},className:"com-expcell-c"+(ee[a.id]?" is-exp":""),children:a.produs||t[0]&&(t[0].name||t[0].produs)||"—"}),s&&e.jsxs("span",{className:"com-prod-more",title:`${t.length} produse — apasă „Extinde" ca să le vezi pe toate`,children:["+",t.length-1]})]}),ee[a.id]&&!s&&a.sku&&e.jsxs("span",{className:"com-sku-wrap",children:[e.jsx("code",{className:"com-sku-code",children:a.sku}),r(a.sku)]})]})})()}),e.jsx("td",{className:"com-td-status","data-label":"Status",children:e.jsx("span",{className:"com-badge",style:{background:ve[a.status]||"#888"},children:a.status==="la_atelier"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"com-badge-w",children:"În lucru"}),e.jsx("span",{className:"com-badge-w",children:"la atelier"})]}):M[a.status]||a.status})}),U.includes("gramaj")&&e.jsx("td",{className:"com-td-gram","data-label":"Gramaj",children:(()=>{const t=Ra(a.configuratie?.gramaj),s=Ra(a.gramajReal),r=s>0?+(s-t).toFixed(2):null;return e.jsxs("div",{className:"com-gram-stack",children:[e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"estimat"}),e.jsx("span",{className:"com-gram-est",children:$a(t)})]}),e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"real"}),e.jsx("span",{className:"com-gram-real"+(s>0?"":" pend"),children:s>0?$a(s):"—"})]}),r!=null&&r!==0&&e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"diferență"}),e.jsxs("span",{className:"com-gram-dv "+(r>0?"plus":"minus"),children:[r>0?"+":"−",Math.abs(r).toLocaleString("ro-RO")," g"]})]})]})})()}),U.includes("pret")&&e.jsx("td",{className:"com-td-gram","data-label":"Preț est/încasat",children:(()=>{const t=Array.isArray(a.breakdown)?a.breakdown.find(l=>l.total):null,s=(Array.isArray(a.corectii)?a.corectii:[]).reduce((l,u)=>l+(Number(u.suma)||0),0),r=t&&t.val?t.val+s:Number(a.pret)||0,n=Jt(a),o=Math.max(0,+(r-Qt(a)-n).toFixed(2));return e.jsxs("div",{className:"com-gram-stack",children:[e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"estimat"}),e.jsx("span",{className:"com-gram-est",children:De(r)})]}),e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"avans"}),e.jsx("span",{className:"com-gram-real"+(n>0?"":" pend"),children:n>0?De(n):"—"})]}),r>0&&(o>0?e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"rest"}),e.jsx("span",{className:"com-gram-dv plus",children:De(o)})]}):e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"rest"}),e.jsx("span",{className:"com-gram-dv minus",children:"achitat ✓"})]}))]})})()}),e.jsx("td",{className:"com-td-data","data-label":"Data",children:e.jsxs("div",{className:"com-date-stack",children:[e.jsxs("div",{className:"com-data-badge",title:"Data plasării comenzii",children:[e.jsx(xs,{})," ",re(a.createdAt)]}),a.termenEliberare&&e.jsxs("div",{className:"com-termen-badge",title:"Termen de eliberare (calendar atelier)",children:[e.jsx(mt,{})," ",re(a.termenEliberare)]}),ee[a.id]&&a.termenAI&&e.jsxs("div",{className:"com-ai-badge",title:"Termen intern domnul calendar - estimare dinamica din coada, NU e oficial; nu se trimite clientului",children:["🤖 ",re(a.termenAI),a.ordineAI?` · #${a.ordineAI}`:""]})]})}),e.jsx("td",{className:"com-td-fisa","data-label":"Print",children:b("comenzi.view")?wa[a.status]?e.jsx("button",{type:"button",className:"com-fisa-btn com-fisa-btn--eq",onClick:()=>Ta(a.id,"atelier",wa[a.status].faza),title:`Printează fișa pentru zona „${wa[a.status].label}" (statusul curent)`,children:a.status==="la_atelier"?e.jsxs("span",{className:"com-fisa-lines",children:[e.jsx("span",{className:"com-fisa-w",children:"🛠 Atelier"}),e.jsx("span",{className:"com-fisa-w",children:"(comasat)"})]}):wa[a.status].label}):!a.doarFinanciar&&(["eliberata","trimisa","platita","completa"].includes(a.status)||a.awb)?e.jsxs("div",{className:"com-print-stack",children:[e.jsx("button",{type:"button",className:"com-fisa-btn com-fisa-btn--cert com-fisa-btn--eq",onClick:()=>ct(a),title:"Certificat de autenticitate (PDF) — la eliberare (magazin/curier)",children:"🏅 Certificat"}),a.sursa==="emag"&&(()=>{const t=Array.isArray(a.facturi)?a.facturi.filter(s=>s&&["factura","finala"].includes(s.tip)&&s.status!=="anulata").pop():null;return t?e.jsx("button",{type:"button",className:"com-fisa-btn com-fisa-btn--eq",onClick:()=>ta(a.id,t.numar),title:t.status==="incasata"?`Factură ${t.serie}-${t.numar} · Încasată`:`Factură ${t.serie}-${t.numar}`,children:e.jsxs("span",{className:"com-fisa-lines",children:[e.jsxs("span",{className:"com-fisa-w",children:["🧾 Factură",t.status==="incasata"?e.jsx("span",{style:{color:"#2e9e52",marginLeft:4,fontWeight:800},title:"Încasată în SmartBill",children:"✓"}):""]}),e.jsxs("span",{className:"com-fisa-w",children:[t.serie,"-",t.numar]})]})}):null})(),a.awb&&ee[a.id]&&e.jsx("button",{type:"button",className:"com-fisa-btn",onClick:()=>Ma(a),title:`AWB ${a.awb}
28 — print etichetă colet`,children:e.jsxs("span",{className:"com-fisa-lines",children:[e.jsx("span",{className:"com-fisa-w",children:"📦 AWB"}),e.jsx("span",{className:"com-fisa-w",children:a.awb})]})})]}):a.doarFinanciar?a.migratInspre?e.jsx("span",{className:"com-fisa-btn",style:{cursor:"default"},title:`Migrată: ${a.numarComanda} → ${a.migratInspre}`,children:e.jsxs("span",{className:"com-fisa-lines",style:{alignItems:"flex-start"},children:[e.jsxs("span",{className:"com-fisa-w",children:[e.jsx("span",{style:{display:"inline-block",width:20,textAlign:"center",verticalAlign:"-3px"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),e.jsx("path",{d:"M16 17l5-5-5-5"}),e.jsx("path",{d:"M21 12H9"})]})}),a.numarComanda]}),e.jsxs("span",{className:"com-fisa-w",children:[e.jsx("span",{style:{display:"inline-block",width:20,textAlign:"center",verticalAlign:"-3px"},children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{transform:"scaleX(-1)"},children:[e.jsx("path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"}),e.jsx("path",{d:"M16 17l5-5-5-5"}),e.jsx("path",{d:"M21 12H9"})]})}),a.migratInspre]})]})}):e.jsx("span",{className:"com-fisa-empty",children:"—"}):["plasata","preluata"].includes(a.status)?e.jsx("button",{type:"button",className:"com-fisa-btn",onClick:()=>Ta(a.id),title:"Bonul de comandă (print) — îl poți da fizic clientului la magazin",children:"📄 Comandă"}):e.jsx("span",{className:"com-fisa-empty",children:"—"}):e.jsx("span",{className:"com-fisa-empty",children:"—"})}),e.jsx("td",{className:"com-td-actions",children:e.jsxs("div",{className:"com-act-wrap",children:[b("comenzi.edit")&&e.jsx("button",{className:"com-status-btn com-status-btn--primary",onClick:t=>{t.stopPropagation(),Te(a),Fe(""),Xe(""),Me(""),Ne(!1),Ze(!1),Za(a.detaliiFaze||{}),Ja({bijutier:a.atribuiri?.la_bijutier||"",tintuit:a.atribuiri?.la_tintuit||"",finisat:a.atribuiri?.la_finisat||"",gravat:a.atribuiri?.la_gravat||""}),k.get("/api/orders/atribuiri/useri").then(s=>Sa(s.data.map||{})).catch(()=>{})},children:"🔄 Status"}),b("comenzi.edit")&&e.jsx("button",{className:"btn-edit",onClick:()=>nt(a),children:"Editează"}),a.status==="anulata"&&(b("comenzi.edit")||b("comenzi.reactiveaza")&&(parseFloat(a.avans)||0)+(Array.isArray(a.plati)?a.plati.reduce((t,s)=>t+(Number(s.suma)||0),0):0)===0)&&e.jsx("button",{className:"com-status-btn com-react-btn",style:{background:"linear-gradient(135deg,#2e7d32,#1b5e20)",color:"#fff"},title:'Reactivează comanda — o mută din „Anulată" în „Preluată" și își reia cursul normal',onClick:async t=>{t.stopPropagation(),await Ie({title:"Reactivezi comanda?",msg:'Trece din „Anulată" în „Preluată" și își reia cursul normal.',okText:"Da, reactivează",tone:"danger",icon:"♻"})&&lt(a,"preluata")},children:"♻ Reactivează"}),b("comenzi.delete")&&_a&&e.jsx("button",{className:"btn-del",onClick:()=>Qr(a),children:"Șterge"})]})})]},a.id))}),(U.includes("gramaj")||U.includes("pret"))&&le.length>0&&(()=>{const a=le.reduce((u,d)=>u+Ra(d.configuratie?.gramaj),0),t=le.reduce((u,d)=>u+Ra(d.gramajReal),0),s=t>0?+(t-a).toFixed(2):null,r=le.reduce((u,d)=>u+(Number(d.pret)||0),0),n=le.reduce((u,d)=>u+Qt(d),0),o=le.reduce((u,d)=>u+Jt(d),0),l=Math.max(0,+(r-n-o).toFixed(2));return e.jsx("tfoot",{children:e.jsxs("tr",{className:"com-tfoot-gram",children:[e.jsxs("td",{colSpan:4,className:"com-tfoot-label",children:["Σ TOTAL — ",le.length," ",le.length===1?"comandă":"comenzi",se||ie?" · perioada filtrată":""]}),U.includes("gramaj")&&e.jsx("td",{className:"com-td-gram",children:e.jsxs("div",{className:"com-gram-stack",children:[e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"estimat"}),e.jsx("span",{className:"com-gram-est",children:$a(a)})]}),e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"real"}),e.jsx("span",{className:"com-gram-real"+(t>0?"":" pend"),children:t>0?$a(t):"—"})]}),s!=null&&s!==0&&e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"diferență"}),e.jsxs("span",{className:"com-gram-dv "+(s>0?"plus":"minus"),children:[s>
280?"+":"−",Math.abs(s).toLocaleString("ro-RO")," g"]})]})]})}),U.includes("pret")&&e.jsx("td",{className:"com-td-gram",children:e.jsxs("div",{className:"com-gram-stack",children:[e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"estimat"}),e.jsx("span",{className:"com-gram-est",children:De(r)})]}),e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"avans"}),e.jsx("span",{className:"com-gram-real"+(o>0?"":" pend"),children:o>0?De(o):"—"})]}),r>0&&(l>0?e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"rest"}),e.jsx("span",{className:"com-gram-dv plus",children:De(l)})]}):e.jsxs("div",{className:"com-gram-line",children:[e.jsx("span",{className:"com-gram-lbl",children:"rest"}),e.jsx("span",{className:"com-gram-dv minus",children:"achitat ✓"})]}))]})}),e.jsx("td",{colSpan:3})]})})})()]})}),Pr&&e.jsx("div",{className:"com-overlay",onClick:()=>it(!1),children:e.jsxs("div",{className:"com-rapid-popup",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"com-rapid-head",children:[e.jsxs("h3",{children:["⚖️ Coloane gramaj rapide ",e.jsxs(We,{title:"Coloane rapide",children:["Bifează ce vrei să vezi direct în listă, fără să intri în comandă. ",e.jsx("b",{children:"Gramaj"}),' = estimat + real (la „Terminată"). ',e.jsx("b",{children:"Preț"})," = estimat (comandă) + încasat (avans/achitat), cu restul de încasat. Fiecare coloană are total jos și respectă filtrul de dată."]})]}),e.jsx("button",{className:"com-rapid-close",onClick:()=>it(!1),title:"Închide",children:"✕"})]}),e.jsx("div",{className:"com-rapid-list",children:[{k:"gramaj",label:"⚖️ Gramaj (estimat + real)"},{k:"pret",label:"💰 Preț (estimat + încasat)"}].map(a=>e.jsxs("label",{className:`com-rapid-item${U.includes(a.k)?" on":""}`,children:[e.jsx("input",{type:"checkbox",checked:U.includes(a.k),onChange:()=>Lr(a.k)}),e.jsx("span",{children:a.label})]},a.k))}),U.length>0&&e.jsx("button",{type:"button",className:"com-rapid-clear",onClick:()=>{Zt([]);try{localStorage.setItem("comGramajCols","[]")}catch{}},children:"Ascunde toate coloanele"})]})}),(Y==="create"||Y==="edit")&&e.jsx("div",{className:"com-overlay",onClick:Se.tryClose,children:e.jsxs("div",{className:"com-modal",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"com-modal-header",children:[e.jsxs("h2",{children:[Y==="create"?"Comandă nouă":e.jsxs(e.Fragment,{children:["Editare — ",i.sursa==="emag"&&i.emagId?e.jsxs("span",{style:{color:"#1f6feb"},children:["#",i.emagId]}):i.numarComanda||"#"+i.id]}),Y!=="create"&&i.versiune&&i.versiune!=="A"&&e.jsxs("span",{className:"com-rev-badge",title:`Comandă modificată după plasare — versiunea curentă: ${i.versiune}`,children:["rev. ",i.versiune]})]}),e.jsx("button",{className:"modal-close",onClick:Se.tryClose,children:"×"})]}),e.jsx("div",{className:"com-modal-tabs",children:[["general","General"],["produs","Produs"],["note","Note & Istoric"],...Y==="edit"?[["plati","💳 Plăți & Facturi"]]:[]].map(([a,t])=>e.jsx("button",{className:`com-tab ${Re===a?"com-tab--active":""}`,onClick:()=>ba(a),children:t},a))}),e.jsxs("div",{className:"com-modal-body",children:[Y==="edit"&&e.jsxs("div",{className:"com-print-top",children:[e.jsxs("div",{className:"com-plati-actions",children:[e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Ta(i.id),title:"Bonul de comandă (print) — îl poți da fizic clientului",children:"📄 Print comandă"}),!i.doarFinanciar&&(["eliberata","trimisa","platita","completa"].includes(i.status)||i.awb)&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>ct(i),title:"Certificat de autenticitate (PDF) — la eliberare",children:"🏅 Certificat"}),i.awb&&e.jsxs("button",{type:"button",className:"com-fact-btn",onClick:()=>Ma(i),title:`AWB ${i.awb} — print etichetă colet`,children:["📦 AWB ",i.awb]}),e.jsx(We,{title:"Print comandă",children:'🖨 „Print comandă" — bonul fizic pt. client (mereu disponibil). Printul pe faze din popup-ul „Status"; certificatul la eliberare.'})]}),i.awb&&e.jsxs("div",{className:"com-awb-box",style:{marginTop:10,padding:"10px 14px",border:"1px solid #0277bd",borderRadius:8,background:"rgba(2,119,189,.08)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsxs("strong",{style:{color:"#0277bd"},children:["📦 ",i.curier||"Curier"]}),i.curierTest&&e.jsx("span",{style:{background:"#b26a00",color:"#fff",fontSize:".7rem",fontWeight:700,padding:"2px 7px",borderRadius:5},children:"MOD TEST"}),e.jsxs("span",{children:["AWB: ",e.jsx("strong",{children:i.awb})]})]}),i.curierOpt&&e.jsxs("div",{className:"com-newpay-info",style:{marginTop:4},children:[i.curierOpt.service||"Standard"," · ",i.curierOpt.plata==="ramburs"?`Ramburs ${i.curierOpt.ramburs} lei (${i.curierOpt.rambursMod==="plic"?"plic":"cont"})`:"Achitat"," · ",i.curierOpt.livrare==="fanbox"?`${i.sursa==="emag"?"EasyBox":"FANbox"}: ${i.curierOpt.fanbox||"—"}
28`:"La adresă",Array.isArray(i.curierOpt.optiuni)&&i.curierOpt.optiuni.length?" · "+i.curierOpt.optiuni.join(", "):""]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:8,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Ma(i),title:"Etichetă AWB pentru colet",children:"🖨 Print etichetă"}),i.trackingUrl&&e.jsx("a",{className:"com-fact-btn",href:i.trackingUrl,target:"_blank",rel:"noopener noreferrer",style:{textDecoration:"none"},children:"📍 Urmărește coletul"}),i.sursa!=="emag"&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Fa(i,"awb-cheama-curier"),title:"Cheamă curierul pentru ridicare",children:"🚚 Cheamă curier"}),i.sursa!=="emag"&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Fa(i,"awb-borderou"),title:"Borderou expedieri (lista coletelor predate)",children:"📋 Borderou"}),e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>nr(i),title:"Anulează AWB-ul (FAN: în aceeași zi)",style:{borderColor:"#b71c1c",color:"#b71c1c"},children:"🗑 Anulează AWB"})]}),i.curierTest&&e.jsx("div",{className:"com-newpay-info",style:{marginTop:6},children:'AWB generat în mod test (fără API real). Pune curierul pe „live" în Setări când ești gata.'})]})]}),Re==="general"&&e.jsxs("div",{className:"com-form-section",children:[(i.vanzator?.name||i.firmaNume||i.creetatDe)&&e.jsxs("div",{className:"com-meta-line",children:[i.vanzator?.name?e.jsxs("span",{children:["👤 Preluată de ",e.jsx("strong",{children:i.vanzator.name}),i.vanzator.functie?` · ${i.vanzator.functie}`:""]}):e.jsxs("span",{children:["👤 ",i.creetatDe||"—"]}),i.firmaNume&&e.jsxs("span",{children:[" · 🏢 ",e.jsx("strong",{children:i.firmaNume})]})]}),i.migratDin&&e.jsxs("div",{style:{margin:"4px 0 10px",padding:"8px 10px",borderRadius:8,background:"rgba(30,111,235,0.10)",border:"1px solid rgba(30,111,235,0.35)",fontSize:"0.82rem"},children:["🔀 ",e.jsx("b",{children:"Migrată din"})," ",e.jsxs("button",{type:"button",onClick:()=>{const a=(D||[]).find(t=>t.numarComanda===i.migratDin);a?nt(a):y("Comanda "+i.migratDin+" nu e în lista curentă (schimbă filtrul de status).")},style:{background:"none",border:"none",color:p.gold,fontWeight:800,cursor:"pointer",textDecoration:"underline",padding:0},children:["← ",i.migratDin]})," ","— avansul e considerat achitat (fiscal pe cealaltă firmă). Aici se face producția + eliberarea + lichidarea."]}),e.jsxs("div",{className:"prod-row-2",children:[e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Nr. Comandă ",e.jsx("small",{children:"(gol = auto-generat)"})]}),e.jsx("input",{value:i.numarComanda,onChange:a=>ae("numarComanda",a.target.value),placeholder:"ex: CMD-0001"})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Status"}),e.jsx("select",{value:i.status,onChange:a=>ae("status",a.target.value),children:q.map(a=>e.jsx("option",{value:a,children:M[a]||a},a))})]})]}),e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Client ",e.jsx("em",{children:"*"})]}),e.jsx("input",{value:i.client,onChange:a=>ae("client",a.target.value),placeholder:"Numele clientului",autoFocus:!0})]}),e.jsxs("div",{className:"prod-row-2",children:[e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Telefon"}),e.jsx("input",{value:i.telefon,onChange:a=>ae("telefon",a.target.value),placeholder:"+40 7XX XXX XXX"})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Email"}),e.jsx("input",{type:"email",value:i.email,onChange:a=>ae("email",a.target.value),placeholder:"[email protected]"})]})]}),e.jsxs("div",{className:"com-adr-block",children:[e.jsxs("div",{className:"com-adr-head",children:["📍 Adresă de livrare ",e.jsx("small",{children:"— corectează datele clientului dacă a greșit la plasare"})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Stradă, nr."}),e.jsx("input",{value:i.adresa?.strada||"",onChange:a=>je("strada",a.target.value),placeholder:"Str. ... nr. ..., bl., sc., ap."})]}),e.jsxs("div",{className:"prod-row-2",children:[e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Județ",i.livrareMod!=="international"&&na.length>0&&e.jsx("small",{children:" (listă FAN)"})]}),i.livrareMod!=="international"&&na.length>0?e.jsxs("select",{value:i.adresa?.judet||"",onChange:a=>{je("judet",a.target.value),je("oras","")},children:[e.jsx("option",{value:"",children:"— alege județul —"}),i.adresa?.judet&&!na.some(a=>a.name===i.adresa.judet)&&e.jsx("option",{value:i.adresa.judet,children:i.adresa.judet}),na.map(a=>e.jsx("option",{value:a.name,children:a.name},a.id))]}):e.jsx("input",{value:i.adresa?.judet||"",onChange:a=>je("judet",a.target.value),placeholder:"Județ"})]}),e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Localitate",i.livrareMod!=="international"&&la.length>0&&e.jsx("small",{children:" (listă FAN)"})]}),i.livrareMod!=="international"&&la.length>0?e.jsxs("select",{value:i.adresa?.oras||"",onChange:a=>je("oras",a.target.value),children:[e.jsx("option",{value:"",children:"— alege localitatea —"}),i.adresa?.oras&&!la.some(a=>a.name===i.adresa.oras)&&e.jsx("option",{value:i.adresa.oras,children:i.adresa.oras}),la.map(a=>e.jsx("option",{value:a.name,children:a.name},a.name))]}):e.jsx("input",{value:i.adresa?.oras||"",onChange:a=>je("oras",a.target.value),placeholder:i.adresa?.judet?"alege localitatea":"Oraș / localitate"})]})]}),e.jsxs("div",{className:"prod-row-2",children:[e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Cod poștal"}),e.jsx("input",{value:i.adresa?.codPostal||"",onChange:a=>je("codPostal",a.target.value),placeholder:"Cod poștal"})]}),e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Nume destinatar ",e.jsx("small",{children:"(adresă)"})]}),e.jsx("input",{value:i.adresa?.nume||"",onChange:a=>je("nume",a.target.value),placeholder:"Nume pe colet"})]})]})]}),e.jsxs("div",{className:"prod-row-2",children:[e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Preț total (lei)"}),e.jsx("input",{type:"number",value:i.pret,min:0,onChange:a=>ae("pret",parseFloat(a.target.value)||0)})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Avans primit (lei)"}),e.jsx("input",{type:"number",value:i.avans,min:0,onChange:a=>ae("avans",parseFloat(a.target.value)||0)})]})]}),Y==="edit"&&b("comenzi.corectie")&&i.sursa!=="emag"&&!i.doarFinanciar&&!i.migratInspre&&(()=>{const a=Array.isArray(i.breakdown)?i.breakdown.find(n=>n.total):null,t=a&&a.val?a.val:Number(i.pret)||0,s=Number(i.avans)||0,r=Math.round((t-s)*100)/100;return s<=0||r<=0?null:e.jsxs("div",{style:{marginTop:14,padding:"10px 12px",border:`1px dashed ${p.softBd}`,borderRadius:8},children:[e.jsx("div",{style:{fontWeight:700,fontSize:"0.9rem",marginBottom:4},children:"🔀 Migrează comanda pe altă firmă"}),e.jsxs("div",{style:{color:p.dim,fontSize:"0.78rem",marginBottom:8},children:["Închide comanda aici la avans (",e.jsxs("b",{children:[s.toLocaleStr
28ing("ro-RO")," lei"]}),") și mută restul (",e.jsxs("b",{children:[r.toLocaleString("ro-RO")," lei"]}),") pe altă firmă, ca o comandă nouă cu tot fluxul (producție, eliberare, aur). Avansul nu se dublează."]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[e.jsxs("select",{value:Aa,onChange:n=>Ut(n.target.value),disabled:st,style:{padding:"7px 10px",borderRadius:6,border:`1px solid ${p.softBd}`,background:p.inputBg||"transparent",color:p.text||"inherit",fontSize:"0.85rem",minWidth:200},children:[e.jsx("option",{value:"",children:"Alege firma…"}),(ea||[]).filter(n=>String(n.id)!==String(i.firmaId??"")).map(n=>e.jsx("option",{value:n.id,children:n.denumire},n.id))]}),e.jsx("button",{type:"button",className:"com-fact-btn com-fact-btn--emit",disabled:st||!Aa,onClick:()=>Hr(i.id),children:st?"Se migrează…":"🔀 Migrează"})]})]})})(),Y==="edit"&&b("comenzi.corectie")&&i.sursa!=="emag"&&!i.doarFinanciar&&(()=>{const a=Array.isArray(i.breakdown)?i.breakdown.find(o=>o.total):null,t=(Array.isArray(i.corectii)?i.corectii:[]).reduce((o,l)=>o+(Number(l.suma)||0),0),s=a&&a.val?a.val+t:Number(i.pret)||0,r=parseFloat(we),n=we!==""&&!isNaN(r)&&r>=0&&Math.round(r*100)!==Math.round(s*100);return e.jsxs("div",{style:{marginTop:14,padding:"10px 12px",border:`1px dashed ${p.softBd}`,borderRadius:8},children:[e.jsx("div",{style:{fontWeight:700,fontSize:"0.9rem",marginBottom:4},children:"✏️ Ajustează totalul comenzii"}),e.jsxs("div",{style:{color:p.dim,fontSize:"0.78rem",marginBottom:8},children:['Rescrie totalul la o sumă negociată (ex: „îți dau verighetele la 7.500"). Apare curat, ca și cum ăsta a fost prețul de la început — ',e.jsx("b",{children:"fără"})," linie de discount. Restul de plată se recalculează singur. ",e.jsx("i",{children:"(Rotunjirea/discount-ul vizibil se face din Plăți → 🧮 Corecție preț.)"})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[e.jsxs("span",{style:{fontSize:"0.82rem",color:p.dim},children:["Total actual: ",e.jsxs("b",{style:{color:p.text||"inherit"},children:[Math.round(s).toLocaleString("ro-RO")," lei"]})]}),e.jsx("input",{type:"number",min:0,value:we,placeholder:"total nou (ex: 7500)",onChange:o=>qt(o.target.value),disabled:za,style:{padding:"7px 10px",borderRadius:6,border:`1px solid ${p.softBd}`,background:p.inputBg||"transparent",color:p.text||"inherit",fontSize:"0.85rem",width:150}}),e.jsx("input",{value:Ht,placeholder:"motiv (opțional, doar intern)",onChange:o=>Kt(o.target.value),disabled:za,style:{padding:"7px 10px",borderRadius:6,border:`1px solid ${p.softBd}`,background:p.inputBg||"transparent",color:p.text||"inherit",fontSize:"0.85rem",minWidth:160,flex:1}}),e.jsx("button",{type:"button",className:"com-fact-btn com-fact-btn--emit",disabled:za||!n,onClick:()=>Yr(i.id),style:n?{background:"#c9a84c",borderColor:"#b8923a",color:"#1a1208",fontWeight:700}:void 0,children:za?"Se aplică…":n?`✏️ Aplică noul total (${Math.round(s).toLocaleString("ro-RO")} → ${Math.round(r).toLocaleString("ro-RO")} lei)`:"✏️ Aplică noul total"})]})]})})()]}),Re==="produs"&&e.jsxs("div",{className:"com-form-section",children:[e.jsxs("div",{className:"prod-row-2",style:{marginBottom:"0.6rem"},children:[e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Produs"}),e.jsx("input",{value:i.produs,onChange:a=>ae("produs",a.target.value),placeholder:"ex: Verighete din aur galben"})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"SKU"}),e.jsx("input",{value:i.sku,onChange:a=>ae("sku",a.target.value),placeholder:"ex: ATC06"})]})]}),Y==="edit"&&i.sku&&e.jsx("button",{type:"button",className:"com-fact-btn",style:{width:"100%",marginBottom:"1rem",borderColor:"rgba(156,39,176,0.5)",color:"#ce93d8"},onClick:()=>window.open(`/produse/${encodeURIComponent(i.sku)}?reconfig=${i.id}`,"_blank"),title:"Redeschide configuratorul produsului pre-completat; schimbi ce vrei, diferența de preț intră ca regularizare",children:"✏️ Reconfigurează produsul (gravură / culoare / pietre / finisaj…)"}),Y==="edit"&&(()=>{const a=typeof i.configuratie=="object"&&i.configuratie||{},t=tr(a),s=["la_gravat","terminata","la_magazin","eliberata","trimisa","platita","completa"].includes(i.status)||Array.isArray(i.istoricStatus)&&i.istoricStatus.some(r=>r.status==="la_gravat"||r.status==="la_atelier");return e.jsx("div",{className:"com-gravedit",children:Nr?e.jsxs("div",{className:"com-gravedit-panel",children:[e.jsx("div",{className:"com-gravedit-h",children:"✎ Gravură & detalii"}),s&&e.jsx("div",{className:"com-gravedit-warn",children:"⚠ Pies
28a e deja la gravat (sau mai departe) — anunță gravorul de modificare."}),t.map(r=>e.jsxs("label",{className:"com-gravedit-field",children:[e.jsxs("span",{children:["Gravură ",r.label]}),e.jsx("input",{value:Ct[r.key]??"",onChange:n=>kt(o=>({...o,[r.key]:n.target.value})),placeholder:"ex: Alex & Dana · 12.09.2026"})]},r.key)),e.jsxs("label",{className:"com-gravedit-field",children:[e.jsx("span",{children:"Detalii suplimentare"}),e.jsx("textarea",{rows:2,value:At,onChange:r=>zt(r.target.value),placeholder:"ex: cu email negru pe interior"})]}),e.jsxs("div",{className:"com-gravedit-actions",children:[e.jsx("button",{type:"button",className:"com-gravedit-cancel",onClick:()=>Xa(!1),disabled:Ya,children:"Renunță"}),e.jsx("button",{type:"button",className:"com-gravedit-save",onClick:Gr,disabled:Ya,children:Ya?"Se salvează…":"💾 Salvează & propagă"})]})]}):e.jsx("button",{type:"button",className:"com-gravedit-toggle",onClick:Wr,title:"Schimbă textul gravurii sau adaugă un detaliu — se propagă în comandă, fișă și emailuri. Fără comandă nouă.",children:"✎ Modifică gravura & detaliile"})})})(),Array.isArray(i.revizii)&&i.revizii.length>0&&e.jsxs("details",{className:"com-revizii",children:[e.jsxs("summary",{children:["🕑 Versiuni anterioare (",i.revizii.length,") — comanda a fost modificată după plasare"]}),e.jsxs("div",{className:"com-revizii-body",children:[[...i.revizii].reverse().map((a,t)=>{const s=Array.isArray(a.configuratie?._lines)?a.configuratie._lines:a.configuratie?.sel?Object.values(a.configuratie.sel).flatMap(r=>Object.entries(r||{}).map(([n,o])=>`${n}: ${o}`)):[];return e.jsxs("div",{className:"com-rev-item",children:[e.jsxs("div",{className:"com-rev-item-h",children:[e.jsxs("span",{className:"com-rev-badge",children:["rev. ",a.versiune]}),e.jsxs("span",{className:"com-rev-pret",children:[Number(a.pret||0).toLocaleString("ro-RO")," lei"]}),e.jsxs("span",{className:"com-rev-meta",children:[a.data?new Date(a.data).toLocaleString("ro-RO"):"",a.inlocuitDe?` · ${a.inlocuitDe}`:""]})]}),!!s.length&&e.jsx("div",{className:"com-rev-lines",children:s.join(" · ")})]},t)}),e.jsxs("div",{className:"com-rev-note",children:["Versiunea curentă: ",e.jsxs("strong",{children:["rev. ",i.versiune||"B"]}),". Reviziile de mai sus sunt arhivate — nimic nu se pierde."]})]})]}),Array.isArray(i.produse)&&i.produse.length>1&&e.jsxs("div",{className:"com-prod-list",children:[e.jsxs("div",{className:"com-prod-list-h",children:["🛍️ ",i.produse.length," produse în această comandă"]}),i.produse.map((a,t)=>e.jsxs("div",{className:"com-prod-list-row",children:[e.jsxs("span",{className:"com-prod-list-name",children:[t+1,". ",a.name]}),a.sku&&e.jsx("code",{className:"com-sku-code",children:a.sku}),e.jsxs("span",{className:"com-prod-list-pret",children:[Number(a.pret||0).toLocaleString("ro-RO")," lei"]})]},t)),e.jsxs("div",{className:"com-prod-list-note",children:["ℹ Configurația fiecărui produs (damă/bărbat, gravură etc.) se vede pe ",e.jsx("strong",{children:"fișa de producție"})," — o pagină per produs."]})]}),(()=>{const a=typeof i.configuratie=="object"&&i.configuratie||{},t=a.culoriText||"",s=a.photo2||"",r=!!s||t.includes("·"),n=i.photo||"",o=Array.isArray(a._lines)?a._lines:[],l=gs(a),u=l?[]:hs(a);return e.jsxs(e.Fragment,{children:[r&&t&&e.jsxs("div",{className:"com-color-alert",children:["⚠ ",e.jsx("strong",{children:"2 culori diferite"})," — ",t]}),(n||s)&&(()=>{const d=!!(n&&s),v=t.split(" · "),x=v[0]||"Damă",m=v[1]||"Bărbat";return e.jsxs("div",{className:`com-prod-photos${d?" com-prod-photos--dual":" com-prod-photos--single"}`,children:[n&&e.jsxs("div",{className:"com-photo-cell",children:[e.jsx("button",{type:"button",className:"com-photo-zoom",title:"Click — mărește poza",onClick:()=>he(n),children:e.jsx("img",{src:n,alt:"Produs configurat"})}),d&&e.jsx("span",{className:"com-photo-lbl",children:x})]}),s&&e.jsxs("div",{className:"com-photo-cell",children:[e.jsx("button",{type:"button",className:"com-photo-zoom",title:"A 2-a culoare — click, mărește",onClick:()=>he(s),children:e.jsx("img",{src:s,alt:"A 2-a culoare"})}),e.jsx("span",{className:"com-photo-lbl",children:m})]})]})})(),l?e.jsxs("div",{className:"com-cfg-grouped",children:[l.attributes.map((d,v)=>e.jsxs("div",{className:`com-cfg-attr${d.important&&!d.same?" com-cfg-attr--imp":""}`,children:[e.jsxs("div",{className:"com-cfg-attr-h",children:[d.label,d.important&&!d.same?" ⚠":""]}),d.same?e.jsxs("div",{className:"com-cfg-attr-row",children:[e.jsx("span",{className:"com-cfg-it",children:l.items.join(" + ")}),e.jsx("span",{className:"com-cfg-vv",children:d.value||"—"})]}):l.items.map(x=>e.jsxs("div",{className:"com-cfg-attr-row",children:[e.jsx("span",{className:"com-cfg-it",children:x}),e.jsx("span",{className:"com-cfg-vv",children:d.byItem[x]||"—"})]},x))]},v)),l.general.length>0&&e.jsxs("div",{className:"com-cfg-attr",children:[e.jsx("div",{className:"com-cfg-attr-h",children:"General"}),l.general.map((d,v)=>e.jsxs("div",{className:"com-cfg-attr-row",children:[e.jsx("span",{className:"com-cfg-it",children:d.label}),e.jsx("span",{className:/simbol/i.test(String(d.label))?"com-cfg-vv com-cfg-vv--opt":"com-cfg-vv",children:d.value})]},v))]})]}):u.length>0?e.jsx("div",{className:"com-cfg-grouped",children:u.map((d,v)=>e.jsxs("div",{className:"com-cfg-attr",children:[e.jsx("div",{className:"com-cfg-attr-h",children:d.label}),d.rows.map((x,m)=>e.jsxs("div",{className:"com-cfg-attr-row",children:[e.jsx("span",{className:"com-cfg-it",children:x.label}),e.jsx("span",{className:/simbol/i.test(String(x.label))?"com-cfg-vv com-cfg-vv--opt":"com-cfg-vv",children:x.value})]},m))]},v))}):o.length>0?e.jsx("div",{className:"com-cfg-lines",children:o.map((d,v)=>e.jsx("div",{className:/simbol/i.test(String(d))?"com-cfg-line com-cfg-line--opt":"com-cfg-line",children:d},v))}):null,i.pietreInfo&&Object.keys(i.pietreInfo).length>0&&(()=>{const d=v=>{const x=(a.activeItems||[]).find(m=>m&&typeof m=="object"&&m.key===v);return x&&x.label||(v==="dama"?"Damă":v==="barbat"?"Bărbat":v==="_single"?"Pietre":v)};return e.jsxs("div",{className:"com-pietre-calc",children:[e.jsx("div",{className:"com-pietre-calc-h",children:"💎 Pietre (calculate din comandă)"}),Object.entries(i.pietreInfo).map(([v,x],m)=>e.jsxs("div",{className:"com-cfg-attr-row",children:[e.jsx("span",{className:"com-cfg-it",children:d(v)}),e.jsx("span",{className:"com-cfg-vv",children:x.nr>0?`${x.nr}
28 buc${x.mm?" · "+x.mm+" mm":""}`:"fără pietre"})]},m))]})})()]})})()]}),Re==="note"&&e.jsxs("div",{className:"com-form-section",children:[e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Observații (din comandă)"}),e.jsx("textarea",{rows:3,value:i.observatii,onChange:a=>ae("observatii",a.target.value),placeholder:"Note, detalii speciale, instrucțiuni bijutier..."})]}),i.infoPlasare&&e.jsxs("div",{className:"com-newpay-info",style:{marginTop:6},children:["📋 ",e.jsx("b",{children:"Info plasare:"})," ",i.infoPlasare]}),e.jsxs("label",{className:"form-label",style:{marginTop:"12px"},children:[e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"6px"},children:["📝 Notă Internă",e.jsx("small",{style:{color:"#555",fontWeight:400},children:"(vizibilă doar în admin)"})]}),e.jsx("textarea",{rows:4,value:i.notaInterna||"",onChange:a=>ae("notaInterna",a.target.value),placeholder:"Note private despre client, bijutier, termen de livrare...",style:{borderColor:i.notaInterna?"#c9a84c44":void 0}})]}),i.operatii?.length>0&&e.jsxs("div",{className:"com-history",children:[e.jsx("div",{className:"com-history-title",children:"🧾 Istoric operații — cine & ce a făcut"}),[...i.operatii].reverse().map((a,t)=>{const s={creata:"🆕",status:"🔄",plata:"💳",corectie:"🧮",retur:"↩️"}[a.op]||"•";return e.jsxs("div",{className:"com-op-row",children:[e.jsx("span",{className:"com-op-ic",children:s}),e.jsx("span",{className:"com-op-detail",children:a.detail||a.op}),e.jsxs("span",{className:"com-op-by",children:[a.de,a.functie?` · ${a.functie}`:""]}),e.jsx("span",{className:"com-op-time",children:ye(a.la)})]},t)})]}),i.istoricStatus?.length>0&&e.jsxs("div",{className:"com-history",children:[e.jsx("div",{className:"com-history-title",children:"Istoric status"}),[...i.istoricStatus].reverse().map((a,t)=>e.jsxs("div",{className:"com-history-row",children:[e.jsx("span",{className:"com-history-badge",style:{background:ve[a.status]||"#888"},children:M[a.status]||a.status}),e.jsx("span",{className:"com-history-time",children:ye(a.la)}),a.de&&e.jsxs("span",{className:"com-history-by",children:["de ",a.de]})]},t))]})]}),Re==="plati"&&e.jsx("div",{className:"com-form-section com-plati-section",children:dt(i)}),yt&&e.jsx("div",{className:"form-error",children:yt})]}),e.jsxs("div",{className:"com-modal-footer com-modal-footer--big",children:[ja&&e.jsx("span",{className:"footer-flash",children:ja}),Se.isPending?e.jsx(os,{onStay:Se.cancelClose,onExit:Se.forceClose}):e.jsxs(e.Fragment,{children:[Re!=="plati"&&(()=>{const a=Array.isArray(i?.breakdown)?i.breakdown.find(o=>o.total):null,t=(Array.isArray(i?.corectii)?i.corectii:[]).reduce((o,l)=>o+(Number(l.suma)||0),0),s=a&&a.val?a.val+t:Number(i?.pret)||0,r=parseFloat(we),n=b("comenzi.corectie")&&we!==""&&!isNaN(r)&&r>=0&&Math.round(r*100)!==Math.round(s*100);return e.jsx("button",{className:"btn-primary",onClick:Br,disabled:jt||n,title:n?'Ai un total nou în casetă, neaplicat — apasă întâi „Aplică noul total", apoi salvează comanda.':void 0,children:jt?"Se salvează...":n?"💾 Aplică întâi noul total ↑":"💾 Salvează"})})(),e.jsx("button",{className:"btn-cancel",onClick:Se.tryClose,children:"Închide"})]})]})]})}),Rr&&e.jsx("div",{className:"com-overlay com-overlay--aur",onClick:()=>ka(!1),children:e.jsxs("div",{className:"com-modal com-modal--narrow",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"com-modal-header",children:[e.jsx("h2",{children:"🧾 Fișă de cumpărare — aur la schimb"}),e.jsx("button",{className:"modal-close",onClick:()=>ka(!1),children:"×"})]}),e.jsx("div",{className:"com-modal-body",children:e.jsx(ms,{notaNr:Be,setNotaNr:tt,rows:be,setRows:rt,withKarat:!0,litAdd:!0})})]})}),Y==="view"&&e.jsx("div",{className:"com-overlay",onClick:()=>fe(null),children:e.jsxs("div",{className:"com-modal com-modal--actions-top",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"com-modal-header",children:[e.jsxs("h2",{children:["Comandă — ",i.sursa==="emag"&&i.emagId?e.jsxs(e.Fragment,{children:[e.jsxs("span",{style:{color:"#1f6feb"},children:["#",i.emagId]})," ",e.jsxs("span",{className:"com-emag-badge",style:{marginLeft:6,verticalAlign:"middle"},title:`Comandă eMAG.${i.emagPlatform||"ro"} #${i.emagId}`,children:[e.jsx("span",{className:"com-emag-e",children:"e"}),"MAG.",i.emagPlatform||"ro"]})]}):i.numarComanda]}),e.jsx("button",{className:"btn-cancel",onClick:()=>fe(null),children:"← Înapoi"})]}),e.jsxs("div",{className:"com-modal-body",children:[i.awb&&e.jsxs("div",{className:"com-awb-box",style:{marginBottom:12,padding:"10px 14px",border:"1px solid #0277bd",borderRadius:8,background:"rgba(2,119,189,.08)"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsxs("strong",{style:{color:"#0277bd"},children:["📦 ",i.curier||"Curier"]}),i.curierTest&&e.jsx("span",{style:{background:"#b26a00",color:"#fff",fontSize:".7rem",fontWeight:700,padding:"2px 7px",borderRadius:5},children:"MOD TEST"}),e.jsxs("span",{children:["AWB: ",e.jsx("strong",{children:i.awb})]})]}),i.curierOpt&&e.jsxs("div",{className:"com-newpay-info",style:{marginTop:4},children:[i.curierOpt.service||"Standard"," · ",i.curierOpt.plata==="ramburs"?`Ramburs ${i.curierOpt.ramburs} lei (${i.curierOpt.rambursMod==="plic"?"plic":"cont"})`:"Achitat"," · ",i.curierOpt.livrare==="fanbox"?`${i.sursa==="emag"?"EasyBox":"FANbox"}: ${i.curierOpt.fanbox||"—"}
28`:"La adresă",Array.isArray(i.curierOpt.optiuni)&&i.curierOpt.optiuni.length?" · "+i.curierOpt.optiuni.join(", "):""]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:8,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Ma(i),title:"Etichetă AWB pentru colet",children:"🖨 Print etichetă"}),i.trackingUrl&&e.jsx("a",{className:"com-fact-btn",href:i.trackingUrl,target:"_blank",rel:"noopener noreferrer",style:{textDecoration:"none"},children:"📍 Urmărește coletul"}),i.sursa!=="emag"&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Fa(i,"awb-cheama-curier"),title:"Cheamă curierul pentru ridicare",children:"🚚 Cheamă curier"}),i.sursa!=="emag"&&e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>Fa(i,"awb-borderou"),title:"Borderou expedieri (lista coletelor predate)",children:"📋 Borderou"}),e.jsx("button",{type:"button",className:"com-fact-btn",onClick:()=>nr(i),title:"Anulează AWB-ul (FAN: în aceeași zi)",style:{borderColor:"#b71c1c",color:"#b71c1c"},children:"🗑 Anulează AWB"})]}),i.curierTest&&e.jsx("div",{className:"com-newpay-info",style:{marginTop:6},children:'AWB generat în mod test (fără API real). Pune curierul pe „live" în Setări când ești gata.'})]}),e.jsxs("div",{className:"com-view-grid",children:[e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Status"}),e.jsx("span",{className:"com-badge",style:{background:ve[i.status]||"#888"},children:M[i.status]||i.status})]}),i.termenEliberare&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Termen eliberare"}),e.jsxs("span",{className:"com-termen-badge",title:"Termen de eliberare (calendar atelier)",children:[e.jsx(mt,{})," ",re(i.termenEliberare)]})]}),e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Client"}),e.jsx("strong",{children:sa(i.client)})]}),i.telefon&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Telefon"}),e.jsx("span",{children:i.telefon})]}),i.email&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Email"}),e.jsx("span",{children:i.email})]}),Array.isArray(i.produse)&&i.produse.length>1?e.jsxs("div",{className:"com-view-row",children:[e.jsxs("span",{className:"com-vl",children:["Produse (",i.produse.length,")"]}),e.jsx("span",{children:i.produse.map((a,t)=>e.jsxs("div",{style:{padding:"2px 0"},children:[t+1,". ",a.name," ",a.sku&&e.jsxs("code",{children:["(",a.sku,")"]})," — ",e.jsxs("strong",{children:[Number(a.pret||0).toLocaleString("ro-RO")," lei"]})]},t))})]}):i.produs&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Produs"}),e.jsxs("span",{children:[i.produs," ",i.sku&&e.jsxs("code",{children:["(",i.sku,")"]})]})]}),i.pret>0&&(()=>{const a=Array.isArray(i.breakdown)?i.breakdown.find(n=>n.total):null,t=(Array.isArray(i.corectii)?i.corectii:[]).reduce((n,o)=>n+(Number(o.suma)||0),0),s=a&&a.val?a.val:(i.pret||0)-t,r=s+t;return e.jsxs(e.Fragment,{children:[t!==0&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Preț inițial"}),e.jsxs("span",{children:[s.toLocaleString("ro-RO")," lei"]})]}),t!==0&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"🧮 Corecție aplicată"}),e.jsxs("span",{style:{color:t<0?"#2e7d32":"#e0a020"},children:[t<0?"− ":"+ ",Math.abs(t).toLocaleString("ro-RO")," lei"]})]}),e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Preț total"}),e.jsxs("span",{className:"com-vl-price",children:[r.toLocaleString("ro-RO")," lei"]})]})]})})(),i.avans>0&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Avans primit"}),e.jsxs("span",{children:[i.avans.toLocaleString("ro-RO")," lei"]})]}),i.cardDiscountApplied&&i.cardDiscount>0&&e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Bonus card (aplicat)"}),e.jsxs("span",{style:{color:"#2e7d32"}
28,children:["−",Number(i.cardDiscount).toLocaleString("ro-RO")," lei"]})]}),i.pret>0&&i.avans>0&&(()=>{const a=Array.isArray(i.breakdown)?i.breakdown.find(n=>n.total):null,t=(Array.isArray(i.corectii)?i.corectii:[]).reduce((n,o)=>n+(Number(o.suma)||0),0),r=(a&&a.val?a.val+t:i.pret||0)-(i.cardDiscountApplied&&i.cardDiscount||0);return e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Rest de plată"}),e.jsxs("span",{className:r-i.avans>0?"com-vl-rest":"com-vl-paid",children:[(r-i.avans).toLocaleString("ro-RO")," lei"]})]})})(),i.sursa==="emag"&&(()=>{const a=i.emagPlatit??i.emag?.platit,t=i.emagRamburs??i.emag?.ramburs,s=i.emagMetodaPlata||i.emag?.plata||(t?"Ramburs":"Card online"),r=Number(i.pret)||0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Achitat"}),e.jsx("span",{style:{color:a?"#2e7d32":"#b8791b",fontWeight:700},children:a?`${r.toLocaleString("ro-RO")} lei · ${s}`:`0 lei · ${s} (la livrare)`})]}),e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Rest de plată"}),e.jsx("span",{className:a?"com-vl-paid":"com-vl-rest",children:a?"0 lei · achitat ✓":`${r.toLocaleString("ro-RO")} lei · încasează curierul eMAG.ro`})]})]})})(),Array.isArray(i.plati)&&i.plati.length>0&&e.jsxs("div",{className:"com-view-row com-view-row--obs",id:"view-plati",children:[e.jsx("span",{className:"com-vl",children:"Plăți înregistrate"}),e.jsx("span",{style:{display:"flex",flexDirection:"column",gap:"4px",flex:1},children:i.plati.map((a,t)=>{const s=(i.facturi||[]).find(r=>r.plataRef===a.ref);return e.jsxs("span",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:"8px",fontSize:"0.85rem",flexWrap:"wrap"},children:[e.jsxs("span",{style:{color:"#888",minWidth:0},children:["Plata ",t+1,a.data?` · ${ye(a.data)}`:""]}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsxs("span",{style:{color:"#2e7d32",fontWeight:600},children:[(a.suma||0).toLocaleString("ro-RO")," lei"]}),s?e.jsxs("button",{type:"button",onClick:()=>ta(i.id,s.numar),style:{background:"rgba(201,168,76,.12)",border:"1px solid rgba(201,168,76,.4)",color:"#c9a84c",borderRadius:6,padding:"2px 8px",fontSize:"0.72rem",cursor:"pointer",whiteSpace:"nowrap"},title:`${s.tipLabel||"Factură"} ${s.serie}-${s.numar}`,children:["🧾 ",s.serie,"-",s.numar]}):null]})]},t)})})]}),i.observatii&&e.jsxs("div",{className:"com-view-row com-view-row--obs",children:[e.jsx("span",{className:"com-vl",children:"Observații"}),e.jsx("span",{children:i.observatii})]}),i.infoPlasare&&e.jsxs("div",{className:"com-view-row com-view-row--obs",children:[e.jsx("span",{className:"com-vl",children:"📋 Info plasare"}),e.jsx("span",{children:i.infoPlasare})]}),i.corectieGramaj?.nota&&e.jsxs("div",{className:"com-view-row com-view-row--obs",children:[e.jsx("span",{className:"com-vl",children:"⚖️ Corecție gramaj"}),e.jsx("span",{children:i.corectieGramaj.nota})]}),e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Creat la"}),e.jsx("span",{children:ye(i.createdAt)})]}),e.jsxs("div",{className:"com-view-row",children:[e.jsx("span",{className:"com-vl",children:"Creat de"}),e.jsx("span",{children:i.creetatDe||"—"})]})]}),i.istoricStatus?.length>0&&e.jsxs("div",{className:"com-history",children:[e.jsx("div",{className:"com-history-title",children:"Flux producție"}),e.jsx("div",{className:"com-history-timeline",children:i.istoricStatus.map((a,t)=>e.jsxs("div",{className:"com-hist-step",children:[e.jsx("div",{className:"com-hist-dot",style:{background:ve[a.status]||"#888"}}),e.jsxs("div",{className:"com-hist-content",children:[e.jsx("span",{className:"com-history-badge",style:{background:ve[a.status]||"#888"},children:M[a.status]||a.status}),e.jsx("span",{className:"com-history-time",children:ye(a.la)}),a.de&&e.jsxs("span",{className:"com-history-by",children:["— ",a.de]})]})]},t))})]})]}),e.jsxs("div",{className:"com-modal-footer com-modal-footer--fill",children:[e.jsxs("div",{className:"com-footer-support",children:[e.jsxs("button",{className:"btn-print",onClick:()=>Ta(i.id),title:"Print bon comandă (PDF)",children:["🖨 Print",e.jsx("br",{}),"comandă"]}),b("comenzi.edit")&&i.email&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn-act-o btn-o-cyan",disabled:Ca==="confirmare",onClick:()=>sr(i.id,"confirmare"),children:Ca==="confirmare"?"…":e.jsxs(e.Fragment,{children:["✉ Retrimite",e.jsx("br",{}),"comandă"]})}),e.jsx("button",{className:"btn-act-o btn-o-purple",disabled:Ca==="status",onClick:()=>sr(i.id,"status"),children:Ca==="status"?"…":e.jsxs(e.Fragment,{children:["✉ Retrimite",e.jsx("br",{}),"statusul"]})})]}),(()=>{const a=(i.plati||[]).filter(s=>s.metoda==="aur_schimb"&&s.aur),t=a[a.length-1];return t?e.jsxs("button",{type:"button",className:"btn-act-o btn-o-amber",onClick:()=>ir(i.id,t.ref),title:"Print bon de cumpărare aur — ultima fișă (aurul adus la schimb)",children:["🟨 Bon aur",e.jsx("br",{}),"achiziție"]}):null})(),!i.doarFinanciar&&(["eliberata","trimisa","platita","completa"].includes(i.status)||i.awb)&&e.jsxs("button",{type:"button",className:"btn-act-o btn-o-green",onClick:()=>ct(i),title:"Certificat de garanție (PDF)",children:["🖨 Certificat",e.jsx("br",{}),"garanție"]})]}
28),b("comenzi.edit")&&e.jsxs("button",{className:"com-act com-act--pay",title:"Încasează / adaugă plată",onClick:()=>{fe("edit"),ba("plati")},children:["💰 Plăți",e.jsx("br",{}),"și facturi"]})]})]})}),g&&e.jsx("div",{className:"com-overlay com-overlay--top",children:e.jsxs("div",{className:"com-status-pop",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"com-status-pop-h",children:[e.jsxs("span",{children:["🔄 Schimbă status — ",e.jsx("strong",{style:g.sursa==="emag"?{color:"#1f6feb"}:void 0,children:g.sursa==="emag"&&g.emagId?`#${g.emagId}`:g.numarComanda})]}),e.jsxs("div",{className:"com-status-pop-h-right",children:[b("comenzi.status.override")&&(Array.isArray(ia[g.status])&&ia[g.status].length?e.jsx("button",{type:"button",className:`com-status-showall${ya?" on":""}`,onClick:()=>Ze(t=>!t),title:"Caz extrem: arată TOATE statusurile (ex. anulată → înapoi în flux), nu doar cele din flux",children:ya?"🎯 Doar relevante":"🔓 Toate statusurile"}):null),e.jsx("button",{type:"button",className:"modal-close",onClick:()=>Te(null),title:"Închide",children:"×"})]})]}),e.jsx("div",{className:"com-status-acc",children:(()=>{const a=ya?null:Array.isArray(ia[g.status])?ia[g.status]:null;return q.filter(t=>(ya||t!==g.status)&&(!a||!a.length||a.includes(t))&&!(t==="completa"&&!b("comenzi.status.completa")))})().map(a=>{const t=G===a,s=Pe[a],r=Pt.includes(a);let n=s?Je(s):r?Ot():[];const o=g.atribuiri&&g.atribuiri[a];return o&&(n=[...n.filter(l=>l.name===o),...n.filter(l=>l.name!==o)]),e.jsxs("div",{id:`status-acc-${a}`,className:`com-status-item${t?" com-status-item--open":""}`,children:[e.jsxs("button",{type:"button",className:"com-status-row",style:{"--dc":ve[a]||"#888"},onClick:()=>{const l=!t;if(Fe(l?a:""),Xe(""),ga(!1),Me(l&&Qa.includes(a)&&n.length===1?n[0].name:""),l&&["la_atelier","la_bijutier","la_tintuit","la_finisat","la_gravat"].includes(a)&&Tt(g.urgentFisa!==void 0?g.urgentFisa!==!1:wr),l&&a==="preluata"&&(xa(g.termenEliberare||""),ht(null),k.get(`/api/orders/${g.id}/termen-sugerat`).then(u=>
28{ht(u.data),g.termenEliberare||xa(u.data.date||"")}).catch(()=>{})),l&&a==="terminata"){da({...g.ctcChecks||{}});const u=g.gramajReal||{};ze({female:u.female??"",male:u.male??"",pair:u.pair??""}),ua(!1),ha("")}if(l&&a==="trimisa"){const u=Array.isArray(g.breakdown)?g.breakdown.find(c=>c.total):null,d=(Array.isArray(g.corectii)?g.corectii:[]).reduce((c,j)=>c+(Number(j.suma)||0),0),v=u&&u.val?u.val+d:g.pret||0,x=Math.max(0,v-(g.avans||0)),m=g.sursa==="emag",f=m&&!g.emagPlatit&&g.emagRamburs,S=m?f?v:0:x,P=["A se contacta telefonic"],T=m&&(g.emag?.livrareMod==="pickup"||g.curierOpt?.livrareLa==="easybox"),te=m&&(g.emag?.lockerId||g.curierOpt?.locker)||"";ca({service:"Standard",plata:m?f?"ramburs":"achitat":S>0?"ramburs":"achitat",ramburs:S,rambursMod:"cont",livrare:T?"fanbox":"adresa",fanbox:te,uit:"",optiuni:P,colete:0,plicuri:1,asigurare:0,formatAwb:"A4"});const Q=g.livrareMod==="international"||g.curierPref==="dhl",E=m?ce.find(c=>c.provider==="sameday")||ce.find(c=>/sameday/i.test(c.label||""))||ce[0]:Q?ce.find(c=>c.provider==="dhl"):ce.find(c=>c.provider&&c.provider!=="dhl")||ce[0];Ua(E?.label||"")}if(l&&a==="eliberata"){const u=Array.isArray(g.breakdown)?g.breakdown.find(m=>m.total):null,d=(Array.isArray(g.corectii)?g.corectii:[]).reduce((m,f)=>m+(Number(f.suma)||0),0),v=u&&u.val?u.val+d:g.pret||0,x=Math.max(0,v-(g.avans||0));gr({metoda:Ce[0]?.id||"numerar",suma:x>0?String(x):""})}},children:[e.jsx("span",{className:"com-dropdown-dot"}),e.jsxs("span",{className:"com-status-row-lbl",children:[M[a]||a,a===g.status?" · curent (re-trimite)":"",g.sursa==="emag"&&a==="returnata"?" · stornată la ei":""]}),g.sursa==="emag"&&["preluata","trimisa","eliberata","anulata","returnata"].includes(a)&&e.jsxs("span",{title:a==="trimisa"||a==="eliberata"?`Cuplat cu eMAG.${g.emagPlatform||"ro"} — finalizează comanda la ei (Finalizată) + AWB`:`Cuplat cu eMAG.${g.emagPlatform||"ro"} — la acest status se schimbă automat și la ei (prin API)`,style:{marginLeft:8,background:"#1f6feb",color:"#fff",fontSize:"0.6rem",fontWeight:700,padding:"1px 6px",borderRadius:4,letterSpacing:".3px",whiteSpace:"nowrap"},children:["eMAG.",g.emagPlatform||"ro"," ⇄"]}),e.jsx("span",{className:"com-status-caret",children:t?"▲":"▾"})]}),t&&e.jsxs("div",{className:"com-status-opts",children:[Lt[a]&&e.jsxs("div",{className:"com-newpay-info",style:{display:"flex",gap:8,alignItems:"flex-start",background:"rgba(201,168,76,.1)",borderLeft:"3px solid #c9a84c",padding:"10px 12px",borderRadius:6,marginBottom:10,lineHeight:1.5},children:[e.jsx("span",{children:"ℹ️"}),e.jsx("span",{children:Lt[a]})]}),Qa.includes(a)&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"form-label",id:"assignee-box",children:[e.jsxs("span",{children:["👤 ",s?`Atribuie ${s}`:"Cine a făcut operația",n.length>0?e.jsx("span",{style:{color:"#e05a4a"},children:" *"}):""]}),e.jsxs("select",{value:Ye,style:n.length>0&&!Ye?{borderColor:"#e05a4a",boxShadow:"0 0 0 2px rgba(224,90,74,.25)"}:void 0,onChange:l=>{Me(l.target.value),l.target.value&&Ne(!1)},children:[e.jsx("option",{value:"",children:s?`— alege ${s.toLowerCase()} —`:"— alege userul —"}),n.map(l=>e.jsx("option",{value:l.name,children:l.name},l.id))]}),n.length>0&&!Ye&&e.jsx("span",{style:{color:"#e05a4a",fontSize:".78rem",marginTop:4},children:"⚠ Obligatoriu — alege cine a făcut operația (pentru istoric)"})]}),s&&n.length===0&&e.jsxs("div",{className:"com-newpay-info",children:["Niciun user „",s,'". Creează-l în Useri → Tipuri de useri și atribuie-l.']})]}),["la_atelier","la_bijutier","la_tintuit","la_finisat","la_gravat"].includes(a)&&e.jsxs("div",{style:{background:"rgba(176,125,26,.08)",border:"1px solid rgba(176,125,26,.35)",borderRadius:8,padding:10,marginBottom:10},children:[e.jsxs("div",{style:{fontWeight:700,color:p.amber,fontSize:".82rem",marginBottom:6},children:["🧩 Repartizează detaliile pe operații ",a==="la_atelier"?"(mod rapid)":""]}),(()=>{const l=kr(g);return l?e.jsxs("div",{style:{fontSize:".8rem",background:p.noteBg,border:"1px solid "+p.noteBd,borderRadius:6,padding:"7px 9px",marginBottom:8,color:p.noteTxt,lineHeight:1.5},children:[e.jsx("b",{children:"Detalii client:"})," ",l]}):e.jsx("div",{className:"com-newpay-info",style:{marginBottom:8},children:"Clientul n-a scris detalii speciale — completează manual mai jos dacă e cazul."})})(),et.filter(l=>
28a==="la_atelier"||l.k===a.replace("la_","")).map(l=>{const u=Pe["la_"+l.k],d=Je(u),v=Na[l.k]||(d.length===1?d[0].name:""),x=a==="la_atelier"&&d.length>=2&&!Na[l.k];return e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:[l.l,a==="la_atelier"&&d.length>0?e.jsxs("span",{style:{color:x?"#e05a4a":"#8a8578",fontWeight:600},children:[" · ",u,d.length>=2?" *":""]}):""]}),a==="la_atelier"&&d.length>0&&e.jsxs("select",{id:"detfaza-"+l.k,value:v,style:{marginBottom:5,...x?{borderColor:"#e05a4a",boxShadow:"0 0 0 2px rgba(224,90,74,.25)"}:{}},onChange:m=>Ja(f=>({...f,[l.k]:m.target.value})),children:[e.jsxs("option",{value:"",children:["— alege ",u.toLowerCase()," —"]}),d.map(m=>e.jsx("option",{value:m.name,children:m.name},m.id))]}),e.jsx("textarea",{rows:2,value:Rt[l.k]||"",onChange:m=>Za(f=>({...f,[l.k]:m.target.value})),placeholder:"— gol = nu apare pe fișă —"})]},l.k)}),e.jsx("div",{style:{fontSize:".72rem",color:"#8a8578",marginTop:4},children:"Ce nu aloci rămâne ascuns (nu apare pe fișă). Se salvează cu butonul de status de jos."})]}),a==="preluata"&&e.jsxs("div",{className:"com-termen-box",children:[e.jsx("div",{className:"com-termen-h",children:"📅 Termen de eliberare"}),de?e.jsxs("div",{className:"com-termen-sug",children:["Sugerat de calendar: ",e.jsx("b",{children:re(de.date)}),e.jsxs("span",{className:"com-termen-meta",children:[" · ",de.tip," · ",de.zileExecutie," zile lucru + ",de.marjaTampon," tampon",de.ocupareZi>0?` · ${de.ocupareZi}/${de.capacitateZi} ocupat în zi`:""]}),!de.activ&&e.jsx("span",{className:"com-termen-off",children:" (calendar inactiv — se calculează, dar nu blochează)"})]}):e.jsx("div",{className:"com-termen-sug",children:"Se calculează termenul sugerat…"}),e.jsxs("label",{className:"form-label",style:{marginTop:8},children:[e.jsx("span",{children:"Data eliberării"}),e.jsxs("button",{type:"button",className:"com-termen-field",onClick:()=>fa(!0),children:[e.jsx("span",{className:Ve?"":"com-termen-field-ph",children:Ve?re(Ve):"📅 Apasă pentru a alege din calendar…"}),e.jsx(mt,{})]})]}),fr&&e.jsx(us,{orderId:g.id,value:Ve,onPick:l=>{xa(l),fa(!1)},onClear:()=>{xa(""),fa(!1)},onClose:()=>fa(!1)}),e.jsx("div",{style:{fontSize:".72rem",color:"#8a8578",marginTop:4},children:"Termenul apare în comandă, pe fișă și sub data plasării în listă. Îl poți schimba oricând."})]}),a==="terminata"&&(()=>{const l=Array.isArray(g.configuratie?.activeItems)?g.configuratie.activeItems:[],u=l.length>=2?l.map((w,R)=>({k:`item_${R}`,l:`📦 ${w.label||w.key||"Articol "+(R+1)}`})):[],d=[...gt,...u],v=w=>{ga(!1),da(R=>({...R,[w]:!R[w]}))},x=d.length>0&&d.every(w=>oa[w.k]),m=()=>{ga(!1);const w=!x,R={};d.forEach(ke=>{R[ke.k]=w}),da(ke=>({...ke,...R}))},f=l.length>=2,S=f?l[0]?.label||l[0]?.key||"Damă":"Produs",P=f?l[1]?.label||l[1]?.key||"Bărbat":"",T=g.configuratie?.gramaj&&typeof g.configuratie.gramaj=="object"?g.configuratie.gramaj:{},te=Number(T.female)||Number(g.weightFemale)||0,Q=Number(T.male)||Number(g.weightMale)||0,E=Number(T.pair)||Number(g.weightPair)||te+Q||0,c=W.female!==""&&W.female!=null||W.male!==""&&W.male!=null,j=(Number(W.female)||0)+(Number(W.male)||0),N=f&&c?j:Number(W.pair)||0,B=String(g.configuratie?.sel?.dama?.material||""),K=String(g.configuratie?.sel?.barbat?.material||""),I=f&&!!B&&!!K&&B!==K,Ee=String(g.configuratie?.material||"").toLowerCase();return/argint/.test(Ee)?Number(Va.gram_argint):/18\s*k|750/.test(Ee)?Number(Va.gram_aur_18k):Number(Va.gram_aur_14k),e.jsxs(e.Fragment,{children:[e.jsxs("div",{id:"gramaj-box",style:{background:oe?"rgba(224,90,90,.10)":"rgba(201,168,76,.06)",border:`1px solid ${oe?"#e05a5a":"rgba(201,168,76,.3)"}`,borderRadius:8,padding:10,marginBottom:10},children:[e.jsxs("div",{style:{fontWeight:700,color:p.gold,fontSize:".82rem",marginBottom:6},children:["⚖️ Gramaj real — de pe cântar ",e.jsxs("span",{style:{color:p.dim,fontWeight:500},children:["(estimat la comandă: ",E.toFixed(2)," g)"]})]}),(I||oe)&&e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"flex-start",marginBottom:8,padding:"8px 10px",borderRadius:7,lineHeight:1.5,fontSize:".8rem",background:oe?"rgba(224,90,90,.12)":p.infoBg,border:`1px solid ${oe?"rgba(224,90,90,.5)":p.infoBd}`,color:oe?p.errTxt:p.infoTxt},children:[e.jsx("span",{style:{fontSize:"1rem",lineHeight:1.2},children:oe?"⚠":"ℹ️"}),e.jsxs("div",{children:[I?e.jsxs(e.Fragment,{children:[e.jsx("b",{style:{color:oe?p.errTxt:p.infoStrong},children:"Titluri diferite"})," (",S," ",B," · ",P," ",K,") — cântărește ",e.jsx("b",{children:"AMBELE piese separat"})," și pune gramajul ",e.jsx("b",{children:"individual"}),". Totalul e blocat și se face automat, iar în gestiune fiecare piesă se convertește pe titlul ei (14K)."]}):f?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Obligatoriu:"})," pune ",S," + ",P,", sau doar totalul perechii."]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{children:"Obligatoriu:"})," pune gramajul real de pe cântar."]}),oe&&e.jsxs(e.Fragment,{children:[" Fără gramajul real, ",e.jsx("b",{children:"gestiunea de aur nu scade corect"})," și ",e.jsx("b",{children:"certificatul iese greșit"}),"."]})]})]}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[e.jsxs("label",{className:"form-label",style:{flex:1,minWidth:110},children:[e.jsxs("span",{children:[S," (g)",te>0&&e.jsxs("span",{style:{color:p.gold,fontWeight:600},children:[" · estimat ~",te.toFixed(2)," g"]})]}),e.jsxs("span",{style:{position:"relative",display:"block"},children:[e.jsx("span",{style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",display:"flex",pointerEvents:"none"},children:e.jsx(Oa,{})}),e.jsx("input",{type:"number",step:"0.01",min:"0",style:{paddingLeft:38},value:W.female,onChange:w=>{_e(!1),ze(R=>({...R,female:w.target.value,pair:""}))},placeholder:"de pe cântar"})]})]}),e.jsxs("label",{className:"form-label",style:{flex:1,minWidth:110},children:[e.jsxs("span",{children:[P," (g)",Q>0&&e.jsxs("span",{style:{color:p.gold,fontWeight:600},children:[" · estimat ~",Q.toFixed(2)," g"]})]}),e.jsxs("span",{style:{position:"relative",display:"block"},children:[e.jsx("span",{style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",display:"flex",pointerEvents:"none"},children:e.jsx(Oa,{})}),e.jsx("input",{type:"number",step:"0.01",min:"0",style:{paddingLeft:38},value:W.male,onChange:w=>{_e(!1),ze(R=>({...R,male:w.target.value,pair:""}))},placeholder:"de pe cântar"})]})]})]}),e.jsxs("label",{className:"form-label",style:{marginTop:8}
28,children:[!I&&e.jsxs("span",{children:["Total pereche (g)",c?e.jsxs("span",{style:{color:p.dim,fontWeight:500},children:[" — auto din ",S," + ",P]}):e.jsx("span",{style:{color:p.dim,fontWeight:500},children:" — sau pune direct totalul (cântărite împreună)"})]}),e.jsxs("span",{style:{position:"relative",display:"block"},children:[e.jsx("span",{style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",display:"flex",pointerEvents:"none",opacity:I||c?.6:1},children:e.jsx(Oa,{})}),e.jsx("input",{type:"number",step:"0.01",min:"0",value:I?j>0?j.toFixed(2):"":c?j.toFixed(2):W.pair,readOnly:I||c,onChange:w=>{_e(!1),ze(R=>({...R,pair:w.target.value}))},placeholder:I?"Total pereche — se completează singur din cele două":"de pe cântar (ambele împreună)",style:I||c?{paddingLeft:38,opacity:.7,cursor:"not-allowed",fontWeight:700}:{paddingLeft:38}})]})]})]}):e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Gramaj total (g)",E>0&&e.jsxs("span",{style:{color:p.gold,fontWeight:600},children:[" · estimat la comandă ~",E.toFixed(2)," g"]})]}),e.jsxs("span",{style:{position:"relative",display:"block"},children:[e.jsx("span",{style:{position:"absolute",left:10,top:"50%",transform:"translateY(-50%)",display:"flex",pointerEvents:"none"},children:e.jsx(Oa,{})}),e.jsx("input",{type:"number",step:"0.01",min:"0",style:{paddingLeft:38},value:W.pair,onChange:w=>{_e(!1),ze(R=>({...R,pair:w.target.value}))},placeholder:"gramajul de pe cântar"})]})]}),(E>0||N>0)&&e.jsxs("div",{style:{marginTop:8,fontSize:".85rem"},children:[E?e.jsxs("div",{style:{display:"flex",gap:10,padding:"3px 0",color:p.dim},children:[e.jsxs("b",{style:{minWidth:78,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[E.toFixed(2)," g"]}),e.jsx("span",{children:"— Estimat inițial la comandă"})]}):null,N>0&&e.jsxs("div",{style:{display:"flex",gap:10,padding:"3px 0",color:p.txt},children:[e.jsxs("b",{style:{minWidth:78,textAlign:"right",color:p.gold,fontVariantNumeric:"tabular-nums"},children:[N.toFixed(2)," g"]}),e.jsx("span",{children:"— Real cântărit pe cântar"})]}),E>0&&N>0&&N!==E&&(()=>{const w=N-E,R=w<0;return e.jsxs("div",{style:{display:"flex",gap:10,paddingTop:1,color:R?p.green:p.warn},children:[e.jsxs("b",{style:{minWidth:78,textAlign:"right",fontVariantNumeric:"tabular-nums"},children:[R?"−":"+",Math.abs(w).toFixed(2)," g"]}),e.jsx("span",{children:"— versus estimarea inițială"})]})})()]})]}),e.jsxs("div",{style:{background:p.softBg,border:"1px solid "+p.softBd,borderRadius:8,padding:10,marginBottom:10},children:[e.jsxs("div",{style:{fontWeight:700,color:p.dim2,fontSize:".82rem",marginBottom:6,lineHeight:1.45},children:["💰 Preț final ",e.jsxs("span",{style:{fontWeight:500,color:p.dim},children:["— dacă nu atingi nimic mai jos, prețul se recalculează singur din gramajul real ",e.jsx("b",{style:{color:p.green},children:"(corect pentru client)"}),": piesa ",e.jsx("b",{style:{color:p.green},children:"mai ușoară"})," decât estimatul → primește diferența înapoi (storno); ",e.jsx("b",{style:{color:p.warn},children:"mai grea"})," → o achită în plus."]})]}),e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",fontSize:".85rem",color:p.txt,flex:"1 1 46%",minWidth:180},children:[e.jsx("input",{type:"checkbox",checked:ma,onChange:w=>{ua(w.target.checked),w.target.checked&&ha("")},style:{width:"auto",flexShrink:0}}),e.jsx("span",{children:"Păstrez prețul, nu dau nimic înapoi"})]}),e.jsx("input",{type:"number",min:"0",value:pa,disabled:ma,onChange:w=>{ha(w.target.value),w.target.value&&ua(!1)},placeholder:"sau: dau ce sumă vreau eu",style:{flex:"1 1 46%",minWidth:160,opacity:ma?.5:1}})]})]}),e.jsxs("div",{id:"ctc-box",style:{background:Ue?"rgba(183,28,28,.1)":"rgba(46,125,50,.08)",border:Ue?"2px solid #e0534f":"1px solid rgba(46,125,50,.3)",boxShadow:Ue?"0 0 0 3px rgba(224,83,79,.25)":"none",borderRadius:8,padding:10,marginBottom:10},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,marginBottom:6},children:[e.jsx("span",{style:{fontWeight:700,color:Ue?p.errTxt:"#2e7d32",fontSize:".82rem"},children:"✓ Verificare CTC — obligatoriu"}),e.jsx("button",{type:"button",onClick:m,style:{background:x?"rgba(46,125,50,.3)":"rgba(46,125,50,.14)",border:"1px solid rgba(46,125,50,.5)",color:p.green,borderRadius:6,padding:"3px 10px",cursor:"pointer",fontSize:".76rem",fontWeight:700,whiteSpace:"nowrap"},children:x?"✓ Tot OK":"Bifează tot"})]}),Ue&&e.jsx("div",{style:{color:p.errTxt,fontSize:".8rem",fontWeight:700,margin:"0 0 6px"},children:'⚠ Bifează toate verificările (sau apasă „Bifează tot") ca să poți salva.'}),d.map(w=>e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"4px 0",cursor:"pointer",fontSize:".88rem"},children:[e.jsx("input",{type:"checkbox",checked:!!oa[w.k],onChange:()=>v(w.k),style:{width:"auto"}}),e.jsx("span",{children:w.l})]},w.k))]})]})})(),a==="eliberata"&&e.jsxs("div",{style:{marginBottom:10},children:[e.jsx("div",{style:{fontWeight:700,color:"#c9a84c",fontSize:".82rem",marginBottom:8},children:'🏪 Eliberare la magazin — încasează restul (orice metodă), apoi „📦 Eliberează" jos'}),dt(g)]}),s||r?e.jsx(e.Fragment,{children:a==="trimisa"&&e.jsxs(e.Fragment,{children:[(()=>{const l=D.find(f=>f.id===g.id)||g,u=Array.isArray(l.breakdown)?l.breakdown.find(f=>f.total):null,d=(Array.isArray(l.corectii)?l.corectii:[]).reduce((f,S
28)=>f+(Number(S.suma)||0),0),v=Math.max(0,(u&&u.val?u.val+d:l.pret||0)-(l.avans||0)),x=l.sursa==="emag",m=x?0:v;return e.jsxs("div",{style:{border:"1px solid rgba(201,168,76,.3)",borderRadius:8,marginBottom:8,background:"rgba(201,168,76,.04)"},children:[e.jsxs("button",{type:"button",onClick:()=>hr(f=>!f),style:{width:"100%",display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,background:"none",border:"none",padding:"10px 12px",cursor:"pointer",color:!x&&m>0?"#e05a4a":"#2e7d32",fontWeight:700,fontSize:".86rem",fontFamily:"inherit"},children:[e.jsx("span",{children:x?`💳 Plată eMAG.ro · ${l.emagPlatit?"achitată (nu se încasează aici)":"ramburs — încasează Sameday la livrare"}`:`💳 Închidere plată ${m>0?`· rest ${m.toLocaleString("ro-RO")} lei`:"· ✓ achitată"}`}),e.jsx("span",{style:{transform:pt?"rotate(180deg)":"none",transition:"transform .2s"},children:"▼"})]}),pt&&e.jsx("div",{style:{padding:"0 12px 12px"},children:dt(g,{curier:!0})})]})})(),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"🚚 Firmă curierat"}),e.jsxs("select",{value:ge,onChange:l=>Ua(l.target.value),children:[e.jsx("option",{value:"",children:"— alege curierul —"}),ce.map(l=>e.jsx("option",{value:l.label,children:l.label},l.id))]}),ce.length===0&&e.jsx("small",{className:"com-newpay-info",children:"Niciun curier activ. Adaugă în Setări → Curieri."})]}),ge&&(()=>{const l=Ge,u=(m,f)=>ca(S=>({...S,[m]:f})),d=Array.isArray(g.breakdown)?g.breakdown.find(m=>m.total):null,v=(Array.isArray(g.corectii)?g.corectii:[]).reduce((m,f)=>m+(Number(f.suma)||0),0),x=Math.max(0,(d&&d.val?d.val+v:g.pret||0)-(g.avans||0));return e.jsxs("div",{style:{border:"1px solid #0277bd",borderRadius:8,padding:10,marginTop:4,background:"rgba(2,119,189,.06)"},children:[e.jsx("div",{style:{fontWeight:700,color:"#0277bd",fontSize:".82rem",marginBottom:8},children:"📦 Opțiuni expediere (nu mai intri pe site-ul curierului)"}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Serviciu"}),e.jsxs("select",{value:l.service,onChange:m=>u("service",m.target.value),children:[e.jsx("option",{children:"Standard"}),e.jsx("option",{children:"Cont Colector"})]})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Plată"}),e.jsxs("select",{value:l.plata,onChange:m=>{const f=m.target.value;ca(S=>({...S,plata:f,ramburs:f==="ramburs"&&(S.ramburs||x)||0}))},children:[e.jsx("option",{value:"achitat",children:"Achitat online (fără ramburs)"}),e.jsx("option",{value:"ramburs",children:"Ramburs (încasează la livrare)"})]})]}),l.plata==="ramburs"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["Sumă ramburs (lei) ",e.jsx("span",{style:{color:"#9c9484",fontWeight:500},children:"· 🔒 = restul de plată (blocat)"})]}),e.jsx("input",{type:"number",min:"0",value:x,readOnly:!0,title:"Rambursul e blocat pe restul exact de plată — curierul încasează fix cât mai are de plătit clientul (anti-fraudă). Adu restul la 0 din plăți/corecție dacă vrei altă sumă.",style:{opacity:.75,cursor:"not-allowed",background:"rgba(2,119,189,.05)"}})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Mod ramburs"}),e.jsxs("select",{value:l.rambursMod,onChange:m=>u("rambursMod",m.target.value),children:[e.jsx("option",{value:"cont",children:"Cont colector (banii intră în cont bancar)"}),e.jsx("option",{value:"plic",children:"Plic (cash real, în plic)"})]})]})]}),e.jsxs("label",{className:"form-label",children:[e.jsx("span",{children:"Livrare la"}),e.jsxs("select",{value:l.livrare,onChange:m=>u("livrare",m.target.value),children:[e.jsx("option",{value:"adresa",children:"Adresa clientului"}),e.jsx("option",{value:"fanbox",children:"FANbox / easybox (locker)"})]})]}),l.livrare==="fanbox"&&e.jsxs("label",{className:"form-label",children:[e.jsxs("span",{children:["📍 Locker FANbox (din zona clientului",g.adresa?.oras?` · ${g.adresa.oras}`:"",") ",e.jsx(We,{title:"Locker FANbox",children:"La live: listă cu lockerele FAN din zona clientului (alegi cel mai aproape). Dacă alege clientul la checkout, vine automat — nu mai intri pe FAN."})]}),e.jsx("input",{value:l.fanbox,onChange:m=>u("fanbox",m.target.value),placeholder:"cel mai apropiat de client"})]}),e.jsxs("div",{style:{marginTop:8},children:[e.jsx("div",{style:{fontSize:".78rem",color:"#0277bd",fontWeight:600,marginBottom:6},children:"Opțiuni speciale"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:7},children:["A se contacta telefonic","Deschidere la livrare","Livrare urgentă","Atenție-FRAGIL","Livrare personală cu CNP/Serie CI"].map(m=>{const f=(l.optiuni||[]).includes(m);return e.jsxs("label",{style:{display:"flex",alignItems:"center",justifyContent:"flex-start",ga
28p:8,fontSize:".85rem",cursor:"pointer",textAlign:"left"},children:[e.jsx("input",{type:"checkbox",checked:f,style:{flexShrink:0,margin:0},onChange:S=>u("optiuni",S.target.checked?[...l.optiuni||[],m]:(l.optiuni||[]).filter(P=>P!==m))}),e.jsx("span",{style:{flex:1},children:m})]},m)})})]}),g.sursa==="emag"&&e.jsxs("div",{style:{marginTop:10,background:"rgba(31,111,235,.06)",border:"1px solid rgba(31,111,235,.35)",borderRadius:8,padding:10},children:[e.jsxs("div",{style:{fontSize:".82rem",color:"#1f6feb",fontWeight:700,marginBottom:8},children:["📦 Informații AWB ",e.jsx("span",{style:{fontWeight:500,color:"#7a8aa0"},children:"· pre-completat din comandă (Sameday prin eMAG.ro)"})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[e.jsxs("label",{className:"form-label",style:{flex:"1 1 120px",minWidth:110},children:[e.jsx("span",{children:"Nr. plicuri"}),e.jsx("input",{type:"number",min:"0",value:l.plicuri??1,onChange:m=>u("plicuri",Math.max(0,parseInt(m.target.value||"0",10)))})]}),e.jsxs("label",{className:"form-label",style:{flex:"1 1 120px",minWidth:110},children:[e.jsx("span",{children:"Nr. colete"}),e.jsx("input",{type:"number",min:"0",value:l.colete??0,onChange:m=>u("colete",Math.max(0,parseInt(m.target.value||"0",10)))})]})]}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginTop:4},children:[e.jsxs("label",{className:"form-label",style:{flex:"1 1 120px",minWidth:110},children:[e.jsxs("span",{children:["Valoare asigurată (lei) ",e.jsx("span",{style:{color:"#9c9484",fontWeight:500},children:"· 0 = fără (anti-furt)"})]}),e.jsx("input",{type:"number",min:"0",value:l.asigurare??0,onChange:m=>u("asigurare",Math.max(0,Number(m.target.value)||0))})]}),e.jsxs("label",{className:"form-label",style:{flex:"1 1 120px",minWidth:110},children:[e.jsx("span",{children:"Format AWB"}),e.jsxs("select",{value:l.formatAwb||"A4",onChange:m=>u("formatAwb",m.target.value),children:[e.jsx("option",{children:"A4"}),e.jsx("option",{children:"A6"})]})]})]}),e.jsxs("div",{style:{fontSize:".76rem",color:"#7a8aa0",marginTop:6,lineHeight:1.45},children:["Cont curier: ",e.jsx("b",{children:ge||"Sameday"}),'. Rambursul se ia din „Plată" mai sus (card = 0). Destinatarul îl completează eMAG.ro din comandă — nu-l mai scrii.']})]})]})})()]})}):null,["la_atelier","la_bijutier","la_tintuit","la_finisat","la_gravat"].includes(a)&&/urgen/i.test(JSON.stringify(g.configuratie||{}))&&e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:8,background:"rgba(198,40,40,.08)",border:"1px solid rgba(198,40,40,.45)",borderRadius:8,padding:"9px 11px",marginBottom:10,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:$t,onChange:l=>Tt(l.target.checked),style:{marginTop:2,accentColor:"#c62828",width:16,height:16,flex:"0 0 auto"}}),e.jsxs("span",{style:{fontSize:".82rem",color:"#c62828",fontWeight:700,lineHeight:1.45},children:["⚡ Printează fișa cu URGENȚĂ (banner roșu + watermark)"," ",e.jsxs(We,{title:"Urgență pe fișă",children:["Comanda are ",e.jsx("b",{children:"taxă de urgență"}),". ",e.jsx("b",{children:"Bifat (implicit)"}),' = fișa se tipărește cu banner roșu „URGENT 24/48h" + watermark → semnal pentru atelier că se face ',e.jsx("b",{children:"peste program"})," (bijutierul ia comision). ",e.jsx("b",{children:"Debifat"})," = fișă normală, fără roșu → se face în ",e.jsx("b",{children:"programul standard"}),", când atelierul are loc (fără extra/comision). Nu schimbă taxa plătită de client — doar modul de lucru și aspectul fișei."]})]})]}),(()=>{if(a==="returnata")return e.jsxs("div",{style:{marginTop:4,display:"flex",flexDirection:"column",gap:"0.6rem"},children:[e.jsxs("div",{className:"com-newpay-info",style:{marginTop:0,marginBottom:0},children:["↩️ Returul nu e doar o etichetă: se emit ",e.jsx("strong",{children:"storno + factură cu minus"}),", clientul primește email și se programează ",e.jsx("strong",{children:"rambursarea"}),'. Completează mai jos, apoi apasă butonul roșu — comanda trece singură în „Returnată".']}),rs(g.id)]});if(!(a==="eliberata"||a==="trimisa"))return e.jsx("button",{type:"button",className:"com-status-save",onClick:rr,children:`✓ Salvează „${M[a]||a}"`});const u=D.find(c=>c.id===g.id)||g,d=Array.isArray(u.breakdown)?u.breakdown.find(c=>c.total):null,v=(Array.isArray(u.corectii)?u.corectii:[]).reduce((c,j)=>c+(Number(j.suma)||0),0),x=d&&d.val?d.val+v:u.pret||0,m=u.cardDiscountApplied&&u.cardDiscount||0,f=u.sursa==="emag"?0:Math.max(0,+(x-m-(u.avans||0)).toFixed(2)),S={background:"#e74c3c",color:"#fff",borderColor:"#c0392b",fontWeight:800,cursor:"pointer",boxShadow:"0 3px 12px rgba(231,76,60,.35)"},P={background:"linear-gradient(180deg,#2e9e52,#1f7d3e)",color:"#fff",borderColor:"#1f7d3e",fontWeight:800,boxShadow:"0 3px 12px rgba(31,125,62,.35)"},T=a==="trimisa",te=T?"expedia":"elibera";if(!(Array.isArray(u.istoricStatus)&&u.istoricStatus.some(c=>c.status==="terminata")))return e.jsx("button",{type:"button",className:"com-status-save",style:S,onClick:()=>va({icon:"🔒",tone:"danger",title:`Nu poți ${te} — comanda nu e finalizată`,msg:e.jsxs(e.Fragment,{children:["Comanda nu a fost ",e.jsx("strong",{children:"cântărită real"}),'. Fără statusul „Terminată": prețul/„zero" e ESTIMAT (fals), stocul din gestiune nu se scade, iar ',e.jsx("strong",{children:"certificatul de garanție ar fi FALS"}),".",e.jsx("br",{}),e.jsx("br",{}),"👉 Treci întâi prin ",e.jsx("strong",{children:'„Terminată"'})," (cântărește gramajul real + CTC), apoi butonul se aprinde verde",T?" și poți expedia":" și poți elibera","."]})}),children:"🔒 BLOCAT — nu e finalizată (Terminată). Apasă pentru detalii"});const E=Ge.plata==="ramburs";return f>0&&!(T&&E)?e.jsxs("button",{type:"button",className:"com-status-save",style:S,onClick:()=>va({icon:"🔒",tone:"danger",title:`Nu poți ${te} — mai are rest de plată`,msg:e.jsxs(e.Fragment,{children:["Comanda mai are de încasat ",e.jsxs("strong",{children:[f.toLocaleStr
28ing("ro-RO")," lei"]})," — nu poți ",te," neîncasat.",e.jsx("br",{}),e.jsx("br",{}),"👉 Încasează restul (aur / cash / card / transfer) din caseta de mai sus sau adu-l la 0 printr-o ",e.jsx("strong",{children:"corecție"}),T?e.jsxs(e.Fragment,{children:[", ori pune ",e.jsx("strong",{children:'Plata pe „Ramburs"'})," — atunci curierul îi ia banii clientului la livrare"]}):"",", apoi butonul se aprinde verde."]})}),children:["🔒 BLOCAT — mai are de încasat ",f.toLocaleString("ro-RO")," lei. Apasă pentru detalii"]}):T&&!ge?e.jsx("button",{type:"button",className:"com-status-save",style:S,onClick:()=>va({icon:"🚚",tone:"danger",title:"Alege firma de curierat",msg:e.jsxs(e.Fragment,{children:["Nu poți expedia fără curier — n-ai AWB și clientul n-are ce urmări.",e.jsx("br",{}),e.jsx("br",{}),"👉 Alege ",e.jsx("strong",{children:'„Firmă curierat"'})," mai sus, apoi butonul se aprinde verde."]})}),children:"🔒 BLOCAT — alege firma de curierat ↑. Apasă pentru detalii"}):e.jsx("button",{type:"button",className:"com-status-save",onClick:rr,style:P,children:T?E&&f>0?`🚚 Trimite cu ${ge} — ramburs ${f.toLocaleString("ro-RO")} lei la livrare ✓`:`🚚 Trimite cu ${ge} — achitată integral ✓`:"📦 Eliberează comanda — achitată integral ✓"})})()]})]},a)})})]})}),e.jsx(or,{open:!!Ke,onClose:()=>va(null),title:Ke?.title,icon:Ke?.icon,tone:Ke?.tone||"danger",children:Ke?.msg}),e.jsxs(or,{open:!!He,onClose:()=>Ka(null),title:"Confirmare anulare",icon:"⚠",tone:"warn",btnText:"⚠ Confirmă anularea",cancelText:"Înapoi",onBtn:()=>{lt(He.comanda,He.newStatus,He.meta||{}),Ka(null)},children:["Marchezi comanda ",e.jsx("strong",{children:He?.comanda?.numarComanda})," ca ",e.jsx("strong",{children:"Anulată"}),".",e.jsx("br",{}),e.jsx("br",{}),e.jsx("strong",{children:"Clientul a anulat comanda"})," după ce a plasat-o, fără să fi plătit. Nicio pierdere financiară directă, dar este o situație negativă.",e.jsx("br",{}),e.jsx("br",{}),"Se poate modifica ulterior — comanda anulată are butonul ",e.jsx("strong",{children:'„♻ Reactivează"'})," în listă."]})]})}export{Ms 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.