@nice2dev/ui-printing 1.1.7 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.mjs +1900 -1734
  3. package/dist/ui-printing.css +1 -1
  4. package/package.json +3 -2
  5. package/src/print-button/NicePrintButton.tsx +39 -17
  6. package/src/print-button/PrintButton.module.css +9 -9
  7. package/src/print-preview/NicePrintPreview.tsx +10 -9
  8. package/src/print-preview/PrintPreview.module.css +7 -7
  9. package/src/print-queue/NicePrintQueue.tsx +76 -42
  10. package/src/print-queue/PrintQueue.module.css +9 -9
  11. package/src/template-browser/NiceTemplateBrowser.tsx +39 -18
  12. package/src/template-browser/TemplateBrowser.module.css +17 -17
  13. package/src/template-editor/NiceTemplateEditor.tsx +306 -179
  14. package/src/template-editor/TemplateEditor.module.css +90 -83
  15. package/src/types/printingTypes.ts +1 -1
  16. package/dist/index.d.ts.map +0 -1
  17. package/dist/print-button/NicePrintButton.d.ts.map +0 -1
  18. package/dist/print-button/index.d.ts.map +0 -1
  19. package/dist/print-preview/NicePrintPreview.d.ts.map +0 -1
  20. package/dist/print-preview/index.d.ts.map +0 -1
  21. package/dist/print-queue/NicePrintQueue.d.ts.map +0 -1
  22. package/dist/print-queue/index.d.ts.map +0 -1
  23. package/dist/style.css +0 -1
  24. package/dist/template-browser/NiceTemplateBrowser.d.ts.map +0 -1
  25. package/dist/template-browser/index.d.ts.map +0 -1
  26. package/dist/template-editor/NiceTemplateEditor.d.ts.map +0 -1
  27. package/dist/template-editor/index.d.ts.map +0 -1
  28. package/dist/types/printingTypes.d.ts.map +0 -1
  29. package/src/template-editor/NiceTemplateEditor.tsx.first +0 -1011
  30. package/src/template-editor/NiceTemplateEditor.tsx.tmp +0 -392
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("react"),ve=require("@nice2dev/ui"),Ae=require("react-dom"),Me="_root_142ej_3",Ee="_dark_142ej_27",Fe="_toolbar_142ej_39",Ge="_toolbarGroup_142ej_75",He="_toolbarBtn_142ej_107",We="_toolbarBtnActive_142ej_171",Oe="_toolbarBtnDanger_142ej_195",Ue="_toolbarSelect_142ej_207",qe="_toolbarSep_142ej_237",Ye="_insertWrapper_142ej_263",Ke="_insertBtn_142ej_271",Ve="_insertDropdown_142ej_293",Ze="_insertCategory_142ej_333",Xe="_insertItem_142ej_351",Qe="_insertIcon_142ej_395",Je="_zoomSelect_142ej_409",et="_saveBtn_142ej_441",tt="_editorBody_142ej_477",st="_leftPanel_142ej_493",at="_leftTabs_142ej_523",nt="_leftTab_142ej_523",lt="_leftTabActive_142ej_601",rt="_leftTabIcon_142ej_621",it="_leftTabLabel_142ej_629",ot="_leftContent_142ej_639",ct="_panelHeader_142ej_653",dt="_panelHeaderIcon_142ej_677",ut="_panelHeaderName_142ej_685",pt="_searchBox_142ej_699",mt="_searchInput_142ej_707",_t="_fieldList_142ej_753",ht="_fieldItem_142ej_763",xt="_fieldItemIcon_142ej_807",jt="_fieldItemInfo_142ej_821",yt="_fieldItemLabel_142ej_831",bt="_fieldItemPath_142ej_847",gt="_fieldItemType_142ej_863",vt="_layerList_142ej_883",Nt="_layerItem_142ej_895",wt="_layerItemSelected_142ej_931",kt="_layerIcon_142ej_949",ft="_layerName_142ej_961",St="_layerActions_142ej_977",Ct="_layerBtn_142ej_999",Bt="_wmList_142ej_1031",It="_wmItem_142ej_1039",Lt="_wmRow_142ej_1065",zt="_wmLabel_142ej_1079",Dt="_wmInput_142ej_1091",Tt="_wmInputNum_142ej_1123",$t="_wmSelect_142ej_1143",Rt="_wmSlider_142ej_1175",Pt="_wmValue_142ej_1185",At="_wmUnit_142ej_1199",Mt="_wmDelete_142ej_1209",Et="_addBtn_142ej_1241",Ft="_settingsForm_142ej_1277",Gt="_settingsRow_142ej_1285",Ht="_settingsLabel_142ej_1299",Wt="_settingsInput_142ej_1311",Ot="_settingsInputNum_142ej_1343",Ut="_settingsTextarea_142ej_1375",qt="_settingsDivider_142ej_1409",Yt="_settingsUnit_142ej_1429",Kt="_emptyMsg_142ej_1441",Vt="_canvasArea_142ej_1459",Zt="_testDataBar_142ej_1485",Xt="_testDataLabel_142ej_1517",Qt="_testDataSelect_142ej_1527",Jt="_rulerWrapper_142ej_1547",es="_rulerCorner_142ej_1563",ts="_ruler_142ej_1547",ss="_ruler_h_142ej_1621",as="_ruler_v_142ej_1631",ns="_rulerTick_142ej_1651",ls="_rulerTickMajor_142ej_1691",rs="_rulerLabel_142ej_1711",is="_paperScroll_142ej_1749",os="_paperShadow_142ej_1767",cs="_marginGuide_142ej_1795",ds="_watermark_142ej_1811",us="_sectionCanvas_142ej_1837",ps="_sectionCanvasOver_142ej_1851",ms="_sectionTypeChip_142ej_1859",_s="_sectionResizeBar_142ej_1891",hs="_sectionResizeGrip_142ej_1925",xs="_fieldImagePlaceholder_142ej_1941",js="_fieldBarcodePlaceholder_142ej_1963",ys="_fieldSignaturePlaceholder_142ej_1991",bs="_resizeHandle_142ej_2017",gs="_handle_n_142ej_2037",vs="_handle_s_142ej_2049",Ns="_handle_e_142ej_2061",ws="_handle_w_142ej_2073",ks="_handle_ne_142ej_2085",fs="_handle_nw_142ej_2095",Ss="_handle_se_142ej_2105",Cs="_handle_sw_142ej_2115",Bs="_rightPanel_142ej_2129",Is="_rightTabs_142ej_2159",Ls="_rightTab_142ej_2159",zs="_rightTabActive_142ej_2229",Ds="_propsBody_142ej_2241",Ts="_propsEmpty_142ej_2253",$s="_propsEmptyIcon_142ej_2275",Rs="_propsEmptyText_142ej_2285",Ps="_posGrid_142ej_2297",As="_posCell_142ej_2311",Ms="_posLabel_142ej_2323",Es="_posInput_142ej_2335",Fs="_posUnit_142ej_2377",Gs="_snapSection_142ej_2389",Hs="_snapTitle_142ej_2397",Ws="_snapRow_142ej_2415",Os="_snapBtn_142ej_2425",Us="_styleGroup_142ej_2459",qs="_styleGroupTitle_142ej_2467",Ys="_styleRow_142ej_2497",Ks="_styleLabel_142ej_2511",Vs="_styleSelect_142ej_2525",Zs="_styleSelectFull_142ej_2555",Xs="_styleSelectSm_142ej_2587",Qs="_styleSelectXs_142ej_2607",Js="_styleInput_142ej_2639",ea="_styleInputFull_142ej_2671",ta="_styleUnit_142ej_2703",sa="_styleValue_142ej_2715",aa="_toggleGroup_142ej_2729",na="_toggleBtn_142ej_2739",la="_toggleBtnActive_142ej_2773",ra="_colorPicker_142ej_2787",ia="_colorHex_142ej_2805",oa="_clearBtn_142ej_2839",ca="_sliderInput_142ej_2871",da="_conditionalHint_142ej_2883",ua="_clearConditionalBtn_142ej_2915",pa="_shortcutGrid_142ej_2947",ma="_shortcutChip_142ej_2961",_a="_shortcutKeys_142ej_2993",ha="_shortcutLabel_142ej_3013",t={root:Me,dark:Ee,toolbar:Fe,toolbarGroup:Ge,toolbarBtn:He,toolbarBtnActive:We,toolbarBtnDanger:Oe,toolbarSelect:Ue,toolbarSep:qe,insertWrapper:Ye,insertBtn:Ke,insertDropdown:Ve,insertCategory:Ze,insertItem:Xe,insertIcon:Qe,zoomSelect:Je,saveBtn:et,editorBody:tt,leftPanel:st,leftTabs:at,leftTab:nt,leftTabActive:lt,leftTabIcon:rt,leftTabLabel:it,leftContent:ot,panelHeader:ct,panelHeaderIcon:dt,panelHeaderName:ut,searchBox:pt,searchInput:mt,fieldList:_t,fieldItem:ht,fieldItemIcon:xt,fieldItemInfo:jt,fieldItemLabel:yt,fieldItemPath:bt,fieldItemType:gt,layerList:vt,layerItem:Nt,layerItemSelected:wt,layerIcon:kt,layerName:ft,layerActions:St,layerBtn:Ct,wmList:Bt,wmItem:It,wmRow:Lt,wmLabel:zt,wmInput:Dt,wmInputNum:Tt,wmSelect:$t,wmSlider:Rt,wmValue:Pt,wmUnit:At,wmDelete:Mt,addBtn:Et,settingsForm:Ft,settingsRow:Gt,settingsLabel:Ht,settingsInput:Wt,settingsInputNum:Ot,settingsTextarea:Ut,settingsDivider:qt,settingsUnit:Yt,emptyMsg:Kt,canvasArea:Vt,testDataBar:Zt,testDataLabel:Xt,testDataSelect:Qt,rulerWrapper:Jt,rulerCorner:es,ruler:ts,ruler_h:ss,ruler_v:as,rulerTick:ns,rulerTickMajor:ls,rulerLabel:rs,paperScroll:is,paperShadow:os,marginGuide:cs,watermark:ds,sectionCanvas:us,sectionCanvasOver:ps,sectionTypeChip:ms,sectionResizeBar:_s,sectionResizeGrip:hs,fieldImagePlaceholder:xs,fieldBarcodePlaceholder:js,fieldSignaturePlaceholder:ys,resizeHandle:bs,handle_n:gs,handle_s:vs,handle_e:Ns,handle_w:ws,handle_ne:ks,handle_nw:fs,handle_se:Ss,handle_sw:Cs,rightPanel:Bs,rightTabs:Is,rightTab:Ls,rightTabActive:zs,propsBody:Ds,propsEmpty:Ts,propsEmptyIcon:$s,propsEmptyText:Rs,posGrid:Ps,posCell:As,posLabel:Ms,posInput:Es,posUnit:Fs,snapSection:Gs,snapTitle:Hs,snapRow:Ws,snapBtn:Os,styleGroup:Us,styleGroupTitle:qs,styleRow:Ys,styleLabel:Ks,styleSelect:Vs,styleSelectFull:Zs,styleSelectSm:Xs,styleSelectXs:Qs,styleInput:Js,styleInputFull:ea,styleUnit:ta,styleValue:sa,toggleGroup:aa,toggleBtn:na,toggleBtnActive:la,colorPicker:ra,colorHex:ia,clearBtn:oa,sliderInput:ca,conditionalHint:da,clearConditionalBtn:ua,shortcutGrid:pa,shortcutChip:ma,shortcutKeys:_a,shortcutLabel:ha},G=3.78,xe={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432],custom:[210,297]},xa=["sans-serif","serif","monospace","Arial","Times New Roman","Courier New","Georgia","Verdana","Tahoma"],je=[6,7,8,9,10,11,12,14,16,18,20,24,28,32,36,48,60,72],le={text:"📝",number:"#",currency:"€",date:"📅",datetime:"🕐",boolean:"✓",image:"🖼",barcode:"▮▌▮",qr:"⬛",signature:"✍",static_text:"T",static_image:"🖼",line:"─",rect:"▭",page_number:"#p",total_pages:"#pp",print_date:"📅"},re={text:"Tekst",number:"Liczba",currency:"Waluta",date:"Data",datetime:"Data i czas",boolean:"Tak/Nie",image:"Obraz",barcode:"Kod kreskowy",qr:"QR",signature:"Podpis",static_text:"Tekst stały",static_image:"Obraz stały",line:"Linia",rect:"Prostokąt",page_number:"Numer strony",total_pages:"Liczba stron",print_date:"Data wydruku"};function ja(s,r){switch(r.type){case"UPDATE":return{past:[...s.past.slice(-50),s.present],present:r.payload,future:[]};case"UNDO":return s.past.length?{past:s.past.slice(0,-1),present:s.past[s.past.length-1],future:[s.present,...s.future]}:s;case"REDO":return s.future.length?{past:[...s.past,s.present],present:s.future[0],future:s.future.slice(1)}:s;default:return s}}function te(){return`f-${Date.now()}-${Math.floor(Math.random()*1e3)}`}function ye(s,r){const d={id:te(),name:(r==null?void 0:r.label)??re[s]??s,label:(r==null?void 0:r.label)??re[s]??s,type:s,dataPath:(r==null?void 0:r.path)??"",fallback:s==="static_text"?"Tekst statyczny":void 0,format:s==="date"||s==="datetime"?"DD.MM.YYYY":void 0,position:{x:15,y:15,width:s==="line"?80:60,height:s==="line"?1:s==="image"?30:8},style:{fontSize:10,color:"var(--nice-text, #000000)",fontFamily:"sans-serif"}};return s==="rect"&&(d.style.backgroundColor="var(--nice-bg-secondary, #f1f5f9)"),s==="line"&&(d.style={...d.style,borderWidth:.5,borderColor:"var(--nice-text, #000000)",borderStyle:"solid"}),d}const be=({lengthMm:s,zoom:r,orientation:d})=>{const l=[],w=r<.6?20:r<1?10:5;for(let m=0;m<=s;m+=w){const k=m*r*G,y=m%(w*2)===0;l.push(e.jsx("div",{className:`${t.rulerTick} ${y?t.rulerTickMajor:""}`,style:d==="h"?{left:k}:{top:k},children:y&&e.jsx("span",{className:t.rulerLabel,children:m})},m))}return e.jsx("div",{className:`${t.ruler} ${t[`ruler_${d}`]}`,children:l})},ya=["n","s","e","w","ne","nw","se","sw"],ba=({onResizeStart:s})=>e.jsx(e.Fragment,{children:ya.map(r=>e.jsx("div",{className:`${t.resizeHandle} ${t[`handle_${r}`]}`,onMouseDown:d=>{d.stopPropagation(),s(r,d)}},r))});function ga(s,r){if(s.type==="static_text")return s.fallback??"Tekst";if(s.type==="page_number")return"1";if(s.type==="total_pages")return"3";if(s.type==="print_date")return new Date().toLocaleDateString("pl-PL");if(r&&s.dataPath){const d=s.dataPath.split(".").reduce((l,w)=>l&&typeof l=="object"?l[w]:null,r);if(d!=null)return String(d)}return s.label?`{${s.label}}`:`{${s.dataPath}}`}const va=({field:s,zoom:r,selected:d,sampleData:l,onClick:w,onDragStart:m,onResizeStart:k,readOnly:y})=>{const h=s.position,g=s.style,o=u=>u*r*G,D=s.type==="line",v=s.type==="rect",n=s.type==="image"||s.type==="static_image",a=s.type==="barcode"||s.type==="qr",p={position:"absolute",left:o(h.x),top:o(h.y),width:o(h.width),height:o(h.height),zIndex:h.zIndex??1,transform:g.rotation?`rotate(${g.rotation}deg)`:void 0,boxSizing:"border-box",overflow:"hidden",...!D&&!v?{fontSize:(g.fontSize??10)*r,fontFamily:g.fontFamily??"sans-serif",fontWeight:g.fontWeight??"normal",fontStyle:g.fontStyle??"normal",color:g.color??"var(--nice-text, #000)",textAlign:g.textAlign??"left",lineHeight:g.lineHeight??1.4,letterSpacing:g.letterSpacing?`${g.letterSpacing}em`:void 0,padding:g.padding?o(g.padding):0}:{},backgroundColor:g.backgroundColor,borderWidth:g.borderWidth??0,borderColor:g.borderColor??"transparent",borderStyle:g.borderStyle??"solid",borderRadius:g.borderRadius,opacity:g.opacity,outline:d?"1.5px solid var(--nice-primary-hover, #2563eb)":"1px dashed transparent",outlineOffset:1,cursor:y?"default":"move"};return e.jsxs("div",{style:p,onClick:w,onMouseDown:y?void 0:m,children:[D?e.jsx("div",{style:{width:"100%",borderBottom:`${(g.borderWidth??.5)*r}px ${g.borderStyle??"solid"} ${g.borderColor??"var(--nice-text, #000)"}`}}):v?null:n?e.jsx("div",{className:t.fieldImagePlaceholder,children:"🖼"}):a?e.jsx("div",{className:t.fieldBarcodePlaceholder,children:s.type==="qr"?"⬛ QR":"▮▌▮ Barcode"}):s.type==="signature"?e.jsxs("div",{className:t.fieldSignaturePlaceholder,children:["✍ ",s.label]}):e.jsx("span",{style:{display:"block",width:"100%"},children:ga(s,l)}),d&&!y&&e.jsx(ba,{onResizeStart:k})]})},Na=({section:s,zoom:r,paperWidthMm:d,selectedIds:l,sampleData:w,readOnly:m,showGrid:k,onFieldClick:y,onFieldDragStart:h,onResizeStart:g,onSectionHeightChange:o,onDropField:D})=>{const v=(s.heightMm??(s.type==="body"?200:40))*r*G,n=d*r*G,[a,p]=j.useState(!1),u={header:"rgba(219,234,254,0.35)",footer:"rgba(220,252,231,0.35)",background:"rgba(254,249,195,0.35)",body:"transparent"};return e.jsxs("div",{className:`${t.sectionCanvas} ${a?t.sectionCanvasOver:""}`,style:{width:n,height:v,position:"relative",background:u[s.type]??"transparent",backgroundImage:k?`repeating-linear-gradient(0deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*r*G}px),
2
- repeating-linear-gradient(90deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*r*G}px)`:void 0},onDragOver:N=>{N.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:N=>{N.preventDefault(),p(!1);const z=N.dataTransfer.getData("fieldPath");if(!z)return;const x=N.currentTarget.getBoundingClientRect(),I=(N.clientX-x.left)/(r*G),C=(N.clientY-x.top)/(r*G);D(s.id,z,Math.max(0,I),Math.max(0,C))},children:[e.jsx("div",{className:t.sectionTypeChip,children:s.type}),s.fields.map(N=>e.jsx(va,{field:N,zoom:r,selected:l.has(N.id),sampleData:w,readOnly:m,onClick:z=>y(N.id,z),onDragStart:z=>h(N.id,z),onResizeStart:(z,x)=>g(N.id,z,x)},N.id)),!m&&s.type!=="body"&&e.jsx("div",{className:t.sectionResizeBar,onMouseDown:N=>{N.preventDefault();const z=N.clientY,x=s.heightMm??40,I=P=>{const A=(P.clientY-z)/(r*G);o(s.id,Math.max(10,x+A))},C=()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",I),document.addEventListener("mouseup",C)},children:e.jsx("div",{className:t.sectionResizeGrip})})]})},ee=({keys:s,label:r})=>e.jsxs("div",{className:t.shortcutChip,children:[e.jsx("span",{className:t.shortcutKeys,children:s}),e.jsx("span",{className:t.shortcutLabel,children:r})]}),wa=[{id:"fields",icon:"📝",label:"Pola"},{id:"layers",icon:"◧",label:"Warstwy"},{id:"watermarks",icon:"💧",label:"Znaki"},{id:"signatures",icon:"✍",label:"Podpisy"},{id:"settings",icon:"⚙",label:"Ustawienia"}],ka=[{id:"position",label:"Pozycja"},{id:"style",label:"Styl"},{id:"data",label:"Dane"},{id:"conditional",label:"Warunki"}],fa=({tpl:s,zoom:r,canUndo:d,canRedo:l,showGrid:w,showRulers:m,readOnly:k,selectedCount:y,onPaperChange:h,onZoom:g,onUndo:o,onRedo:D,onToggleGrid:v,onToggleRulers:n,onInsert:a,onDelete:p,onDuplicate:u,onAlignH:N,onAlignV:z,onBringForward:x,onSendBackward:I,onSave:C})=>{const[P,A]=j.useState(!1),R=[.5,.75,1,1.25,1.5,2];return e.jsxs("div",{className:t.toolbar,children:[e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("select",{className:t.toolbarSelect,value:s.paperSize,onChange:_=>h(_.target.value,s.orientation),children:["A4","A5","A3","Letter","Legal","Tabloid","custom"].map(_=>e.jsx("option",{value:_,children:_},_))}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="portrait"?t.toolbarBtnActive:""}`,onClick:()=>h(s.paperSize,"portrait"),title:"Pion",children:"⬜"}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="landscape"?t.toolbarBtnActive:""}`,onClick:()=>h(s.paperSize,"landscape"),title:"Poziom",children:"▭"})]}),!k&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,disabled:!d,onClick:o,title:"Cofnij (Ctrl+Z)",children:"↩"}),e.jsx("button",{className:t.toolbarBtn,disabled:!l,onClick:D,title:"Ponów (Ctrl+Y)",children:"↪"})]}),!k&&e.jsxs("div",{className:t.insertWrapper,children:[e.jsx("button",{className:`${t.toolbarBtn} ${t.insertBtn}`,onClick:()=>A(_=>!_),children:"+ Wstaw ▾"}),P&&e.jsxs("div",{className:t.insertDropdown,onMouseLeave:()=>A(!1),children:[e.jsx("div",{className:t.insertCategory,children:"Pola danych"}),["text","number","currency","date","image","barcode","qr"].map(_=>e.jsxs("button",{className:t.insertItem,onClick:()=>{a(_),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:le[_]}),re[_]]},_)),e.jsx("div",{className:t.insertCategory,children:"Elementy statyczne"}),["static_text","static_image","line","rect","page_number","total_pages","print_date"].map(_=>e.jsxs("button",{className:t.insertItem,onClick:()=>{a(_),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:le[_]}),re[_]]},_)),e.jsx("div",{className:t.insertCategory,children:"Specjalne"}),e.jsxs("button",{className:t.insertItem,onClick:()=>{a("watermark"),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:"💧"}),"Znak wodny"]}),e.jsxs("button",{className:t.insertItem,onClick:()=>{a("signature"),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:"✍"}),"Podpis"]})]})]}),!k&&y>0&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:u,title:"Duplikuj (Ctrl+D)",children:"⧉"}),e.jsx("button",{className:`${t.toolbarBtn} ${t.toolbarBtnDanger}`,onClick:p,title:"Usuń (Del)",children:"🗑"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>N("left"),title:"Wyrównaj lewo",children:"⬛□□"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>N("center"),title:"Wyśrodkuj",children:"□⬛□"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>N("right"),title:"Wyrównaj prawo",children:"□□⬛"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("top"),title:"Góra",children:"⊤"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("center"),title:"Środek V",children:"⊕"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("bottom"),title:"Dół",children:"⊥"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:x,title:"Do przodu",children:"▲"}),e.jsx("button",{className:t.toolbarBtn,onClick:I,title:"Do tyłu",children:"▼"})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:`${t.toolbarBtn} ${w?t.toolbarBtnActive:""}`,onClick:v,title:"Siatka",children:"⊞"}),e.jsx("button",{className:`${t.toolbarBtn} ${m?t.toolbarBtnActive:""}`,onClick:n,title:"Linijki",children:"⊢"})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:()=>g(Math.max(.25,r-.1)),children:"−"}),e.jsx("select",{className:t.zoomSelect,value:R.includes(r)?r:"",onChange:_=>g(+_.target.value),children:R.map(_=>e.jsxs("option",{value:_,children:[Math.round(_*100),"%"]},_))}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>g(Math.min(3,r+.1)),children:"+"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>g(1),title:"100%",children:"⊡"})]}),!k&&C&&e.jsx("button",{className:t.saveBtn,onClick:C,children:"💾 Zapisz"})]})},Sa=({activeTab:s,onTabChange:r,schema:d,tpl:l,allFields:w,selectedIds:m,onInsertSchemaField:k,onSelectField:y,onUpdateTpl:h,onReorderField:g})=>{const[o,D]=j.useState(""),v=d==null?void 0:d.fields.filter(n=>n.label.toLowerCase().includes(o.toLowerCase())||n.path.toLowerCase().includes(o.toLowerCase()));return e.jsxs("div",{className:t.leftPanel,children:[e.jsx("div",{className:t.leftTabs,children:wa.map(n=>e.jsxs("button",{className:`${t.leftTab} ${s===n.id?t.leftTabActive:""}`,onClick:()=>r(n.id),title:n.label,children:[e.jsx("span",{className:t.leftTabIcon,children:n.icon}),e.jsx("span",{className:t.leftTabLabel,children:n.label})]},n.id))}),e.jsxs("div",{className:t.leftContent,children:[s==="fields"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Pola danych"}),e.jsx("div",{className:t.searchBox,children:e.jsx("input",{className:t.searchInput,placeholder:"Szukaj...",value:o,onChange:n=>D(n.target.value)})}),d?e.jsxs("div",{className:t.fieldList,children:[(v??[]).map(n=>e.jsxs("div",{className:t.fieldItem,draggable:!0,onDragStart:a=>{a.dataTransfer.setData("fieldPath",n.path),a.dataTransfer.setData("fieldLabel",n.label),a.dataTransfer.setData("fieldType",n.type)},onClick:()=>k(n),children:[e.jsx("span",{className:t.fieldItemIcon,children:le[n.type]??"📝"}),e.jsxs("div",{className:t.fieldItemInfo,children:[e.jsx("div",{className:t.fieldItemLabel,children:n.label}),e.jsx("div",{className:t.fieldItemPath,children:n.path})]}),e.jsx("span",{className:t.fieldItemType,children:n.type})]},n.path)),(v==null?void 0:v.length)===0&&e.jsx("div",{className:t.emptyMsg,children:"Brak wyników"})]}):e.jsx("div",{className:t.emptyMsg,children:"Brak schematu danych. Przypisz encję w zakładce Ustawienia."})]}),s==="layers"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.panelHeader,children:["Warstwy (",w.length,")"]}),e.jsxs("div",{className:t.layerList,children:[w.length===0&&e.jsx("div",{className:t.emptyMsg,children:"Brak elementów"}),w.slice().reverse().map(n=>e.jsxs("div",{className:`${t.layerItem} ${m.has(n.id)?t.layerItemSelected:""}`,onClick:()=>y(n.id),children:[e.jsx("span",{className:t.layerIcon,children:le[n.type]??"📝"}),e.jsx("span",{className:t.layerName,children:n.name||n.label}),e.jsxs("div",{className:t.layerActions,children:[e.jsx("button",{className:t.layerBtn,onClick:a=>{a.stopPropagation(),g(n.id,-1)},title:"Do przodu",children:"↑"}),e.jsx("button",{className:t.layerBtn,onClick:a=>{a.stopPropagation(),g(n.id,1)},title:"Do tyłu",children:"↓"})]})]},n.id))]})]}),s==="watermarks"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Znaki wodne"}),e.jsxs("div",{className:t.wmList,children:[(l.watermarks??[]).map(n=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Typ"}),e.jsxs("select",{className:t.wmSelect,value:n.type,onChange:a=>{var p;return h({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,type:a.target.value}:u)})},children:[e.jsx("option",{value:"text",children:"Tekst"}),e.jsx("option",{value:"image",children:"Obraz"})]})]}),n.type==="text"&&e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Tekst"}),e.jsx("input",{className:t.wmInput,value:n.text??"",onChange:a=>{var p;return h({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,text:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.02,max:.5,step:.01,className:t.wmSlider,value:n.opacity,onChange:a=>{var p;return h({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,opacity:+a.target.value}:u)})}}),e.jsxs("span",{className:t.wmValue,children:[Math.round(n.opacity*100),"%"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Kąt"}),e.jsx("input",{type:"range",min:-90,max:90,step:5,className:t.wmSlider,value:n.angle,onChange:a=>{var p;return h({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,angle:+a.target.value}:u)})}}),e.jsxs("span",{className:t.wmValue,children:[n.angle,"°"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Rozmiar"}),e.jsx("input",{type:"number",min:8,max:200,className:t.wmInputNum,value:n.fontSize??48,onChange:a=>{var p;return h({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,fontSize:+a.target.value}:u)})}}),e.jsx("span",{className:t.wmUnit,children:"pt"})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Kolor"}),e.jsx("input",{type:"color",className:t.colorPicker,value:n.color??"var(--nice-text-muted, #94a3b8)",onChange:a=>{var p;return h({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,color:a.target.value}:u)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var a;return h({watermarks:(a=l.watermarks)==null?void 0:a.filter(p=>p.id!==n.id)})},children:"Usuń"})]},n.id)),e.jsx("button",{className:t.addBtn,onClick:()=>h({watermarks:[...l.watermarks??[],{id:te(),type:"text",text:"KOPIA",opacity:.12,angle:-45,fontSize:60,color:"var(--nice-text-muted, #94a3b8)"}]}),children:"+ Dodaj znak wodny"})]})]}),s==="signatures"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Podpisy"}),e.jsxs("div",{className:t.wmList,children:[(l.signatures??[]).map(n=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Etykieta"}),e.jsx("input",{className:t.wmInput,value:n.label,onChange:a=>{var p;return h({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,label:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Nazwisko"}),e.jsx("input",{className:t.wmInput,value:n.signerName??"",onChange:a=>{var p;return h({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,signerName:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Linia"}),e.jsx("input",{type:"checkbox",checked:n.showLine??!0,onChange:a=>{var p;return h({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,showLine:a.target.checked}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Pokaż datę"}),e.jsx("input",{type:"checkbox",checked:n.showDate??!1,onChange:a=>{var p;return h({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,showDate:a.target.checked}:u)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var a;return h({signatures:(a=l.signatures)==null?void 0:a.filter(p=>p.id!==n.id)})},children:"Usuń"})]},n.id)),e.jsx("button",{className:t.addBtn,onClick:()=>h({signatures:[...l.signatures??[],{id:te(),label:"Podpis",position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),children:"+ Dodaj podpis"})]})]}),s==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Ustawienia szablonu"}),e.jsxs("div",{className:t.settingsForm,children:[e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Nazwa"}),e.jsx("input",{className:t.settingsInput,value:l.name,onChange:n=>h({name:n.target.value})})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Opis"}),e.jsx("textarea",{className:t.settingsTextarea,value:l.description??"",onChange:n=>h({description:n.target.value}),rows:2})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Kategoria"}),e.jsx("input",{className:t.settingsInput,value:l.category??"",onChange:n=>h({category:n.target.value})})]}),e.jsx("div",{className:t.settingsDivider,children:"Marginesy (mm)"}),["top","right","bottom","left"].map(n=>e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:n==="top"?"Góra":n==="right"?"Prawo":n==="bottom"?"Dół":"Lewo"}),e.jsx("input",{type:"number",min:0,max:50,step:1,className:t.settingsInputNum,value:l.margins[n],onChange:a=>h({margins:{...l.margins,[n]:+a.target.value}})}),e.jsx("span",{className:t.settingsUnit,children:"mm"})]},n))]})]})]})]})},Ca=({field:s,activeTab:r,onTabChange:d,onChange:l,paperWidthMm:w,paperHeightMm:m})=>{var o,D,v,n;const k=j.useCallback(a=>s&&l({position:{...s.position,...a}}),[s,l]),y=j.useCallback(a=>s&&l({style:{...(s==null?void 0:s.style)??{},...a}}),[s,l]);if(!s)return e.jsxs("div",{className:t.rightPanel,children:[e.jsx("div",{className:t.panelHeader,children:"Właściwości"}),e.jsxs("div",{className:t.propsEmpty,children:[e.jsx("div",{className:t.propsEmptyIcon,children:"⬚"}),e.jsx("div",{className:t.propsEmptyText,children:"Zaznacz element na szablonie"}),e.jsxs("div",{className:t.shortcutGrid,children:[e.jsx(ee,{keys:"Del",label:"Usuń"}),e.jsx(ee,{keys:"Ctrl+D",label:"Duplikuj"}),e.jsx(ee,{keys:"↑↓←→",label:"Przesuń"}),e.jsx(ee,{keys:"Ctrl+Z",label:"Cofnij"}),e.jsx(ee,{keys:"Ctrl+A",label:"Zaznacz wszystko"}),e.jsx(ee,{keys:"Shift+↑",label:"Przesuń 5mm"})]})]})]});const h=!["line","rect","image","static_image","barcode","qr","signature"].includes(s.type),g=!["static_text","static_image","line","rect","page_number","total_pages","print_date"].includes(s.type);return e.jsxs("div",{className:t.rightPanel,children:[e.jsxs("div",{className:t.panelHeader,children:[e.jsx("span",{className:t.panelHeaderIcon,children:le[s.type]}),e.jsx("span",{className:t.panelHeaderName,children:s.name})]}),e.jsx("div",{className:t.rightTabs,children:ka.map(a=>a.id==="data"&&!g?null:e.jsx("button",{className:`${t.rightTab} ${r===a.id?t.rightTabActive:""}`,onClick:()=>d(a.id),children:a.label},a.id))}),e.jsxs("div",{className:t.propsBody,children:[r==="position"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.posGrid,children:[[{key:"x",label:"X",unit:"mm"},{key:"y",label:"Y",unit:"mm"},{key:"width",label:"Szer.",unit:"mm"},{key:"height",label:"Wys.",unit:"mm"}].map(({key:a,label:p,unit:u})=>e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:p}),e.jsx("input",{type:"number",step:.5,className:t.posInput,value:Math.round(s.position[a]*10)/10,onChange:N=>k({[a]:+N.target.value})}),e.jsx("span",{className:t.posUnit,children:u})]},a)),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Obrót"}),e.jsx("input",{type:"number",step:5,className:t.posInput,value:s.style.rotation??0,onChange:a=>y({rotation:+a.target.value})}),e.jsx("span",{className:t.posUnit,children:"°"})]}),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Z-idx"}),e.jsx("input",{type:"number",step:1,min:1,className:t.posInput,value:s.position.zIndex??1,onChange:a=>k({zIndex:+a.target.value})})]})]}),e.jsxs("div",{className:t.snapSection,children:[e.jsx("div",{className:t.snapTitle,children:"Wyrównanie do strony"}),e.jsxs("div",{className:t.snapRow,children:[e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:0}),title:"Lewa krawędź",children:"⫷"}),e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:(w-s.position.width)/2}),title:"Środek poziomy",children:"⊕"}),e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:w-s.position.width}),title:"Prawa krawędź",children:"⫸"})]})]})]}),r==="style"&&e.jsxs(e.Fragment,{children:[h&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Czcionka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rodzina"}),e.jsx("select",{className:t.styleSelectFull,value:s.style.fontFamily??"sans-serif",onChange:a=>y({fontFamily:a.target.value}),children:xa.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rozmiar"}),e.jsx("select",{className:t.styleSelectSm,value:je.includes(s.style.fontSize??10)?s.style.fontSize??10:"",onChange:a=>y({fontSize:+a.target.value}),children:je.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("input",{type:"number",step:.5,min:4,max:200,className:t.styleInput,value:s.style.fontSize??10,onChange:a=>y({fontSize:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"pt"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Kolor"}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.color??"var(--nice-text, #000000)",onChange:a=>y({color:a.target.value})}),e.jsx("input",{className:t.colorHex,value:s.style.color??"var(--nice-text, #000000)",onChange:a=>y({color:a.target.value}),maxLength:7})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Styl"}),e.jsxs("div",{className:t.toggleGroup,children:[e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontWeight==="bold"?t.toggleBtnActive:""}`,onClick:()=>y({fontWeight:s.style.fontWeight==="bold"?"normal":"bold"}),children:e.jsx("b",{children:"B"})}),e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontStyle==="italic"?t.toggleBtnActive:""}`,onClick:()=>y({fontStyle:s.style.fontStyle==="italic"?"normal":"italic"}),children:e.jsx("i",{children:"I"})})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Wyrówn."}),e.jsx("div",{className:t.toggleGroup,children:["left","center","right","justify"].map(a=>e.jsx("button",{title:a,className:`${t.toggleBtn} ${(s.style.textAlign??"left")===a?t.toggleBtnActive:""}`,onClick:()=>y({textAlign:a}),children:a==="left"?"≡L":a==="center"?"≡C":a==="right"?"≡R":"≡J"},a))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"W. linii"}),e.jsx("input",{type:"number",step:.1,min:1,max:4,className:t.styleInput,value:s.style.lineHeight??1.4,onChange:a=>y({lineHeight:+a.target.value})})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Odstępy"}),e.jsx("input",{type:"number",step:.01,min:-.1,max:.5,className:t.styleInput,value:s.style.letterSpacing??0,onChange:a=>y({letterSpacing:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"em"})]})]}),e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Tło i ramka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Tło"}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.backgroundColor??"var(--nice-bg, #fff)",onChange:a=>y({backgroundColor:a.target.value})}),e.jsx("button",{className:t.clearBtn,onClick:()=>y({backgroundColor:void 0}),title:"Wyczyść tło",children:"✕"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ramka"}),e.jsx("input",{type:"number",step:.5,min:0,max:10,className:t.styleInput,value:s.style.borderWidth??0,onChange:a=>y({borderWidth:+a.target.value})}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.borderColor??"var(--nice-text, #000000)",onChange:a=>y({borderColor:a.target.value})}),e.jsxs("select",{className:t.styleSelectXs,value:s.style.borderStyle??"solid",onChange:a=>y({borderStyle:a.target.value}),children:[e.jsx("option",{value:"solid",children:"─"}),e.jsx("option",{value:"dashed",children:"- -"}),e.jsx("option",{value:"dotted",children:"···"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Zaokr."}),e.jsx("input",{type:"number",step:1,min:0,max:50,className:t.styleInput,value:s.style.borderRadius??0,onChange:a=>y({borderRadius:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"px"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Padding"}),e.jsx("input",{type:"number",step:.5,min:0,max:20,className:t.styleInput,value:s.style.padding??0,onChange:a=>y({padding:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"mm"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.1,max:1,step:.05,className:t.sliderInput,value:s.style.opacity??1,onChange:a=>y({opacity:+a.target.value})}),e.jsxs("span",{className:t.styleValue,children:[Math.round((s.style.opacity??1)*100),"%"]})]})]})]}),r==="data"&&g&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Źródło danych"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ścieżka"}),e.jsx("input",{className:t.styleInputFull,value:s.dataPath,onChange:a=>l({dataPath:a.target.value}),placeholder:"np. invoice.number"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Format"}),e.jsx("input",{className:t.styleInputFull,value:s.format??"",onChange:a=>l({format:a.target.value}),placeholder:"DD.MM.YYYY / #,##0.00"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Domyślny"}),e.jsx("input",{className:t.styleInputFull,value:s.fallback??"",onChange:a=>l({fallback:a.target.value}),placeholder:"Gdy brak wartości"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Typ"}),e.jsx("select",{className:t.styleSelectFull,value:s.type,onChange:a=>l({type:a.target.value}),children:Object.entries(re).map(([a,p])=>e.jsx("option",{value:a,children:p},a))})]}),(s.type==="barcode"||s.type==="qr")&&e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Format kodu"}),e.jsx("select",{className:t.styleSelectFull,value:s.barcodeType??"code128",onChange:a=>l({barcodeType:a.target.value}),children:["ean13","ean8","code128","code39","upc","itf14","datamatrix"].map(a=>e.jsx("option",{value:a,children:a.toUpperCase()},a))})]})]}),r==="conditional"&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Widoczność warunkowa"}),e.jsx("div",{className:t.conditionalHint,children:"Element zostanie ukryty gdy warunek nie jest spełniony."}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Pole"}),e.jsx("input",{className:t.styleInputFull,value:((o=s.conditional)==null?void 0:o.field)??"",onChange:a=>{var p,u;return l({conditional:{field:a.target.value,operator:((p=s.conditional)==null?void 0:p.operator)??"eq",value:(u=s.conditional)==null?void 0:u.value}})},placeholder:"np. invoice.isPaid"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Operator"}),e.jsxs("select",{className:t.styleSelectFull,value:((D=s.conditional)==null?void 0:D.operator)??"eq",onChange:a=>{var p,u;return l({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:a.target.value,value:(u=s.conditional)==null?void 0:u.value}})},children:[e.jsx("option",{value:"eq",children:"= r�wne"}),e.jsx("option",{value:"neq",children:"≠ różne"}),e.jsx("option",{value:"gt",children:"> wieksze"}),e.jsx("option",{value:"lt",children:"< mniejsze"}),e.jsx("option",{value:"contains",children:"zawiera"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Wartosc"}),e.jsx("input",{className:t.styleInputFull,value:String(((v=s.conditional)==null?void 0:v.value)??""),onChange:a=>{var p,u;return l({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:((u=s.conditional)==null?void 0:u.operator)??"eq",value:a.target.value}})},placeholder:'np. true / "PAID"'})]}),((n=s.conditional)==null?void 0:n.field)&&e.jsx("button",{className:t.clearConditionalBtn,onClick:()=>l({conditional:void 0}),children:"Wyczyść warunek"})]})]})]})};function Ba(){return{id:`tpl-${Date.now()}`,name:"Nowy szablon",description:"",paperSize:"A4",orientation:"portrait",margins:{top:20,right:15,bottom:20,left:15},sections:[{id:"sec-header",type:"header",heightMm:35,fields:[]},{id:"sec-body",type:"body",fields:[]},{id:"sec-footer",type:"footer",heightMm:20,fields:[]}],watermarks:[],signatures:[]}}const Ia=({template:s,dataSchema:r,sampleData:d=[],onChange:l,onSave:w,readOnly:m=!1,className:k,style:y,theme:h="light"})=>{const[{past:g,present:o,future:D},v]=j.useReducer(ja,{past:[],present:s??Ba(),future:[]}),[n,a]=j.useState(new Set),[p,u]=j.useState("sec-body"),[N,z]=j.useState(1),[x,I]=j.useState(0),[C,P]=j.useState("fields"),[A,R]=j.useState("position"),[_,O]=j.useState(!1),[ie,Ne]=j.useState(!0),T=j.useCallback(i=>{const c={...o,...i};v({type:"UPDATE",payload:c}),l==null||l(c)},[o,l]),[Y,oe]=j.useMemo(()=>{const[i,c]=xe[o.paperSize]??xe.A4;return o.orientation==="landscape"?[c,i]:[i,c]},[o.paperSize,o.orientation]),K=j.useMemo(()=>o.sections.flatMap(i=>i.fields),[o]),M=j.useMemo(()=>K.find(i=>n.has(i.id))??null,[K,n]),ce=j.useCallback((i,c)=>{T({sections:o.sections.map(S=>({...S,fields:S.fields.map(f=>f.id===i?{...f,...c,style:{...f.style,...c.style??{}}}:f)}))})},[o,T]),se=j.useCallback(i=>{T({sections:o.sections.map(c=>({...c,fields:c.fields.map(S=>n.has(S.id)?{...S,...i,style:{...S.style,...i.style??{}}}:S)}))})},[o,n,T]),me=j.useCallback((i,c)=>{if(i==="watermark"){T({watermarks:[...o.watermarks??[],{id:te(),type:"text",text:"KOPIA",opacity:.12,angle:-45,fontSize:60,color:"var(--nice-text-muted, #94a3b8)"}]}),P("watermarks");return}if(i==="signature"){T({signatures:[...o.signatures??[],{id:te(),label:"Podpis",position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),P("signatures");return}const S=o.sections.find(E=>E.id===p)??o.sections.find(E=>E.type==="body");if(!S)return;const f=ye(i,c),$={sections:o.sections.map(E=>E.id===S.id?{...E,fields:[...E.fields,f]}:E)};v({type:"UPDATE",payload:{...o,...$}}),l==null||l({...o,...$}),a(new Set([f.id]))},[o,p,l]),we=j.useCallback((i,c,S,f)=>{const $=r==null?void 0:r.fields.find(H=>H.path===c),E=ye(($==null?void 0:$.type)??"text",$);E.position.x=Math.round(S*2)/2,E.position.y=Math.round(f*2)/2;const V={sections:o.sections.map(H=>H.id===i?{...H,fields:[...H.fields,E]}:H)};v({type:"UPDATE",payload:{...o,...V}}),l==null||l({...o,...V}),a(new Set([E.id]))},[o,r,l]),ke=j.useCallback((i,c)=>{c.ctrlKey||c.metaKey?a(S=>{const f=new Set(S);return f.has(i)?f.delete(i):f.add(i),f}):c.shiftKey?a(S=>new Set([...S,i])):a(new Set([i]))},[]),fe=j.useCallback((i,c)=>{if(m)return;c.preventDefault(),n.has(i)||a(new Set([i]));const S=c.clientX,f=c.clientY,$=o.sections.map(H=>({id:H.id,fields:H.fields.map(Z=>({id:Z.id,pos:{...Z.position}}))})),E=H=>{const Z=(H.clientX-S)/(N*G),Q=(H.clientY-f)/(N*G),ae=n.has(i)?n:new Set([i]),ne=o.sections.map(X=>{const U=$.find(W=>W.id===X.id);return{...X,fields:X.fields.map(W=>{var he;if(!ae.has(W.id))return W;const _e=((he=U==null?void 0:U.fields.find(Pe=>Pe.id===W.id))==null?void 0:he.pos)??W.position;return{...W,position:{...W.position,x:Math.max(0,Math.round((_e.x+Z)*2)/2),y:Math.max(0,Math.round((_e.y+Q)*2)/2)}}})}}),J={...o,sections:ne};l==null||l(J),v({type:"UPDATE",payload:J})},V=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",V)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",V)},[o,N,n,m,l]),Se=j.useCallback((i,c,S)=>{if(m)return;S.preventDefault();const f=K.find(Q=>Q.id===i);if(!f)return;const $={...f.position},E=S.clientX,V=S.clientY,H=Q=>{const ae=(Q.clientX-E)/(N*G),ne=(Q.clientY-V)/(N*G);let{x:J,y:X,width:U,height:W}=$;c.includes("e")&&(U=Math.max(5,U+ae)),c.includes("s")&&(W=Math.max(3,W+ne)),c.includes("w")&&(J=J+ae,U=Math.max(5,U-ae)),c.includes("n")&&(X=X+ne,W=Math.max(3,W-ne)),ce(i,{position:{...$,x:Math.round(J*2)/2,y:Math.round(X*2)/2,width:Math.round(U*2)/2,height:Math.round(W*2)/2}})},Z=()=>{document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",Z)};document.addEventListener("mousemove",H),document.addEventListener("mouseup",Z)},[K,N,m,ce]),de=j.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.filter(c=>!n.has(c.id))}))}),a(new Set)},[o,n,T]),ue=j.useCallback(()=>{const i=new Set;T({sections:o.sections.map(c=>{const S=c.fields.filter(f=>n.has(f.id)).map(f=>{const $={...f,id:te(),position:{...f.position,x:f.position.x+5,y:f.position.y+5}};return i.add($.id),$});return{...c,fields:[...c.fields,...S]}})}),a(i)},[o,n,T]),Ce=j.useCallback(i=>{T({sections:o.sections.map(c=>({...c,fields:c.fields.map(S=>{if(!n.has(S.id))return S;const f=i==="left"?o.margins.left:i==="right"?Y-o.margins.right-S.position.width:(Y-S.position.width)/2;return{...S,position:{...S.position,x:f}}})}))})},[o,n,Y,T]),Be=j.useCallback(i=>{const c=o.sections.find(f=>f.id===p);if(!c)return;const S=c.heightMm??200;T({sections:o.sections.map(f=>f.id!==p?f:{...f,fields:f.fields.map($=>{if(!n.has($.id))return $;const E=i==="top"?0:i==="bottom"?S-$.position.height:(S-$.position.height)/2;return{...$,position:{...$.position,y:E}}})})})},[o,n,p,T]),Ie=j.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.map(c=>n.has(c.id)?{...c,position:{...c.position,zIndex:(c.position.zIndex??1)+1}}:c)}))})},[o,n,T]),Le=j.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.map(c=>n.has(c.id)?{...c,position:{...c.position,zIndex:Math.max(1,(c.position.zIndex??1)-1)}}:c)}))})},[o,n,T]),ze=j.useCallback((i,c)=>{T({sections:o.sections.map(S=>({...S,fields:S.fields.map(f=>f.id===i?{...f,position:{...f.position,zIndex:Math.max(1,(f.position.zIndex??1)-c)}}:f)}))})},[o,T]);j.useEffect(()=>{const i=c=>{const S=c.target.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;const f=c.shiftKey?5:.5;c.key==="Delete"||c.key==="Backspace"?n.size&&(c.preventDefault(),de()):c.ctrlKey&&c.key==="z"?(c.preventDefault(),v({type:"UNDO"})):c.ctrlKey&&(c.key==="y"||c.key==="Y")?(c.preventDefault(),v({type:"REDO"})):c.ctrlKey&&(c.key==="d"||c.key==="D")?(c.preventDefault(),n.size&&ue()):c.ctrlKey&&c.key==="a"?(c.preventDefault(),a(new Set(K.map($=>$.id)))):c.key==="ArrowLeft"?(c.preventDefault(),se({position:{...M.position,x:((M==null?void 0:M.position.x)??0)-f}})):c.key==="ArrowRight"?(c.preventDefault(),se({position:{...M.position,x:((M==null?void 0:M.position.x)??0)+f}})):c.key==="ArrowUp"?(c.preventDefault(),se({position:{...M.position,y:((M==null?void 0:M.position.y)??0)-f}})):c.key==="ArrowDown"&&(c.preventDefault(),se({position:{...M.position,y:((M==null?void 0:M.position.y)??0)+f}}))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n,K,M,de,ue,se]);const De=j.useCallback((i,c)=>{T({sections:o.sections.map(S=>S.id===i?{...S,heightMm:Math.round(c*2)/2}:S)})},[o,T]),Te=j.useMemo(()=>{const i=Array.isArray(d)?d[x]:d;return i?"data"in i?i.data:i:{}},[d,x]),$e=Y*N*G,Re=oe*N*G;return e.jsx(ve.NiceAppShell,{flush:!0,className:`${t.root} ${h==="dark"?t.dark:""} ${k??""}`,style:y,toolbar:e.jsx(fa,{tpl:o,zoom:N,canUndo:g.length>0,canRedo:D.length>0,showGrid:_,showRulers:ie,readOnly:m,selectedCount:n.size,onPaperChange:(i,c)=>T({paperSize:i,orientation:c}),onZoom:z,onUndo:()=>v({type:"UNDO"}),onRedo:()=>v({type:"REDO"}),onToggleGrid:()=>O(i=>!i),onToggleRulers:()=>Ne(i=>!i),onInsert:me,onDelete:de,onDuplicate:ue,onAlignH:Ce,onAlignV:Be,onBringForward:Ie,onSendBackward:Le,onSave:w?()=>w(o):void 0}),sidebar:e.jsx(Sa,{activeTab:C,onTabChange:P,schema:r,tpl:o,allFields:K,selectedIds:n,onInsertSchemaField:i=>me(i.type,i),onSelectField:i=>a(new Set([i])),onUpdateTpl:i=>T(i),onReorderField:ze}),rightSidebar:e.jsx(Ca,{field:M,activeTab:A,onTabChange:R,onChange:i=>M&&ce(M.id,i),paperWidthMm:Y,paperHeightMm:oe}),children:e.jsxs("div",{className:t.canvasArea,onClick:()=>a(new Set),children:[Array.isArray(d)&&d.length>0&&e.jsxs("div",{className:t.testDataBar,children:[e.jsx("span",{className:t.testDataLabel,children:"Dane testowe:"}),e.jsx("select",{className:t.testDataSelect,value:x,onChange:i=>I(+i.target.value),children:d.map((i,c)=>e.jsxs("option",{value:c,children:["Rekord ",c+1]},c))})]}),ie&&e.jsxs("div",{className:t.rulerWrapper,children:[e.jsx("div",{className:t.rulerCorner}),e.jsx(be,{lengthMm:Y,zoom:N,orientation:"h"}),e.jsx(be,{lengthMm:oe,zoom:N,orientation:"v"})]}),e.jsx("div",{className:t.paperScroll,onClick:i=>i.stopPropagation(),children:e.jsxs("div",{className:t.paperShadow,style:{width:$e,minHeight:Re},children:[e.jsx("div",{className:t.marginGuide,style:{top:o.margins.top*N*G,right:o.margins.right*N*G,bottom:o.margins.bottom*N*G,left:o.margins.left*N*G}}),(o.watermarks??[]).map(i=>e.jsx("div",{className:t.watermark,style:{fontSize:(i.fontSize??60)*N,color:i.color??"var(--nice-text-muted, #94a3b8)",opacity:i.opacity,transform:`translate(-50%, -50%) rotate(${i.angle}deg)`},children:i.type==="text"?i.text:"??"},i.id)),o.sections.map(i=>e.jsx("div",{children:e.jsx(Na,{section:i,zoom:N,paperWidthMm:Y,selectedIds:n,sampleData:Te,readOnly:m,showGrid:_,onFieldClick:ke,onFieldDragStart:fe,onResizeStart:Se,onSectionHeightChange:De,onDropField:we})},i.id))]})})]})})},La="_root_85lw2_1",za="_dark_85lw2_25",Da="_topBar_85lw2_39",Ta="_searchInput_85lw2_69",$a="_actionBtn_85lw2_111",Ra="_categoryRow_85lw2_157",Pa="_catChip_85lw2_187",Aa="_catChipActive_85lw2_217",Ma="_grid_85lw2_231",Ea="_card_85lw2_253",Fa="_cardSelected_85lw2_285",Ga="_thumbnail_85lw2_307",Ha="_thumbnailImg_85lw2_321",Wa="_thumbnailPlaceholder_85lw2_333",Oa="_paperMini_85lw2_347",Ua="_paperLine_85lw2_371",qa="_cardOverlay_85lw2_385",Ya="_overlayBtn_85lw2_405",Ka="_overlayBtnDanger_85lw2_441",Va="_cardBody_85lw2_481",Za="_cardName_85lw2_489",Xa="_cardDesc_85lw2_517",Qa="_cardMeta_85lw2_539",Ja="_cardSize_85lw2_553",en="_cardCat_85lw2_569",tn="_cardTags_85lw2_585",sn="_cardTag_85lw2_585",an="_emptyState_85lw2_617",nn="_emptyIcon_85lw2_639",B={root:La,dark:za,topBar:Da,searchInput:Ta,actionBtn:$a,categoryRow:Ra,catChip:Pa,catChipActive:Aa,grid:Ma,card:Ea,cardSelected:Fa,thumbnail:Ga,thumbnailImg:Ha,thumbnailPlaceholder:Wa,paperMini:Oa,paperLine:Ua,cardOverlay:qa,overlayBtn:Ya,overlayBtnDanger:Ka,cardBody:Va,cardName:Za,cardDesc:Xa,cardMeta:Qa,cardSize:Ja,cardCat:en,cardTags:tn,cardTag:sn,emptyState:an,emptyIcon:nn},ln=["Faktury","Raporty","Etykiety","Listy","Umowy","Inne"];function rn(s){return new Promise((r,d)=>{const l=new FileReader;l.onload=w=>{var m;try{r(JSON.parse((m=w.target)==null?void 0:m.result))}catch(k){d(k)}},l.readAsText(s)})}function on(s){const r=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),d=URL.createObjectURL(r),l=document.createElement("a");l.href=d,l.download=`${s.name.replace(/\s+/g,"_")}.json`,l.click(),URL.revokeObjectURL(d)}const cn=({templates:s,selectedId:r,onSelect:d,onImport:l,onExport:w,onDelete:m,onNew:k,className:y,style:h,theme:g="light"})=>{const[o,D]=j.useState(""),[v,n]=j.useState(null),[a,p]=j.useState(null),u=j.useRef(null),N=async x=>{var C;const I=(C=x.target.files)==null?void 0:C[0];if(I){try{const P=await rn(I);l==null||l(P)}catch{}x.target.value=""}},z=s.filter(x=>{const I=!o||x.name.toLowerCase().includes(o.toLowerCase())||(x.description??"").toLowerCase().includes(o.toLowerCase())||(x.tags??[]).some(P=>P.toLowerCase().includes(o.toLowerCase())),C=!v||x.category===v;return I&&C});return e.jsxs("div",{className:`${B.root} ${g==="dark"?B.dark:""} ${y??""}`,style:h,children:[e.jsxs("div",{className:B.topBar,children:[e.jsx("input",{type:"search",className:B.searchInput,placeholder:"Szukaj szablonów…",value:o,onChange:x=>D(x.target.value)}),e.jsx("button",{className:B.actionBtn,onClick:k,title:"Nowy szablon",children:"+ Nowy"}),e.jsx("button",{className:B.actionBtn,onClick:()=>{var x;return(x=u.current)==null?void 0:x.click()},title:"Importuj JSON",children:"⬆ Import"}),e.jsx("input",{ref:u,type:"file",accept:".json",hidden:!0,onChange:N})]}),e.jsxs("div",{className:B.categoryRow,children:[e.jsx("button",{className:`${B.catChip} ${v?"":B.catChipActive}`,onClick:()=>n(null),children:"Wszystkie"}),ln.map(x=>e.jsx("button",{className:`${B.catChip} ${v===x?B.catChipActive:""}`,onClick:()=>n(I=>I===x?null:x),children:x},x))]}),e.jsxs("div",{className:B.grid,children:[z.map(x=>e.jsxs("div",{className:`${B.card} ${r===x.id?B.cardSelected:""}`,onClick:()=>d==null?void 0:d(x),onMouseEnter:()=>p(x.id),onMouseLeave:()=>p(null),children:[e.jsxs("div",{className:B.thumbnail,children:[x.previewImageUrl?e.jsx("img",{src:x.previewImageUrl,alt:x.name,className:B.thumbnailImg}):e.jsx("div",{className:B.thumbnailPlaceholder,children:e.jsxs("div",{className:B.paperMini,children:[e.jsx("div",{className:B.paperLine,style:{width:"80%"}}),e.jsx("div",{className:B.paperLine,style:{width:"60%"}}),e.jsx("div",{className:B.paperLine,style:{width:"90%"}}),e.jsx("div",{className:B.paperLine,style:{width:"50%"}})]})}),a===x.id&&e.jsxs("div",{className:B.cardOverlay,children:[e.jsx("button",{className:B.overlayBtn,onClick:I=>{I.stopPropagation(),w==null||w(x),on(x)},title:"Eksportuj",children:"⬇"}),m&&e.jsx("button",{className:B.overlayBtnDanger,onClick:I=>{I.stopPropagation(),m(x.id)},title:"Usuń",children:"✕"})]})]}),e.jsxs("div",{className:B.cardBody,children:[e.jsx("div",{className:B.cardName,children:x.name}),x.description&&e.jsx("div",{className:B.cardDesc,children:x.description}),e.jsxs("div",{className:B.cardMeta,children:[e.jsxs("span",{className:B.cardSize,children:[x.paperSize," ",x.orientation==="landscape"?"↔":"↕"]}),x.category&&e.jsx("span",{className:B.cardCat,children:x.category})]}),x.tags&&x.tags.length>0&&e.jsx("div",{className:B.cardTags,children:x.tags.slice(0,3).map(I=>e.jsx("span",{className:B.cardTag,children:I},I))})]})]},x.id)),z.length===0&&e.jsxs("div",{className:B.emptyState,children:[e.jsx("span",{className:B.emptyIcon,children:"📄"}),e.jsx("span",{children:o?`Brak wyników dla "${o}"`:"Brak szablonów. Utwórz pierwszy!"})]})]})]})},dn="_root_10i1f_1",un="_dark_10i1f_19",pn="_headerBar_10i1f_31",mn="_entityNav_10i1f_59",_n="_navBtn_10i1f_69",hn="_navLabel_10i1f_103",xn="_sampleBadge_10i1f_117",jn="_zoomBar_10i1f_135",yn="_zoomBtn_10i1f_147",bn="_zoomLabel_10i1f_179",gn="_printBtn_10i1f_193",vn="_canvas_10i1f_223",Nn="_page_10i1f_243",wn="_watermark_10i1f_269",kn="_footerBar_10i1f_299",F={root:dn,dark:un,headerBar:pn,entityNav:mn,navBtn:_n,navLabel:hn,sampleBadge:xn,zoomBar:jn,zoomBtn:yn,zoomLabel:bn,printBtn:gn,canvas:vn,page:Nn,watermark:wn,footerBar:kn},q=3.78,ge={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432]};function fn(s,r){try{return s.split(".").reduce((d,l)=>d&&typeof d=="object"?d[l]:null,r)}catch{return null}}function Sn(s,r,d){if(s==null)return"";if(r==="date"&&d)try{const l=new Date(s);if(d==="DD.MM.YYYY"){const w=String(l.getDate()).padStart(2,"0"),m=String(l.getMonth()+1).padStart(2,"0");return`${w}.${m}.${l.getFullYear()}`}return l.toLocaleDateString()}catch{return String(s)}if(r==="currency"&&d){const l=Number(s);if(!isNaN(l))return`${l.toFixed(2)} ${d}`}return r==="number"&&typeof s=="number"?s.toLocaleString("pl-PL"):String(s)}const Cn=({field:s,data:r,zoom:d})=>{const l=s.dataPath?fn(s.dataPath,r):null,w=l!=null?Sn(l,s.type,s.format):s.fallback??"",m=y=>y*d*q,k={position:"absolute",left:m(s.position.x),top:m(s.position.y),width:m(s.position.width),height:m(s.position.height),fontSize:(s.style.fontSize??10)*d,fontWeight:s.style.fontWeight??"normal",fontStyle:s.style.fontStyle??"normal",color:s.style.color??"var(--nice-text-primary, #0f172a)",textAlign:s.style.textAlign??"left",backgroundColor:s.style.backgroundColor,transform:s.style.rotation?`rotate(${s.style.rotation}deg)`:void 0,overflow:"hidden",display:"flex",alignItems:s.style.verticalAlign==="middle"?"center":s.style.verticalAlign==="bottom"?"flex-end":"flex-start",lineHeight:s.style.lineHeight??1.4,padding:s.style.padding?m(s.style.padding):0,boxSizing:"border-box",borderWidth:s.style.borderWidth,borderColor:s.style.borderColor,borderStyle:s.style.borderStyle,borderRadius:s.style.borderRadius,zIndex:s.position.zIndex??1};return s.type==="image"&&l?e.jsx("div",{style:k,children:e.jsx("img",{src:String(l),alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}})}):s.type==="barcode"||s.type==="qr"?e.jsxs("div",{style:{...k,background:"var(--nice-bg-secondary, #f8fafc)",border:"1px dashed var(--nice-border-color, #e2e8f0)",alignItems:"center",justifyContent:"center",fontSize:10*d},children:[s.type==="qr"?"⬛":"▮▌▮"," ",w]}):s.type==="signature"?e.jsx("div",{style:{...k,borderBottom:"1px solid var(--nice-text-primary, #0f172a)",alignItems:"flex-end"},children:e.jsx("span",{style:{fontSize:8*d,color:"var(--nice-text-muted, #94a3b8)"},children:s.label})}):s.type==="line"?e.jsx("div",{style:{...k,borderBottom:`${s.style.borderWidth??1}px ${s.style.borderStyle??"solid"} ${s.style.borderColor??"var(--nice-text-primary, #0f172a)"}`}}):e.jsx("div",{style:k,children:w})},Bn=({template:s,data:r,zoom:d})=>{var y;const[l,w]=(()=>{const[h,g]=ge[s.paperSize]??ge.A4;return s.orientation==="landscape"?[g*q*d,h*q*d]:[h*q*d,g*q*d]})(),m=s.margins,k=s.sections.flatMap(h=>h.fields);return e.jsxs("div",{className:F.page,style:{width:l,minHeight:w},children:[e.jsx("div",{style:{position:"absolute",top:m.top*d*q,left:m.left*d*q,right:m.right*d*q,bottom:m.bottom*d*q},children:k.map(h=>e.jsx(Cn,{field:h,data:r,zoom:d},h.id))}),(y=s.watermarks)==null?void 0:y.map(h=>e.jsx("div",{className:F.watermark,style:{opacity:h.opacity,transform:`rotate(${h.angle}deg)`,fontSize:(h.fontSize??48)*d},children:h.type==="text"?h.text:e.jsx("img",{src:h.imageUrl,alt:"wm",style:{maxWidth:200*d}})},h.id))]})},In=({template:s,entities:r=[],sampleData:d,onPrint:l,className:w,style:m,theme:k="light",asPopup:y=!0,open:h,onClose:g})=>{const{t:o}=ve.useNiceTranslation(),[D,v]=j.useState(0),[n,a]=j.useState(.8),[p,u]=j.useState(!0),N=h!==void 0,z=N?h:p,x=()=>{N||u(!1),g==null||g()};j.useEffect(()=>{if(!y||!z)return;const R=_=>{_.key==="Escape"&&x()};return document.addEventListener("keydown",R),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=""}},[y,z]);const I=j.useMemo(()=>r.length>0?r:d?[d.data]:[{}],[r,d]),C=I[D]??{};if(y&&!z)return null;const P=e.jsxs("div",{className:`${F.root} ${k==="dark"?F.dark:""} ${w??""}`,style:m,children:[e.jsxs("div",{className:F.headerBar,children:[e.jsxs("div",{className:F.entityNav,children:[I.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:F.navBtn,disabled:D===0,onClick:()=>v(R=>R-1),children:"‹"}),e.jsxs("span",{className:F.navLabel,children:[D+1," / ",I.length]}),e.jsx("button",{className:F.navBtn,disabled:D>=I.length-1,onClick:()=>v(R=>R+1),children:"›"})]}),r.length===0&&d&&e.jsx("span",{className:F.sampleBadge,children:"Przykładowe dane"})]}),e.jsxs("div",{className:F.zoomBar,children:[e.jsx("button",{className:F.zoomBtn,onClick:()=>a(R=>Math.max(.3,R-.1)),children:"−"}),e.jsxs("span",{className:F.zoomLabel,children:[Math.round(n*100),"%"]}),e.jsx("button",{className:F.zoomBtn,onClick:()=>a(R=>Math.min(2.5,R+.1)),children:"+"}),e.jsx("button",{className:F.zoomBtn,onClick:()=>a(.8),title:"Dopasuj",children:"⊡"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:F.printBtn,onClick:()=>l==null?void 0:l({copies:1,printerId:""}),children:o("printPreview.print","Drukuj")}),y&&e.jsx("button",{type:"button",className:F.zoomBtn,onClick:x,"aria-label":o("common.close","Zamknij"),title:o("common.close","Zamknij"),children:"✕"})]})]}),e.jsx("div",{className:F.canvas,children:e.jsx(Bn,{template:s,data:C,zoom:n})}),e.jsxs("div",{className:F.footerBar,children:[e.jsx("span",{children:s.name}),e.jsxs("span",{children:[s.paperSize," · ",s.orientation==="portrait"?"Pion":"Poziom"]}),s.sections.reduce((R,_)=>R+_.fields.length,0)," pól"]})]});if(!y)return P;const A=e.jsx("div",{style:{position:"fixed",inset:0,background:"color-mix(in srgb, var(--nice-text-primary, #000) 50%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:24},onMouseDown:R=>{R.target===R.currentTarget&&x()},role:"presentation",children:e.jsx("div",{role:"dialog","aria-modal":"true",style:{background:"var(--nice-bg-elevated, var(--nice-bg-primary, #ffffff))",borderRadius:12,boxShadow:"0 20px 60px color-mix(in srgb, var(--nice-text-primary, #000) 30%, transparent)",maxWidth:"90vw",maxHeight:"90vh",overflow:"auto"},children:P})});return Ae.createPortal(A,document.body)},Ln="_root_lsn26_1",zn="_dark_lsn26_23",Dn="_statsBar_lsn26_37",Tn="_stat_lsn26_37",$n="_dot_lsn26_75",Rn="_statPrinting_lsn26_87",Pn="_statQueued_lsn26_93",An="_statDone_lsn26_99",Mn="_statError_lsn26_105",En="_toolbar_lsn26_115",Fn="_filterTabs_lsn26_139",Gn="_filterTab_lsn26_139",Hn="_filterTabActive_lsn26_177",Wn="_filterCount_lsn26_187",On="_bulkActions_lsn26_211",Un="_bulkCount_lsn26_223",qn="_bulkBtn_lsn26_231",Yn="_bulkBtnRemove_lsn26_255",Kn="_jobList_lsn26_273",Vn="_listHeader_lsn26_281",Zn="_headerLabel_lsn26_313",Xn="_jobRow_lsn26_323",Qn="_jobRowSelected_lsn26_359",Jn="_jobCheckbox_lsn26_373",el="_statusBadge_lsn26_387",tl="_pulse_lsn26_1",sl="_jobInfo_lsn26_479",al="_jobName_lsn26_485",nl="_jobMeta_lsn26_497",ll="_jobTime_lsn26_513",rl="_jobDuration_lsn26_519",il="_jobError_lsn26_525",ol="_progressBar_lsn26_539",cl="_progressFill_lsn26_553",dl="_copiesEditor_lsn26_569",ul="_copiesBtn_lsn26_581",pl="_copiesValue_lsn26_621",ml="_jobActions_lsn26_635",_l="_actionBtn_lsn26_645",hl="_removeBtn_lsn26_677",xl="_emptyState_lsn26_695",b={root:Ln,dark:zn,statsBar:Dn,stat:Tn,dot:$n,statPrinting:Rn,statQueued:Pn,statDone:An,statError:Mn,toolbar:En,filterTabs:Fn,filterTab:Gn,filterTabActive:Hn,filterCount:Wn,bulkActions:On,bulkCount:Un,bulkBtn:qn,bulkBtnRemove:Yn,jobList:Kn,listHeader:Vn,headerLabel:Zn,jobRow:Xn,jobRowSelected:Qn,jobCheckbox:Jn,statusBadge:el,"badge-queued":"_badge-queued_lsn26_405","badge-printing":"_badge-printing_lsn26_413",pulse:tl,"badge-done":"_badge-done_lsn26_423","badge-error":"_badge-error_lsn26_431","badge-paused":"_badge-paused_lsn26_439","badge-cancelled":"_badge-cancelled_lsn26_447",jobInfo:sl,jobName:al,jobMeta:nl,jobTime:ll,jobDuration:rl,jobError:il,progressBar:ol,progressFill:cl,copiesEditor:dl,copiesBtn:ul,copiesValue:pl,jobActions:ml,actionBtn:_l,removeBtn:hl,emptyState:xl},pe={queued:"Kolejka",printing:"Drukowanie",done:"Wydrukowano",error:"Błąd",paused:"Wstrzymano",cancelled:"Anulowano"};function jl(s){try{return new Date(s).toLocaleTimeString("pl-PL",{hour:"2-digit",minute:"2-digit"})}catch{return s}}function yl(s){const r=Date.now()-new Date(s).getTime(),d=Math.floor(r/1e3);return d<60?`${d}s`:`${Math.floor(d/60)}m ${d%60}s`}const bl=({jobs:s})=>{const r=s.filter(m=>m.status==="printing").length,d=s.filter(m=>m.status==="queued").length,l=s.filter(m=>m.status==="done").length,w=s.filter(m=>m.status==="error").length;return e.jsxs("div",{className:b.statsBar,children:[e.jsxs("span",{className:`${b.stat} ${b.statPrinting}`,children:[e.jsx("span",{className:b.dot}),"Drukuje: ",e.jsx("strong",{children:r})]}),e.jsxs("span",{className:`${b.stat} ${b.statQueued}`,children:[e.jsx("span",{className:b.dot}),"W kolejce: ",e.jsx("strong",{children:d})]}),e.jsxs("span",{className:`${b.stat} ${b.statDone}`,children:[e.jsx("span",{className:b.dot}),"Gotowe: ",e.jsx("strong",{children:l})]}),w>0&&e.jsxs("span",{className:`${b.stat} ${b.statError}`,children:[e.jsx("span",{className:b.dot}),"Błędy: ",e.jsx("strong",{children:w})]})]})},gl=({job:s,index:r,total:d,printers:l,selected:w,onSelect:m,onUpdate:k,onRemove:y,onPrint:h,onReorder:g})=>{const o=l.find(n=>n.id===s.options.printerId),D=r>0&&s.status==="queued",v=r<d-1&&s.status==="queued";return e.jsxs("div",{className:`${b.jobRow} ${w?b.jobRowSelected:""} ${b[`status-${s.status}`]??""}`,children:[e.jsx("input",{type:"checkbox",className:b.jobCheckbox,checked:w,onChange:()=>m(s.id)}),e.jsx("span",{className:`${b.statusBadge} ${b[`badge-${s.status}`]}`,children:pe[s.status]??s.status}),e.jsxs("div",{className:b.jobInfo,children:[e.jsx("div",{className:b.jobName,children:s.templateName??s.templateId}),e.jsxs("div",{className:b.jobMeta,children:[s.entityLabel&&e.jsx("span",{children:s.entityLabel}),o&&e.jsxs("span",{children:["🖨 ",o.name]}),e.jsxs("span",{children:["×",s.options.copies]}),s.createdAt&&e.jsx("span",{className:b.jobTime,children:jl(s.createdAt)}),s.startedAt&&s.status!=="done"&&e.jsx("span",{className:b.jobDuration,children:yl(s.startedAt)})]}),s.status==="printing"&&s.progress!=null&&e.jsx("div",{className:b.progressBar,children:e.jsx("div",{className:b.progressFill,style:{width:`${s.progress}%`}})}),s.status==="error"&&s.errorMessage&&e.jsx("div",{className:b.jobError,children:s.errorMessage})]}),e.jsxs("div",{className:b.copiesEditor,children:[e.jsx("button",{className:b.copiesBtn,disabled:s.options.copies<=1,onClick:()=>k(s.id,{options:{...s.options,copies:s.options.copies-1}}),children:"−"}),e.jsx("span",{className:b.copiesValue,children:s.options.copies}),e.jsx("button",{className:b.copiesBtn,onClick:()=>k(s.id,{options:{...s.options,copies:s.options.copies+1}}),children:"+"})]}),e.jsxs("div",{className:b.jobActions,children:[D&&e.jsx("button",{className:b.actionBtn,title:"Przesuń wyżej",onClick:()=>g(r,r-1),children:"↑"}),v&&e.jsx("button",{className:b.actionBtn,title:"Przesuń niżej",onClick:()=>g(r,r+1),children:"↓"}),s.status==="queued"&&e.jsx("button",{className:b.actionBtn,title:"Drukuj teraz",onClick:()=>h(s.id),children:"▶"}),s.status==="printing"&&e.jsx("button",{className:b.actionBtn,title:"Wstrzymaj",onClick:()=>k(s.id,{status:"paused"}),children:"⏸"}),s.status==="paused"&&e.jsx("button",{className:b.actionBtn,title:"Wznów",onClick:()=>k(s.id,{status:"queued"}),children:"▶"}),e.jsx("button",{className:`${b.actionBtn} ${b.removeBtn}`,title:"Usuń",onClick:()=>y(s.id),children:"✕"})]})]})},vl=({jobs:s,printers:r=[],onJobUpdate:d,onJobRemove:l,onJobReorder:w,onJobPrint:m,onBulkRemove:k,onBulkPrint:y,maxHeight:h=500,className:g,style:o,theme:D="light"})=>{const[v,n]=j.useState(new Set),[a,p]=j.useState("all"),u=a==="all"?s:s.filter(C=>C.status===a),N=j.useCallback(C=>{n(P=>{const A=new Set(P);return A.has(C)?A.delete(C):A.add(C),A})},[]),z=j.useCallback(()=>{v.size===u.length?n(new Set):n(new Set(u.map(C=>C.id)))},[u,v.size]),x=j.useCallback(()=>{k==null||k(Array.from(v)),n(new Set)},[v,k]),I=j.useCallback(()=>{y==null||y(Array.from(v)),n(new Set)},[v,y]);return e.jsxs("div",{className:`${b.root} ${D==="dark"?b.dark:""} ${g??""}`,style:o,children:[e.jsx(bl,{jobs:s}),e.jsxs("div",{className:b.toolbar,children:[e.jsx("div",{className:b.filterTabs,children:["all","queued","printing","done","error"].map(C=>e.jsxs("button",{className:`${b.filterTab} ${a===C?b.filterTabActive:""}`,onClick:()=>p(C),children:[C==="all"?"Wszystkie":pe[C],e.jsx("span",{className:b.filterCount,children:C==="all"?s.length:s.filter(P=>P.status===C).length})]},C))}),v.size>0&&e.jsxs("div",{className:b.bulkActions,children:[e.jsxs("span",{className:b.bulkCount,children:[v.size," zaznaczonych"]}),y&&e.jsx("button",{className:b.bulkBtn,onClick:I,children:"▶ Drukuj wybrane"}),k&&e.jsx("button",{className:`${b.bulkBtn} ${b.bulkBtnRemove}`,onClick:x,children:"✕ Usuń wybrane"})]})]}),e.jsx("div",{className:b.jobList,style:{maxHeight:h},children:u.length===0?e.jsx("div",{className:b.emptyState,children:a==="all"?"Brak zadań w kolejce":`Brak zadań ze statusem "${pe[a]}"`}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:b.listHeader,children:[e.jsx("input",{type:"checkbox",onChange:z,checked:v.size===u.length&&u.length>0}),e.jsx("span",{className:b.headerLabel,children:"Zadanie"}),e.jsx("span",{className:b.headerLabel,children:"Kopie"}),e.jsx("span",{className:b.headerLabel,children:"Akcje"})]}),u.map((C,P)=>e.jsx(gl,{job:C,index:s.indexOf(C),total:s.length,printers:r,selected:v.has(C.id),onSelect:N,onUpdate:d,onRemove:l,onPrint:m,onReorder:w},C.id))]})})]})},Nl="_container_yxz96_1",wl="_buttonGroup_yxz96_19",kl="_trigger_yxz96_31",fl="_triggerDisabled_yxz96_57",Sl="_mainAction_yxz96_151",Cl="_dropdownToggle_yxz96_175",Bl="_chevron_yxz96_201",Il="_chevronUp_yxz96_211",Ll="_dropdown_yxz96_175",zl="_dark_yxz96_245",Dl="_section_yxz96_257",Tl="_sectionLabel_yxz96_263",$l="_divider_yxz96_283",Rl="_copiesRow_yxz96_301",Pl="_copiesBtn_yxz96_311",Al="_copiesValue_yxz96_351",Ml="_printerSelect_yxz96_375",El="_printerStatus_yxz96_415",Fl="_printerDot_yxz96_429",Gl="_printerStatusLabel_yxz96_463",Hl="_submitBtn_yxz96_473",Wl="_spinner_yxz96_515",Ol="_spin_yxz96_515",L={container:Nl,buttonGroup:wl,trigger:kl,triggerDisabled:fl,"variant-primary":"_variant-primary_yxz96_69","variant-secondary":"_variant-secondary_yxz96_83","variant-ghost":"_variant-ghost_yxz96_99","size-sm":"_size-sm_yxz96_117","size-md":"_size-md_yxz96_127","size-lg":"_size-lg_yxz96_137",mainAction:Sl,dropdownToggle:Cl,chevron:Bl,chevronUp:Il,dropdown:Ll,dark:zl,section:Dl,sectionLabel:Tl,divider:$l,copiesRow:Rl,copiesBtn:Pl,copiesValue:Al,printerSelect:Ml,printerStatus:El,printerDot:Fl,"dot-ready":"_dot-ready_yxz96_439","dot-busy":"_dot-busy_yxz96_445","dot-offline":"_dot-offline_yxz96_451","dot-error":"_dot-error_yxz96_457",printerStatusLabel:Gl,submitBtn:Hl,spinner:Wl,spin:Ol},Ul=({onPrint:s,printers:r=[],defaultPrinterId:d,defaultCopies:l=1,disabled:w=!1,loading:m=!1,variant:k="primary",size:y="md",label:h="Drukuj",className:g,style:o,theme:D="light"})=>{var R;const[v,n]=j.useState(!1),[a,p]=j.useState(l),[u,N]=j.useState(d??((R=r[0])==null?void 0:R.id)??""),z=j.useRef(null);j.useEffect(()=>{if(!v)return;const _=O=>{z.current&&!z.current.contains(O.target)&&n(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[v]);const x=j.useCallback(()=>{s({copies:a,printerId:u}),n(!1)},[a,u,s]),I=j.useCallback(()=>p(_=>Math.min(99,_+1)),[]),C=j.useCallback(()=>p(_=>Math.max(1,_-1)),[]),P=[L.container,D==="dark"?L.dark:"",g??""].filter(Boolean).join(" "),A=[L.trigger,L[`variant-${k}`],L[`size-${y}`],w||m?L.triggerDisabled:""].filter(Boolean).join(" ");return e.jsxs("div",{ref:z,className:P,style:o,children:[e.jsxs("div",{className:L.buttonGroup,children:[e.jsxs("button",{className:`${A} ${L.mainAction}`,disabled:w||m,onClick:x,"aria-label":h,children:[m?e.jsx("span",{className:L.spinner}):e.jsx("span",{children:"🖨"}),e.jsx("span",{children:h})]}),e.jsx("button",{className:`${A} ${L.dropdownToggle}`,disabled:w||m,onClick:()=>n(_=>!_),"aria-label":"Opcje druku","aria-expanded":v,children:e.jsx("span",{className:`${L.chevron} ${v?L.chevronUp:""}`,children:"▾"})})]}),v&&e.jsxs("div",{className:L.dropdown,children:[e.jsxs("div",{className:L.section,children:[e.jsx("label",{className:L.sectionLabel,children:"Liczba kopii"}),e.jsxs("div",{className:L.copiesRow,children:[e.jsx("button",{className:L.copiesBtn,onClick:C,disabled:a<=1,children:"−"}),e.jsx("span",{className:L.copiesValue,children:a}),e.jsx("button",{className:L.copiesBtn,onClick:I,disabled:a>=99,children:"+"})]})]}),e.jsx("div",{className:L.divider}),r.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:L.section,children:[e.jsx("label",{className:L.sectionLabel,children:"Drukarka"}),e.jsx("select",{className:L.printerSelect,value:u,onChange:_=>N(_.target.value),children:r.map(_=>e.jsxs("option",{value:_.id,disabled:_.status==="offline"||!_.isOnline&&_.status==null,children:[_.name," ",_.status==="offline"||!_.isOnline&&_.status==null?"(Offline)":_.status==="busy"?"(Zajęta)":""]},_.id))}),r.find(_=>_.id===u)&&e.jsx("div",{className:L.printerStatus,children:(()=>{const _=r.find(ie=>ie.id===u),O=_.status??(_.isOnline?"ready":"offline");return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`${L.printerDot} ${L[`dot-${O}`]}`}),e.jsx("span",{className:L.printerStatusLabel,children:O==="ready"?"Gotowa":O==="busy"?"Zajęta":O==="offline"?"Offline":"Błąd"})]})})()})]}),e.jsx("div",{className:L.divider})]}),e.jsx("div",{className:L.section,children:e.jsx("button",{className:L.submitBtn,onClick:x,disabled:w||m||r.length>0&&(()=>{const _=r.find(O=>O.id===u);return _!=null&&(_.status==="offline"||!_.isOnline&&_.status==null)})(),children:m?"Drukowanie...":`🖨 Drukuj${a>1?` (${a} kopie)`:""}`})})]})]})};exports.NicePrintButton=Ul;exports.NicePrintPreview=In;exports.NicePrintQueue=vl;exports.NiceTemplateBrowser=cn;exports.NiceTemplateEditor=Ia;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),_=require("@nice2dev/ui"),x=require("react"),Ge=require("react-dom"),Oe="_root_lceud_3",qe="_dark_lceud_27",We="_toolbar_lceud_39",Ue="_toolbarGroup_lceud_75",Ye="_toolbarBtn_lceud_107",Ve="_toolbarBtnActive_lceud_171",Ke="_toolbarBtnDanger_lceud_195",Xe="_toolbarSelect_lceud_207",Je="_toolbarSep_lceud_237",Qe="_insertWrapper_lceud_263",Ze="_insertBtn_lceud_271",et="_insertDropdown_lceud_293",tt="_insertCategory_lceud_333",st="_insertItem_lceud_351",nt="_insertIcon_lceud_395",at="_zoomSelect_lceud_409",it="_saveBtn_lceud_441",lt="_editorBody_lceud_477",rt="_leftPanel_lceud_493",ot="_leftTabs_lceud_523",ct="_leftTab_lceud_523",dt="_leftTabActive_lceud_601",pt="_leftTabIcon_lceud_621",ut="_leftTabLabel_lceud_629",mt="_leftContent_lceud_639",ht="_panelHeader_lceud_653",_t="_panelHeaderIcon_lceud_677",gt="_panelHeaderName_lceud_685",bt="_searchBox_lceud_699",xt="_searchInput_lceud_707",yt="_fieldList_lceud_753",vt="_fieldItem_lceud_763",jt="_fieldItemIcon_lceud_807",Nt="_fieldItemInfo_lceud_821",ft="_fieldItemLabel_lceud_831",wt="_fieldItemPath_lceud_847",kt="_fieldItemType_lceud_863",St="_layerList_lceud_883",It="_layerItem_lceud_895",Ct="_layerItemSelected_lceud_931",Bt="_layerIcon_lceud_949",Lt="_layerName_lceud_961",zt="_layerActions_lceud_977",Tt="_layerBtn_lceud_999",Dt="_wmList_lceud_1031",$t="_wmItem_lceud_1039",Rt="_wmRow_lceud_1065",At="_wmLabel_lceud_1079",Mt="_wmInput_lceud_1091",Pt="_wmInputNum_lceud_1123",Et="_wmSelect_lceud_1143",Ft="_wmSlider_lceud_1175",Ht="_wmValue_lceud_1185",Gt="_wmUnit_lceud_1199",Ot="_wmDelete_lceud_1209",qt="_addBtn_lceud_1241",Wt="_settingsForm_lceud_1277",Ut="_settingsRow_lceud_1285",Yt="_settingsLabel_lceud_1299",Vt="_settingsInput_lceud_1311",Kt="_settingsInputNum_lceud_1343",Xt="_settingsTextarea_lceud_1375",Jt="_settingsDivider_lceud_1409",Qt="_settingsUnit_lceud_1429",Zt="_emptyMsg_lceud_1441",es="_canvasArea_lceud_1459",ts="_testDataBar_lceud_1485",ss="_testDataLabel_lceud_1517",ns="_testDataSelect_lceud_1527",as="_rulerWrapper_lceud_1547",is="_rulerCorner_lceud_1563",ls="_ruler_lceud_1547",rs="_ruler_h_lceud_1621",os="_ruler_v_lceud_1631",cs="_rulerTick_lceud_1651",ds="_rulerTickMajor_lceud_1691",ps="_rulerLabel_lceud_1711",us="_paperScroll_lceud_1749",ms="_paperShadow_lceud_1767",hs="_marginGuide_lceud_1803",_s="_watermark_lceud_1819",gs="_sectionCanvas_lceud_1845",bs="_sectionCanvasOver_lceud_1859",xs="_sectionTypeChip_lceud_1867",ys="_sectionResizeBar_lceud_1899",vs="_sectionResizeGrip_lceud_1933",js="_fieldImagePlaceholder_lceud_1949",Ns="_fieldBarcodePlaceholder_lceud_1971",fs="_fieldSignaturePlaceholder_lceud_1999",ws="_resizeHandle_lceud_2031",ks="_handle_n_lceud_2051",Ss="_handle_s_lceud_2063",Is="_handle_e_lceud_2075",Cs="_handle_w_lceud_2087",Bs="_handle_ne_lceud_2099",Ls="_handle_nw_lceud_2109",zs="_handle_se_lceud_2119",Ts="_handle_sw_lceud_2129",Ds="_rightPanel_lceud_2143",$s="_rightTabs_lceud_2173",Rs="_rightTab_lceud_2173",As="_rightTabActive_lceud_2243",Ms="_propsBody_lceud_2255",Ps="_propsEmpty_lceud_2267",Es="_propsEmptyIcon_lceud_2289",Fs="_propsEmptyText_lceud_2299",Hs="_posGrid_lceud_2311",Gs="_posCell_lceud_2325",Os="_posLabel_lceud_2337",qs="_posInput_lceud_2349",Ws="_posUnit_lceud_2391",Us="_snapSection_lceud_2403",Ys="_snapTitle_lceud_2411",Vs="_snapRow_lceud_2429",Ks="_snapBtn_lceud_2439",Xs="_styleGroup_lceud_2473",Js="_styleGroupTitle_lceud_2481",Qs="_styleRow_lceud_2511",Zs="_styleLabel_lceud_2525",en="_styleSelect_lceud_2539",tn="_styleSelectFull_lceud_2569",sn="_styleSelectSm_lceud_2601",nn="_styleSelectXs_lceud_2621",an="_styleInput_lceud_2653",ln="_styleInputFull_lceud_2685",rn="_styleUnit_lceud_2717",on="_styleValue_lceud_2729",cn="_toggleGroup_lceud_2743",dn="_toggleBtn_lceud_2753",pn="_toggleBtnActive_lceud_2787",un="_colorPicker_lceud_2801",mn="_colorHex_lceud_2819",hn="_clearBtn_lceud_2853",_n="_sliderInput_lceud_2885",gn="_conditionalHint_lceud_2897",bn="_clearConditionalBtn_lceud_2929",xn="_shortcutGrid_lceud_2961",yn="_shortcutChip_lceud_2975",vn="_shortcutKeys_lceud_3007",jn="_shortcutLabel_lceud_3027",t={root:Oe,dark:qe,toolbar:We,toolbarGroup:Ue,toolbarBtn:Ye,toolbarBtnActive:Ve,toolbarBtnDanger:Ke,toolbarSelect:Xe,toolbarSep:Je,insertWrapper:Qe,insertBtn:Ze,insertDropdown:et,insertCategory:tt,insertItem:st,insertIcon:nt,zoomSelect:at,saveBtn:it,editorBody:lt,leftPanel:rt,leftTabs:ot,leftTab:ct,leftTabActive:dt,leftTabIcon:pt,leftTabLabel:ut,leftContent:mt,panelHeader:ht,panelHeaderIcon:_t,panelHeaderName:gt,searchBox:bt,searchInput:xt,fieldList:yt,fieldItem:vt,fieldItemIcon:jt,fieldItemInfo:Nt,fieldItemLabel:ft,fieldItemPath:wt,fieldItemType:kt,layerList:St,layerItem:It,layerItemSelected:Ct,layerIcon:Bt,layerName:Lt,layerActions:zt,layerBtn:Tt,wmList:Dt,wmItem:$t,wmRow:Rt,wmLabel:At,wmInput:Mt,wmInputNum:Pt,wmSelect:Et,wmSlider:Ft,wmValue:Ht,wmUnit:Gt,wmDelete:Ot,addBtn:qt,settingsForm:Wt,settingsRow:Ut,settingsLabel:Yt,settingsInput:Vt,settingsInputNum:Kt,settingsTextarea:Xt,settingsDivider:Jt,settingsUnit:Qt,emptyMsg:Zt,canvasArea:es,testDataBar:ts,testDataLabel:ss,testDataSelect:ns,rulerWrapper:as,rulerCorner:is,ruler:ls,ruler_h:rs,ruler_v:os,rulerTick:cs,rulerTickMajor:ds,rulerLabel:ps,paperScroll:us,paperShadow:ms,marginGuide:hs,watermark:_s,sectionCanvas:gs,sectionCanvasOver:bs,sectionTypeChip:xs,sectionResizeBar:ys,sectionResizeGrip:vs,fieldImagePlaceholder:js,fieldBarcodePlaceholder:Ns,fieldSignaturePlaceholder:fs,resizeHandle:ws,handle_n:ks,handle_s:Ss,handle_e:Is,handle_w:Cs,handle_ne:Bs,handle_nw:Ls,handle_se:zs,handle_sw:Ts,rightPanel:Ds,rightTabs:$s,rightTab:Rs,rightTabActive:As,propsBody:Ms,propsEmpty:Ps,propsEmptyIcon:Es,propsEmptyText:Fs,posGrid:Hs,posCell:Gs,posLabel:Os,posInput:qs,posUnit:Ws,snapSection:Us,snapTitle:Ys,snapRow:Vs,snapBtn:Ks,styleGroup:Xs,styleGroupTitle:Js,styleRow:Qs,styleLabel:Zs,styleSelect:en,styleSelectFull:tn,styleSelectSm:sn,styleSelectXs:nn,styleInput:an,styleInputFull:ln,styleUnit:rn,styleValue:on,toggleGroup:cn,toggleBtn:dn,toggleBtnActive:pn,colorPicker:un,colorHex:mn,clearBtn:hn,sliderInput:_n,conditionalHint:gn,clearConditionalBtn:bn,shortcutGrid:xn,shortcutChip:yn,shortcutKeys:vn,shortcutLabel:jn},O=3.78,Ne={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432],custom:[210,297]},Nn=["sans-serif","serif","monospace","Arial","Times New Roman","Courier New","Georgia","Verdana","Tahoma"],fe=[6,7,8,9,10,11,12,14,16,18,20,24,28,32,36,48,60,72],ce={text:"type",number:"hash",currency:"dollar",date:"calendar",datetime:"clock",boolean:"check-square",image:"image",barcode:"barcode",qr:"qr-code",signature:"pen",static_text:"type",static_image:"image",line:"line",rect:"square",page_number:"hash",total_pages:"layers",print_date:"calendar"},de={text:"Text",number:"Number",currency:"Currency",date:"Date",datetime:"Date and time",boolean:"Yes/No",image:"Image",barcode:"Barcode",qr:"QR",signature:"Signature",static_text:"Static text",static_image:"Static image",line:"Line",rect:"Rectangle",page_number:"Page number",total_pages:"Total pages",print_date:"Print date"},be=(s,l)=>de[l]?s(`printing.fieldType.${l}`,de[l]):l;function fn(s,l){switch(l.type){case"UPDATE":return{past:[...s.past.slice(-50),s.present],present:l.payload,future:[]};case"UNDO":return s.past.length?{past:s.past.slice(0,-1),present:s.past[s.past.length-1],future:[s.present,...s.future]}:s;case"REDO":return s.future.length?{past:[...s.past,s.present],present:s.future[0],future:s.future.slice(1)}:s;default:return s}}const te="#000000",pe="#94a3b8";function ie(){return`f-${Date.now()}-${Math.floor(Math.random()*1e3)}`}function we(s,l){const c={id:ie(),name:(l==null?void 0:l.label)??de[s]??s,label:(l==null?void 0:l.label)??de[s]??s,type:s,dataPath:(l==null?void 0:l.path)??"",fallback:s==="static_text"?"Static text":void 0,format:s==="date"||s==="datetime"?"DD.MM.YYYY":void 0,position:{x:15,y:15,width:s==="line"?80:60,height:s==="line"?1:s==="image"?30:8},style:{fontSize:10,color:te,fontFamily:"sans-serif"}};return s==="rect"&&(c.style.backgroundColor="var(--nice-bg-secondary, #f1f5f9)"),s==="line"&&(c.style={...c.style,borderWidth:.5,borderColor:te,borderStyle:"solid"}),c}const ke=({lengthMm:s,zoom:l,orientation:c})=>{const r=[],w=l<.6?20:l<1?10:5;for(let b=0;b<=s;b+=w){const u=b*l*O,I=b%(w*2)===0;r.push(e.jsx("div",{className:`${t.rulerTick} ${I?t.rulerTickMajor:""}`,style:c==="h"?{left:u}:{top:u},children:I&&e.jsx("span",{className:t.rulerLabel,children:b})},b))}return e.jsx("div",{className:`${t.ruler} ${t[`ruler_${c}`]}`,children:r})},wn=["n","s","e","w","ne","nw","se","sw"],kn=({onResizeStart:s})=>e.jsx(e.Fragment,{children:wn.map(l=>e.jsx("div",{className:`${t.resizeHandle} ${t[`handle_${l}`]}`,onMouseDown:c=>{c.stopPropagation(),s(l,c)}},l))});function Sn(s,l){if(s.type==="static_text")return s.fallback??"Text";if(s.type==="page_number")return"1";if(s.type==="total_pages")return"3";if(s.type==="print_date")return new Date().toLocaleDateString("pl-PL");if(l&&s.dataPath){const c=s.dataPath.split(".").reduce((r,w)=>r&&typeof r=="object"?r[w]:null,l);if(c!=null)return String(c)}return s.label?`{${s.label}}`:`{${s.dataPath}}`}const In=({field:s,zoom:l,selected:c,sampleData:r,onClick:w,onDragStart:b,onResizeStart:u,readOnly:I})=>{const m=s.position,j=s.style,a=h=>h*l*O,L=s.type==="line",N=s.type==="rect",C=s.type==="image"||s.type==="static_image",i=s.type==="barcode"||s.type==="qr",n={position:"absolute",left:a(m.x),top:a(m.y),width:a(m.width),height:a(m.height),zIndex:m.zIndex??1,transform:j.rotation?`rotate(${j.rotation}deg)`:void 0,boxSizing:"border-box",overflow:"hidden",...!L&&!N?{fontSize:(j.fontSize??10)*l,fontFamily:j.fontFamily??"sans-serif",fontWeight:j.fontWeight??"normal",fontStyle:j.fontStyle??"normal",color:j.color??te,textAlign:j.textAlign??"left",lineHeight:j.lineHeight??1.4,letterSpacing:j.letterSpacing?`${j.letterSpacing}em`:void 0,padding:j.padding?a(j.padding):0}:{},backgroundColor:j.backgroundColor,borderWidth:j.borderWidth??0,borderColor:j.borderColor??"transparent",borderStyle:j.borderStyle??"solid",borderRadius:j.borderRadius,opacity:j.opacity,outline:c?"1.5px solid var(--nice-primary-hover, #2563eb)":"1px dashed transparent",outlineOffset:1,cursor:I?"default":"move"};return e.jsxs("div",{style:n,onClick:w,onMouseDown:I?void 0:b,children:[L?e.jsx("div",{style:{width:"100%",borderBottom:`${(j.borderWidth??.5)*l}px ${j.borderStyle??"solid"} ${j.borderColor??te}`}}):N?null:C?e.jsx("div",{className:t.fieldImagePlaceholder,children:e.jsx(_.NiceIcon,{name:"image",size:24})}):i?e.jsxs("div",{className:t.fieldBarcodePlaceholder,children:[e.jsx(_.NiceIcon,{name:s.type==="qr"?"qr-code":"barcode",size:14})," ",s.type==="qr"?"QR":"Barcode"]}):s.type==="signature"?e.jsxs("div",{className:t.fieldSignaturePlaceholder,children:[e.jsx(_.NiceIcon,{name:"pen",size:14})," ",s.label]}):e.jsx("span",{style:{display:"block",width:"100%"},children:Sn(s,r)}),c&&!I&&e.jsx(kn,{onResizeStart:u})]})},Cn=({section:s,zoom:l,paperWidthMm:c,selectedIds:r,sampleData:w,readOnly:b,showGrid:u,onFieldClick:I,onFieldDragStart:m,onResizeStart:j,onSectionHeightChange:a,onDropField:L})=>{const N=(s.heightMm??(s.type==="body"?200:40))*l*O,C=c*l*O,[i,n]=x.useState(!1),h={header:"rgba(219,234,254,0.35)",footer:"rgba(220,252,231,0.35)",background:"rgba(254,249,195,0.35)",body:"transparent"};return e.jsxs("div",{className:`${t.sectionCanvas} ${i?t.sectionCanvasOver:""}`,style:{width:C,height:N,position:"relative",background:h[s.type]??"transparent",backgroundImage:u?`repeating-linear-gradient(0deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*l*O}px),
2
+ repeating-linear-gradient(90deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*l*O}px)`:void 0},onDragOver:d=>{d.preventDefault(),n(!0)},onDragLeave:()=>n(!1),onDrop:d=>{d.preventDefault(),n(!1);const f=d.dataTransfer.getData("fieldPath");if(!f)return;const P=d.currentTarget.getBoundingClientRect(),g=(d.clientX-P.left)/(l*O),D=(d.clientY-P.top)/(l*O);L(s.id,f,Math.max(0,g),Math.max(0,D))},children:[e.jsx("div",{className:t.sectionTypeChip,children:s.type}),s.fields.map(d=>e.jsx(In,{field:d,zoom:l,selected:r.has(d.id),sampleData:w,readOnly:b,onClick:f=>I(d.id,f),onDragStart:f=>m(d.id,f),onResizeStart:(f,P)=>j(d.id,f,P)},d.id)),!b&&s.type!=="body"&&e.jsx("div",{className:t.sectionResizeBar,onMouseDown:d=>{d.preventDefault();const f=d.clientY,P=s.heightMm??40,g=v=>{const E=(v.clientY-f)/(l*O);a(s.id,Math.max(10,P+E))},D=()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",D)};document.addEventListener("mousemove",g),document.addEventListener("mouseup",D)},children:e.jsx("div",{className:t.sectionResizeGrip})})]})},ae=({keys:s,label:l})=>e.jsxs("div",{className:t.shortcutChip,children:[e.jsx("span",{className:t.shortcutKeys,children:s}),e.jsx("span",{className:t.shortcutLabel,children:l})]}),Bn=[{id:"fields",icon:"list",key:"printing.editor.tabFields",label:"Fields"},{id:"layers",icon:"layers",key:"printing.editor.tabLayers",label:"Layers"},{id:"watermarks",icon:"droplet",key:"printing.editor.tabWatermarks",label:"Watermarks"},{id:"signatures",icon:"pen",key:"printing.editor.tabSignatures",label:"Signatures"},{id:"settings",icon:"settings",key:"printing.editor.tabSettings",label:"Settings"}],Ln=[{id:"position",key:"printing.editor.tabPosition",label:"Position"},{id:"style",key:"printing.editor.tabStyle",label:"Style"},{id:"data",key:"printing.editor.tabData",label:"Data"},{id:"conditional",key:"printing.editor.tabConditional",label:"Conditions"}],zn=({tpl:s,zoom:l,canUndo:c,canRedo:r,showGrid:w,showRulers:b,readOnly:u,selectedCount:I,onPaperChange:m,onZoom:j,onUndo:a,onRedo:L,onToggleGrid:N,onToggleRulers:C,onInsert:i,onDelete:n,onDuplicate:h,onAlignH:d,onAlignV:f,onBringForward:P,onSendBackward:g,onSave:D})=>{const{t:v}=_.useNiceTranslation(),[E,T]=x.useState(!1),U=[.5,.75,1,1.25,1.5,2];return e.jsxs("div",{className:t.toolbar,children:[e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("select",{className:t.toolbarSelect,value:s.paperSize,onChange:R=>m(R.target.value,s.orientation),children:["A4","A5","A3","Letter","Legal","Tabloid","custom"].map(R=>e.jsx("option",{value:R,children:R},R))}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="portrait"?t.toolbarBtnActive:""}`,onClick:()=>m(s.paperSize,"portrait"),title:"Pion",children:e.jsx(_.NiceIcon,{name:"file",size:14})}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="landscape"?t.toolbarBtnActive:""}`,onClick:()=>m(s.paperSize,"landscape"),title:"Poziom",children:e.jsx(_.NiceIcon,{name:"file",size:14,style:{transform:"rotate(90deg)"}})})]}),!u&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,disabled:!c,onClick:a,title:`${v("printing.editor.undo","Undo")} (Ctrl+Z)`,children:e.jsx(_.NiceIcon,{name:"undo",size:14})}),e.jsx("button",{className:t.toolbarBtn,disabled:!r,onClick:L,title:`${v("printing.editor.redo","Redo")} (Ctrl+Y)`,children:e.jsx(_.NiceIcon,{name:"redo",size:14})})]}),!u&&e.jsxs("div",{className:t.insertWrapper,children:[e.jsxs("button",{className:`${t.toolbarBtn} ${t.insertBtn}`,onClick:()=>T(R=>!R),children:[e.jsx(_.NiceIcon,{name:"plus",size:14})," ",v("printing.editor.insert","Insert")," ",e.jsx(_.NiceIcon,{name:"chevron-down",size:12})]}),E&&e.jsxs("div",{className:t.insertDropdown,onMouseLeave:()=>T(!1),children:[e.jsx("div",{className:t.insertCategory,children:v("printing.editor.dataFields","Data fields")}),["text","number","currency","date","image","barcode","qr"].map(R=>e.jsxs("button",{className:t.insertItem,onClick:()=>{i(R),T(!1)},children:[e.jsx("span",{className:t.insertIcon,children:ce[R]}),be(v,R)]},R)),e.jsx("div",{className:t.insertCategory,children:"Elementy statyczne"}),["static_text","static_image","line","rect","page_number","total_pages","print_date"].map(R=>e.jsxs("button",{className:t.insertItem,onClick:()=>{i(R),T(!1)},children:[e.jsx("span",{className:t.insertIcon,children:ce[R]}),be(v,R)]},R)),e.jsx("div",{className:t.insertCategory,children:"Specjalne"}),e.jsxs("button",{className:t.insertItem,onClick:()=>{i("watermark"),T(!1)},children:[e.jsx("span",{className:t.insertIcon,children:e.jsx(_.NiceIcon,{name:"droplet",size:14})}),v("printing.editor.watermark","Watermark")]}),e.jsxs("button",{className:t.insertItem,onClick:()=>{i("signature"),T(!1)},children:[e.jsx("span",{className:t.insertIcon,children:e.jsx(_.NiceIcon,{name:"pen",size:14})}),v("printing.editor.signature","Signature")]})]})]}),!u&&I>0&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:h,title:`${v("printing.editor.duplicate","Duplicate")} (Ctrl+D)`,children:e.jsx(_.NiceIcon,{name:"copy",size:14})}),e.jsx("button",{className:`${t.toolbarBtn} ${t.toolbarBtnDanger}`,onClick:n,title:`${v("printing.action.remove","Remove")} (Del)`,children:e.jsx(_.NiceIcon,{name:"trash",size:14})}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>d("left"),title:v("printing.editor.alignLeft","Align left"),children:e.jsx(_.NiceIcon,{name:"align-left",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>d("center"),title:v("printing.editor.alignCenter","Align centre"),children:e.jsx(_.NiceIcon,{name:"align-center",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>d("right"),title:v("printing.editor.alignRight","Align right"),children:e.jsx(_.NiceIcon,{name:"align-right",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>f("top"),title:v("printing.editor.alignTop","Align top"),children:"⊤"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>f("center"),title:v("printing.editor.alignMiddle","Align middle"),children:"⊕"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>f("bottom"),title:v("printing.editor.alignBottom","Align bottom"),children:"⊥"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:P,title:"Do przodu",children:e.jsx(_.NiceIcon,{name:"arrow-up",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:g,title:v("printing.editor.sendBackward","Send backward"),children:e.jsx(_.NiceIcon,{name:"arrow-down",size:14})})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:`${t.toolbarBtn} ${w?t.toolbarBtnActive:""}`,onClick:N,title:v("printing.editor.grid","Grid"),children:"⊞"}),e.jsx("button",{className:`${t.toolbarBtn} ${b?t.toolbarBtnActive:""}`,onClick:C,title:v("printing.editor.rulers","Rulers"),children:e.jsx(_.NiceIcon,{name:"ruler",size:14})})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:()=>j(Math.max(.25,l-.1)),children:"−"}),e.jsx("select",{className:t.zoomSelect,value:U.includes(l)?l:"",onChange:R=>j(+R.target.value),children:U.map(R=>e.jsxs("option",{value:R,children:[Math.round(R*100),"%"]},R))}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j(Math.min(3,l+.1)),children:"+"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j(1),title:"100%",children:"⊡"})]}),!u&&D&&e.jsxs("button",{className:t.saveBtn,onClick:D,children:[e.jsx(_.NiceIcon,{name:"save",size:14})," ",v("printing.editor.save","Save")]})]})},Tn=({activeTab:s,onTabChange:l,schema:c,tpl:r,allFields:w,selectedIds:b,onInsertSchemaField:u,onSelectField:I,onUpdateTpl:m,onReorderField:j})=>{const{t:a}=_.useNiceTranslation(),[L,N]=x.useState(""),C=c==null?void 0:c.fields.filter(i=>i.label.toLowerCase().includes(L.toLowerCase())||i.path.toLowerCase().includes(L.toLowerCase()));return e.jsxs("div",{className:t.leftPanel,children:[e.jsx("div",{className:t.leftTabs,children:Bn.map(i=>e.jsxs("button",{className:`${t.leftTab} ${s===i.id?t.leftTabActive:""}`,onClick:()=>l(i.id),title:a(i.key,i.label),children:[e.jsx("span",{className:t.leftTabIcon,children:e.jsx(_.NiceIcon,{name:i.icon,size:16})}),e.jsx("span",{className:t.leftTabLabel,children:a(i.key,i.label)})]},i.id))}),e.jsxs("div",{className:t.leftContent,children:[s==="fields"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:a("printing.editor.dataFields","Data fields")}),e.jsx("div",{className:t.searchBox,children:e.jsx("input",{className:t.searchInput,placeholder:a("printing.editor.search","Search…"),value:L,onChange:i=>N(i.target.value)})}),c?e.jsxs("div",{className:t.fieldList,children:[(C??[]).map(i=>e.jsxs("div",{className:t.fieldItem,draggable:!0,onDragStart:n=>{n.dataTransfer.setData("fieldPath",i.path),n.dataTransfer.setData("fieldLabel",i.label),n.dataTransfer.setData("fieldType",i.type)},onClick:()=>u(i),children:[e.jsx("span",{className:t.fieldItemIcon,children:e.jsx(_.NiceIcon,{name:ce[i.type]??"type",size:14})}),e.jsxs("div",{className:t.fieldItemInfo,children:[e.jsx("div",{className:t.fieldItemLabel,children:i.label}),e.jsx("div",{className:t.fieldItemPath,children:i.path})]}),e.jsx("span",{className:t.fieldItemType,children:i.type})]},i.path)),(C==null?void 0:C.length)===0&&e.jsx("div",{className:t.emptyMsg,children:a("printing.editor.noMatches","No matches")})]}):e.jsx("div",{className:t.emptyMsg,children:a("printing.editor.noSchema","No data schema. Assign an entity in the Settings tab.")})]}),s==="layers"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.panelHeader,children:[a("printing.editor.layers","Layers")," (",w.length,")"]}),e.jsxs("div",{className:t.layerList,children:[w.length===0&&e.jsx("div",{className:t.emptyMsg,children:a("printing.editor.noElements","No elements")}),w.slice().reverse().map(i=>e.jsxs("div",{className:`${t.layerItem} ${b.has(i.id)?t.layerItemSelected:""}`,onClick:()=>I(i.id),children:[e.jsx("span",{className:t.layerIcon,children:e.jsx(_.NiceIcon,{name:ce[i.type]??"type",size:14})}),e.jsx("span",{className:t.layerName,children:i.name||i.label}),e.jsxs("div",{className:t.layerActions,children:[e.jsx("button",{className:t.layerBtn,onClick:n=>{n.stopPropagation(),j(i.id,-1)},title:a("printing.editor.bringForward","Bring forward"),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:12})}),e.jsx("button",{className:t.layerBtn,onClick:n=>{n.stopPropagation(),j(i.id,1)},title:a("printing.editor.sendBackward","Send backward"),children:e.jsx(_.NiceIcon,{name:"arrow-down",size:12})})]})]},i.id))]})]}),s==="watermarks"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Znaki wodne"}),e.jsxs("div",{className:t.wmList,children:[(r.watermarks??[]).map(i=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.editor.type","Type")}),e.jsxs("select",{className:t.wmSelect,value:i.type,onChange:n=>{var h;return m({watermarks:(h=r.watermarks)==null?void 0:h.map(d=>d.id===i.id?{...d,type:n.target.value}:d)})},children:[e.jsx("option",{value:"text",children:a("printing.fieldType.text","Text")}),e.jsx("option",{value:"image",children:a("printing.fieldType.image","Image")})]})]}),i.type==="text"&&e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.fieldType.text","Text")}),e.jsx("input",{className:t.wmInput,value:i.text??"",onChange:n=>{var h;return m({watermarks:(h=r.watermarks)==null?void 0:h.map(d=>d.id===i.id?{...d,text:n.target.value}:d)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.02,max:.5,step:.01,className:t.wmSlider,value:i.opacity,onChange:n=>{var h;return m({watermarks:(h=r.watermarks)==null?void 0:h.map(d=>d.id===i.id?{...d,opacity:+n.target.value}:d)})}}),e.jsxs("span",{className:t.wmValue,children:[Math.round(i.opacity*100),"%"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.editor.angle","Angle")}),e.jsx("input",{type:"range",min:-90,max:90,step:5,className:t.wmSlider,value:i.angle,onChange:n=>{var h;return m({watermarks:(h=r.watermarks)==null?void 0:h.map(d=>d.id===i.id?{...d,angle:+n.target.value}:d)})}}),e.jsxs("span",{className:t.wmValue,children:[i.angle,"°"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.editor.size","Size")}),e.jsx("input",{type:"number",min:8,max:200,className:t.wmInputNum,value:i.fontSize??48,onChange:n=>{var h;return m({watermarks:(h=r.watermarks)==null?void 0:h.map(d=>d.id===i.id?{...d,fontSize:+n.target.value}:d)})}}),e.jsx("span",{className:t.wmUnit,children:"pt"})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.editor.colour","Colour")}),e.jsx("input",{type:"color",className:t.colorPicker,value:i.color??pe,onChange:n=>{var h;return m({watermarks:(h=r.watermarks)==null?void 0:h.map(d=>d.id===i.id?{...d,color:n.target.value}:d)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var n;return m({watermarks:(n=r.watermarks)==null?void 0:n.filter(h=>h.id!==i.id)})},children:a("printing.action.remove","Remove")})]},i.id)),e.jsxs("button",{className:t.addBtn,onClick:()=>m({watermarks:[...r.watermarks??[],{id:ie(),type:"text",text:"COPY",opacity:.12,angle:-45,fontSize:60,color:pe}]}),children:[e.jsx(_.NiceIcon,{name:"plus",size:12})," ",a("printing.editor.addWatermark","Add watermark")]})]})]}),s==="signatures"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Podpisy"}),e.jsxs("div",{className:t.wmList,children:[(r.signatures??[]).map(i=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Etykieta"}),e.jsx("input",{className:t.wmInput,value:i.label,onChange:n=>{var h;return m({signatures:(h=r.signatures)==null?void 0:h.map(d=>d.id===i.id?{...d,label:n.target.value}:d)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Nazwisko"}),e.jsx("input",{className:t.wmInput,value:i.signerName??"",onChange:n=>{var h;return m({signatures:(h=r.signatures)==null?void 0:h.map(d=>d.id===i.id?{...d,signerName:n.target.value}:d)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.fieldType.line","Line")}),e.jsx("input",{type:"checkbox",checked:i.showLine??!0,onChange:n=>{var h;return m({signatures:(h=r.signatures)==null?void 0:h.map(d=>d.id===i.id?{...d,showLine:n.target.checked}:d)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:a("printing.editor.showDate","Show date")}),e.jsx("input",{type:"checkbox",checked:i.showDate??!1,onChange:n=>{var h;return m({signatures:(h=r.signatures)==null?void 0:h.map(d=>d.id===i.id?{...d,showDate:n.target.checked}:d)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var n;return m({signatures:(n=r.signatures)==null?void 0:n.filter(h=>h.id!==i.id)})},children:a("printing.action.remove","Remove")})]},i.id)),e.jsxs("button",{className:t.addBtn,onClick:()=>m({signatures:[...r.signatures??[],{id:ie(),label:a("printing.editor.signature","Signature"),position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),children:[e.jsx(_.NiceIcon,{name:"plus",size:12})," ",a("printing.editor.addSignature","Add signature")]})]})]}),s==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:a("printing.editor.templateSettings","Template settings")}),e.jsxs("div",{className:t.settingsForm,children:[e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:a("printing.editor.name","Name")}),e.jsx("input",{className:t.settingsInput,value:r.name,onChange:i=>m({name:i.target.value})})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:a("printing.editor.description","Description")}),e.jsx("textarea",{className:t.settingsTextarea,value:r.description??"",onChange:i=>m({description:i.target.value}),rows:2})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Kategoria"}),e.jsx("input",{className:t.settingsInput,value:r.category??"",onChange:i=>m({category:i.target.value})})]}),e.jsx("div",{className:t.settingsDivider,children:a("printing.editor.margins","Margins (mm)")}),["top","right","bottom","left"].map(i=>e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:i==="top"?a("printing.editor.marginTop","Top"):i==="right"?a("printing.editor.marginRight","Right"):i==="bottom"?a("printing.editor.marginBottom","Bottom"):a("printing.editor.marginLeft","Left")}),e.jsx("input",{type:"number",min:0,max:50,step:1,className:t.settingsInputNum,value:r.margins[i],onChange:n=>m({margins:{...r.margins,[i]:+n.target.value}})}),e.jsx("span",{className:t.settingsUnit,children:"mm"})]},i))]})]})]})]})},Dn=({field:s,activeTab:l,onTabChange:c,onChange:r,paperWidthMm:w,paperHeightMm:b})=>{var L,N,C,i;const{t:u}=_.useNiceTranslation(),I=x.useCallback(n=>s&&r({position:{...s.position,...n}}),[s,r]),m=x.useCallback(n=>s&&r({style:{...(s==null?void 0:s.style)??{},...n}}),[s,r]);if(!s)return e.jsxs("div",{className:t.rightPanel,children:[e.jsx("div",{className:t.panelHeader,children:u("printing.editor.properties","Properties")}),e.jsxs("div",{className:t.propsEmpty,children:[e.jsx("div",{className:t.propsEmptyIcon,children:e.jsx(_.NiceIcon,{name:"cursor",size:28})}),e.jsx("div",{className:t.propsEmptyText,children:u("printing.editor.selectElement","Select an element on the template")}),e.jsxs("div",{className:t.shortcutGrid,children:[e.jsx(ae,{keys:"Del",label:u("printing.action.remove","Remove")}),e.jsx(ae,{keys:"Ctrl+D",label:u("printing.editor.duplicate","Duplicate")}),e.jsx(ae,{keys:"↑↓←→",label:u("printing.editor.move","Move")}),e.jsx(ae,{keys:"Ctrl+Z",label:u("printing.editor.undo","Undo")}),e.jsx(ae,{keys:"Ctrl+A",label:u("printing.editor.selectAll","Select all")}),e.jsx(ae,{keys:"Shift+↑",label:u("printing.editor.move5mm","Move 5 mm")})]})]})]});const j=!["line","rect","image","static_image","barcode","qr","signature"].includes(s.type),a=!["static_text","static_image","line","rect","page_number","total_pages","print_date"].includes(s.type);return e.jsxs("div",{className:t.rightPanel,children:[e.jsxs("div",{className:t.panelHeader,children:[e.jsx("span",{className:t.panelHeaderIcon,children:ce[s.type]}),e.jsx("span",{className:t.panelHeaderName,children:s.name})]}),e.jsx("div",{className:t.rightTabs,children:Ln.map(n=>n.id==="data"&&!a?null:e.jsx("button",{className:`${t.rightTab} ${l===n.id?t.rightTabActive:""}`,onClick:()=>c(n.id),children:u(n.key,n.label)},n.id))}),e.jsxs("div",{className:t.propsBody,children:[l==="position"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.posGrid,children:[[{key:"x",label:"X",unit:"mm"},{key:"y",label:"Y",unit:"mm"},{key:"width",label:"Szer.",unit:"mm"},{key:"height",label:"Wys.",unit:"mm"}].map(({key:n,label:h,unit:d})=>e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:h}),e.jsx("input",{type:"number",step:.5,className:t.posInput,value:Math.round(s.position[n]*10)/10,onChange:f=>I({[n]:+f.target.value})}),e.jsx("span",{className:t.posUnit,children:d})]},n)),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:u("printing.editor.rotation","Rotation")}),e.jsx("input",{type:"number",step:5,className:t.posInput,value:s.style.rotation??0,onChange:n=>m({rotation:+n.target.value})}),e.jsx("span",{className:t.posUnit,children:"°"})]}),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Z-idx"}),e.jsx("input",{type:"number",step:1,min:1,className:t.posInput,value:s.position.zIndex??1,onChange:n=>I({zIndex:+n.target.value})})]})]}),e.jsxs("div",{className:t.snapSection,children:[e.jsx("div",{className:t.snapTitle,children:u("printing.editor.snapToPage","Snap to page")}),e.jsxs("div",{className:t.snapRow,children:[e.jsx("button",{className:t.snapBtn,onClick:()=>I({x:0}),title:u("printing.editor.leftEdge","Left edge"),children:e.jsx(_.NiceIcon,{name:"align-left",size:14})}),e.jsx("button",{className:t.snapBtn,onClick:()=>I({x:(w-s.position.width)/2}),title:u("printing.editor.horizontalCentre","Horizontal centre"),children:"⊕"}),e.jsx("button",{className:t.snapBtn,onClick:()=>I({x:w-s.position.width}),title:u("printing.editor.rightEdge","Right edge"),children:e.jsx(_.NiceIcon,{name:"align-right",size:14})})]})]})]}),l==="style"&&e.jsxs(e.Fragment,{children:[j&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Czcionka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rodzina"}),e.jsx("select",{className:t.styleSelectFull,value:s.style.fontFamily??"sans-serif",onChange:n=>m({fontFamily:n.target.value}),children:Nn.map(n=>e.jsx("option",{value:n,children:n},n))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.size","Size")}),e.jsx("select",{className:t.styleSelectSm,value:fe.includes(s.style.fontSize??10)?s.style.fontSize??10:"",onChange:n=>m({fontSize:+n.target.value}),children:fe.map(n=>e.jsx("option",{value:n,children:n},n))}),e.jsx("input",{type:"number",step:.5,min:4,max:200,className:t.styleInput,value:s.style.fontSize??10,onChange:n=>m({fontSize:+n.target.value})}),e.jsx("span",{className:t.styleUnit,children:"pt"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.colour","Colour")}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.color??te,onChange:n=>m({color:n.target.value})}),e.jsx("input",{className:t.colorHex,value:s.style.color??te,onChange:n=>m({color:n.target.value}),maxLength:7})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.style","Style")}),e.jsxs("div",{className:t.toggleGroup,children:[e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontWeight==="bold"?t.toggleBtnActive:""}`,onClick:()=>m({fontWeight:s.style.fontWeight==="bold"?"normal":"bold"}),children:e.jsx("b",{children:"B"})}),e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontStyle==="italic"?t.toggleBtnActive:""}`,onClick:()=>m({fontStyle:s.style.fontStyle==="italic"?"normal":"italic"}),children:e.jsx("i",{children:"I"})})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.align","Align")}),e.jsx("div",{className:t.toggleGroup,children:["left","center","right","justify"].map(n=>e.jsx("button",{title:n,className:`${t.toggleBtn} ${(s.style.textAlign??"left")===n?t.toggleBtnActive:""}`,onClick:()=>m({textAlign:n}),children:n==="left"?"≡L":n==="center"?"≡C":n==="right"?"≡R":"≡J"},n))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"W. linii"}),e.jsx("input",{type:"number",step:.1,min:1,max:4,className:t.styleInput,value:s.style.lineHeight??1.4,onChange:n=>m({lineHeight:+n.target.value})})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.spacing","Spacing")}),e.jsx("input",{type:"number",step:.01,min:-.1,max:.5,className:t.styleInput,value:s.style.letterSpacing??0,onChange:n=>m({letterSpacing:+n.target.value})}),e.jsx("span",{className:t.styleUnit,children:"em"})]})]}),e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:u("printing.editor.background","Background and border")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.fill","Fill")}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.backgroundColor??"var(--nice-bg, #fff)",onChange:n=>m({backgroundColor:n.target.value})}),e.jsx("button",{className:t.clearBtn,onClick:()=>m({backgroundColor:void 0}),title:u("printing.editor.clearFill","Clear fill"),children:e.jsx(_.NiceIcon,{name:"close",size:12})})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ramka"}),e.jsx("input",{type:"number",step:.5,min:0,max:10,className:t.styleInput,value:s.style.borderWidth??0,onChange:n=>m({borderWidth:+n.target.value})}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.borderColor??te,onChange:n=>m({borderColor:n.target.value})}),e.jsxs("select",{className:t.styleSelectXs,value:s.style.borderStyle??"solid",onChange:n=>m({borderStyle:n.target.value}),children:[e.jsx("option",{value:"solid",children:"─"}),e.jsx("option",{value:"dashed",children:"- -"}),e.jsx("option",{value:"dotted",children:"···"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Zaokr."}),e.jsx("input",{type:"number",step:1,min:0,max:50,className:t.styleInput,value:s.style.borderRadius??0,onChange:n=>m({borderRadius:+n.target.value})}),e.jsx("span",{className:t.styleUnit,children:"px"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Padding"}),e.jsx("input",{type:"number",step:.5,min:0,max:20,className:t.styleInput,value:s.style.padding??0,onChange:n=>m({padding:+n.target.value})}),e.jsx("span",{className:t.styleUnit,children:"mm"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.1,max:1,step:.05,className:t.sliderInput,value:s.style.opacity??1,onChange:n=>m({opacity:+n.target.value})}),e.jsxs("span",{className:t.styleValue,children:[Math.round((s.style.opacity??1)*100),"%"]})]})]})]}),l==="data"&&a&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:u("printing.editor.dataSource","Data source")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.path","Path")}),e.jsx("input",{className:t.styleInputFull,value:s.dataPath,onChange:n=>r({dataPath:n.target.value}),placeholder:"np. invoice.number"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.format","Format")}),e.jsx("input",{className:t.styleInputFull,value:s.format??"",onChange:n=>r({format:n.target.value}),placeholder:"DD.MM.YYYY / #,##0.00"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.default","Default")}),e.jsx("input",{className:t.styleInputFull,value:s.fallback??"",onChange:n=>r({fallback:n.target.value}),placeholder:u("printing.editor.whenEmpty","When there is no value")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.type","Type")}),e.jsx("select",{className:t.styleSelectFull,value:s.type,onChange:n=>r({type:n.target.value}),children:Object.keys(de).map(n=>e.jsx("option",{value:n,children:be(u,n)},n))})]}),(s.type==="barcode"||s.type==="qr")&&e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.codeFormat","Code format")}),e.jsx("select",{className:t.styleSelectFull,value:s.barcodeType??"code128",onChange:n=>r({barcodeType:n.target.value}),children:["ean13","ean8","code128","code39","upc","itf14","datamatrix"].map(n=>e.jsx("option",{value:n,children:n.toUpperCase()},n))})]})]}),l==="conditional"&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:u("printing.editor.conditionalVisibility","Conditional visibility")}),e.jsx("div",{className:t.conditionalHint,children:u("printing.editor.conditionalHint","The element is hidden when the condition is not met.")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.conditionalField","Field")}),e.jsx("input",{className:t.styleInputFull,value:((L=s.conditional)==null?void 0:L.field)??"",onChange:n=>{var h,d;return r({conditional:{field:n.target.value,operator:((h=s.conditional)==null?void 0:h.operator)??"eq",value:(d=s.conditional)==null?void 0:d.value}})},placeholder:"np. invoice.isPaid"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Operator"}),e.jsxs("select",{className:t.styleSelectFull,value:((N=s.conditional)==null?void 0:N.operator)??"eq",onChange:n=>{var h,d;return r({conditional:{field:((h=s.conditional)==null?void 0:h.field)??"",operator:n.target.value,value:(d=s.conditional)==null?void 0:d.value}})},children:[e.jsxs("option",{value:"eq",children:["= ",u("printing.editor.opEqual","equal")]}),e.jsxs("option",{value:"neq",children:["≠ ",u("printing.editor.opNotEqual","not equal")]}),e.jsx("option",{value:"gt",children:"> wieksze"}),e.jsx("option",{value:"lt",children:"< mniejsze"}),e.jsx("option",{value:"contains",children:"zawiera"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:u("printing.editor.value","Value")}),e.jsx("input",{className:t.styleInputFull,value:String(((C=s.conditional)==null?void 0:C.value)??""),onChange:n=>{var h,d;return r({conditional:{field:((h=s.conditional)==null?void 0:h.field)??"",operator:((d=s.conditional)==null?void 0:d.operator)??"eq",value:n.target.value}})},placeholder:'np. true / "PAID"'})]}),((i=s.conditional)==null?void 0:i.field)&&e.jsx("button",{className:t.clearConditionalBtn,onClick:()=>r({conditional:void 0}),children:u("printing.editor.clearCondition","Clear condition")})]})]})]})};function $n(){return{id:`tpl-${Date.now()}`,name:"New template",description:"",paperSize:"A4",orientation:"portrait",margins:{top:20,right:15,bottom:20,left:15},sections:[{id:"sec-header",type:"header",heightMm:35,fields:[]},{id:"sec-body",type:"body",fields:[]},{id:"sec-footer",type:"footer",heightMm:20,fields:[]}],watermarks:[],signatures:[]}}const Rn=({template:s,dataSchema:l,sampleData:c=[],onChange:r,onSave:w,readOnly:b=!1,className:u,style:I,theme:m="light"})=>{const[{past:j,present:a,future:L},N]=x.useReducer(fn,{past:[],present:s??$n(),future:[]}),{t:C}=_.useNiceTranslation(),[i,n]=x.useState(new Set),[h,d]=x.useState("sec-body"),[f,P]=x.useState(1),[g,D]=x.useState(0),[v,E]=x.useState("fields"),[T,U]=x.useState("position"),[R,z]=x.useState(!1),[Y,ue]=x.useState(!0),A=x.useCallback(o=>{const p={...a,...o};N({type:"UPDATE",payload:p}),r==null||r(p)},[a,r]),[X,me]=x.useMemo(()=>{const[o,p]=Ne[a.paperSize]??Ne.A4;return a.orientation==="landscape"?[p,o]:[o,p]},[a.paperSize,a.orientation]),J=x.useMemo(()=>a.sections.flatMap(o=>o.fields),[a]),F=x.useMemo(()=>J.find(o=>i.has(o.id))??null,[J,i]),he=x.useCallback((o,p)=>{A({sections:a.sections.map(S=>({...S,fields:S.fields.map(k=>k.id===o?{...k,...p,style:{...k.style,...p.style??{}}}:k)}))})},[a,A]),le=x.useCallback(o=>{A({sections:a.sections.map(p=>({...p,fields:p.fields.map(S=>i.has(S.id)?{...S,...o,style:{...S.style,...o.style??{}}}:S)}))})},[a,i,A]),ye=x.useCallback((o,p)=>{if(o==="watermark"){A({watermarks:[...a.watermarks??[],{id:ie(),type:"text",text:"COPY",opacity:.12,angle:-45,fontSize:60,color:pe}]}),E("watermarks");return}if(o==="signature"){A({signatures:[...a.signatures??[],{id:ie(),label:C("printing.editor.signature","Signature"),position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),E("signatures");return}const S=a.sections.find(H=>H.id===h)??a.sections.find(H=>H.type==="body");if(!S)return;const k=we(o,p),M={sections:a.sections.map(H=>H.id===S.id?{...H,fields:[...H.fields,k]}:H)};N({type:"UPDATE",payload:{...a,...M}}),r==null||r({...a,...M}),n(new Set([k.id]))},[a,h,r]),Ce=x.useCallback((o,p,S,k)=>{const M=l==null?void 0:l.fields.find(q=>q.path===p),H=we((M==null?void 0:M.type)??"text",M);H.position.x=Math.round(S*2)/2,H.position.y=Math.round(k*2)/2;const Q={sections:a.sections.map(q=>q.id===o?{...q,fields:[...q.fields,H]}:q)};N({type:"UPDATE",payload:{...a,...Q}}),r==null||r({...a,...Q}),n(new Set([H.id]))},[a,l,r]),Be=x.useCallback((o,p)=>{p.ctrlKey||p.metaKey?n(S=>{const k=new Set(S);return k.has(o)?k.delete(o):k.add(o),k}):p.shiftKey?n(S=>new Set([...S,o])):n(new Set([o]))},[]),Le=x.useCallback((o,p)=>{if(b)return;p.preventDefault(),i.has(o)||n(new Set([o]));const S=p.clientX,k=p.clientY,M=a.sections.map(q=>({id:q.id,fields:q.fields.map(Z=>({id:Z.id,pos:{...Z.position}}))})),H=q=>{const Z=(q.clientX-S)/(f*O),se=(q.clientY-k)/(f*O),re=i.has(o)?i:new Set([o]),oe=a.sections.map(ee=>{const V=M.find(W=>W.id===ee.id);return{...ee,fields:ee.fields.map(W=>{var je;if(!re.has(W.id))return W;const ve=((je=V==null?void 0:V.fields.find(He=>He.id===W.id))==null?void 0:je.pos)??W.position;return{...W,position:{...W.position,x:Math.max(0,Math.round((ve.x+Z)*2)/2),y:Math.max(0,Math.round((ve.y+se)*2)/2)}}})}}),ne={...a,sections:oe};r==null||r(ne),N({type:"UPDATE",payload:ne})},Q=()=>{document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",Q)};document.addEventListener("mousemove",H),document.addEventListener("mouseup",Q)},[a,f,i,b,r]),ze=x.useCallback((o,p,S)=>{if(b)return;S.preventDefault();const k=J.find(se=>se.id===o);if(!k)return;const M={...k.position},H=S.clientX,Q=S.clientY,q=se=>{const re=(se.clientX-H)/(f*O),oe=(se.clientY-Q)/(f*O);let{x:ne,y:ee,width:V,height:W}=M;p.includes("e")&&(V=Math.max(5,V+re)),p.includes("s")&&(W=Math.max(3,W+oe)),p.includes("w")&&(ne=ne+re,V=Math.max(5,V-re)),p.includes("n")&&(ee=ee+oe,W=Math.max(3,W-oe)),he(o,{position:{...M,x:Math.round(ne*2)/2,y:Math.round(ee*2)/2,width:Math.round(V*2)/2,height:Math.round(W*2)/2}})},Z=()=>{document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",Z)};document.addEventListener("mousemove",q),document.addEventListener("mouseup",Z)},[J,f,b,he]),_e=x.useCallback(()=>{A({sections:a.sections.map(o=>({...o,fields:o.fields.filter(p=>!i.has(p.id))}))}),n(new Set)},[a,i,A]),ge=x.useCallback(()=>{const o=new Set;A({sections:a.sections.map(p=>{const S=p.fields.filter(k=>i.has(k.id)).map(k=>{const M={...k,id:ie(),position:{...k.position,x:k.position.x+5,y:k.position.y+5}};return o.add(M.id),M});return{...p,fields:[...p.fields,...S]}})}),n(o)},[a,i,A]),Te=x.useCallback(o=>{A({sections:a.sections.map(p=>({...p,fields:p.fields.map(S=>{if(!i.has(S.id))return S;const k=o==="left"?a.margins.left:o==="right"?X-a.margins.right-S.position.width:(X-S.position.width)/2;return{...S,position:{...S.position,x:k}}})}))})},[a,i,X,A]),De=x.useCallback(o=>{const p=a.sections.find(k=>k.id===h);if(!p)return;const S=p.heightMm??200;A({sections:a.sections.map(k=>k.id!==h?k:{...k,fields:k.fields.map(M=>{if(!i.has(M.id))return M;const H=o==="top"?0:o==="bottom"?S-M.position.height:(S-M.position.height)/2;return{...M,position:{...M.position,y:H}}})})})},[a,i,h,A]),$e=x.useCallback(()=>{A({sections:a.sections.map(o=>({...o,fields:o.fields.map(p=>i.has(p.id)?{...p,position:{...p.position,zIndex:(p.position.zIndex??1)+1}}:p)}))})},[a,i,A]),Re=x.useCallback(()=>{A({sections:a.sections.map(o=>({...o,fields:o.fields.map(p=>i.has(p.id)?{...p,position:{...p.position,zIndex:Math.max(1,(p.position.zIndex??1)-1)}}:p)}))})},[a,i,A]),Ae=x.useCallback((o,p)=>{A({sections:a.sections.map(S=>({...S,fields:S.fields.map(k=>k.id===o?{...k,position:{...k.position,zIndex:Math.max(1,(k.position.zIndex??1)-p)}}:k)}))})},[a,A]);x.useEffect(()=>{const o=p=>{const S=p.target.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;const k=p.shiftKey?5:.5;p.key==="Delete"||p.key==="Backspace"?i.size&&(p.preventDefault(),_e()):p.ctrlKey&&p.key==="z"?(p.preventDefault(),N({type:"UNDO"})):p.ctrlKey&&(p.key==="y"||p.key==="Y")?(p.preventDefault(),N({type:"REDO"})):p.ctrlKey&&(p.key==="d"||p.key==="D")?(p.preventDefault(),i.size&&ge()):p.ctrlKey&&p.key==="a"?(p.preventDefault(),n(new Set(J.map(M=>M.id)))):p.key==="ArrowLeft"?(p.preventDefault(),le({position:{...F.position,x:((F==null?void 0:F.position.x)??0)-k}})):p.key==="ArrowRight"?(p.preventDefault(),le({position:{...F.position,x:((F==null?void 0:F.position.x)??0)+k}})):p.key==="ArrowUp"?(p.preventDefault(),le({position:{...F.position,y:((F==null?void 0:F.position.y)??0)-k}})):p.key==="ArrowDown"&&(p.preventDefault(),le({position:{...F.position,y:((F==null?void 0:F.position.y)??0)+k}}))};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[i,J,F,_e,ge,le]);const Me=x.useCallback((o,p)=>{A({sections:a.sections.map(S=>S.id===o?{...S,heightMm:Math.round(p*2)/2}:S)})},[a,A]),Pe=x.useMemo(()=>{const o=Array.isArray(c)?c[g]:c;return o?"data"in o?o.data:o:{}},[c,g]),Ee=X*f*O,Fe=me*f*O;return e.jsx(_.NiceAppShell,{flush:!0,className:`${t.root} ${m==="dark"?t.dark:""} ${u??""}`,style:I,toolbar:e.jsx(zn,{tpl:a,zoom:f,canUndo:j.length>0,canRedo:L.length>0,showGrid:R,showRulers:Y,readOnly:b,selectedCount:i.size,onPaperChange:(o,p)=>A({paperSize:o,orientation:p}),onZoom:P,onUndo:()=>N({type:"UNDO"}),onRedo:()=>N({type:"REDO"}),onToggleGrid:()=>z(o=>!o),onToggleRulers:()=>ue(o=>!o),onInsert:ye,onDelete:_e,onDuplicate:ge,onAlignH:Te,onAlignV:De,onBringForward:$e,onSendBackward:Re,onSave:w?()=>w(a):void 0}),sidebar:e.jsx(Tn,{activeTab:v,onTabChange:E,schema:l,tpl:a,allFields:J,selectedIds:i,onInsertSchemaField:o=>ye(o.type,o),onSelectField:o=>n(new Set([o])),onUpdateTpl:o=>A(o),onReorderField:Ae}),rightSidebar:e.jsx(Dn,{field:F,activeTab:T,onTabChange:U,onChange:o=>F&&he(F.id,o),paperWidthMm:X,paperHeightMm:me}),children:e.jsxs("div",{className:t.canvasArea,onClick:()=>n(new Set),children:[Array.isArray(c)&&c.length>0&&e.jsxs("div",{className:t.testDataBar,children:[e.jsxs("span",{className:t.testDataLabel,children:[C("printing.editor.testData","Sample data"),":"]}),e.jsx("select",{className:t.testDataSelect,value:g,onChange:o=>D(+o.target.value),children:c.map((o,p)=>e.jsxs("option",{value:p,children:[C("printing.editor.record","Record")," ",p+1]},p))})]}),Y&&e.jsxs("div",{className:t.rulerWrapper,children:[e.jsx("div",{className:t.rulerCorner}),e.jsx(ke,{lengthMm:X,zoom:f,orientation:"h"}),e.jsx(ke,{lengthMm:me,zoom:f,orientation:"v"})]}),e.jsx("div",{className:t.paperScroll,onClick:o=>o.stopPropagation(),children:e.jsxs("div",{className:t.paperShadow,style:{width:Ee,minHeight:Fe},children:[e.jsx("div",{className:t.marginGuide,style:{top:a.margins.top*f*O,right:a.margins.right*f*O,bottom:a.margins.bottom*f*O,left:a.margins.left*f*O}}),(a.watermarks??[]).map(o=>e.jsx("div",{className:t.watermark,style:{fontSize:(o.fontSize??60)*f,color:o.color??pe,opacity:o.opacity,transform:`translate(-50%, -50%) rotate(${o.angle}deg)`},children:o.type==="text"?o.text:e.jsx(_.NiceIcon,{name:"image",size:(o.fontSize??60)*f})},o.id)),a.sections.map(o=>e.jsx("div",{children:e.jsx(Cn,{section:o,zoom:f,paperWidthMm:X,selectedIds:i,sampleData:Pe,readOnly:b,showGrid:R,onFieldClick:Be,onFieldDragStart:Le,onResizeStart:ze,onSectionHeightChange:Me,onDropField:Ce})},o.id))]})})]})})},An="_root_7m4s0_1",Mn="_dark_7m4s0_25",Pn="_topBar_7m4s0_39",En="_searchInput_7m4s0_69",Fn="_actionBtn_7m4s0_111",Hn="_categoryRow_7m4s0_157",Gn="_catChip_7m4s0_187",On="_catChipActive_7m4s0_217",qn="_grid_7m4s0_231",Wn="_card_7m4s0_253",Un="_cardSelected_7m4s0_285",Yn="_thumbnail_7m4s0_307",Vn="_thumbnailImg_7m4s0_321",Kn="_thumbnailPlaceholder_7m4s0_333",Xn="_paperMini_7m4s0_347",Jn="_paperLine_7m4s0_371",Qn="_cardOverlay_7m4s0_385",Zn="_overlayBtn_7m4s0_405",ea="_overlayBtnDanger_7m4s0_441",ta="_cardBody_7m4s0_481",sa="_cardName_7m4s0_489",na="_cardDesc_7m4s0_517",aa="_cardMeta_7m4s0_539",ia="_cardSize_7m4s0_553",la="_cardCat_7m4s0_569",ra="_cardTags_7m4s0_585",oa="_cardTag_7m4s0_585",ca="_emptyState_7m4s0_617",da="_emptyIcon_7m4s0_639",B={root:An,dark:Mn,topBar:Pn,searchInput:En,actionBtn:Fn,categoryRow:Hn,catChip:Gn,catChipActive:On,grid:qn,card:Wn,cardSelected:Un,thumbnail:Yn,thumbnailImg:Vn,thumbnailPlaceholder:Kn,paperMini:Xn,paperLine:Jn,cardOverlay:Qn,overlayBtn:Zn,overlayBtnDanger:ea,cardBody:ta,cardName:sa,cardDesc:na,cardMeta:aa,cardSize:ia,cardCat:la,cardTags:ra,cardTag:oa,emptyState:ca,emptyIcon:da},pa=[{key:"printing.category.invoices",fallback:"Invoices"},{key:"printing.category.reports",fallback:"Reports"},{key:"printing.category.labels",fallback:"Labels"},{key:"printing.category.letters",fallback:"Letters"},{key:"printing.category.contracts",fallback:"Contracts"},{key:"printing.category.other",fallback:"Other"}];function ua(s){return new Promise((l,c)=>{const r=new FileReader;r.onload=w=>{var b;try{l(JSON.parse((b=w.target)==null?void 0:b.result))}catch(u){c(u)}},r.readAsText(s)})}function ma(s){const l=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),c=URL.createObjectURL(l),r=document.createElement("a");r.href=c,r.download=`${s.name.replace(/\s+/g,"_")}.json`,r.click(),URL.revokeObjectURL(c)}const ha=({templates:s,selectedId:l,onSelect:c,onImport:r,onExport:w,onDelete:b,onNew:u,className:I,style:m,theme:j="light"})=>{const{t:a}=_.useNiceTranslation(),[L,N]=x.useState(""),[C,i]=x.useState(null),[n,h]=x.useState(null),d=x.useRef(null),f=async g=>{var v;const D=(v=g.target.files)==null?void 0:v[0];if(D){try{const E=await ua(D);r==null||r(E)}catch{}g.target.value=""}},P=s.filter(g=>{const D=!L||g.name.toLowerCase().includes(L.toLowerCase())||(g.description??"").toLowerCase().includes(L.toLowerCase())||(g.tags??[]).some(E=>E.toLowerCase().includes(L.toLowerCase())),v=!C||g.category===C;return D&&v});return e.jsxs("div",{className:`${B.root} ${j==="dark"?B.dark:""} ${I??""}`,style:m,children:[e.jsxs("div",{className:B.topBar,children:[e.jsx("input",{type:"search",className:B.searchInput,placeholder:a("printing.searchTemplates","Search templates…"),value:L,onChange:g=>N(g.target.value)}),e.jsxs("button",{className:B.actionBtn,onClick:u,title:a("printing.newTemplate","New template"),children:[e.jsx(_.NiceIcon,{name:"plus",size:14})," ",a("printing.new","New")]}),e.jsxs("button",{className:B.actionBtn,onClick:()=>{var g;return(g=d.current)==null?void 0:g.click()},title:a("printing.importJson","Import JSON"),children:[e.jsx(_.NiceIcon,{name:"upload",size:14})," ",a("printing.import","Import")]}),e.jsx("input",{ref:d,type:"file",accept:".json",hidden:!0,onChange:f})]}),e.jsxs("div",{className:B.categoryRow,children:[e.jsx("button",{className:`${B.catChip} ${C?"":B.catChipActive}`,onClick:()=>i(null),children:a("printing.filter.all","All")}),pa.map(g=>e.jsx("button",{className:`${B.catChip} ${C===g.fallback?B.catChipActive:""}`,onClick:()=>i(D=>D===g.fallback?null:g.fallback),children:a(g.key,g.fallback)},g.key))]}),e.jsxs("div",{className:B.grid,children:[P.map(g=>e.jsxs("div",{className:`${B.card} ${l===g.id?B.cardSelected:""}`,onClick:()=>c==null?void 0:c(g),onMouseEnter:()=>h(g.id),onMouseLeave:()=>h(null),children:[e.jsxs("div",{className:B.thumbnail,children:[g.previewImageUrl?e.jsx("img",{src:g.previewImageUrl,alt:g.name,className:B.thumbnailImg}):e.jsx("div",{className:B.thumbnailPlaceholder,children:e.jsxs("div",{className:B.paperMini,children:[e.jsx("div",{className:B.paperLine,style:{width:"80%"}}),e.jsx("div",{className:B.paperLine,style:{width:"60%"}}),e.jsx("div",{className:B.paperLine,style:{width:"90%"}}),e.jsx("div",{className:B.paperLine,style:{width:"50%"}})]})}),n===g.id&&e.jsxs("div",{className:B.cardOverlay,children:[e.jsx("button",{className:B.overlayBtn,onClick:D=>{D.stopPropagation(),w==null||w(g),ma(g)},title:a("printing.export","Export"),children:e.jsx(_.NiceIcon,{name:"download",size:14})}),b&&e.jsx("button",{className:B.overlayBtnDanger,onClick:D=>{D.stopPropagation(),b(g.id)},title:a("printing.action.remove","Remove"),children:e.jsx(_.NiceIcon,{name:"trash",size:14})})]})]}),e.jsxs("div",{className:B.cardBody,children:[e.jsx("div",{className:B.cardName,children:g.name}),g.description&&e.jsx("div",{className:B.cardDesc,children:g.description}),e.jsxs("div",{className:B.cardMeta,children:[e.jsxs("span",{className:B.cardSize,children:[g.paperSize," ",g.orientation==="landscape"?a("printing.orientation.landscape","landscape"):a("printing.orientation.portrait","portrait")]}),g.category&&e.jsx("span",{className:B.cardCat,children:g.category})]}),g.tags&&g.tags.length>0&&e.jsx("div",{className:B.cardTags,children:g.tags.slice(0,3).map(D=>e.jsx("span",{className:B.cardTag,children:D},D))})]})]},g.id)),P.length===0&&e.jsxs("div",{className:B.emptyState,children:[e.jsx("span",{className:B.emptyIcon,children:e.jsx(_.NiceIcon,{name:"file",size:32})}),e.jsx("span",{children:L?`${a("printing.noMatches","No matches for")} "${L}"`:a("printing.noTemplates","No templates yet.")})]})]})]})},_a="_root_91917_1",ga="_dark_91917_19",ba="_headerBar_91917_31",xa="_entityNav_91917_59",ya="_navBtn_91917_69",va="_navLabel_91917_103",ja="_sampleBadge_91917_117",Na="_zoomBar_91917_135",fa="_zoomBtn_91917_147",wa="_zoomLabel_91917_179",ka="_printBtn_91917_193",Sa="_canvas_91917_223",Ia="_page_91917_243",Ca="_watermark_91917_269",Ba="_footerBar_91917_299",G={root:_a,dark:ga,headerBar:ba,entityNav:xa,navBtn:ya,navLabel:va,sampleBadge:ja,zoomBar:Na,zoomBtn:fa,zoomLabel:wa,printBtn:ka,canvas:Sa,page:Ia,watermark:Ca,footerBar:Ba},K=3.78,Se={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432]};function La(s,l){try{return s.split(".").reduce((c,r)=>c&&typeof c=="object"?c[r]:null,l)}catch{return null}}function za(s,l,c){if(s==null)return"";if(l==="date"&&c)try{const r=new Date(s);if(c==="DD.MM.YYYY"){const w=String(r.getDate()).padStart(2,"0"),b=String(r.getMonth()+1).padStart(2,"0");return`${w}.${b}.${r.getFullYear()}`}return r.toLocaleDateString()}catch{return String(s)}if(l==="currency"&&c){const r=Number(s);if(!isNaN(r))return`${r.toFixed(2)} ${c}`}return l==="number"&&typeof s=="number"?s.toLocaleString("pl-PL"):String(s)}const Ta=({field:s,data:l,zoom:c})=>{const r=s.dataPath?La(s.dataPath,l):null,w=r!=null?za(r,s.type,s.format):s.fallback??"",b=I=>I*c*K,u={position:"absolute",left:b(s.position.x),top:b(s.position.y),width:b(s.position.width),height:b(s.position.height),fontSize:(s.style.fontSize??10)*c,fontWeight:s.style.fontWeight??"normal",fontStyle:s.style.fontStyle??"normal",color:s.style.color??"var(--nice-text-primary, #0f172a)",textAlign:s.style.textAlign??"left",backgroundColor:s.style.backgroundColor,transform:s.style.rotation?`rotate(${s.style.rotation}deg)`:void 0,overflow:"hidden",display:"flex",alignItems:s.style.verticalAlign==="middle"?"center":s.style.verticalAlign==="bottom"?"flex-end":"flex-start",lineHeight:s.style.lineHeight??1.4,padding:s.style.padding?b(s.style.padding):0,boxSizing:"border-box",borderWidth:s.style.borderWidth,borderColor:s.style.borderColor,borderStyle:s.style.borderStyle,borderRadius:s.style.borderRadius,zIndex:s.position.zIndex??1};return s.type==="image"&&r?e.jsx("div",{style:u,children:e.jsx("img",{src:String(r),alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}})}):s.type==="barcode"||s.type==="qr"?e.jsxs("div",{style:{...u,background:"var(--nice-bg-secondary, #f8fafc)",border:"1px dashed var(--nice-border-color, #e2e8f0)",alignItems:"center",justifyContent:"center",fontSize:10*c},children:[e.jsx(_.NiceIcon,{name:s.type==="qr"?"qr-code":"barcode",size:12*c})," ",w]}):s.type==="signature"?e.jsx("div",{style:{...u,borderBottom:"1px solid var(--nice-border-color, #0f172a)",alignItems:"flex-end"},children:e.jsx("span",{style:{fontSize:8*c,color:"var(--nice-text-muted, #94a3b8)"},children:s.label})}):s.type==="line"?e.jsx("div",{style:{...u,borderBottom:`${s.style.borderWidth??1}px ${s.style.borderStyle??"solid"} ${s.style.borderColor??"var(--nice-text-primary, #0f172a)"}`}}):e.jsx("div",{style:u,children:w})},Da=({template:s,data:l,zoom:c})=>{var I;const[r,w]=(()=>{const[m,j]=Se[s.paperSize]??Se.A4;return s.orientation==="landscape"?[j*K*c,m*K*c]:[m*K*c,j*K*c]})(),b=s.margins,u=s.sections.flatMap(m=>m.fields);return e.jsxs("div",{className:G.page,style:{width:r,minHeight:w},children:[e.jsx("div",{style:{position:"absolute",top:b.top*c*K,left:b.left*c*K,right:b.right*c*K,bottom:b.bottom*c*K},children:u.map(m=>e.jsx(Ta,{field:m,data:l,zoom:c},m.id))}),(I=s.watermarks)==null?void 0:I.map(m=>e.jsx("div",{className:G.watermark,style:{opacity:m.opacity,transform:`rotate(${m.angle}deg)`,fontSize:(m.fontSize??48)*c},children:m.type==="text"?m.text:e.jsx("img",{src:m.imageUrl,alt:"wm",style:{maxWidth:200*c}})},m.id))]})},$a=({template:s,entities:l=[],sampleData:c,onPrint:r,className:w,style:b,theme:u="light",asPopup:I=!0,open:m,onClose:j})=>{const{t:a}=_.useNiceTranslation(),[L,N]=x.useState(0),[C,i]=x.useState(.8),[n,h]=x.useState(!0),d=m!==void 0,f=d?m:n,P=()=>{d||h(!1),j==null||j()};x.useEffect(()=>{if(!I||!f)return;const T=U=>{U.key==="Escape"&&P()};return document.addEventListener("keydown",T),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",T),document.body.style.overflow=""}},[I,f]);const g=x.useMemo(()=>l.length>0?l:c?[c.data]:[{}],[l,c]),D=g[L]??{};if(I&&!f)return null;const v=e.jsxs("div",{className:`${G.root} ${u==="dark"?G.dark:""} ${w??""}`,style:b,children:[e.jsxs("div",{className:G.headerBar,children:[e.jsxs("div",{className:G.entityNav,children:[g.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:G.navBtn,disabled:L===0,onClick:()=>N(T=>T-1),children:"‹"}),e.jsxs("span",{className:G.navLabel,children:[L+1," / ",g.length]}),e.jsx("button",{className:G.navBtn,disabled:L>=g.length-1,onClick:()=>N(T=>T+1),children:"›"})]}),l.length===0&&c&&e.jsx("span",{className:G.sampleBadge,children:a("printing.sampleData","Sample data")})]}),e.jsxs("div",{className:G.zoomBar,children:[e.jsx("button",{className:G.zoomBtn,onClick:()=>i(T=>Math.max(.3,T-.1)),children:"−"}),e.jsxs("span",{className:G.zoomLabel,children:[Math.round(C*100),"%"]}),e.jsx("button",{className:G.zoomBtn,onClick:()=>i(T=>Math.min(2.5,T+.1)),children:"+"}),e.jsx("button",{className:G.zoomBtn,onClick:()=>i(.8),title:"Dopasuj",children:"⊡"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:G.printBtn,onClick:()=>r==null?void 0:r({copies:1,printerId:""}),children:a("printPreview.print","Print")}),I&&e.jsx("button",{type:"button",className:G.zoomBtn,onClick:P,"aria-label":a("close","Close"),title:a("close","Close"),children:e.jsx(_.NiceIcon,{name:"close",size:16})})]})]}),e.jsx("div",{className:G.canvas,children:e.jsx(Da,{template:s,data:D,zoom:C})}),e.jsxs("div",{className:G.footerBar,children:[e.jsx("span",{children:s.name}),e.jsxs("span",{children:[s.paperSize," · ",s.orientation==="portrait"?"Pion":"Poziom"]}),s.sections.reduce((T,U)=>T+U.fields.length,0)," ",a("printing.fields","fields")]})]});if(!I)return v;const E=e.jsx("div",{style:{position:"fixed",inset:0,background:"color-mix(in srgb, var(--nice-text-primary, #000) 50%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:24},onMouseDown:T=>{T.target===T.currentTarget&&P()},role:"presentation",children:e.jsx("div",{role:"dialog","aria-modal":"true",style:{background:"var(--nice-bg-elevated, var(--nice-bg-primary, #ffffff))",borderRadius:12,boxShadow:"0 20px 60px color-mix(in srgb, var(--nice-text-primary, #000) 30%, transparent)",maxWidth:"90vw",maxHeight:"90vh",overflow:"auto"},children:v})});return Ge.createPortal(E,document.body)},Ra="_root_lbbp6_1",Aa="_dark_lbbp6_23",Ma="_statsBar_lbbp6_37",Pa="_stat_lbbp6_37",Ea="_dot_lbbp6_75",Fa="_statPrinting_lbbp6_87",Ha="_statQueued_lbbp6_93",Ga="_statDone_lbbp6_99",Oa="_statError_lbbp6_105",qa="_toolbar_lbbp6_115",Wa="_filterTabs_lbbp6_139",Ua="_filterTab_lbbp6_139",Ya="_filterTabActive_lbbp6_177",Va="_filterCount_lbbp6_187",Ka="_bulkActions_lbbp6_211",Xa="_bulkCount_lbbp6_223",Ja="_bulkBtn_lbbp6_231",Qa="_bulkBtnRemove_lbbp6_255",Za="_jobList_lbbp6_273",ei="_listHeader_lbbp6_281",ti="_headerLabel_lbbp6_313",si="_jobRow_lbbp6_323",ni="_jobRowSelected_lbbp6_359",ai="_jobCheckbox_lbbp6_373",ii="_statusBadge_lbbp6_387",li="_pulse_lbbp6_1",ri="_jobInfo_lbbp6_479",oi="_jobName_lbbp6_485",ci="_jobMeta_lbbp6_497",di="_jobTime_lbbp6_513",pi="_jobDuration_lbbp6_519",ui="_jobError_lbbp6_525",mi="_progressBar_lbbp6_539",hi="_progressFill_lbbp6_553",_i="_copiesEditor_lbbp6_569",gi="_copiesBtn_lbbp6_581",bi="_copiesValue_lbbp6_621",xi="_jobActions_lbbp6_635",yi="_actionBtn_lbbp6_645",vi="_removeBtn_lbbp6_677",ji="_emptyState_lbbp6_695",y={root:Ra,dark:Aa,statsBar:Ma,stat:Pa,dot:Ea,statPrinting:Fa,statQueued:Ha,statDone:Ga,statError:Oa,toolbar:qa,filterTabs:Wa,filterTab:Ua,filterTabActive:Ya,filterCount:Va,bulkActions:Ka,bulkCount:Xa,bulkBtn:Ja,bulkBtnRemove:Qa,jobList:Za,listHeader:ei,headerLabel:ti,jobRow:si,jobRowSelected:ni,jobCheckbox:ai,statusBadge:ii,"badge-queued":"_badge-queued_lbbp6_405","badge-printing":"_badge-printing_lbbp6_413",pulse:li,"badge-done":"_badge-done_lbbp6_423","badge-error":"_badge-error_lbbp6_431","badge-paused":"_badge-paused_lbbp6_439","badge-cancelled":"_badge-cancelled_lbbp6_447",jobInfo:ri,jobName:oi,jobMeta:ci,jobTime:di,jobDuration:pi,jobError:ui,progressBar:mi,progressFill:hi,copiesEditor:_i,copiesBtn:gi,copiesValue:bi,jobActions:xi,actionBtn:yi,removeBtn:vi,emptyState:ji},Ie={queued:"Queued",printing:"Printing",done:"Printed",error:"Error",paused:"Paused",cancelled:"Cancelled"},xe=(s,l)=>Ie[l]?s(`printing.status.${l}`,Ie[l]):l;function Ni(s,l){try{return new Date(l).toLocaleTimeString(s,{hour:"2-digit",minute:"2-digit"})}catch{return l}}function fi(s){const l=Math.floor((Date.now()-new Date(s).getTime())/1e3);if(l<60)return`${l}s`;const c=Math.floor(l/60);if(c<60)return`${c}m ${l%60}s`;const r=Math.floor(c/60);return r<24?`${r}h ${c%60}m`:`${Math.floor(r/24)}d ${r%24}h`}const wi=({jobs:s})=>{const{t:l}=_.useNiceTranslation(),c=s.filter(u=>u.status==="printing").length,r=s.filter(u=>u.status==="queued").length,w=s.filter(u=>u.status==="done").length,b=s.filter(u=>u.status==="error").length;return e.jsxs("div",{className:y.statsBar,children:[e.jsxs("span",{className:`${y.stat} ${y.statPrinting}`,children:[e.jsx("span",{className:y.dot}),l("printing.stats.active","Printing"),": ",e.jsx("strong",{children:c})]}),e.jsxs("span",{className:`${y.stat} ${y.statQueued}`,children:[e.jsx("span",{className:y.dot}),l("printing.stats.queued","In queue"),": ",e.jsx("strong",{children:r})]}),e.jsxs("span",{className:`${y.stat} ${y.statDone}`,children:[e.jsx("span",{className:y.dot}),l("printing.stats.done","Done"),": ",e.jsx("strong",{children:w})]}),b>0&&e.jsxs("span",{className:`${y.stat} ${y.statError}`,children:[e.jsx("span",{className:y.dot}),l("printing.stats.errors","Errors"),": ",e.jsx("strong",{children:b})]})]})},ki=({job:s,index:l,total:c,printers:r,selected:w,onSelect:b,onUpdate:u,onRemove:I,onPrint:m,onReorder:j})=>{const{t:a,lang:L}=_.useNiceTranslation(),N=r.find(n=>n.id===s.options.printerId),C=l>0&&s.status==="queued",i=l<c-1&&s.status==="queued";return e.jsxs("div",{className:`${y.jobRow} ${w?y.jobRowSelected:""} ${y[`status-${s.status}`]??""}`,children:[e.jsx("input",{type:"checkbox",className:y.jobCheckbox,checked:w,onChange:()=>b(s.id)}),e.jsx("span",{className:`${y.statusBadge} ${y[`badge-${s.status}`]}`,children:xe(a,s.status)}),e.jsxs("div",{className:y.jobInfo,children:[e.jsx("div",{className:y.jobName,children:s.templateName??s.templateId}),e.jsxs("div",{className:y.jobMeta,children:[s.entityLabel&&e.jsx("span",{children:s.entityLabel}),N&&e.jsxs("span",{children:[e.jsx(_.NiceIcon,{name:"printer",size:12})," ",N.name]}),e.jsxs("span",{children:["×",s.options.copies]}),s.createdAt&&e.jsx("span",{className:y.jobTime,children:Ni(L,s.createdAt)}),s.startedAt&&s.status!=="done"&&e.jsx("span",{className:y.jobDuration,children:fi(s.startedAt)})]}),s.status==="printing"&&s.progress!=null&&e.jsx("div",{className:y.progressBar,children:e.jsx("div",{className:y.progressFill,style:{width:`${s.progress}%`}})}),s.status==="error"&&s.errorMessage&&e.jsx("div",{className:y.jobError,children:s.errorMessage})]}),e.jsxs("div",{className:y.copiesEditor,children:[e.jsx("button",{className:y.copiesBtn,disabled:s.options.copies<=1,"aria-label":a("printing.copies.decrease","One copy fewer"),onClick:()=>u(s.id,{options:{...s.options,copies:s.options.copies-1}}),children:e.jsx(_.NiceIcon,{name:"minus",size:12})}),e.jsx("span",{className:y.copiesValue,children:s.options.copies}),e.jsx("button",{className:y.copiesBtn,"aria-label":a("printing.copies.increase","One copy more"),onClick:()=>u(s.id,{options:{...s.options,copies:s.options.copies+1}}),children:e.jsx(_.NiceIcon,{name:"plus",size:12})})]}),e.jsxs("div",{className:y.jobActions,children:[C&&e.jsx("button",{className:y.actionBtn,title:a("printing.action.moveUp","Move up"),onClick:()=>j(l,l-1),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:14})}),i&&e.jsx("button",{className:y.actionBtn,title:a("printing.action.moveDown","Move down"),onClick:()=>j(l,l+1),children:e.jsx(_.NiceIcon,{name:"arrow-down",size:14})}),s.status==="queued"&&e.jsx("button",{className:y.actionBtn,title:a("printing.action.printNow","Print now"),onClick:()=>m(s.id),children:e.jsx(_.NiceIcon,{name:"play",size:14})}),s.status==="printing"&&e.jsx("button",{className:y.actionBtn,title:a("printing.action.pause","Pause"),onClick:()=>u(s.id,{status:"paused"}),children:e.jsx(_.NiceIcon,{name:"pause",size:14})}),s.status==="paused"&&e.jsx("button",{className:y.actionBtn,title:a("printing.action.resume","Resume"),onClick:()=>u(s.id,{status:"queued"}),children:e.jsx(_.NiceIcon,{name:"play",size:14})}),e.jsx("button",{className:`${y.actionBtn} ${y.removeBtn}`,title:a("printing.action.remove","Remove"),onClick:()=>I(s.id),children:e.jsx(_.NiceIcon,{name:"close",size:14})})]})]})},Si=({jobs:s,printers:l=[],onJobUpdate:c,onJobRemove:r,onJobReorder:w,onJobPrint:b,onBulkRemove:u,onBulkPrint:I,maxHeight:m=500,className:j,style:a,theme:L="light"})=>{const{t:N}=_.useNiceTranslation(),[C,i]=x.useState(new Set),[n,h]=x.useState("all"),d=n==="all"?s:s.filter(v=>v.status===n),f=x.useCallback(v=>{i(E=>{const T=new Set(E);return T.has(v)?T.delete(v):T.add(v),T})},[]),P=x.useCallback(()=>{C.size===d.length?i(new Set):i(new Set(d.map(v=>v.id)))},[d,C.size]),g=x.useCallback(()=>{u==null||u(Array.from(C)),i(new Set)},[C,u]),D=x.useCallback(()=>{I==null||I(Array.from(C)),i(new Set)},[C,I]);return e.jsxs("div",{className:`${y.root} ${L==="dark"?y.dark:""} ${j??""}`,style:a,children:[e.jsx(wi,{jobs:s}),e.jsxs("div",{className:y.toolbar,children:[e.jsx("div",{className:y.filterTabs,children:["all","queued","printing","done","error"].map(v=>e.jsxs("button",{className:`${y.filterTab} ${n===v?y.filterTabActive:""}`,onClick:()=>h(v),children:[v==="all"?N("printing.filter.all","All"):xe(N,v),e.jsx("span",{className:y.filterCount,children:v==="all"?s.length:s.filter(E=>E.status===v).length})]},v))}),C.size>0&&e.jsxs("div",{className:y.bulkActions,children:[e.jsxs("span",{className:y.bulkCount,children:[C.size," ",N("printing.bulk.selected","selected")]}),I&&e.jsxs("button",{className:y.bulkBtn,onClick:D,children:[e.jsx(_.NiceIcon,{name:"printer",size:14})," ",N("printing.bulk.print","Print selected")]}),u&&e.jsxs("button",{className:`${y.bulkBtn} ${y.bulkBtnRemove}`,onClick:g,children:[e.jsx(_.NiceIcon,{name:"trash",size:14})," ",N("printing.bulk.remove","Remove selected")]})]})]}),e.jsx("div",{className:y.jobList,style:{maxHeight:m},children:d.length===0?e.jsx("div",{className:y.emptyState,children:n==="all"?N("printing.empty.queue","No jobs in the queue"):`${N("printing.empty.filtered","No jobs with status")} "${xe(N,n)}"`}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:y.listHeader,children:[e.jsx("input",{type:"checkbox",onChange:P,checked:C.size===d.length&&d.length>0}),e.jsx("span",{className:y.headerLabel,children:N("printing.col.job","Job")}),e.jsx("span",{className:y.headerLabel,children:N("printing.col.copies","Copies")}),e.jsx("span",{className:y.headerLabel,children:N("printing.col.actions","Actions")})]}),d.map((v,E)=>e.jsx(ki,{job:v,index:s.indexOf(v),total:s.length,printers:l,selected:C.has(v.id),onSelect:f,onUpdate:c,onRemove:r,onPrint:b,onReorder:w},v.id))]})})]})},Ii="_container_1f76z_1",Ci="_buttonGroup_1f76z_19",Bi="_trigger_1f76z_31",Li="_triggerDisabled_1f76z_57",zi="_mainAction_1f76z_151",Ti="_dropdownToggle_1f76z_175",Di="_chevron_1f76z_201",$i="_chevronUp_1f76z_211",Ri="_dropdown_1f76z_175",Ai="_dark_1f76z_245",Mi="_section_1f76z_257",Pi="_sectionLabel_1f76z_263",Ei="_divider_1f76z_283",Fi="_copiesRow_1f76z_301",Hi="_copiesBtn_1f76z_311",Gi="_copiesValue_1f76z_351",Oi="_printerSelect_1f76z_375",qi="_printerStatus_1f76z_415",Wi="_printerDot_1f76z_429",Ui="_printerStatusLabel_1f76z_463",Yi="_submitBtn_1f76z_473",Vi="_spinner_1f76z_515",Ki="_spin_1f76z_515",$={container:Ii,buttonGroup:Ci,trigger:Bi,triggerDisabled:Li,"variant-primary":"_variant-primary_1f76z_69","variant-secondary":"_variant-secondary_1f76z_83","variant-ghost":"_variant-ghost_1f76z_99","size-sm":"_size-sm_1f76z_117","size-md":"_size-md_1f76z_127","size-lg":"_size-lg_1f76z_137",mainAction:zi,dropdownToggle:Ti,chevron:Di,chevronUp:$i,dropdown:Ri,dark:Ai,section:Mi,sectionLabel:Pi,divider:Ei,copiesRow:Fi,copiesBtn:Hi,copiesValue:Gi,printerSelect:Oi,printerStatus:qi,printerDot:Wi,"dot-ready":"_dot-ready_1f76z_439","dot-busy":"_dot-busy_1f76z_445","dot-offline":"_dot-offline_1f76z_451","dot-error":"_dot-error_1f76z_457",printerStatusLabel:Ui,submitBtn:Yi,spinner:Vi,spin:Ki},Xi=({onPrint:s,printers:l=[],defaultPrinterId:c,defaultCopies:r=1,disabled:w=!1,loading:b=!1,variant:u="primary",size:I="md",label:m,className:j,style:a,theme:L="light"})=>{var R;const{t:N}=_.useNiceTranslation(),C=m??N("printing.print","Print"),[i,n]=x.useState(!1),[h,d]=x.useState(r),[f,P]=x.useState(c??((R=l[0])==null?void 0:R.id)??""),g=x.useRef(null);x.useEffect(()=>{if(!i)return;const z=Y=>{g.current&&!g.current.contains(Y.target)&&n(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[i]);const D=x.useCallback(()=>{s({copies:h,printerId:f}),n(!1)},[h,f,s]),v=x.useCallback(()=>d(z=>Math.min(99,z+1)),[]),E=x.useCallback(()=>d(z=>Math.max(1,z-1)),[]),T=[$.container,L==="dark"?$.dark:"",j??""].filter(Boolean).join(" "),U=[$.trigger,$[`variant-${u}`],$[`size-${I}`],w||b?$.triggerDisabled:""].filter(Boolean).join(" ");return e.jsxs("div",{ref:g,className:T,style:a,children:[e.jsxs("div",{className:$.buttonGroup,children:[e.jsxs("button",{className:`${U} ${$.mainAction}`,disabled:w||b,onClick:D,"aria-label":C,children:[b?e.jsx("span",{className:$.spinner}):e.jsx(_.NiceIcon,{name:"printer",size:16}),e.jsx("span",{children:C})]}),e.jsx("button",{className:`${U} ${$.dropdownToggle}`,disabled:w||b,onClick:()=>n(z=>!z),"aria-label":N("printing.options","Print options"),"aria-expanded":i,children:e.jsx("span",{className:`${$.chevron} ${i?$.chevronUp:""}`,children:e.jsx(_.NiceIcon,{name:"chevron-down",size:12})})})]}),i&&e.jsxs("div",{className:$.dropdown,children:[e.jsxs("div",{className:$.section,children:[e.jsx("label",{className:$.sectionLabel,children:N("printing.copies.label","Copies")}),e.jsxs("div",{className:$.copiesRow,children:[e.jsx("button",{className:$.copiesBtn,onClick:E,disabled:h<=1,"aria-label":N("printing.copies.decrease","One copy fewer"),children:e.jsx(_.NiceIcon,{name:"minus",size:12})}),e.jsx("span",{className:$.copiesValue,children:h}),e.jsx("button",{className:$.copiesBtn,onClick:v,disabled:h>=99,"aria-label":N("printing.copies.increase","One copy more"),children:e.jsx(_.NiceIcon,{name:"plus",size:12})})]})]}),e.jsx("div",{className:$.divider}),l.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:$.section,children:[e.jsx("label",{className:$.sectionLabel,children:N("printing.printer","Printer")}),e.jsx("select",{className:$.printerSelect,value:f,onChange:z=>P(z.target.value),children:l.map(z=>e.jsxs("option",{value:z.id,disabled:z.status==="offline"||!z.isOnline&&z.status==null,children:[z.name," ",z.status==="offline"||!z.isOnline&&z.status==null?"(Offline)":z.status==="busy"?`(${N("printing.printerBusyLabel","Busy")})`:""]},z.id))}),l.find(z=>z.id===f)&&e.jsx("div",{className:$.printerStatus,children:(()=>{const z=l.find(ue=>ue.id===f),Y=z.status??(z.isOnline?"ready":"offline");return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`${$.printerDot} ${$[`dot-${Y}`]}`}),e.jsx("span",{className:$.printerStatusLabel,children:Y==="ready"?N("printing.printerReady","Ready"):Y==="busy"?N("printing.printerBusyLabel","Busy"):Y==="offline"?"Offline":N("printing.printerError","Error")})]})})()})]}),e.jsx("div",{className:$.divider})]}),e.jsx("div",{className:$.section,children:e.jsx("button",{className:$.submitBtn,onClick:D,disabled:w||b||l.length>0&&(()=>{const z=l.find(Y=>Y.id===f);return z!=null&&(z.status==="offline"||!z.isOnline&&z.status==null)})(),children:b?N("printing.printing","Printing…"):e.jsxs(e.Fragment,{children:[e.jsx(_.NiceIcon,{name:"printer",size:14})," ",C,h>1?` (${h})`:""]})})})]})]})};exports.NicePrintButton=Xi;exports.NicePrintPreview=$a;exports.NicePrintQueue=Si;exports.NiceTemplateBrowser=ha;exports.NiceTemplateEditor=Rn;