@nice2dev/ui-printing 1.2.1 → 1.2.2
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.
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"),_=require("@nice2dev/ui"),N=require("react"),Ge=require("react-dom"),Oe="_root_19f1m_3",qe="_dark_19f1m_27",We="_toolbar_19f1m_39",Ye="_toolbarGroup_19f1m_75",Ue="_toolbarBtn_19f1m_107",Ve="_toolbarBtnActive_19f1m_171",Xe="_toolbarBtnDanger_19f1m_195",Ke="_toolbarSelect_19f1m_207",Je="_toolbarSep_19f1m_237",Qe="_insertWrapper_19f1m_263",Ze="_insertBtn_19f1m_271",et="_insertDropdown_19f1m_293",tt="_insertCategory_19f1m_333",st="_insertItem_19f1m_351",nt="_insertIcon_19f1m_395",at="_zoomSelect_19f1m_409",it="_saveBtn_19f1m_441",rt="_editorBody_19f1m_477",ot="_leftPanel_19f1m_493",lt="_leftTabs_19f1m_523",ct="_leftTab_19f1m_523",dt="_leftTabActive_19f1m_601",mt="_leftTabIcon_19f1m_621",pt="_leftTabLabel_19f1m_629",ut="_leftContent_19f1m_639",ht="_panelHeader_19f1m_653",_t="_panelHeaderIcon_19f1m_677",gt="_panelHeaderName_19f1m_685",bt="_searchBox_19f1m_699",xt="_searchInput_19f1m_707",yt="_fieldList_19f1m_753",ft="_fieldItem_19f1m_763",jt="_fieldItemIcon_19f1m_807",vt="_fieldItemInfo_19f1m_821",Nt="_fieldItemLabel_19f1m_831",wt="_fieldItemPath_19f1m_847",kt="_fieldItemType_19f1m_863",St="_layerList_19f1m_883",It="_layerItem_19f1m_895",Ct="_layerItemSelected_19f1m_931",Bt="_layerIcon_19f1m_949",Lt="_layerName_19f1m_961",Tt="_layerActions_19f1m_977",zt="_layerBtn_19f1m_999",Dt="_wmList_19f1m_1031",$t="_wmItem_19f1m_1039",Rt="_wmRow_19f1m_1065",At="_wmLabel_19f1m_1079",Mt="_wmInput_19f1m_1091",Et="_wmInputNum_19f1m_1123",Pt="_wmSelect_19f1m_1143",Ft="_wmSlider_19f1m_1175",Ht="_wmValue_19f1m_1185",Gt="_wmUnit_19f1m_1199",Ot="_wmDelete_19f1m_1209",qt="_addBtn_19f1m_1241",Wt="_settingsForm_19f1m_1277",Yt="_settingsRow_19f1m_1285",Ut="_settingsLabel_19f1m_1299",Vt="_settingsInput_19f1m_1311",Xt="_settingsInputNum_19f1m_1343",Kt="_settingsTextarea_19f1m_1375",Jt="_settingsDivider_19f1m_1409",Qt="_settingsUnit_19f1m_1429",Zt="_emptyMsg_19f1m_1441",es="_canvasArea_19f1m_1459",ts="_testDataBar_19f1m_1485",ss="_testDataLabel_19f1m_1517",ns="_testDataSelect_19f1m_1527",as="_rulerWrapper_19f1m_1547",is="_rulerCorner_19f1m_1563",rs="_ruler_19f1m_1547",os="_ruler_h_19f1m_1621",ls="_ruler_v_19f1m_1631",cs="_rulerTick_19f1m_1651",ds="_rulerTickMajor_19f1m_1691",ms="_rulerLabel_19f1m_1711",ps="_paperScroll_19f1m_1749",us="_paperShadow_19f1m_1767",hs="_marginGuide_19f1m_1803",_s="_watermark_19f1m_1819",gs="_sectionCanvas_19f1m_1845",bs="_sectionCanvasOver_19f1m_1859",xs="_sectionTypeChip_19f1m_1867",ys="_sectionResizeBar_19f1m_1899",fs="_sectionResizeGrip_19f1m_1933",js="_fieldImagePlaceholder_19f1m_1949",vs="_fieldBarcodePlaceholder_19f1m_1971",Ns="_fieldSignaturePlaceholder_19f1m_1999",ws="_resizeHandle_19f1m_2031",ks="_handle_n_19f1m_2051",Ss="_handle_s_19f1m_2063",Is="_handle_e_19f1m_2075",Cs="_handle_w_19f1m_2087",Bs="_handle_ne_19f1m_2099",Ls="_handle_nw_19f1m_2109",Ts="_handle_se_19f1m_2119",zs="_handle_sw_19f1m_2129",Ds="_rightPanel_19f1m_2143",$s="_rightTabs_19f1m_2173",Rs="_rightTab_19f1m_2173",As="_rightTabActive_19f1m_2243",Ms="_propsBody_19f1m_2255",Es="_propsEmpty_19f1m_2267",Ps="_propsEmptyIcon_19f1m_2289",Fs="_propsEmptyText_19f1m_2299",Hs="_posGrid_19f1m_2311",Gs="_posCell_19f1m_2325",Os="_posLabel_19f1m_2337",qs="_posInput_19f1m_2349",Ws="_posUnit_19f1m_2391",Ys="_snapSection_19f1m_2403",Us="_snapTitle_19f1m_2411",Vs="_snapRow_19f1m_2429",Xs="_snapBtn_19f1m_2439",Ks="_styleGroup_19f1m_2473",Js="_styleGroupTitle_19f1m_2481",Qs="_styleRow_19f1m_2511",Zs="_styleLabel_19f1m_2525",en="_styleSelect_19f1m_2539",tn="_styleSelectFull_19f1m_2569",sn="_styleSelectSm_19f1m_2601",nn="_styleSelectXs_19f1m_2621",an="_styleInput_19f1m_2653",rn="_styleInputFull_19f1m_2685",on="_styleUnit_19f1m_2717",ln="_styleValue_19f1m_2729",cn="_toggleGroup_19f1m_2743",dn="_toggleBtn_19f1m_2753",mn="_toggleBtnActive_19f1m_2787",pn="_colorPicker_19f1m_2801",un="_colorHex_19f1m_2819",hn="_clearBtn_19f1m_2853",_n="_sliderInput_19f1m_2885",gn="_conditionalHint_19f1m_2897",bn="_clearConditionalBtn_19f1m_2929",xn="_shortcutGrid_19f1m_2961",yn="_shortcutChip_19f1m_2975",fn="_shortcutKeys_19f1m_3007",jn="_shortcutLabel_19f1m_3027",t={root:Oe,dark:qe,toolbar:We,toolbarGroup:Ye,toolbarBtn:Ue,toolbarBtnActive:Ve,toolbarBtnDanger:Xe,toolbarSelect:Ke,toolbarSep:Je,insertWrapper:Qe,insertBtn:Ze,insertDropdown:et,insertCategory:tt,insertItem:st,insertIcon:nt,zoomSelect:at,saveBtn:it,editorBody:rt,leftPanel:ot,leftTabs:lt,leftTab:ct,leftTabActive:dt,leftTabIcon:mt,leftTabLabel:pt,leftContent:ut,panelHeader:ht,panelHeaderIcon:_t,panelHeaderName:gt,searchBox:bt,searchInput:xt,fieldList:yt,fieldItem:ft,fieldItemIcon:jt,fieldItemInfo:vt,fieldItemLabel:Nt,fieldItemPath:wt,fieldItemType:kt,layerList:St,layerItem:It,layerItemSelected:Ct,layerIcon:Bt,layerName:Lt,layerActions:Tt,layerBtn:zt,wmList:Dt,wmItem:$t,wmRow:Rt,wmLabel:At,wmInput:Mt,wmInputNum:Et,wmSelect:Pt,wmSlider:Ft,wmValue:Ht,wmUnit:Gt,wmDelete:Ot,addBtn:qt,settingsForm:Wt,settingsRow:Yt,settingsLabel:Ut,settingsInput:Vt,settingsInputNum:Xt,settingsTextarea:Kt,settingsDivider:Jt,settingsUnit:Qt,emptyMsg:Zt,canvasArea:es,testDataBar:ts,testDataLabel:ss,testDataSelect:ns,rulerWrapper:as,rulerCorner:is,ruler:rs,ruler_h:os,ruler_v:ls,rulerTick:cs,rulerTickMajor:ds,rulerLabel:ms,paperScroll:ps,paperShadow:us,marginGuide:hs,watermark:_s,sectionCanvas:gs,sectionCanvasOver:bs,sectionTypeChip:xs,sectionResizeBar:ys,sectionResizeGrip:fs,fieldImagePlaceholder:js,fieldBarcodePlaceholder:vs,fieldSignaturePlaceholder:Ns,resizeHandle:ws,handle_n:ks,handle_s:Ss,handle_e:Is,handle_w:Cs,handle_ne:Bs,handle_nw:Ls,handle_se:Ts,handle_sw:zs,rightPanel:Ds,rightTabs:$s,rightTab:Rs,rightTabActive:As,propsBody:Ms,propsEmpty:Es,propsEmptyIcon:Ps,propsEmptyText:Fs,posGrid:Hs,posCell:Gs,posLabel:Os,posInput:qs,posUnit:Ws,snapSection:Ys,snapTitle:Us,snapRow:Vs,snapBtn:Xs,styleGroup:Ks,styleGroupTitle:Js,styleRow:Qs,styleLabel:Zs,styleSelect:en,styleSelectFull:tn,styleSelectSm:sn,styleSelectXs:nn,styleInput:an,styleInputFull:rn,styleUnit:on,styleValue:ln,toggleGroup:cn,toggleBtn:dn,toggleBtnActive:mn,colorPicker:pn,colorHex:un,clearBtn:hn,sliderInput:_n,conditionalHint:gn,clearConditionalBtn:bn,shortcutGrid:xn,shortcutChip:yn,shortcutKeys:fn,shortcutLabel:jn},G=3.78,ve={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432],custom:[210,297]},vn=["sans-serif","serif","monospace","Arial","Times New Roman","Courier New","Georgia","Verdana","Tahoma"],Ne=[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,a)=>de[a]?s(`printing.fieldType.${a}`,de[a]):a;function Nn(s,a){switch(a.type){case"UPDATE":return{past:[...s.past.slice(-50),s.present],present:a.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",me="#94a3b8";function ie(){return`f-${Date.now()}-${Math.floor(Math.random()*1e3)}`}function we(s,a){const d={id:ie(),name:(a==null?void 0:a.label)??de[s]??s,label:(a==null?void 0:a.label)??de[s]??s,type:s,dataPath:(a==null?void 0:a.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"&&(d.style.backgroundColor="var(--nice-bg-secondary, #f1f5f9)"),s==="line"&&(d.style={...d.style,borderWidth:.5,borderColor:te,borderStyle:"solid"}),d}const ke=({lengthMm:s,zoom:a,orientation:d})=>{const r=[],S=a<.6?20:a<1?10:5;for(let j=0;j<=s;j+=S){const b=j*a*G,u=j%(S*2)===0;r.push(e.jsx("div",{className:`${t.rulerTick} ${u?t.rulerTickMajor:""}`,style:d==="h"?{left:b}:{top:b},children:u&&e.jsx("span",{className:t.rulerLabel,children:j})},j))}return e.jsx("div",{className:`${t.ruler} ${t[`ruler_${d}`]}`,children:r})},wn=["n","s","e","w","ne","nw","se","sw"],kn=({onResizeStart:s})=>e.jsx(e.Fragment,{children:wn.map(a=>e.jsx("div",{className:`${t.resizeHandle} ${t[`handle_${a}`]}`,onMouseDown:d=>{d.stopPropagation(),s(a,d)}},a))});function Sn(s,a){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(a&&s.dataPath){const d=s.dataPath.split(".").reduce((r,S)=>r&&typeof r=="object"?r[S]:null,a);if(d!=null)return String(d)}return s.label?`{${s.label}}`:`{${s.dataPath}}`}const In=({field:s,zoom:a,selected:d,sampleData:r,onClick:S,onDragStart:j,onResizeStart:b,readOnly:u})=>{const g=s.position,h=s.style,o=n=>n*a*G,y=s.type==="line",k=s.type==="rect",L=s.type==="image"||s.type==="static_image",x=s.type==="barcode"||s.type==="qr",i={position:"absolute",left:o(g.x),top:o(g.y),width:o(g.width),height:o(g.height),zIndex:g.zIndex??1,transform:h.rotation?`rotate(${h.rotation}deg)`:void 0,boxSizing:"border-box",overflow:"hidden",...!y&&!k?{fontSize:(h.fontSize??10)*a,fontFamily:h.fontFamily??"sans-serif",fontWeight:h.fontWeight??"normal",fontStyle:h.fontStyle??"normal",color:h.color??te,textAlign:h.textAlign??"left",lineHeight:h.lineHeight??1.4,letterSpacing:h.letterSpacing?`${h.letterSpacing}em`:void 0,padding:h.padding?o(h.padding):0}:{},backgroundColor:h.backgroundColor,borderWidth:h.borderWidth??0,borderColor:h.borderColor??"transparent",borderStyle:h.borderStyle??"solid",borderRadius:h.borderRadius,opacity:h.opacity,outline:d?"1.5px solid var(--nice-primary-hover, #2563eb)":"1px dashed transparent",outlineOffset:1,cursor:u?"default":"move"};return e.jsxs("div",{style:i,onClick:S,onMouseDown:u?void 0:j,children:[y?e.jsx("div",{style:{width:"100%",borderBottom:`${(h.borderWidth??.5)*a}px ${h.borderStyle??"solid"} ${h.borderColor??te}`}}):k?null:L?e.jsx("div",{className:t.fieldImagePlaceholder,children:e.jsx(_.NiceIcon,{name:"image",size:24})}):x?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)}),d&&!u&&e.jsx(kn,{onResizeStart:b})]})},Cn=({section:s,zoom:a,paperWidthMm:d,selectedIds:r,sampleData:S,readOnly:j,showGrid:b,onFieldClick:u,onFieldDragStart:g,onResizeStart:h,onSectionHeightChange:o,onDropField:y})=>{const k=(s.heightMm??(s.type==="body"?200:40))*a*G,L=d*a*G,[x,i]=N.useState(!1),n={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} ${x?t.sectionCanvasOver:""}`,style:{width:L,height:k,position:"relative",background:n[s.type]??"transparent",backgroundImage:b?`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*a*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*a*G}px)`:void 0},onDragOver:p=>{p.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:p=>{p.preventDefault(),i(!1);const l=p.dataTransfer.getData("fieldPath");if(!l)return;const E=p.currentTarget.getBoundingClientRect(),f=(p.clientX-E.left)/(a*G),D=(p.clientY-E.top)/(a*G);y(s.id,l,Math.max(0,f),Math.max(0,D))},children:[e.jsx("div",{className:t.sectionTypeChip,children:s.type}),s.fields.map(p=>e.jsx(In,{field:p,zoom:a,selected:r.has(p.id),sampleData:S,readOnly:j,onClick:l=>u(p.id,l),onDragStart:l=>g(p.id,l),onResizeStart:(l,E)=>h(p.id,l,E)},p.id)),!j&&s.type!=="body"&&e.jsx("div",{className:t.sectionResizeBar,onMouseDown:p=>{p.preventDefault();const l=p.clientY,E=s.heightMm??40,f=B=>{const T=(B.clientY-l)/(a*G);o(s.id,Math.max(10,E+T))},D=()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",D)};document.addEventListener("mousemove",f),document.addEventListener("mouseup",D)},children:e.jsx("div",{className:t.sectionResizeGrip})})]})},ae=({keys:s,label:a})=>e.jsxs("div",{className:t.shortcutChip,children:[e.jsx("span",{className:t.shortcutKeys,children:s}),e.jsx("span",{className:t.shortcutLabel,children:a})]}),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"}],Tn=({tpl:s,zoom:a,canUndo:d,canRedo:r,showGrid:S,showRulers:j,readOnly:b,selectedCount:u,onPaperChange:g,onZoom:h,onUndo:o,onRedo:y,onToggleGrid:k,onToggleRulers:L,onInsert:x,onDelete:i,onDuplicate:n,onAlignH:p,onAlignV:l,onBringForward:E,onSendBackward:f,onSave:D})=>{const{t:B}=_.useNiceTranslation(),{t:T}=_.useNiceTranslation(),[R,O]=N.useState(!1),X=[.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:v=>g(v.target.value,s.orientation),children:["A4","A5","A3","Letter","Legal","Tabloid","custom"].map(v=>e.jsx("option",{value:v,children:v},v))}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="portrait"?t.toolbarBtnActive:""}`,onClick:()=>g(s.paperSize,"portrait"),title:B("templateEditor.portrait","Portrait"),children:e.jsx(_.NiceIcon,{name:"file",size:14})}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="landscape"?t.toolbarBtnActive:""}`,onClick:()=>g(s.paperSize,"landscape"),title:B("templateEditor.landscape","Landscape"),children:e.jsx(_.NiceIcon,{name:"file",size:14,style:{transform:"rotate(90deg)"}})})]}),!b&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,disabled:!d,onClick:o,title:`${T("printing.editor.undo","Undo")} (Ctrl+Z)`,children:e.jsx(_.NiceIcon,{name:"undo",size:14})}),e.jsx("button",{className:t.toolbarBtn,disabled:!r,onClick:y,title:`${T("printing.editor.redo","Redo")} (Ctrl+Y)`,children:e.jsx(_.NiceIcon,{name:"redo",size:14})})]}),!b&&e.jsxs("div",{className:t.insertWrapper,children:[e.jsxs("button",{className:`${t.toolbarBtn} ${t.insertBtn}`,onClick:()=>O(v=>!v),children:[e.jsx(_.NiceIcon,{name:"plus",size:14})," ",T("printing.editor.insert","Insert")," ",e.jsx(_.NiceIcon,{name:"chevron-down",size:12})]}),R&&e.jsxs("div",{className:t.insertDropdown,onMouseLeave:()=>O(!1),children:[e.jsx("div",{className:t.insertCategory,children:T("printing.editor.dataFields","Data fields")}),["text","number","currency","date","image","barcode","qr"].map(v=>e.jsxs("button",{className:t.insertItem,onClick:()=>{x(v),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:ce[v]}),be(T,v)]},v)),e.jsx("div",{className:t.insertCategory,children:B("templateEditor.staticElements","Static elements")}),["static_text","static_image","line","rect","page_number","total_pages","print_date"].map(v=>e.jsxs("button",{className:t.insertItem,onClick:()=>{x(v),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:ce[v]}),be(T,v)]},v)),e.jsx("div",{className:t.insertCategory,children:B("templateEditor.special","Special")}),e.jsxs("button",{className:t.insertItem,onClick:()=>{x("watermark"),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:e.jsx(_.NiceIcon,{name:"droplet",size:14})}),T("printing.editor.watermark","Watermark")]}),e.jsxs("button",{className:t.insertItem,onClick:()=>{x("signature"),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:e.jsx(_.NiceIcon,{name:"pen",size:14})}),T("printing.editor.signature","Signature")]})]})]}),!b&&u>0&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:n,title:`${T("printing.editor.duplicate","Duplicate")} (Ctrl+D)`,children:e.jsx(_.NiceIcon,{name:"copy",size:14})}),e.jsx("button",{className:`${t.toolbarBtn} ${t.toolbarBtnDanger}`,onClick:i,title:`${T("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:()=>p("left"),title:T("printing.editor.alignLeft","Align left"),children:e.jsx(_.NiceIcon,{name:"align-left",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>p("center"),title:T("printing.editor.alignCenter","Align centre"),children:e.jsx(_.NiceIcon,{name:"align-center",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>p("right"),title:T("printing.editor.alignRight","Align right"),children:e.jsx(_.NiceIcon,{name:"align-right",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>l("top"),title:T("printing.editor.alignTop","Align top"),children:"⊤"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>l("center"),title:T("printing.editor.alignMiddle","Align middle"),children:"⊕"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>l("bottom"),title:T("printing.editor.alignBottom","Align bottom"),children:"⊥"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:E,title:B("templateEditor.bringForward","Bring forward"),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:f,title:T("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} ${S?t.toolbarBtnActive:""}`,onClick:k,title:T("printing.editor.grid","Grid"),children:"⊞"}),e.jsx("button",{className:`${t.toolbarBtn} ${j?t.toolbarBtnActive:""}`,onClick:L,title:T("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:()=>h(Math.max(.25,a-.1)),children:"−"}),e.jsx("select",{className:t.zoomSelect,value:X.includes(a)?a:"",onChange:v=>h(+v.target.value),children:X.map(v=>e.jsxs("option",{value:v,children:[Math.round(v*100),"%"]},v))}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>h(Math.min(3,a+.1)),children:"+"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>h(1),title:"100%",children:"⊡"})]}),!b&&D&&e.jsxs("button",{className:t.saveBtn,onClick:D,children:[e.jsx(_.NiceIcon,{name:"save",size:14})," ",T("printing.editor.save","Save")]})]})},zn=({activeTab:s,onTabChange:a,schema:d,tpl:r,allFields:S,selectedIds:j,onInsertSchemaField:b,onSelectField:u,onUpdateTpl:g,onReorderField:h})=>{const{t:o}=_.useNiceTranslation(),{t:y}=_.useNiceTranslation(),[k,L]=N.useState(""),x=d==null?void 0:d.fields.filter(i=>i.label.toLowerCase().includes(k.toLowerCase())||i.path.toLowerCase().includes(k.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:()=>a(i.id),title:y(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:y(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:y("printing.editor.dataFields","Data fields")}),e.jsx("div",{className:t.searchBox,children:e.jsx("input",{className:t.searchInput,placeholder:y("printing.editor.search","Search…"),value:k,onChange:i=>L(i.target.value)})}),d?e.jsxs("div",{className:t.fieldList,children:[(x??[]).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:()=>b(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)),(x==null?void 0:x.length)===0&&e.jsx("div",{className:t.emptyMsg,children:y("printing.editor.noMatches","No matches")})]}):e.jsx("div",{className:t.emptyMsg,children:y("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:[y("printing.editor.layers","Layers")," (",S.length,")"]}),e.jsxs("div",{className:t.layerList,children:[S.length===0&&e.jsx("div",{className:t.emptyMsg,children:y("printing.editor.noElements","No elements")}),S.slice().reverse().map(i=>e.jsxs("div",{className:`${t.layerItem} ${j.has(i.id)?t.layerItemSelected:""}`,onClick:()=>u(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(),h(i.id,-1)},title:y("printing.editor.bringForward","Bring forward"),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:12})}),e.jsx("button",{className:t.layerBtn,onClick:n=>{n.stopPropagation(),h(i.id,1)},title:y("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:o("templateEditor.watermarks","Watermarks")}),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:y("printing.editor.type","Type")}),e.jsxs("select",{className:t.wmSelect,value:i.type,onChange:n=>{var p;return g({watermarks:(p=r.watermarks)==null?void 0:p.map(l=>l.id===i.id?{...l,type:n.target.value}:l)})},children:[e.jsx("option",{value:"text",children:y("printing.fieldType.text","Text")}),e.jsx("option",{value:"image",children:y("printing.fieldType.image","Image")})]})]}),i.type==="text"&&e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:y("printing.fieldType.text","Text")}),e.jsx("input",{className:t.wmInput,value:i.text??"",onChange:n=>{var p;return g({watermarks:(p=r.watermarks)==null?void 0:p.map(l=>l.id===i.id?{...l,text:n.target.value}:l)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:o("templateEditor.opacity","Opacity")}),e.jsx("input",{type:"range",min:.02,max:.5,step:.01,className:t.wmSlider,value:i.opacity,onChange:n=>{var p;return g({watermarks:(p=r.watermarks)==null?void 0:p.map(l=>l.id===i.id?{...l,opacity:+n.target.value}:l)})}}),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:y("printing.editor.angle","Angle")}),e.jsx("input",{type:"range",min:-90,max:90,step:5,className:t.wmSlider,value:i.angle,onChange:n=>{var p;return g({watermarks:(p=r.watermarks)==null?void 0:p.map(l=>l.id===i.id?{...l,angle:+n.target.value}:l)})}}),e.jsxs("span",{className:t.wmValue,children:[i.angle,"°"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:y("printing.editor.size","Size")}),e.jsx("input",{type:"number",min:8,max:200,className:t.wmInputNum,value:i.fontSize??48,onChange:n=>{var p;return g({watermarks:(p=r.watermarks)==null?void 0:p.map(l=>l.id===i.id?{...l,fontSize:+n.target.value}:l)})}}),e.jsx("span",{className:t.wmUnit,children:"pt"})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:y("printing.editor.colour","Colour")}),e.jsx("input",{type:"color",className:t.colorPicker,value:i.color??me,onChange:n=>{var p;return g({watermarks:(p=r.watermarks)==null?void 0:p.map(l=>l.id===i.id?{...l,color:n.target.value}:l)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var n;return g({watermarks:(n=r.watermarks)==null?void 0:n.filter(p=>p.id!==i.id)})},children:y("printing.action.remove","Remove")})]},i.id)),e.jsxs("button",{className:t.addBtn,onClick:()=>g({watermarks:[...r.watermarks??[],{id:ie(),type:"text",text:"COPY",opacity:.12,angle:-45,fontSize:60,color:me}]}),children:[e.jsx(_.NiceIcon,{name:"plus",size:12})," ",y("printing.editor.addWatermark","Add watermark")]})]})]}),s==="signatures"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:o("templateEditor.signatures","Signatures")}),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:o("templateEditor.label","Label")}),e.jsx("input",{className:t.wmInput,value:i.label,onChange:n=>{var p;return g({signatures:(p=r.signatures)==null?void 0:p.map(l=>l.id===i.id?{...l,label:n.target.value}:l)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:o("templateEditor.signerName","Name")}),e.jsx("input",{className:t.wmInput,value:i.signerName??"",onChange:n=>{var p;return g({signatures:(p=r.signatures)==null?void 0:p.map(l=>l.id===i.id?{...l,signerName:n.target.value}:l)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:y("printing.fieldType.line","Line")}),e.jsx("input",{type:"checkbox",checked:i.showLine??!0,onChange:n=>{var p;return g({signatures:(p=r.signatures)==null?void 0:p.map(l=>l.id===i.id?{...l,showLine:n.target.checked}:l)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:y("printing.editor.showDate","Show date")}),e.jsx("input",{type:"checkbox",checked:i.showDate??!1,onChange:n=>{var p;return g({signatures:(p=r.signatures)==null?void 0:p.map(l=>l.id===i.id?{...l,showDate:n.target.checked}:l)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var n;return g({signatures:(n=r.signatures)==null?void 0:n.filter(p=>p.id!==i.id)})},children:y("printing.action.remove","Remove")})]},i.id)),e.jsxs("button",{className:t.addBtn,onClick:()=>g({signatures:[...r.signatures??[],{id:ie(),label:y("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})," ",y("printing.editor.addSignature","Add signature")]})]})]}),s==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:y("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:y("printing.editor.name","Name")}),e.jsx("input",{className:t.settingsInput,value:r.name,onChange:i=>g({name:i.target.value})})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:y("printing.editor.description","Description")}),e.jsx("textarea",{className:t.settingsTextarea,value:r.description??"",onChange:i=>g({description:i.target.value}),rows:2})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:o("templateEditor.category","Category")}),e.jsx("input",{className:t.settingsInput,value:r.category??"",onChange:i=>g({category:i.target.value})})]}),e.jsx("div",{className:t.settingsDivider,children:y("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"?y("printing.editor.marginTop","Top"):i==="right"?y("printing.editor.marginRight","Right"):i==="bottom"?y("printing.editor.marginBottom","Bottom"):y("printing.editor.marginLeft","Left")}),e.jsx("input",{type:"number",min:0,max:50,step:1,className:t.settingsInputNum,value:r.margins[i],onChange:n=>g({margins:{...r.margins,[i]:+n.target.value}})}),e.jsx("span",{className:t.settingsUnit,children:"mm"})]},i))]})]})]})]})},Dn=({field:s,activeTab:a,onTabChange:d,onChange:r,paperWidthMm:S,paperHeightMm:j})=>{var k,L,x,i;const{t:b}=_.useNiceTranslation(),{t:u}=_.useNiceTranslation(),g=N.useCallback(n=>s&&r({position:{...s.position,...n}}),[s,r]),h=N.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 o=!["line","rect","image","static_image","barcode","qr","signature"].includes(s.type),y=!["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"&&!y?null:e.jsx("button",{className:`${t.rightTab} ${a===n.id?t.rightTabActive:""}`,onClick:()=>d(n.id),children:u(n.key,n.label)},n.id))}),e.jsxs("div",{className:t.propsBody,children:[a==="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:p,unit:l})=>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[n]*10)/10,onChange:E=>g({[n]:+E.target.value})}),e.jsx("span",{className:t.posUnit,children:l})]},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=>h({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:b("templateEditor.zIdx","Z-idx")}),e.jsx("input",{type:"number",step:1,min:1,className:t.posInput,value:s.position.zIndex??1,onChange:n=>g({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:()=>g({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:()=>g({x:(S-s.position.width)/2}),title:u("printing.editor.horizontalCentre","Horizontal centre"),children:"⊕"}),e.jsx("button",{className:t.snapBtn,onClick:()=>g({x:S-s.position.width}),title:u("printing.editor.rightEdge","Right edge"),children:e.jsx(_.NiceIcon,{name:"align-right",size:14})})]})]})]}),a==="style"&&e.jsxs(e.Fragment,{children:[o&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:b("templateEditor.font","Font")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:b("templateEditor.fontFamily","Family")}),e.jsx("select",{className:t.styleSelectFull,value:s.style.fontFamily??"sans-serif",onChange:n=>h({fontFamily:n.target.value}),children:vn.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:Ne.includes(s.style.fontSize??10)?s.style.fontSize??10:"",onChange:n=>h({fontSize:+n.target.value}),children:Ne.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=>h({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=>h({color:n.target.value})}),e.jsx("input",{className:t.colorHex,value:s.style.color??te,onChange:n=>h({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:()=>h({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:()=>h({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:()=>h({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:b("templateEditor.lineHeight","Line h.")}),e.jsx("input",{type:"number",step:.1,min:1,max:4,className:t.styleInput,value:s.style.lineHeight??1.4,onChange:n=>h({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=>h({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=>h({backgroundColor:n.target.value})}),e.jsx("button",{className:t.clearBtn,onClick:()=>h({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:b("templateEditor.border","Border")}),e.jsx("input",{type:"number",step:.5,min:0,max:10,className:t.styleInput,value:s.style.borderWidth??0,onChange:n=>h({borderWidth:+n.target.value})}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.borderColor??te,onChange:n=>h({borderColor:n.target.value})}),e.jsxs("select",{className:t.styleSelectXs,value:s.style.borderStyle??"solid",onChange:n=>h({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:b("templateEditor.radius","Radius")}),e.jsx("input",{type:"number",step:1,min:0,max:50,className:t.styleInput,value:s.style.borderRadius??0,onChange:n=>h({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:b("templateEditor.padding","Padding")}),e.jsx("input",{type:"number",step:.5,min:0,max:20,className:t.styleInput,value:s.style.padding??0,onChange:n=>h({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:b("templateEditor.opacity","Opacity")}),e.jsx("input",{type:"range",min:.1,max:1,step:.05,className:t.sliderInput,value:s.style.opacity??1,onChange:n=>h({opacity:+n.target.value})}),e.jsxs("span",{className:t.styleValue,children:[Math.round((s.style.opacity??1)*100),"%"]})]})]})]}),a==="data"&&y&&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:b("templateEditor.egInvoiceNumber","e.g. 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:b("templateEditor.ddMmYyyy000","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))})]})]}),a==="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:((k=s.conditional)==null?void 0:k.field)??"",onChange:n=>{var p,l;return r({conditional:{field:n.target.value,operator:((p=s.conditional)==null?void 0:p.operator)??"eq",value:(l=s.conditional)==null?void 0:l.value}})},placeholder:b("templateEditor.egInvoiceIsPaid","e.g. invoice.isPaid")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:b("templateEditor.operator","Operator")}),e.jsxs("select",{className:t.styleSelectFull,value:((L=s.conditional)==null?void 0:L.operator)??"eq",onChange:n=>{var p,l;return r({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:n.target.value,value:(l=s.conditional)==null?void 0:l.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(((x=s.conditional)==null?void 0:x.value)??""),onChange:n=>{var p,l;return r({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:((l=s.conditional)==null?void 0:l.operator)??"eq",value:n.target.value}})},placeholder:b("templateEditor.egTruePaid",'e.g. 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:a,sampleData:d=[],onChange:r,onSave:S,readOnly:j=!1,className:b,style:u,theme:g="light"})=>{const[{past:h,present:o,future:y},k]=N.useReducer(Nn,{past:[],present:s??$n(),future:[]}),{t:L}=_.useNiceTranslation(),[x,i]=N.useState(new Set),[n,p]=N.useState("sec-body"),[l,E]=N.useState(1),[f,D]=N.useState(0),[B,T]=N.useState("fields"),[R,O]=N.useState("position"),[X,v]=N.useState(!1),[Y,pe]=N.useState(!0),A=N.useCallback(c=>{const m={...o,...c};k({type:"UPDATE",payload:m}),r==null||r(m)},[o,r]),[K,ue]=N.useMemo(()=>{const[c,m]=ve[o.paperSize]??ve.A4;return o.orientation==="landscape"?[m,c]:[c,m]},[o.paperSize,o.orientation]),J=N.useMemo(()=>o.sections.flatMap(c=>c.fields),[o]),P=N.useMemo(()=>J.find(c=>x.has(c.id))??null,[J,x]),he=N.useCallback((c,m)=>{A({sections:o.sections.map(C=>({...C,fields:C.fields.map(I=>I.id===c?{...I,...m,style:{...I.style,...m.style??{}}}:I)}))})},[o,A]),re=N.useCallback(c=>{A({sections:o.sections.map(m=>({...m,fields:m.fields.map(C=>x.has(C.id)?{...C,...c,style:{...C.style,...c.style??{}}}:C)}))})},[o,x,A]),ye=N.useCallback((c,m)=>{if(c==="watermark"){A({watermarks:[...o.watermarks??[],{id:ie(),type:"text",text:"COPY",opacity:.12,angle:-45,fontSize:60,color:me}]}),T("watermarks");return}if(c==="signature"){A({signatures:[...o.signatures??[],{id:ie(),label:L("printing.editor.signature","Signature"),position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),T("signatures");return}const C=o.sections.find(F=>F.id===n)??o.sections.find(F=>F.type==="body");if(!C)return;const I=we(c,m),M={sections:o.sections.map(F=>F.id===C.id?{...F,fields:[...F.fields,I]}:F)};k({type:"UPDATE",payload:{...o,...M}}),r==null||r({...o,...M}),i(new Set([I.id]))},[o,n,r]),Ce=N.useCallback((c,m,C,I)=>{const M=a==null?void 0:a.fields.find(q=>q.path===m),F=we((M==null?void 0:M.type)??"text",M);F.position.x=Math.round(C*2)/2,F.position.y=Math.round(I*2)/2;const Q={sections:o.sections.map(q=>q.id===c?{...q,fields:[...q.fields,F]}:q)};k({type:"UPDATE",payload:{...o,...Q}}),r==null||r({...o,...Q}),i(new Set([F.id]))},[o,a,r]),Be=N.useCallback((c,m)=>{m.ctrlKey||m.metaKey?i(C=>{const I=new Set(C);return I.has(c)?I.delete(c):I.add(c),I}):m.shiftKey?i(C=>new Set([...C,c])):i(new Set([c]))},[]),Le=N.useCallback((c,m)=>{if(j)return;m.preventDefault(),x.has(c)||i(new Set([c]));const C=m.clientX,I=m.clientY,M=o.sections.map(q=>({id:q.id,fields:q.fields.map(Z=>({id:Z.id,pos:{...Z.position}}))})),F=q=>{const Z=(q.clientX-C)/(l*G),se=(q.clientY-I)/(l*G),oe=x.has(c)?x:new Set([c]),le=o.sections.map(ee=>{const U=M.find(W=>W.id===ee.id);return{...ee,fields:ee.fields.map(W=>{var je;if(!oe.has(W.id))return W;const fe=((je=U==null?void 0:U.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((fe.x+Z)*2)/2),y:Math.max(0,Math.round((fe.y+se)*2)/2)}}})}}),ne={...o,sections:le};r==null||r(ne),k({type:"UPDATE",payload:ne})},Q=()=>{document.removeEventListener("mousemove",F),document.removeEventListener("mouseup",Q)};document.addEventListener("mousemove",F),document.addEventListener("mouseup",Q)},[o,l,x,j,r]),Te=N.useCallback((c,m,C)=>{if(j)return;C.preventDefault();const I=J.find(se=>se.id===c);if(!I)return;const M={...I.position},F=C.clientX,Q=C.clientY,q=se=>{const oe=(se.clientX-F)/(l*G),le=(se.clientY-Q)/(l*G);let{x:ne,y:ee,width:U,height:W}=M;m.includes("e")&&(U=Math.max(5,U+oe)),m.includes("s")&&(W=Math.max(3,W+le)),m.includes("w")&&(ne=ne+oe,U=Math.max(5,U-oe)),m.includes("n")&&(ee=ee+le,W=Math.max(3,W-le)),he(c,{position:{...M,x:Math.round(ne*2)/2,y:Math.round(ee*2)/2,width:Math.round(U*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,l,j,he]),_e=N.useCallback(()=>{A({sections:o.sections.map(c=>({...c,fields:c.fields.filter(m=>!x.has(m.id))}))}),i(new Set)},[o,x,A]),ge=N.useCallback(()=>{const c=new Set;A({sections:o.sections.map(m=>{const C=m.fields.filter(I=>x.has(I.id)).map(I=>{const M={...I,id:ie(),position:{...I.position,x:I.position.x+5,y:I.position.y+5}};return c.add(M.id),M});return{...m,fields:[...m.fields,...C]}})}),i(c)},[o,x,A]),ze=N.useCallback(c=>{A({sections:o.sections.map(m=>({...m,fields:m.fields.map(C=>{if(!x.has(C.id))return C;const I=c==="left"?o.margins.left:c==="right"?K-o.margins.right-C.position.width:(K-C.position.width)/2;return{...C,position:{...C.position,x:I}}})}))})},[o,x,K,A]),De=N.useCallback(c=>{const m=o.sections.find(I=>I.id===n);if(!m)return;const C=m.heightMm??200;A({sections:o.sections.map(I=>I.id!==n?I:{...I,fields:I.fields.map(M=>{if(!x.has(M.id))return M;const F=c==="top"?0:c==="bottom"?C-M.position.height:(C-M.position.height)/2;return{...M,position:{...M.position,y:F}}})})})},[o,x,n,A]),$e=N.useCallback(()=>{A({sections:o.sections.map(c=>({...c,fields:c.fields.map(m=>x.has(m.id)?{...m,position:{...m.position,zIndex:(m.position.zIndex??1)+1}}:m)}))})},[o,x,A]),Re=N.useCallback(()=>{A({sections:o.sections.map(c=>({...c,fields:c.fields.map(m=>x.has(m.id)?{...m,position:{...m.position,zIndex:Math.max(1,(m.position.zIndex??1)-1)}}:m)}))})},[o,x,A]),Ae=N.useCallback((c,m)=>{A({sections:o.sections.map(C=>({...C,fields:C.fields.map(I=>I.id===c?{...I,position:{...I.position,zIndex:Math.max(1,(I.position.zIndex??1)-m)}}:I)}))})},[o,A]);N.useEffect(()=>{const c=m=>{const C=m.target.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT")return;const I=m.shiftKey?5:.5;m.key==="Delete"||m.key==="Backspace"?x.size&&(m.preventDefault(),_e()):m.ctrlKey&&m.key==="z"?(m.preventDefault(),k({type:"UNDO"})):m.ctrlKey&&(m.key==="y"||m.key==="Y")?(m.preventDefault(),k({type:"REDO"})):m.ctrlKey&&(m.key==="d"||m.key==="D")?(m.preventDefault(),x.size&&ge()):m.ctrlKey&&m.key==="a"?(m.preventDefault(),i(new Set(J.map(M=>M.id)))):m.key==="ArrowLeft"?(m.preventDefault(),re({position:{...P.position,x:((P==null?void 0:P.position.x)??0)-I}})):m.key==="ArrowRight"?(m.preventDefault(),re({position:{...P.position,x:((P==null?void 0:P.position.x)??0)+I}})):m.key==="ArrowUp"?(m.preventDefault(),re({position:{...P.position,y:((P==null?void 0:P.position.y)??0)-I}})):m.key==="ArrowDown"&&(m.preventDefault(),re({position:{...P.position,y:((P==null?void 0:P.position.y)??0)+I}}))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[x,J,P,_e,ge,re]);const Me=N.useCallback((c,m)=>{A({sections:o.sections.map(C=>C.id===c?{...C,heightMm:Math.round(m*2)/2}:C)})},[o,A]),Ee=N.useMemo(()=>{const c=Array.isArray(d)?d[f]:d;return c?"data"in c?c.data:c:{}},[d,f]),Pe=K*l*G,Fe=ue*l*G;return e.jsx(_.NiceAppShell,{flush:!0,className:`${t.root} ${g==="dark"?t.dark:""} ${b??""}`,style:u,toolbar:e.jsx(Tn,{tpl:o,zoom:l,canUndo:h.length>0,canRedo:y.length>0,showGrid:X,showRulers:Y,readOnly:j,selectedCount:x.size,onPaperChange:(c,m)=>A({paperSize:c,orientation:m}),onZoom:E,onUndo:()=>k({type:"UNDO"}),onRedo:()=>k({type:"REDO"}),onToggleGrid:()=>v(c=>!c),onToggleRulers:()=>pe(c=>!c),onInsert:ye,onDelete:_e,onDuplicate:ge,onAlignH:ze,onAlignV:De,onBringForward:$e,onSendBackward:Re,onSave:S?()=>S(o):void 0}),sidebar:e.jsx(zn,{activeTab:B,onTabChange:T,schema:a,tpl:o,allFields:J,selectedIds:x,onInsertSchemaField:c=>ye(c.type,c),onSelectField:c=>i(new Set([c])),onUpdateTpl:c=>A(c),onReorderField:Ae}),rightSidebar:e.jsx(Dn,{field:P,activeTab:R,onTabChange:O,onChange:c=>P&&he(P.id,c),paperWidthMm:K,paperHeightMm:ue}),children:e.jsxs("div",{className:t.canvasArea,onClick:()=>i(new Set),children:[Array.isArray(d)&&d.length>0&&e.jsxs("div",{className:t.testDataBar,children:[e.jsxs("span",{className:t.testDataLabel,children:[L("printing.editor.testData","Sample data"),":"]}),e.jsx("select",{className:t.testDataSelect,value:f,onChange:c=>D(+c.target.value),children:d.map((c,m)=>e.jsxs("option",{value:m,children:[L("printing.editor.record","Record")," ",m+1]},m))})]}),Y&&e.jsxs("div",{className:t.rulerWrapper,children:[e.jsx("div",{className:t.rulerCorner}),e.jsx(ke,{lengthMm:K,zoom:l,orientation:"h"}),e.jsx(ke,{lengthMm:ue,zoom:l,orientation:"v"})]}),e.jsx("div",{className:t.paperScroll,onClick:c=>c.stopPropagation(),children:e.jsxs("div",{className:t.paperShadow,style:{width:Pe,minHeight:Fe},children:[e.jsx("div",{className:t.marginGuide,style:{top:o.margins.top*l*G,right:o.margins.right*l*G,bottom:o.margins.bottom*l*G,left:o.margins.left*l*G}}),(o.watermarks??[]).map(c=>e.jsx("div",{className:t.watermark,style:{fontSize:(c.fontSize??60)*l,color:c.color??me,opacity:c.opacity,transform:`translate(-50%, -50%) rotate(${c.angle}deg)`},children:c.type==="text"?c.text:e.jsx(_.NiceIcon,{name:"image",size:(c.fontSize??60)*l})},c.id)),o.sections.map(c=>e.jsx("div",{children:e.jsx(Cn,{section:c,zoom:l,paperWidthMm:K,selectedIds:x,sampleData:Ee,readOnly:j,showGrid:X,onFieldClick:Be,onFieldDragStart:Le,onResizeStart:Te,onSectionHeightChange:Me,onDropField:Ce})},c.id))]})})]})})},An="_root_7m4s0_1",Mn="_dark_7m4s0_25",En="_topBar_7m4s0_39",Pn="_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",Yn="_cardSelected_7m4s0_285",Un="_thumbnail_7m4s0_307",Vn="_thumbnailImg_7m4s0_321",Xn="_thumbnailPlaceholder_7m4s0_333",Kn="_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",ra="_cardCat_7m4s0_569",oa="_cardTags_7m4s0_585",la="_cardTag_7m4s0_585",ca="_emptyState_7m4s0_617",da="_emptyIcon_7m4s0_639",z={root:An,dark:Mn,topBar:En,searchInput:Pn,actionBtn:Fn,categoryRow:Hn,catChip:Gn,catChipActive:On,grid:qn,card:Wn,cardSelected:Yn,thumbnail:Un,thumbnailImg:Vn,thumbnailPlaceholder:Xn,paperMini:Kn,paperLine:Jn,cardOverlay:Qn,overlayBtn:Zn,overlayBtnDanger:ea,cardBody:ta,cardName:sa,cardDesc:na,cardMeta:aa,cardSize:ia,cardCat:ra,cardTags:oa,cardTag:la,emptyState:ca,emptyIcon:da},ma=[],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((a,d)=>{const r=new FileReader;r.onload=S=>{var j;try{a(JSON.parse((j=S.target)==null?void 0:j.result))}catch(b){d(b)}},r.readAsText(s)})}function ha(s){const a=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),d=URL.createObjectURL(a),r=document.createElement("a");r.href=d,r.download=`${s.name.replace(/\s+/g,"_")}.json`,r.click(),URL.revokeObjectURL(d)}const _a=({templates:s=ma,selectedId:a,onSelect:d,onImport:r,onExport:S,onDelete:j,onNew:b,className:u,style:g,theme:h="light"})=>{const{t:o}=_.useNiceTranslation(),[y,k]=N.useState(""),[L,x]=N.useState(null),[i,n]=N.useState(null),p=N.useRef(null),l=async f=>{var B;const D=(B=f.target.files)==null?void 0:B[0];if(D){try{const T=await ua(D);r==null||r(T)}catch{}f.target.value=""}},E=s.filter(f=>{const D=!y||f.name.toLowerCase().includes(y.toLowerCase())||(f.description??"").toLowerCase().includes(y.toLowerCase())||(f.tags??[]).some(T=>T.toLowerCase().includes(y.toLowerCase())),B=!L||f.category===L;return D&&B});return e.jsxs("div",{className:`${z.root} ${h==="dark"?z.dark:""} ${u??""}`,style:g,children:[e.jsxs("div",{className:z.topBar,children:[e.jsx("input",{type:"search",className:z.searchInput,placeholder:o("printing.searchTemplates","Search templates…"),value:y,onChange:f=>k(f.target.value)}),e.jsxs("button",{className:z.actionBtn,onClick:b,title:o("printing.newTemplate","New template"),children:[e.jsx(_.NiceIcon,{name:"plus",size:14})," ",o("printing.new","New")]}),e.jsxs("button",{className:z.actionBtn,onClick:()=>{var f;return(f=p.current)==null?void 0:f.click()},title:o("printing.importJson","Import JSON"),children:[e.jsx(_.NiceIcon,{name:"upload",size:14})," ",o("printing.import","Import")]}),e.jsx("input",{ref:p,type:"file",accept:".json",hidden:!0,onChange:l})]}),e.jsxs("div",{className:z.categoryRow,children:[e.jsx("button",{className:`${z.catChip} ${L?"":z.catChipActive}`,onClick:()=>x(null),children:o("printing.filter.all","All")}),pa.map(f=>e.jsx("button",{className:`${z.catChip} ${L===f.fallback?z.catChipActive:""}`,onClick:()=>x(D=>D===f.fallback?null:f.fallback),children:o(f.key,f.fallback)},f.key))]}),e.jsxs("div",{className:z.grid,children:[E.map(f=>e.jsxs("div",{className:`${z.card} ${a===f.id?z.cardSelected:""}`,onClick:()=>d==null?void 0:d(f),onMouseEnter:()=>n(f.id),onMouseLeave:()=>n(null),children:[e.jsxs("div",{className:z.thumbnail,children:[f.previewImageUrl?e.jsx("img",{src:f.previewImageUrl,alt:f.name,className:z.thumbnailImg}):e.jsx("div",{className:z.thumbnailPlaceholder,children:e.jsxs("div",{className:z.paperMini,children:[e.jsx("div",{className:z.paperLine,style:{width:"80%"}}),e.jsx("div",{className:z.paperLine,style:{width:"60%"}}),e.jsx("div",{className:z.paperLine,style:{width:"90%"}}),e.jsx("div",{className:z.paperLine,style:{width:"50%"}})]})}),i===f.id&&e.jsxs("div",{className:z.cardOverlay,children:[e.jsx("button",{className:z.overlayBtn,onClick:D=>{D.stopPropagation(),S==null||S(f),ha(f)},title:o("printing.export","Export"),children:e.jsx(_.NiceIcon,{name:"download",size:14})}),j&&e.jsx("button",{className:z.overlayBtnDanger,onClick:D=>{D.stopPropagation(),j(f.id)},title:o("printing.action.remove","Remove"),children:e.jsx(_.NiceIcon,{name:"trash",size:14})})]})]}),e.jsxs("div",{className:z.cardBody,children:[e.jsx("div",{className:z.cardName,children:f.name}),f.description&&e.jsx("div",{className:z.cardDesc,children:f.description}),e.jsxs("div",{className:z.cardMeta,children:[e.jsxs("span",{className:z.cardSize,children:[f.paperSize," ",f.orientation==="landscape"?o("printing.orientation.landscape","landscape"):o("printing.orientation.portrait","portrait")]}),f.category&&e.jsx("span",{className:z.cardCat,children:f.category})]}),f.tags&&f.tags.length>0&&e.jsx("div",{className:z.cardTags,children:f.tags.slice(0,3).map(D=>e.jsx("span",{className:z.cardTag,children:D},D))})]})]},f.id)),E.length===0&&e.jsxs("div",{className:z.emptyState,children:[e.jsx("span",{className:z.emptyIcon,children:e.jsx(_.NiceIcon,{name:"file",size:32})}),e.jsx("span",{children:y?`${o("printing.noMatches","No matches for")} "${y}"`:o("printing.noTemplates","No templates yet.")})]})]})]})},ga="_root_18ja1_1",ba="_dark_18ja1_19",xa="_headerBar_18ja1_31",ya="_entityNav_18ja1_59",fa="_navBtn_18ja1_69",ja="_navLabel_18ja1_103",va="_sampleBadge_18ja1_117",Na="_zoomBar_18ja1_135",wa="_zoomBtn_18ja1_147",ka="_zoomLabel_18ja1_179",Sa="_printBtn_18ja1_193",Ia="_canvas_18ja1_223",Ca="_page_18ja1_243",Ba="_watermark_18ja1_269",La="_footerBar_18ja1_299",H={root:ga,dark:ba,headerBar:xa,entityNav:ya,navBtn:fa,navLabel:ja,sampleBadge:va,zoomBar:Na,zoomBtn:wa,zoomLabel:ka,printBtn:Sa,canvas:Ia,page:Ca,watermark:Ba,footerBar:La},V=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 Ta(s,a){try{return s.split(".").reduce((d,r)=>d&&typeof d=="object"?d[r]:null,a)}catch{return null}}function za(s,a,d){if(s==null)return"";if(a==="date"&&d)try{const r=new Date(s);if(d==="DD.MM.YYYY"){const S=String(r.getDate()).padStart(2,"0"),j=String(r.getMonth()+1).padStart(2,"0");return`${S}.${j}.${r.getFullYear()}`}return r.toLocaleDateString()}catch{return String(s)}if(a==="currency"&&d){const r=Number(s);if(!isNaN(r))return`${r.toFixed(2)} ${d}`}return a==="number"&&typeof s=="number"?s.toLocaleString("pl-PL"):String(s)}const Da=({field:s,data:a,zoom:d})=>{const r=s.dataPath?Ta(s.dataPath,a):null,S=r!=null?za(r,s.type,s.format):s.fallback??"",j=u=>u*d*V,b={position:"absolute",left:j(s.position.x),top:j(s.position.y),width:j(s.position.width),height:j(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?j(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:b,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:{...b,background:"var(--nice-bg-secondary, #f8fafc)",border:"1px dashed var(--nice-border-color, #e2e8f0)",alignItems:"center",justifyContent:"center",fontSize:10*d},children:[e.jsx(_.NiceIcon,{name:s.type==="qr"?"qr-code":"barcode",size:12*d})," ",S]}):s.type==="signature"?e.jsx("div",{style:{...b,borderBottom:"1px solid var(--nice-border-color, #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:{...b,borderBottom:`${s.style.borderWidth??1}px ${s.style.borderStyle??"solid"} ${s.style.borderColor??"var(--nice-text-primary, #0f172a)"}`}}):e.jsx("div",{style:b,children:S})},$a=({template:s,data:a,zoom:d})=>{var u;const[r,S]=(()=>{const[g,h]=Se[s.paperSize]??Se.A4;return s.orientation==="landscape"?[h*V*d,g*V*d]:[g*V*d,h*V*d]})(),j=s.margins,b=s.sections.flatMap(g=>g.fields);return e.jsxs("div",{className:H.page,style:{width:r,minHeight:S},children:[e.jsx("div",{style:{position:"absolute",top:j.top*d*V,left:j.left*d*V,right:j.right*d*V,bottom:j.bottom*d*V},children:b.map(g=>e.jsx(Da,{field:g,data:a,zoom:d},g.id))}),(u=s.watermarks)==null?void 0:u.map(g=>e.jsx("div",{className:H.watermark,style:{opacity:g.opacity,transform:`rotate(${g.angle}deg)`,fontSize:(g.fontSize??48)*d},children:g.type==="text"?g.text:e.jsx("img",{src:g.imageUrl,alt:"wm",style:{maxWidth:200*d}})},g.id))]})},Ra=({template:s,entities:a=[],sampleData:d,onPrint:r,className:S,style:j,theme:b="light",asPopup:u=!0,open:g,onClose:h})=>{const{t:o}=_.useNiceTranslation(),[y,k]=N.useState(0),[L,x]=N.useState(.8),[i,n]=N.useState(!0),p=g!==void 0,l=p?g:i,E=()=>{p||n(!1),h==null||h()};N.useEffect(()=>{if(!u||!l)return;const R=O=>{O.key==="Escape"&&E()};return document.addEventListener("keydown",R),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=""}},[u,l]);const f=N.useMemo(()=>a.length>0?a:d?[d.data]:[{}],[a,d]),D=f[y]??{};if(u&&!l)return null;const B=e.jsxs("div",{className:`${H.root} ${b==="dark"?H.dark:""} ${S??""}`,style:j,children:[e.jsxs("div",{className:H.headerBar,children:[e.jsxs("div",{className:H.entityNav,children:[f.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:H.navBtn,disabled:y===0,onClick:()=>k(R=>R-1),children:"‹"}),e.jsxs("span",{className:H.navLabel,children:[y+1," / ",f.length]}),e.jsx("button",{className:H.navBtn,disabled:y>=f.length-1,onClick:()=>k(R=>R+1),children:"›"})]}),a.length===0&&d&&e.jsx("span",{className:H.sampleBadge,children:o("printing.sampleData","Sample data")})]}),e.jsxs("div",{className:H.zoomBar,children:[e.jsx("button",{className:H.zoomBtn,onClick:()=>x(R=>Math.max(.3,R-.1)),children:"−"}),e.jsxs("span",{className:H.zoomLabel,children:[Math.round(L*100),"%"]}),e.jsx("button",{className:H.zoomBtn,onClick:()=>x(R=>Math.min(2.5,R+.1)),children:"+"}),e.jsx("button",{className:H.zoomBtn,onClick:()=>x(.8),title:o("printing.fit","Fit"),children:"⊡"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:H.printBtn,onClick:()=>r==null?void 0:r({copies:1,printerId:""}),children:o("printPreview.print","Print")}),u&&e.jsx("button",{type:"button",className:H.zoomBtn,onClick:E,"aria-label":o("close","Close"),title:o("close","Close"),children:e.jsx(_.NiceIcon,{name:"close",size:16})})]})]}),e.jsx("div",{className:H.canvas,children:e.jsx($a,{template:s,data:D,zoom:L})}),e.jsxs("div",{className:H.footerBar,children:[e.jsx("span",{children:s.name}),e.jsxs("span",{children:[s.paperSize," · ",s.orientation==="portrait"?"Pion":"Poziom"]}),s.sections.reduce((R,O)=>R+O.fields.length,0)," ",o("printing.fields","fields")]})]});if(!u)return B;const T=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&&E()},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:B})});return Ge.createPortal(T,document.body)},Aa="_root_1f4bm_1",Ma="_dark_1f4bm_23",Ea="_statsBar_1f4bm_37",Pa="_stat_1f4bm_37",Fa="_dot_1f4bm_75",Ha="_statPrinting_1f4bm_87",Ga="_statQueued_1f4bm_93",Oa="_statDone_1f4bm_99",qa="_statError_1f4bm_105",Wa="_toolbar_1f4bm_115",Ya="_filterTabs_1f4bm_139",Ua="_filterTab_1f4bm_139",Va="_filterTabActive_1f4bm_177",Xa="_filterCount_1f4bm_187",Ka="_bulkActions_1f4bm_211",Ja="_bulkCount_1f4bm_223",Qa="_bulkBtn_1f4bm_231",Za="_bulkBtnRemove_1f4bm_255",ei="_jobList_1f4bm_273",ti="_listHeader_1f4bm_281",si="_headerLabel_1f4bm_313",ni="_jobRow_1f4bm_323",ai="_jobRowSelected_1f4bm_359",ii="_jobCheckbox_1f4bm_373",ri="_statusBadge_1f4bm_387",oi="_pulse_1f4bm_1",li="_jobInfo_1f4bm_479",ci="_jobName_1f4bm_485",di="_jobMeta_1f4bm_497",mi="_jobTime_1f4bm_513",pi="_jobDuration_1f4bm_519",ui="_jobError_1f4bm_525",hi="_progressBar_1f4bm_539",_i="_progressFill_1f4bm_553",gi="_copiesEditor_1f4bm_569",bi="_copiesBtn_1f4bm_581",xi="_copiesValue_1f4bm_621",yi="_jobActions_1f4bm_635",fi="_actionBtn_1f4bm_645",ji="_removeBtn_1f4bm_677",vi="_emptyState_1f4bm_695",w={root:Aa,dark:Ma,statsBar:Ea,stat:Pa,dot:Fa,statPrinting:Ha,statQueued:Ga,statDone:Oa,statError:qa,toolbar:Wa,filterTabs:Ya,filterTab:Ua,filterTabActive:Va,filterCount:Xa,bulkActions:Ka,bulkCount:Ja,bulkBtn:Qa,bulkBtnRemove:Za,jobList:ei,listHeader:ti,headerLabel:si,jobRow:ni,jobRowSelected:ai,jobCheckbox:ii,statusBadge:ri,"badge-queued":"_badge-queued_1f4bm_405","badge-printing":"_badge-printing_1f4bm_413",pulse:oi,"badge-done":"_badge-done_1f4bm_423","badge-error":"_badge-error_1f4bm_431","badge-paused":"_badge-paused_1f4bm_439","badge-cancelled":"_badge-cancelled_1f4bm_447",jobInfo:li,jobName:ci,jobMeta:di,jobTime:mi,jobDuration:pi,jobError:ui,progressBar:hi,progressFill:_i,copiesEditor:gi,copiesBtn:bi,copiesValue:xi,jobActions:yi,actionBtn:fi,removeBtn:ji,emptyState:vi},Ni=[],Ie={queued:"Queued",printing:"Printing",done:"Printed",error:"Error",paused:"Paused",cancelled:"Cancelled"},xe=(s,a)=>Ie[a]?s(`printing.status.${a}`,Ie[a]):a;function wi(s,a){try{return new Date(a).toLocaleTimeString(s,{hour:"2-digit",minute:"2-digit"})}catch{return a}}function ki(s){const a=Math.floor((Date.now()-new Date(s).getTime())/1e3);if(a<60)return`${a}s`;const d=Math.floor(a/60);if(d<60)return`${d}m ${a%60}s`;const r=Math.floor(d/60);return r<24?`${r}h ${d%60}m`:`${Math.floor(r/24)}d ${r%24}h`}const Si=({jobs:s})=>{const{t:a}=_.useNiceTranslation(),d=s.filter(b=>b.status==="printing").length,r=s.filter(b=>b.status==="queued").length,S=s.filter(b=>b.status==="done").length,j=s.filter(b=>b.status==="error").length;return e.jsxs("div",{className:w.statsBar,children:[e.jsxs("span",{className:`${w.stat} ${w.statPrinting}`,children:[e.jsx("span",{className:w.dot}),a("printing.stats.active","Printing"),": ",e.jsx("strong",{children:d})]}),e.jsxs("span",{className:`${w.stat} ${w.statQueued}`,children:[e.jsx("span",{className:w.dot}),a("printing.stats.queued","In queue"),": ",e.jsx("strong",{children:r})]}),e.jsxs("span",{className:`${w.stat} ${w.statDone}`,children:[e.jsx("span",{className:w.dot}),a("printing.stats.done","Done"),": ",e.jsx("strong",{children:S})]}),j>0&&e.jsxs("span",{className:`${w.stat} ${w.statError}`,children:[e.jsx("span",{className:w.dot}),a("printing.stats.errors","Errors"),": ",e.jsx("strong",{children:j})]})]})},Ii=({job:s,index:a,total:d,printers:r,selected:S,onSelect:j,onUpdate:b,onRemove:u,onPrint:g,onReorder:h})=>{const{t:o,lang:y}=_.useNiceTranslation(),k=r.find(i=>i.id===s.options.printerId),L=a>0&&s.status==="queued",x=a<d-1&&s.status==="queued";return e.jsxs("div",{className:`${w.jobRow} ${S?w.jobRowSelected:""} ${w[`status-${s.status}`]??""}`,children:[e.jsx("input",{type:"checkbox",className:w.jobCheckbox,checked:S,onChange:()=>j(s.id)}),e.jsx("span",{className:`${w.statusBadge} ${w[`badge-${s.status}`]}`,children:xe(o,s.status)}),e.jsxs("div",{className:w.jobInfo,children:[e.jsx("div",{className:w.jobName,children:s.templateName??s.templateId}),e.jsxs("div",{className:w.jobMeta,children:[s.entityLabel&&e.jsx("span",{children:s.entityLabel}),k&&e.jsxs("span",{children:[e.jsx(_.NiceIcon,{name:"printer",size:12})," ",k.name]}),e.jsxs("span",{children:["×",s.options.copies]}),s.createdAt&&e.jsx("span",{className:w.jobTime,children:wi(y,s.createdAt)}),s.startedAt&&s.status!=="done"&&e.jsx("span",{className:w.jobDuration,children:ki(s.startedAt)})]}),s.status==="printing"&&s.progress!=null&&e.jsx("div",{className:w.progressBar,children:e.jsx("div",{className:w.progressFill,style:{width:`${s.progress}%`}})}),s.status==="error"&&s.errorMessage&&e.jsx("div",{className:w.jobError,children:s.errorMessage})]}),e.jsxs("div",{className:w.copiesEditor,children:[e.jsx("button",{className:w.copiesBtn,disabled:s.options.copies<=1,"aria-label":o("printing.copies.decrease","One copy fewer"),onClick:()=>b(s.id,{options:{...s.options,copies:s.options.copies-1}}),children:e.jsx(_.NiceIcon,{name:"minus",size:12})}),e.jsx("span",{className:w.copiesValue,children:s.options.copies}),e.jsx("button",{className:w.copiesBtn,"aria-label":o("printing.copies.increase","One copy more"),onClick:()=>b(s.id,{options:{...s.options,copies:s.options.copies+1}}),children:e.jsx(_.NiceIcon,{name:"plus",size:12})})]}),e.jsxs("div",{className:w.jobActions,children:[L&&e.jsx("button",{className:w.actionBtn,title:o("printing.action.moveUp","Move up"),onClick:()=>h(a,a-1),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:14})}),x&&e.jsx("button",{className:w.actionBtn,title:o("printing.action.moveDown","Move down"),onClick:()=>h(a,a+1),children:e.jsx(_.NiceIcon,{name:"arrow-down",size:14})}),s.status==="queued"&&e.jsx("button",{className:w.actionBtn,title:o("printing.action.printNow","Print now"),onClick:()=>g(s.id),children:e.jsx(_.NiceIcon,{name:"play",size:14})}),s.status==="printing"&&e.jsx("button",{className:w.actionBtn,title:o("printing.action.pause","Pause"),onClick:()=>b(s.id,{status:"paused"}),children:e.jsx(_.NiceIcon,{name:"pause",size:14})}),s.status==="paused"&&e.jsx("button",{className:w.actionBtn,title:o("printing.action.resume","Resume"),onClick:()=>b(s.id,{status:"queued"}),children:e.jsx(_.NiceIcon,{name:"play",size:14})}),e.jsx("button",{className:`${w.actionBtn} ${w.removeBtn}`,title:o("printing.action.remove","Remove"),onClick:()=>u(s.id),children:e.jsx(_.NiceIcon,{name:"close",size:14})})]})]})},Ci=({jobs:s=Ni,printers:a=[],onJobUpdate:d,onJobRemove:r,onJobReorder:S,onJobPrint:j,onBulkRemove:b,onBulkPrint:u,maxHeight:g=500,className:h,style:o,theme:y="light"})=>{const{t:k}=_.useNiceTranslation(),[L,x]=N.useState(new Set),[i,n]=N.useState("all"),p=i==="all"?s:s.filter(B=>B.status===i),l=N.useCallback(B=>{x(T=>{const R=new Set(T);return R.has(B)?R.delete(B):R.add(B),R})},[]),E=N.useCallback(()=>{L.size===p.length?x(new Set):x(new Set(p.map(B=>B.id)))},[p,L.size]),f=N.useCallback(()=>{b==null||b(Array.from(L)),x(new Set)},[L,b]),D=N.useCallback(()=>{u==null||u(Array.from(L)),x(new Set)},[L,u]);return e.jsxs("div",{className:`${w.root} ${y==="dark"?w.dark:""} ${h??""}`,style:o,children:[e.jsx(Si,{jobs:s}),e.jsxs("div",{className:w.toolbar,children:[e.jsx("div",{className:w.filterTabs,children:["all","queued","printing","done","error"].map(B=>e.jsxs("button",{className:`${w.filterTab} ${i===B?w.filterTabActive:""}`,onClick:()=>n(B),children:[B==="all"?k("printing.filter.all","All"):xe(k,B),e.jsx("span",{className:w.filterCount,children:B==="all"?s.length:s.filter(T=>T.status===B).length})]},B))}),L.size>0&&e.jsxs("div",{className:w.bulkActions,children:[e.jsxs("span",{className:w.bulkCount,children:[L.size," ",k("printing.bulk.selected","selected")]}),u&&e.jsxs("button",{className:w.bulkBtn,onClick:D,children:[e.jsx(_.NiceIcon,{name:"printer",size:14})," ",k("printing.bulk.print","Print selected")]}),b&&e.jsxs("button",{className:`${w.bulkBtn} ${w.bulkBtnRemove}`,onClick:f,children:[e.jsx(_.NiceIcon,{name:"trash",size:14})," ",k("printing.bulk.remove","Remove selected")]})]})]}),e.jsx("div",{className:w.jobList,style:{maxHeight:g},children:p.length===0?e.jsx("div",{className:w.emptyState,children:i==="all"?k("printing.empty.queue","No jobs in the queue"):`${k("printing.empty.filtered","No jobs with status")} "${xe(k,i)}"`}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:w.listHeader,children:[e.jsx("input",{type:"checkbox",onChange:E,checked:L.size===p.length&&p.length>0}),e.jsx("span",{className:w.headerLabel,children:k("printing.col.job","Job")}),e.jsx("span",{className:w.headerLabel,children:k("printing.col.copies","Copies")}),e.jsx("span",{className:w.headerLabel,children:k("printing.col.actions","Actions")})]}),p.map((B,T)=>e.jsx(Ii,{job:B,index:s.indexOf(B),total:s.length,printers:a,selected:L.has(B.id),onSelect:l,onUpdate:d,onRemove:r,onPrint:j,onReorder:S},B.id))]})})]})},Bi="_container_1f76z_1",Li="_buttonGroup_1f76z_19",Ti="_trigger_1f76z_31",zi="_triggerDisabled_1f76z_57",Di="_mainAction_1f76z_151",$i="_dropdownToggle_1f76z_175",Ri="_chevron_1f76z_201",Ai="_chevronUp_1f76z_211",Mi="_dropdown_1f76z_175",Ei="_dark_1f76z_245",Pi="_section_1f76z_257",Fi="_sectionLabel_1f76z_263",Hi="_divider_1f76z_283",Gi="_copiesRow_1f76z_301",Oi="_copiesBtn_1f76z_311",qi="_copiesValue_1f76z_351",Wi="_printerSelect_1f76z_375",Yi="_printerStatus_1f76z_415",Ui="_printerDot_1f76z_429",Vi="_printerStatusLabel_1f76z_463",Xi="_submitBtn_1f76z_473",Ki="_spinner_1f76z_515",Ji="_spin_1f76z_515",$={container:Bi,buttonGroup:Li,trigger:Ti,triggerDisabled:zi,"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:Di,dropdownToggle:$i,chevron:Ri,chevronUp:Ai,dropdown:Mi,dark:Ei,section:Pi,sectionLabel:Fi,divider:Hi,copiesRow:Gi,copiesBtn:Oi,copiesValue:qi,printerSelect:Wi,printerStatus:Yi,printerDot:Ui,"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:Vi,submitBtn:Xi,spinner:Ki,spin:Ji},Qi=({onPrint:s,printers:a=[],defaultPrinterId:d,defaultCopies:r=1,disabled:S=!1,loading:j=!1,variant:b="primary",size:u="md",label:g,className:h,style:o,theme:y="light"})=>{var X;const{t:k}=_.useNiceTranslation(),L=g??k("printing.print","Print"),[x,i]=N.useState(!1),[n,p]=N.useState(r),[l,E]=N.useState(d??((X=a[0])==null?void 0:X.id)??""),f=N.useRef(null);N.useEffect(()=>{if(!x)return;const v=Y=>{f.current&&!f.current.contains(Y.target)&&i(!1)};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[x]);const D=N.useCallback(()=>{s({copies:n,printerId:l}),i(!1)},[n,l,s]),B=N.useCallback(()=>p(v=>Math.min(99,v+1)),[]),T=N.useCallback(()=>p(v=>Math.max(1,v-1)),[]),R=[$.container,y==="dark"?$.dark:"",h??""].filter(Boolean).join(" "),O=[$.trigger,$[`variant-${b}`],$[`size-${u}`],S||j?$.triggerDisabled:""].filter(Boolean).join(" ");return e.jsxs("div",{ref:f,className:R,style:o,children:[e.jsxs("div",{className:$.buttonGroup,children:[e.jsxs("button",{className:`${O} ${$.mainAction}`,disabled:S||j,onClick:D,"aria-label":L,children:[j?e.jsx("span",{className:$.spinner}):e.jsx(_.NiceIcon,{name:"printer",size:16}),e.jsx("span",{children:L})]}),e.jsx("button",{className:`${O} ${$.dropdownToggle}`,disabled:S||j,onClick:()=>i(v=>!v),"aria-label":k("printing.options","Print options"),"aria-expanded":x,children:e.jsx("span",{className:`${$.chevron} ${x?$.chevronUp:""}`,children:e.jsx(_.NiceIcon,{name:"chevron-down",size:12})})})]}),x&&e.jsxs("div",{className:$.dropdown,children:[e.jsxs("div",{className:$.section,children:[e.jsx("label",{className:$.sectionLabel,children:k("printing.copies.label","Copies")}),e.jsxs("div",{className:$.copiesRow,children:[e.jsx("button",{className:$.copiesBtn,onClick:T,disabled:n<=1,"aria-label":k("printing.copies.decrease","One copy fewer"),children:e.jsx(_.NiceIcon,{name:"minus",size:12})}),e.jsx("span",{className:$.copiesValue,children:n}),e.jsx("button",{className:$.copiesBtn,onClick:B,disabled:n>=99,"aria-label":k("printing.copies.increase","One copy more"),children:e.jsx(_.NiceIcon,{name:"plus",size:12})})]})]}),e.jsx("div",{className:$.divider}),a.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:$.section,children:[e.jsx("label",{className:$.sectionLabel,children:k("printing.printer","Printer")}),e.jsx("select",{className:$.printerSelect,value:l,onChange:v=>E(v.target.value),children:a.map(v=>e.jsxs("option",{value:v.id,disabled:v.status==="offline"||!v.isOnline&&v.status==null,children:[v.name," ",v.status==="offline"||!v.isOnline&&v.status==null?"(Offline)":v.status==="busy"?`(${k("printing.printerBusyLabel","Busy")})`:""]},v.id))}),a.find(v=>v.id===l)&&e.jsx("div",{className:$.printerStatus,children:(()=>{const v=a.find(pe=>pe.id===l),Y=v.status??(v.isOnline?"ready":"offline");return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`${$.printerDot} ${$[`dot-${Y}`]}`}),e.jsx("span",{className:$.printerStatusLabel,children:Y==="ready"?k("printing.printerReady","Ready"):Y==="busy"?k("printing.printerBusyLabel","Busy"):Y==="offline"?"Offline":k("printing.printerError","Error")})]})})()})]}),e.jsx("div",{className:$.divider})]}),e.jsx("div",{className:$.section,children:e.jsx("button",{className:$.submitBtn,onClick:D,disabled:S||j||a.length>0&&(()=>{const v=a.find(Y=>Y.id===l);return v!=null&&(v.status==="offline"||!v.isOnline&&v.status==null)})(),children:j?k("printing.printing","Printing…"):e.jsxs(e.Fragment,{children:[e.jsx(_.NiceIcon,{name:"printer",size:14})," ",L,n>1?` (${n})`:""]})})})]})]})};exports.NicePrintButton=Qi;exports.NicePrintPreview=Ra;exports.NicePrintQueue=Ci;exports.NiceTemplateBrowser=_a;exports.NiceTemplateEditor=Rn;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),_=require("@nice2dev/ui"),j=require("react"),Oe=require("react-dom"),qe="_root_19f1m_3",We="_dark_19f1m_27",Ye="_toolbar_19f1m_39",Ue="_toolbarGroup_19f1m_75",Ve="_toolbarBtn_19f1m_107",Xe="_toolbarBtnActive_19f1m_171",Ke="_toolbarBtnDanger_19f1m_195",Je="_toolbarSelect_19f1m_207",Qe="_toolbarSep_19f1m_237",Ze="_insertWrapper_19f1m_263",et="_insertBtn_19f1m_271",tt="_insertDropdown_19f1m_293",st="_insertCategory_19f1m_333",nt="_insertItem_19f1m_351",at="_insertIcon_19f1m_395",it="_zoomSelect_19f1m_409",rt="_saveBtn_19f1m_441",ot="_editorBody_19f1m_477",lt="_leftPanel_19f1m_493",ct="_leftTabs_19f1m_523",dt="_leftTab_19f1m_523",mt="_leftTabActive_19f1m_601",pt="_leftTabIcon_19f1m_621",ut="_leftTabLabel_19f1m_629",ht="_leftContent_19f1m_639",_t="_panelHeader_19f1m_653",gt="_panelHeaderIcon_19f1m_677",bt="_panelHeaderName_19f1m_685",xt="_searchBox_19f1m_699",yt="_searchInput_19f1m_707",ft="_fieldList_19f1m_753",jt="_fieldItem_19f1m_763",vt="_fieldItemIcon_19f1m_807",Nt="_fieldItemInfo_19f1m_821",wt="_fieldItemLabel_19f1m_831",kt="_fieldItemPath_19f1m_847",St="_fieldItemType_19f1m_863",It="_layerList_19f1m_883",Ct="_layerItem_19f1m_895",Bt="_layerItemSelected_19f1m_931",Lt="_layerIcon_19f1m_949",Tt="_layerName_19f1m_961",zt="_layerActions_19f1m_977",Dt="_layerBtn_19f1m_999",$t="_wmList_19f1m_1031",Rt="_wmItem_19f1m_1039",Et="_wmRow_19f1m_1065",At="_wmLabel_19f1m_1079",Mt="_wmInput_19f1m_1091",Pt="_wmInputNum_19f1m_1123",Ft="_wmSelect_19f1m_1143",Ht="_wmSlider_19f1m_1175",Gt="_wmValue_19f1m_1185",Ot="_wmUnit_19f1m_1199",qt="_wmDelete_19f1m_1209",Wt="_addBtn_19f1m_1241",Yt="_settingsForm_19f1m_1277",Ut="_settingsRow_19f1m_1285",Vt="_settingsLabel_19f1m_1299",Xt="_settingsInput_19f1m_1311",Kt="_settingsInputNum_19f1m_1343",Jt="_settingsTextarea_19f1m_1375",Qt="_settingsDivider_19f1m_1409",Zt="_settingsUnit_19f1m_1429",es="_emptyMsg_19f1m_1441",ts="_canvasArea_19f1m_1459",ss="_testDataBar_19f1m_1485",ns="_testDataLabel_19f1m_1517",as="_testDataSelect_19f1m_1527",is="_rulerWrapper_19f1m_1547",rs="_rulerCorner_19f1m_1563",os="_ruler_19f1m_1547",ls="_ruler_h_19f1m_1621",cs="_ruler_v_19f1m_1631",ds="_rulerTick_19f1m_1651",ms="_rulerTickMajor_19f1m_1691",ps="_rulerLabel_19f1m_1711",us="_paperScroll_19f1m_1749",hs="_paperShadow_19f1m_1767",_s="_marginGuide_19f1m_1803",gs="_watermark_19f1m_1819",bs="_sectionCanvas_19f1m_1845",xs="_sectionCanvasOver_19f1m_1859",ys="_sectionTypeChip_19f1m_1867",fs="_sectionResizeBar_19f1m_1899",js="_sectionResizeGrip_19f1m_1933",vs="_fieldImagePlaceholder_19f1m_1949",Ns="_fieldBarcodePlaceholder_19f1m_1971",ws="_fieldSignaturePlaceholder_19f1m_1999",ks="_resizeHandle_19f1m_2031",Ss="_handle_n_19f1m_2051",Is="_handle_s_19f1m_2063",Cs="_handle_e_19f1m_2075",Bs="_handle_w_19f1m_2087",Ls="_handle_ne_19f1m_2099",Ts="_handle_nw_19f1m_2109",zs="_handle_se_19f1m_2119",Ds="_handle_sw_19f1m_2129",$s="_rightPanel_19f1m_2143",Rs="_rightTabs_19f1m_2173",Es="_rightTab_19f1m_2173",As="_rightTabActive_19f1m_2243",Ms="_propsBody_19f1m_2255",Ps="_propsEmpty_19f1m_2267",Fs="_propsEmptyIcon_19f1m_2289",Hs="_propsEmptyText_19f1m_2299",Gs="_posGrid_19f1m_2311",Os="_posCell_19f1m_2325",qs="_posLabel_19f1m_2337",Ws="_posInput_19f1m_2349",Ys="_posUnit_19f1m_2391",Us="_snapSection_19f1m_2403",Vs="_snapTitle_19f1m_2411",Xs="_snapRow_19f1m_2429",Ks="_snapBtn_19f1m_2439",Js="_styleGroup_19f1m_2473",Qs="_styleGroupTitle_19f1m_2481",Zs="_styleRow_19f1m_2511",en="_styleLabel_19f1m_2525",tn="_styleSelect_19f1m_2539",sn="_styleSelectFull_19f1m_2569",nn="_styleSelectSm_19f1m_2601",an="_styleSelectXs_19f1m_2621",rn="_styleInput_19f1m_2653",on="_styleInputFull_19f1m_2685",ln="_styleUnit_19f1m_2717",cn="_styleValue_19f1m_2729",dn="_toggleGroup_19f1m_2743",mn="_toggleBtn_19f1m_2753",pn="_toggleBtnActive_19f1m_2787",un="_colorPicker_19f1m_2801",hn="_colorHex_19f1m_2819",_n="_clearBtn_19f1m_2853",gn="_sliderInput_19f1m_2885",bn="_conditionalHint_19f1m_2897",xn="_clearConditionalBtn_19f1m_2929",yn="_shortcutGrid_19f1m_2961",fn="_shortcutChip_19f1m_2975",jn="_shortcutKeys_19f1m_3007",vn="_shortcutLabel_19f1m_3027",t={root:qe,dark:We,toolbar:Ye,toolbarGroup:Ue,toolbarBtn:Ve,toolbarBtnActive:Xe,toolbarBtnDanger:Ke,toolbarSelect:Je,toolbarSep:Qe,insertWrapper:Ze,insertBtn:et,insertDropdown:tt,insertCategory:st,insertItem:nt,insertIcon:at,zoomSelect:it,saveBtn:rt,editorBody:ot,leftPanel:lt,leftTabs:ct,leftTab:dt,leftTabActive:mt,leftTabIcon:pt,leftTabLabel:ut,leftContent:ht,panelHeader:_t,panelHeaderIcon:gt,panelHeaderName:bt,searchBox:xt,searchInput:yt,fieldList:ft,fieldItem:jt,fieldItemIcon:vt,fieldItemInfo:Nt,fieldItemLabel:wt,fieldItemPath:kt,fieldItemType:St,layerList:It,layerItem:Ct,layerItemSelected:Bt,layerIcon:Lt,layerName:Tt,layerActions:zt,layerBtn:Dt,wmList:$t,wmItem:Rt,wmRow:Et,wmLabel:At,wmInput:Mt,wmInputNum:Pt,wmSelect:Ft,wmSlider:Ht,wmValue:Gt,wmUnit:Ot,wmDelete:qt,addBtn:Wt,settingsForm:Yt,settingsRow:Ut,settingsLabel:Vt,settingsInput:Xt,settingsInputNum:Kt,settingsTextarea:Jt,settingsDivider:Qt,settingsUnit:Zt,emptyMsg:es,canvasArea:ts,testDataBar:ss,testDataLabel:ns,testDataSelect:as,rulerWrapper:is,rulerCorner:rs,ruler:os,ruler_h:ls,ruler_v:cs,rulerTick:ds,rulerTickMajor:ms,rulerLabel:ps,paperScroll:us,paperShadow:hs,marginGuide:_s,watermark:gs,sectionCanvas:bs,sectionCanvasOver:xs,sectionTypeChip:ys,sectionResizeBar:fs,sectionResizeGrip:js,fieldImagePlaceholder:vs,fieldBarcodePlaceholder:Ns,fieldSignaturePlaceholder:ws,resizeHandle:ks,handle_n:Ss,handle_s:Is,handle_e:Cs,handle_w:Bs,handle_ne:Ls,handle_nw:Ts,handle_se:zs,handle_sw:Ds,rightPanel:$s,rightTabs:Rs,rightTab:Es,rightTabActive:As,propsBody:Ms,propsEmpty:Ps,propsEmptyIcon:Fs,propsEmptyText:Hs,posGrid:Gs,posCell:Os,posLabel:qs,posInput:Ws,posUnit:Ys,snapSection:Us,snapTitle:Vs,snapRow:Xs,snapBtn:Ks,styleGroup:Js,styleGroupTitle:Qs,styleRow:Zs,styleLabel:en,styleSelect:tn,styleSelectFull:sn,styleSelectSm:nn,styleSelectXs:an,styleInput:rn,styleInputFull:on,styleUnit:ln,styleValue:cn,toggleGroup:dn,toggleBtn:mn,toggleBtnActive:pn,colorPicker:un,colorHex:hn,clearBtn:_n,sliderInput:gn,conditionalHint:bn,clearConditionalBtn:xn,shortcutGrid:yn,shortcutChip:fn,shortcutKeys:jn,shortcutLabel:vn},G=3.78,ve={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"],Ne=[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,r)=>de[r]?s(`printing.fieldType.${r}`,de[r]):r;function wn(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}}const te="#000000",pe="#94a3b8";function ie(){return`f-${Date.now()}-${Math.floor(Math.random()*1e3)}`}function we(s,r){const d={id:ie(),name:(r==null?void 0:r.label)??de[s]??s,label:(r==null?void 0:r.label)??de[s]??s,type:s,dataPath:(r==null?void 0:r.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"&&(d.style.backgroundColor="var(--nice-bg-secondary, #f1f5f9)"),s==="line"&&(d.style={...d.style,borderWidth:.5,borderColor:te,borderStyle:"solid"}),d}const ke=({lengthMm:s,zoom:r,orientation:d})=>{const o=[],k=r<.6?20:r<1?10:5;for(let f=0;f<=s;f+=k){const g=f*r*G,h=f%(k*2)===0;o.push(e.jsx("div",{className:`${t.rulerTick} ${h?t.rulerTickMajor:""}`,style:d==="h"?{left:g}:{top:g},children:h&&e.jsx("span",{className:t.rulerLabel,children:f})},f))}return e.jsx("div",{className:`${t.ruler} ${t[`ruler_${d}`]}`,children:o})},kn=["n","s","e","w","ne","nw","se","sw"],Sn=({onResizeStart:s})=>e.jsx(e.Fragment,{children:kn.map(r=>e.jsx("div",{className:`${t.resizeHandle} ${t[`handle_${r}`]}`,onMouseDown:d=>{d.stopPropagation(),s(r,d)}},r))});function In(s,r){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(r&&s.dataPath){const d=s.dataPath.split(".").reduce((o,k)=>o&&typeof o=="object"?o[k]:null,r);if(d!=null)return String(d)}return s.label?`{${s.label}}`:`{${s.dataPath}}`}const Cn=({field:s,zoom:r,selected:d,sampleData:o,onClick:k,onDragStart:f,onResizeStart:g,readOnly:h})=>{const{t:b}=_.useNiceTranslation(),N=s.position,u=s.style,i=c=>c*r*G,w=s.type==="line",I=s.type==="rect",B=s.type==="image"||s.type==="static_image",a=s.type==="barcode"||s.type==="qr",n={position:"absolute",left:i(N.x),top:i(N.y),width:i(N.width),height:i(N.height),zIndex:N.zIndex??1,transform:u.rotation?`rotate(${u.rotation}deg)`:void 0,boxSizing:"border-box",overflow:"hidden",...!w&&!I?{fontSize:(u.fontSize??10)*r,fontFamily:u.fontFamily??"sans-serif",fontWeight:u.fontWeight??"normal",fontStyle:u.fontStyle??"normal",color:u.color??te,textAlign:u.textAlign??"left",lineHeight:u.lineHeight??1.4,letterSpacing:u.letterSpacing?`${u.letterSpacing}em`:void 0,padding:u.padding?i(u.padding):0}:{},backgroundColor:u.backgroundColor,borderWidth:u.borderWidth??0,borderColor:u.borderColor??"transparent",borderStyle:u.borderStyle??"solid",borderRadius:u.borderRadius,opacity:u.opacity,outline:d?"1.5px solid var(--nice-primary-hover, #2563eb)":"1px dashed transparent",outlineOffset:1,cursor:h?"default":"move"};return e.jsxs("div",{style:n,onClick:k,onMouseDown:h?void 0:f,children:[w?e.jsx("div",{style:{width:"100%",borderBottom:`${(u.borderWidth??.5)*r}px ${u.borderStyle??"solid"} ${u.borderColor??te}`}}):I?null:B?e.jsx("div",{className:t.fieldImagePlaceholder,children:e.jsx(_.NiceIcon,{name:"image",size:24})}):a?e.jsxs("div",{className:t.fieldBarcodePlaceholder,children:[e.jsx(_.NiceIcon,{name:s.type==="qr"?"qr-code":"barcode",size:14})," ",s.type==="qr"?"QR":b("templateEditor.barcode","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:In(s,o)}),d&&!h&&e.jsx(Sn,{onResizeStart:g})]})},Bn=({section:s,zoom:r,paperWidthMm:d,selectedIds:o,sampleData:k,readOnly:f,showGrid:g,onFieldClick:h,onFieldDragStart:b,onResizeStart:N,onSectionHeightChange:u,onDropField:i})=>{const w=(s.heightMm??(s.type==="body"?200:40))*r*G,I=d*r*G,[B,a]=j.useState(!1),n={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} ${B?t.sectionCanvasOver:""}`,style:{width:I,height:w,position:"relative",background:n[s.type]??"transparent",backgroundImage:g?`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:c=>{c.preventDefault(),a(!0)},onDragLeave:()=>a(!1),onDrop:c=>{c.preventDefault(),a(!1);const p=c.dataTransfer.getData("fieldPath");if(!p)return;const L=c.currentTarget.getBoundingClientRect(),x=(c.clientX-L.left)/(r*G),$=(c.clientY-L.top)/(r*G);i(s.id,p,Math.max(0,x),Math.max(0,$))},children:[e.jsx("div",{className:t.sectionTypeChip,children:s.type}),s.fields.map(c=>e.jsx(Cn,{field:c,zoom:r,selected:o.has(c.id),sampleData:k,readOnly:f,onClick:p=>h(c.id,p),onDragStart:p=>b(c.id,p),onResizeStart:(p,L)=>N(c.id,p,L)},c.id)),!f&&s.type!=="body"&&e.jsx("div",{className:t.sectionResizeBar,onMouseDown:c=>{c.preventDefault();const p=c.clientY,L=s.heightMm??40,x=T=>{const z=(T.clientY-p)/(r*G);u(s.id,Math.max(10,L+z))},$=()=>{document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",$)};document.addEventListener("mousemove",x),document.addEventListener("mouseup",$)},children:e.jsx("div",{className:t.sectionResizeGrip})})]})},ae=({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})]}),Ln=[{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"}],Tn=[{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:r,canUndo:d,canRedo:o,showGrid:k,showRulers:f,readOnly:g,selectedCount:h,onPaperChange:b,onZoom:N,onUndo:u,onRedo:i,onToggleGrid:w,onToggleRulers:I,onInsert:B,onDelete:a,onDuplicate:n,onAlignH:c,onAlignV:p,onBringForward:L,onSendBackward:x,onSave:$})=>{const{t:T}=_.useNiceTranslation(),{t:z}=_.useNiceTranslation(),[E,O]=j.useState(!1),X=[.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:y=>b(y.target.value,s.orientation),children:["A4","A5","A3","Letter","Legal","Tabloid","custom"].map(y=>e.jsx("option",{value:y,children:y},y))}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="portrait"?t.toolbarBtnActive:""}`,onClick:()=>b(s.paperSize,"portrait"),title:T("templateEditor.portrait","Portrait"),children:e.jsx(_.NiceIcon,{name:"file",size:14})}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="landscape"?t.toolbarBtnActive:""}`,onClick:()=>b(s.paperSize,"landscape"),title:T("templateEditor.landscape","Landscape"),children:e.jsx(_.NiceIcon,{name:"file",size:14,style:{transform:"rotate(90deg)"}})})]}),!g&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,disabled:!d,onClick:u,title:`${z("printing.editor.undo","Undo")} (Ctrl+Z)`,children:e.jsx(_.NiceIcon,{name:"undo",size:14})}),e.jsx("button",{className:t.toolbarBtn,disabled:!o,onClick:i,title:`${z("printing.editor.redo","Redo")} (Ctrl+Y)`,children:e.jsx(_.NiceIcon,{name:"redo",size:14})})]}),!g&&e.jsxs("div",{className:t.insertWrapper,children:[e.jsxs("button",{className:`${t.toolbarBtn} ${t.insertBtn}`,onClick:()=>O(y=>!y),children:[e.jsx(_.NiceIcon,{name:"plus",size:14})," ",z("printing.editor.insert","Insert")," ",e.jsx(_.NiceIcon,{name:"chevron-down",size:12})]}),E&&e.jsxs("div",{className:t.insertDropdown,onMouseLeave:()=>O(!1),children:[e.jsx("div",{className:t.insertCategory,children:z("printing.editor.dataFields","Data fields")}),["text","number","currency","date","image","barcode","qr"].map(y=>e.jsxs("button",{className:t.insertItem,onClick:()=>{B(y),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:ce[y]}),be(z,y)]},y)),e.jsx("div",{className:t.insertCategory,children:T("templateEditor.staticElements","Static elements")}),["static_text","static_image","line","rect","page_number","total_pages","print_date"].map(y=>e.jsxs("button",{className:t.insertItem,onClick:()=>{B(y),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:ce[y]}),be(z,y)]},y)),e.jsx("div",{className:t.insertCategory,children:T("templateEditor.special","Special")}),e.jsxs("button",{className:t.insertItem,onClick:()=>{B("watermark"),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:e.jsx(_.NiceIcon,{name:"droplet",size:14})}),z("printing.editor.watermark","Watermark")]}),e.jsxs("button",{className:t.insertItem,onClick:()=>{B("signature"),O(!1)},children:[e.jsx("span",{className:t.insertIcon,children:e.jsx(_.NiceIcon,{name:"pen",size:14})}),z("printing.editor.signature","Signature")]})]})]}),!g&&h>0&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:n,title:`${z("printing.editor.duplicate","Duplicate")} (Ctrl+D)`,children:e.jsx(_.NiceIcon,{name:"copy",size:14})}),e.jsx("button",{className:`${t.toolbarBtn} ${t.toolbarBtnDanger}`,onClick:a,title:`${z("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:()=>c("left"),title:z("printing.editor.alignLeft","Align left"),children:e.jsx(_.NiceIcon,{name:"align-left",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>c("center"),title:z("printing.editor.alignCenter","Align centre"),children:e.jsx(_.NiceIcon,{name:"align-center",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>c("right"),title:z("printing.editor.alignRight","Align right"),children:e.jsx(_.NiceIcon,{name:"align-right",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>p("top"),title:z("printing.editor.alignTop","Align top"),children:"⊤"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>p("center"),title:z("printing.editor.alignMiddle","Align middle"),children:"⊕"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>p("bottom"),title:z("printing.editor.alignBottom","Align bottom"),children:"⊥"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:L,title:T("templateEditor.bringForward","Bring forward"),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:14})}),e.jsx("button",{className:t.toolbarBtn,onClick:x,title:z("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} ${k?t.toolbarBtnActive:""}`,onClick:w,title:z("printing.editor.grid","Grid"),children:"⊞"}),e.jsx("button",{className:`${t.toolbarBtn} ${f?t.toolbarBtnActive:""}`,onClick:I,title:z("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:()=>N(Math.max(.25,r-.1)),children:"−"}),e.jsx("select",{className:t.zoomSelect,value:X.includes(r)?r:"",onChange:y=>N(+y.target.value),children:X.map(y=>e.jsxs("option",{value:y,children:[Math.round(y*100),"%"]},y))}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>N(Math.min(3,r+.1)),children:"+"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>N(1),title:"100%",children:"⊡"})]}),!g&&$&&e.jsxs("button",{className:t.saveBtn,onClick:$,children:[e.jsx(_.NiceIcon,{name:"save",size:14})," ",z("printing.editor.save","Save")]})]})},Dn=({activeTab:s,onTabChange:r,schema:d,tpl:o,allFields:k,selectedIds:f,onInsertSchemaField:g,onSelectField:h,onUpdateTpl:b,onReorderField:N})=>{const{t:u}=_.useNiceTranslation(),{t:i}=_.useNiceTranslation(),[w,I]=j.useState(""),B=d==null?void 0:d.fields.filter(a=>a.label.toLowerCase().includes(w.toLowerCase())||a.path.toLowerCase().includes(w.toLowerCase()));return e.jsxs("div",{className:t.leftPanel,children:[e.jsx("div",{className:t.leftTabs,children:Ln.map(a=>e.jsxs("button",{className:`${t.leftTab} ${s===a.id?t.leftTabActive:""}`,onClick:()=>r(a.id),title:i(a.key,a.label),children:[e.jsx("span",{className:t.leftTabIcon,children:e.jsx(_.NiceIcon,{name:a.icon,size:16})}),e.jsx("span",{className:t.leftTabLabel,children:i(a.key,a.label)})]},a.id))}),e.jsxs("div",{className:t.leftContent,children:[s==="fields"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:i("printing.editor.dataFields","Data fields")}),e.jsx("div",{className:t.searchBox,children:e.jsx("input",{className:t.searchInput,placeholder:i("printing.editor.search","Search…"),value:w,onChange:a=>I(a.target.value)})}),d?e.jsxs("div",{className:t.fieldList,children:[(B??[]).map(a=>e.jsxs("div",{className:t.fieldItem,draggable:!0,onDragStart:n=>{n.dataTransfer.setData("fieldPath",a.path),n.dataTransfer.setData("fieldLabel",a.label),n.dataTransfer.setData("fieldType",a.type)},onClick:()=>g(a),children:[e.jsx("span",{className:t.fieldItemIcon,children:e.jsx(_.NiceIcon,{name:ce[a.type]??"type",size:14})}),e.jsxs("div",{className:t.fieldItemInfo,children:[e.jsx("div",{className:t.fieldItemLabel,children:a.label}),e.jsx("div",{className:t.fieldItemPath,children:a.path})]}),e.jsx("span",{className:t.fieldItemType,children:a.type})]},a.path)),(B==null?void 0:B.length)===0&&e.jsx("div",{className:t.emptyMsg,children:i("printing.editor.noMatches","No matches")})]}):e.jsx("div",{className:t.emptyMsg,children:i("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:[i("printing.editor.layers","Layers")," (",k.length,")"]}),e.jsxs("div",{className:t.layerList,children:[k.length===0&&e.jsx("div",{className:t.emptyMsg,children:i("printing.editor.noElements","No elements")}),k.slice().reverse().map(a=>e.jsxs("div",{className:`${t.layerItem} ${f.has(a.id)?t.layerItemSelected:""}`,onClick:()=>h(a.id),children:[e.jsx("span",{className:t.layerIcon,children:e.jsx(_.NiceIcon,{name:ce[a.type]??"type",size:14})}),e.jsx("span",{className:t.layerName,children:a.name||a.label}),e.jsxs("div",{className:t.layerActions,children:[e.jsx("button",{className:t.layerBtn,onClick:n=>{n.stopPropagation(),N(a.id,-1)},title:i("printing.editor.bringForward","Bring forward"),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:12})}),e.jsx("button",{className:t.layerBtn,onClick:n=>{n.stopPropagation(),N(a.id,1)},title:i("printing.editor.sendBackward","Send backward"),children:e.jsx(_.NiceIcon,{name:"arrow-down",size:12})})]})]},a.id))]})]}),s==="watermarks"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:u("templateEditor.watermarks","Watermarks")}),e.jsxs("div",{className:t.wmList,children:[(o.watermarks??[]).map(a=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.editor.type","Type")}),e.jsxs("select",{className:t.wmSelect,value:a.type,onChange:n=>{var c;return b({watermarks:(c=o.watermarks)==null?void 0:c.map(p=>p.id===a.id?{...p,type:n.target.value}:p)})},children:[e.jsx("option",{value:"text",children:i("printing.fieldType.text","Text")}),e.jsx("option",{value:"image",children:i("printing.fieldType.image","Image")})]})]}),a.type==="text"&&e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.fieldType.text","Text")}),e.jsx("input",{className:t.wmInput,value:a.text??"",onChange:n=>{var c;return b({watermarks:(c=o.watermarks)==null?void 0:c.map(p=>p.id===a.id?{...p,text:n.target.value}:p)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:u("templateEditor.opacity","Opacity")}),e.jsx("input",{type:"range",min:.02,max:.5,step:.01,className:t.wmSlider,value:a.opacity,onChange:n=>{var c;return b({watermarks:(c=o.watermarks)==null?void 0:c.map(p=>p.id===a.id?{...p,opacity:+n.target.value}:p)})}}),e.jsxs("span",{className:t.wmValue,children:[Math.round(a.opacity*100),"%"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.editor.angle","Angle")}),e.jsx("input",{type:"range",min:-90,max:90,step:5,className:t.wmSlider,value:a.angle,onChange:n=>{var c;return b({watermarks:(c=o.watermarks)==null?void 0:c.map(p=>p.id===a.id?{...p,angle:+n.target.value}:p)})}}),e.jsxs("span",{className:t.wmValue,children:[a.angle,"°"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.editor.size","Size")}),e.jsx("input",{type:"number",min:8,max:200,className:t.wmInputNum,value:a.fontSize??48,onChange:n=>{var c;return b({watermarks:(c=o.watermarks)==null?void 0:c.map(p=>p.id===a.id?{...p,fontSize:+n.target.value}:p)})}}),e.jsx("span",{className:t.wmUnit,children:"pt"})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.editor.colour","Colour")}),e.jsx("input",{type:"color",className:t.colorPicker,value:a.color??pe,onChange:n=>{var c;return b({watermarks:(c=o.watermarks)==null?void 0:c.map(p=>p.id===a.id?{...p,color:n.target.value}:p)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var n;return b({watermarks:(n=o.watermarks)==null?void 0:n.filter(c=>c.id!==a.id)})},children:i("printing.action.remove","Remove")})]},a.id)),e.jsxs("button",{className:t.addBtn,onClick:()=>b({watermarks:[...o.watermarks??[],{id:ie(),type:"text",text:u("templateEditor.copy","COPY"),opacity:.12,angle:-45,fontSize:60,color:pe}]}),children:[e.jsx(_.NiceIcon,{name:"plus",size:12})," ",i("printing.editor.addWatermark","Add watermark")]})]})]}),s==="signatures"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:u("templateEditor.signatures","Signatures")}),e.jsxs("div",{className:t.wmList,children:[(o.signatures??[]).map(a=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:u("templateEditor.label","Label")}),e.jsx("input",{className:t.wmInput,value:a.label,onChange:n=>{var c;return b({signatures:(c=o.signatures)==null?void 0:c.map(p=>p.id===a.id?{...p,label:n.target.value}:p)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:u("templateEditor.signerName","Name")}),e.jsx("input",{className:t.wmInput,value:a.signerName??"",onChange:n=>{var c;return b({signatures:(c=o.signatures)==null?void 0:c.map(p=>p.id===a.id?{...p,signerName:n.target.value}:p)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.fieldType.line","Line")}),e.jsx("input",{type:"checkbox",checked:a.showLine??!0,onChange:n=>{var c;return b({signatures:(c=o.signatures)==null?void 0:c.map(p=>p.id===a.id?{...p,showLine:n.target.checked}:p)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:i("printing.editor.showDate","Show date")}),e.jsx("input",{type:"checkbox",checked:a.showDate??!1,onChange:n=>{var c;return b({signatures:(c=o.signatures)==null?void 0:c.map(p=>p.id===a.id?{...p,showDate:n.target.checked}:p)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var n;return b({signatures:(n=o.signatures)==null?void 0:n.filter(c=>c.id!==a.id)})},children:i("printing.action.remove","Remove")})]},a.id)),e.jsxs("button",{className:t.addBtn,onClick:()=>b({signatures:[...o.signatures??[],{id:ie(),label:i("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})," ",i("printing.editor.addSignature","Add signature")]})]})]}),s==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:i("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:i("printing.editor.name","Name")}),e.jsx("input",{className:t.settingsInput,value:o.name,onChange:a=>b({name:a.target.value})})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:i("printing.editor.description","Description")}),e.jsx("textarea",{className:t.settingsTextarea,value:o.description??"",onChange:a=>b({description:a.target.value}),rows:2})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:u("templateEditor.category","Category")}),e.jsx("input",{className:t.settingsInput,value:o.category??"",onChange:a=>b({category:a.target.value})})]}),e.jsx("div",{className:t.settingsDivider,children:i("printing.editor.margins","Margins (mm)")}),["top","right","bottom","left"].map(a=>e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:a==="top"?i("printing.editor.marginTop","Top"):a==="right"?i("printing.editor.marginRight","Right"):a==="bottom"?i("printing.editor.marginBottom","Bottom"):i("printing.editor.marginLeft","Left")}),e.jsx("input",{type:"number",min:0,max:50,step:1,className:t.settingsInputNum,value:o.margins[a],onChange:n=>b({margins:{...o.margins,[a]:+n.target.value}})}),e.jsx("span",{className:t.settingsUnit,children:u("templateEditor.mm","mm")})]},a))]})]})]})]})},$n=({field:s,activeTab:r,onTabChange:d,onChange:o,paperWidthMm:k,paperHeightMm:f})=>{var w,I,B,a;const{t:g}=_.useNiceTranslation(),{t:h}=_.useNiceTranslation(),b=j.useCallback(n=>s&&o({position:{...s.position,...n}}),[s,o]),N=j.useCallback(n=>s&&o({style:{...(s==null?void 0:s.style)??{},...n}}),[s,o]);if(!s)return e.jsxs("div",{className:t.rightPanel,children:[e.jsx("div",{className:t.panelHeader,children:h("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:h("printing.editor.selectElement","Select an element on the template")}),e.jsxs("div",{className:t.shortcutGrid,children:[e.jsx(ae,{keys:"Del",label:h("printing.action.remove","Remove")}),e.jsx(ae,{keys:"Ctrl+D",label:h("printing.editor.duplicate","Duplicate")}),e.jsx(ae,{keys:"↑↓←→",label:h("printing.editor.move","Move")}),e.jsx(ae,{keys:"Ctrl+Z",label:h("printing.editor.undo","Undo")}),e.jsx(ae,{keys:"Ctrl+A",label:h("printing.editor.selectAll","Select all")}),e.jsx(ae,{keys:"Shift+↑",label:h("printing.editor.move5mm","Move 5 mm")})]})]})]});const u=!["line","rect","image","static_image","barcode","qr","signature"].includes(s.type),i=!["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:Tn.map(n=>n.id==="data"&&!i?null:e.jsx("button",{className:`${t.rightTab} ${r===n.id?t.rightTabActive:""}`,onClick:()=>d(n.id),children:h(n.key,n.label)},n.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:g("templateEditor.widthShort","W"),unit:"mm"},{key:"height",label:g("templateEditor.heightShort","H"),unit:"mm"}].map(({key:n,label:c,unit:p})=>e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:c}),e.jsx("input",{type:"number",step:.5,className:t.posInput,value:Math.round(s.position[n]*10)/10,onChange:L=>b({[n]:+L.target.value})}),e.jsx("span",{className:t.posUnit,children:p})]},n)),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:h("printing.editor.rotation","Rotation")}),e.jsx("input",{type:"number",step:5,className:t.posInput,value:s.style.rotation??0,onChange:n=>N({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:g("templateEditor.zIdx","Z-idx")}),e.jsx("input",{type:"number",step:1,min:1,className:t.posInput,value:s.position.zIndex??1,onChange:n=>b({zIndex:+n.target.value})})]})]}),e.jsxs("div",{className:t.snapSection,children:[e.jsx("div",{className:t.snapTitle,children:h("printing.editor.snapToPage","Snap to page")}),e.jsxs("div",{className:t.snapRow,children:[e.jsx("button",{className:t.snapBtn,onClick:()=>b({x:0}),title:h("printing.editor.leftEdge","Left edge"),children:e.jsx(_.NiceIcon,{name:"align-left",size:14})}),e.jsx("button",{className:t.snapBtn,onClick:()=>b({x:(k-s.position.width)/2}),title:h("printing.editor.horizontalCentre","Horizontal centre"),children:"⊕"}),e.jsx("button",{className:t.snapBtn,onClick:()=>b({x:k-s.position.width}),title:h("printing.editor.rightEdge","Right edge"),children:e.jsx(_.NiceIcon,{name:"align-right",size:14})})]})]})]}),r==="style"&&e.jsxs(e.Fragment,{children:[u&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:g("templateEditor.font","Font")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:g("templateEditor.fontFamily","Family")}),e.jsx("select",{className:t.styleSelectFull,value:s.style.fontFamily??"sans-serif",onChange:n=>N({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:h("printing.editor.size","Size")}),e.jsx("select",{className:t.styleSelectSm,value:Ne.includes(s.style.fontSize??10)?s.style.fontSize??10:"",onChange:n=>N({fontSize:+n.target.value}),children:Ne.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=>N({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:h("printing.editor.colour","Colour")}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.color??te,onChange:n=>N({color:n.target.value})}),e.jsx("input",{className:t.colorHex,value:s.style.color??te,onChange:n=>N({color:n.target.value}),maxLength:7})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.style","Style")}),e.jsxs("div",{className:t.toggleGroup,children:[e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontWeight==="bold"?t.toggleBtnActive:""}`,onClick:()=>N({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:()=>N({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:h("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:()=>N({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:g("templateEditor.lineHeight","Line h.")}),e.jsx("input",{type:"number",step:.1,min:1,max:4,className:t.styleInput,value:s.style.lineHeight??1.4,onChange:n=>N({lineHeight:+n.target.value})})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("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=>N({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:h("printing.editor.background","Background and border")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.fill","Fill")}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.backgroundColor??"var(--nice-bg, #fff)",onChange:n=>N({backgroundColor:n.target.value})}),e.jsx("button",{className:t.clearBtn,onClick:()=>N({backgroundColor:void 0}),title:h("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:g("templateEditor.border","Border")}),e.jsx("input",{type:"number",step:.5,min:0,max:10,className:t.styleInput,value:s.style.borderWidth??0,onChange:n=>N({borderWidth:+n.target.value})}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.borderColor??te,onChange:n=>N({borderColor:n.target.value})}),e.jsxs("select",{className:t.styleSelectXs,value:s.style.borderStyle??"solid",onChange:n=>N({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:g("templateEditor.radius","Radius")}),e.jsx("input",{type:"number",step:1,min:0,max:50,className:t.styleInput,value:s.style.borderRadius??0,onChange:n=>N({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:g("templateEditor.padding","Padding")}),e.jsx("input",{type:"number",step:.5,min:0,max:20,className:t.styleInput,value:s.style.padding??0,onChange:n=>N({padding:+n.target.value})}),e.jsx("span",{className:t.styleUnit,children:g("templateEditor.mm","mm")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:g("templateEditor.opacity","Opacity")}),e.jsx("input",{type:"range",min:.1,max:1,step:.05,className:t.sliderInput,value:s.style.opacity??1,onChange:n=>N({opacity:+n.target.value})}),e.jsxs("span",{className:t.styleValue,children:[Math.round((s.style.opacity??1)*100),"%"]})]})]})]}),r==="data"&&i&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:h("printing.editor.dataSource","Data source")}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.path","Path")}),e.jsx("input",{className:t.styleInputFull,value:s.dataPath,onChange:n=>o({dataPath:n.target.value}),placeholder:g("templateEditor.egInvoiceNumber","e.g. invoice.number")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.format","Format")}),e.jsx("input",{className:t.styleInputFull,value:s.format??"",onChange:n=>o({format:n.target.value}),placeholder:g("templateEditor.ddMmYyyy000","DD.MM.YYYY / #,##0.00")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.default","Default")}),e.jsx("input",{className:t.styleInputFull,value:s.fallback??"",onChange:n=>o({fallback:n.target.value}),placeholder:h("printing.editor.whenEmpty","When there is no value")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.type","Type")}),e.jsx("select",{className:t.styleSelectFull,value:s.type,onChange:n=>o({type:n.target.value}),children:Object.keys(de).map(n=>e.jsx("option",{value:n,children:be(h,n)},n))})]}),(s.type==="barcode"||s.type==="qr")&&e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.codeFormat","Code format")}),e.jsx("select",{className:t.styleSelectFull,value:s.barcodeType??"code128",onChange:n=>o({barcodeType:n.target.value}),children:["ean13","ean8","code128","code39","upc","itf14","datamatrix"].map(n=>e.jsx("option",{value:n,children:n.toUpperCase()},n))})]})]}),r==="conditional"&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:h("printing.editor.conditionalVisibility","Conditional visibility")}),e.jsx("div",{className:t.conditionalHint,children:h("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:h("printing.editor.conditionalField","Field")}),e.jsx("input",{className:t.styleInputFull,value:((w=s.conditional)==null?void 0:w.field)??"",onChange:n=>{var c,p;return o({conditional:{field:n.target.value,operator:((c=s.conditional)==null?void 0:c.operator)??"eq",value:(p=s.conditional)==null?void 0:p.value}})},placeholder:g("templateEditor.egInvoiceIsPaid","e.g. invoice.isPaid")})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:g("templateEditor.operator","Operator")}),e.jsxs("select",{className:t.styleSelectFull,value:((I=s.conditional)==null?void 0:I.operator)??"eq",onChange:n=>{var c,p;return o({conditional:{field:((c=s.conditional)==null?void 0:c.field)??"",operator:n.target.value,value:(p=s.conditional)==null?void 0:p.value}})},children:[e.jsxs("option",{value:"eq",children:["= ",h("printing.editor.opEqual","equal")]}),e.jsxs("option",{value:"neq",children:["≠ ",h("printing.editor.opNotEqual","not equal")]}),e.jsx("option",{value:"gt",children:g("templateEditor.greaterThan","> greater than")}),e.jsx("option",{value:"lt",children:g("templateEditor.lessThan","< less than")}),e.jsx("option",{value:"contains",children:g("templateEditor.contains","contains")})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:h("printing.editor.value","Value")}),e.jsx("input",{className:t.styleInputFull,value:String(((B=s.conditional)==null?void 0:B.value)??""),onChange:n=>{var c,p;return o({conditional:{field:((c=s.conditional)==null?void 0:c.field)??"",operator:((p=s.conditional)==null?void 0:p.operator)??"eq",value:n.target.value}})},placeholder:g("templateEditor.egTruePaid",'e.g. true / "PAID"')})]}),((a=s.conditional)==null?void 0:a.field)&&e.jsx("button",{className:t.clearConditionalBtn,onClick:()=>o({conditional:void 0}),children:h("printing.editor.clearCondition","Clear condition")})]})]})]})};function Rn(){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 En=({template:s,dataSchema:r,sampleData:d=[],onChange:o,onSave:k,readOnly:f=!1,className:g,style:h,theme:b="light"})=>{const{t:N}=_.useNiceTranslation(),[{past:u,present:i,future:w},I]=j.useReducer(wn,{past:[],present:s??Rn(),future:[]}),{t:B}=_.useNiceTranslation(),[a,n]=j.useState(new Set),[c,p]=j.useState("sec-body"),[L,x]=j.useState(1),[$,T]=j.useState(0),[z,E]=j.useState("fields"),[O,X]=j.useState("position"),[y,Y]=j.useState(!1),[me,Ce]=j.useState(!0),A=j.useCallback(l=>{const m={...i,...l};I({type:"UPDATE",payload:m}),o==null||o(m)},[i,o]),[K,ue]=j.useMemo(()=>{const[l,m]=ve[i.paperSize]??ve.A4;return i.orientation==="landscape"?[m,l]:[l,m]},[i.paperSize,i.orientation]),J=j.useMemo(()=>i.sections.flatMap(l=>l.fields),[i]),P=j.useMemo(()=>J.find(l=>a.has(l.id))??null,[J,a]),he=j.useCallback((l,m)=>{A({sections:i.sections.map(C=>({...C,fields:C.fields.map(S=>S.id===l?{...S,...m,style:{...S.style,...m.style??{}}}:S)}))})},[i,A]),re=j.useCallback(l=>{A({sections:i.sections.map(m=>({...m,fields:m.fields.map(C=>a.has(C.id)?{...C,...l,style:{...C.style,...l.style??{}}}:C)}))})},[i,a,A]),ye=j.useCallback((l,m)=>{if(l==="watermark"){A({watermarks:[...i.watermarks??[],{id:ie(),type:"text",text:N("templateEditor.copy","COPY"),opacity:.12,angle:-45,fontSize:60,color:pe}]}),E("watermarks");return}if(l==="signature"){A({signatures:[...i.signatures??[],{id:ie(),label:B("printing.editor.signature","Signature"),position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),E("signatures");return}const C=i.sections.find(F=>F.id===c)??i.sections.find(F=>F.type==="body");if(!C)return;const S=we(l,m),M={sections:i.sections.map(F=>F.id===C.id?{...F,fields:[...F.fields,S]}:F)};I({type:"UPDATE",payload:{...i,...M}}),o==null||o({...i,...M}),n(new Set([S.id]))},[i,c,o,N,B,A]),Be=j.useCallback((l,m,C,S)=>{const M=r==null?void 0:r.fields.find(q=>q.path===m),F=we((M==null?void 0:M.type)??"text",M);F.position.x=Math.round(C*2)/2,F.position.y=Math.round(S*2)/2;const Q={sections:i.sections.map(q=>q.id===l?{...q,fields:[...q.fields,F]}:q)};I({type:"UPDATE",payload:{...i,...Q}}),o==null||o({...i,...Q}),n(new Set([F.id]))},[i,r,o]),Le=j.useCallback((l,m)=>{m.ctrlKey||m.metaKey?n(C=>{const S=new Set(C);return S.has(l)?S.delete(l):S.add(l),S}):m.shiftKey?n(C=>new Set([...C,l])):n(new Set([l]))},[]),Te=j.useCallback((l,m)=>{if(f)return;m.preventDefault(),a.has(l)||n(new Set([l]));const C=m.clientX,S=m.clientY,M=i.sections.map(q=>({id:q.id,fields:q.fields.map(Z=>({id:Z.id,pos:{...Z.position}}))})),F=q=>{const Z=(q.clientX-C)/(L*G),se=(q.clientY-S)/(L*G),oe=a.has(l)?a:new Set([l]),le=i.sections.map(ee=>{const U=M.find(W=>W.id===ee.id);return{...ee,fields:ee.fields.map(W=>{var je;if(!oe.has(W.id))return W;const fe=((je=U==null?void 0:U.fields.find(Ge=>Ge.id===W.id))==null?void 0:je.pos)??W.position;return{...W,position:{...W.position,x:Math.max(0,Math.round((fe.x+Z)*2)/2),y:Math.max(0,Math.round((fe.y+se)*2)/2)}}})}}),ne={...i,sections:le};o==null||o(ne),I({type:"UPDATE",payload:ne})},Q=()=>{document.removeEventListener("mousemove",F),document.removeEventListener("mouseup",Q)};document.addEventListener("mousemove",F),document.addEventListener("mouseup",Q)},[i,L,a,f,o]),ze=j.useCallback((l,m,C)=>{if(f)return;C.preventDefault();const S=J.find(se=>se.id===l);if(!S)return;const M={...S.position},F=C.clientX,Q=C.clientY,q=se=>{const oe=(se.clientX-F)/(L*G),le=(se.clientY-Q)/(L*G);let{x:ne,y:ee,width:U,height:W}=M;m.includes("e")&&(U=Math.max(5,U+oe)),m.includes("s")&&(W=Math.max(3,W+le)),m.includes("w")&&(ne=ne+oe,U=Math.max(5,U-oe)),m.includes("n")&&(ee=ee+le,W=Math.max(3,W-le)),he(l,{position:{...M,x:Math.round(ne*2)/2,y:Math.round(ee*2)/2,width:Math.round(U*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,L,f,he]),_e=j.useCallback(()=>{A({sections:i.sections.map(l=>({...l,fields:l.fields.filter(m=>!a.has(m.id))}))}),n(new Set)},[i,a,A]),ge=j.useCallback(()=>{const l=new Set;A({sections:i.sections.map(m=>{const C=m.fields.filter(S=>a.has(S.id)).map(S=>{const M={...S,id:ie(),position:{...S.position,x:S.position.x+5,y:S.position.y+5}};return l.add(M.id),M});return{...m,fields:[...m.fields,...C]}})}),n(l)},[i,a,A]),De=j.useCallback(l=>{A({sections:i.sections.map(m=>({...m,fields:m.fields.map(C=>{if(!a.has(C.id))return C;const S=l==="left"?i.margins.left:l==="right"?K-i.margins.right-C.position.width:(K-C.position.width)/2;return{...C,position:{...C.position,x:S}}})}))})},[i,a,K,A]),$e=j.useCallback(l=>{const m=i.sections.find(S=>S.id===c);if(!m)return;const C=m.heightMm??200;A({sections:i.sections.map(S=>S.id!==c?S:{...S,fields:S.fields.map(M=>{if(!a.has(M.id))return M;const F=l==="top"?0:l==="bottom"?C-M.position.height:(C-M.position.height)/2;return{...M,position:{...M.position,y:F}}})})})},[i,a,c,A]),Re=j.useCallback(()=>{A({sections:i.sections.map(l=>({...l,fields:l.fields.map(m=>a.has(m.id)?{...m,position:{...m.position,zIndex:(m.position.zIndex??1)+1}}:m)}))})},[i,a,A]),Ee=j.useCallback(()=>{A({sections:i.sections.map(l=>({...l,fields:l.fields.map(m=>a.has(m.id)?{...m,position:{...m.position,zIndex:Math.max(1,(m.position.zIndex??1)-1)}}:m)}))})},[i,a,A]),Ae=j.useCallback((l,m)=>{A({sections:i.sections.map(C=>({...C,fields:C.fields.map(S=>S.id===l?{...S,position:{...S.position,zIndex:Math.max(1,(S.position.zIndex??1)-m)}}:S)}))})},[i,A]);j.useEffect(()=>{const l=m=>{const C=m.target.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT")return;const S=m.shiftKey?5:.5;m.key==="Delete"||m.key==="Backspace"?a.size&&(m.preventDefault(),_e()):m.ctrlKey&&m.key==="z"?(m.preventDefault(),I({type:"UNDO"})):m.ctrlKey&&(m.key==="y"||m.key==="Y")?(m.preventDefault(),I({type:"REDO"})):m.ctrlKey&&(m.key==="d"||m.key==="D")?(m.preventDefault(),a.size&&ge()):m.ctrlKey&&m.key==="a"?(m.preventDefault(),n(new Set(J.map(M=>M.id)))):m.key==="ArrowLeft"?(m.preventDefault(),re({position:{...P.position,x:((P==null?void 0:P.position.x)??0)-S}})):m.key==="ArrowRight"?(m.preventDefault(),re({position:{...P.position,x:((P==null?void 0:P.position.x)??0)+S}})):m.key==="ArrowUp"?(m.preventDefault(),re({position:{...P.position,y:((P==null?void 0:P.position.y)??0)-S}})):m.key==="ArrowDown"&&(m.preventDefault(),re({position:{...P.position,y:((P==null?void 0:P.position.y)??0)+S}}))};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[a,J,P,_e,ge,re]);const Me=j.useCallback((l,m)=>{A({sections:i.sections.map(C=>C.id===l?{...C,heightMm:Math.round(m*2)/2}:C)})},[i,A]),Pe=j.useMemo(()=>{const l=Array.isArray(d)?d[$]:d;return l?"data"in l?l.data:l:{}},[d,$]),Fe=K*L*G,He=ue*L*G;return e.jsx(_.NiceAppShell,{flush:!0,className:`${t.root} ${b==="dark"?t.dark:""} ${g??""}`,style:h,toolbar:e.jsx(zn,{tpl:i,zoom:L,canUndo:u.length>0,canRedo:w.length>0,showGrid:y,showRulers:me,readOnly:f,selectedCount:a.size,onPaperChange:(l,m)=>A({paperSize:l,orientation:m}),onZoom:x,onUndo:()=>I({type:"UNDO"}),onRedo:()=>I({type:"REDO"}),onToggleGrid:()=>Y(l=>!l),onToggleRulers:()=>Ce(l=>!l),onInsert:ye,onDelete:_e,onDuplicate:ge,onAlignH:De,onAlignV:$e,onBringForward:Re,onSendBackward:Ee,onSave:k?()=>k(i):void 0}),sidebar:e.jsx(Dn,{activeTab:z,onTabChange:E,schema:r,tpl:i,allFields:J,selectedIds:a,onInsertSchemaField:l=>ye(l.type,l),onSelectField:l=>n(new Set([l])),onUpdateTpl:l=>A(l),onReorderField:Ae}),rightSidebar:e.jsx($n,{field:P,activeTab:O,onTabChange:X,onChange:l=>P&&he(P.id,l),paperWidthMm:K,paperHeightMm:ue}),children:e.jsxs("div",{className:t.canvasArea,onClick:()=>n(new Set),children:[Array.isArray(d)&&d.length>0&&e.jsxs("div",{className:t.testDataBar,children:[e.jsxs("span",{className:t.testDataLabel,children:[B("printing.editor.testData","Sample data"),":"]}),e.jsx("select",{className:t.testDataSelect,value:$,onChange:l=>T(+l.target.value),children:d.map((l,m)=>e.jsxs("option",{value:m,children:[B("printing.editor.record","Record")," ",m+1]},m))})]}),me&&e.jsxs("div",{className:t.rulerWrapper,children:[e.jsx("div",{className:t.rulerCorner}),e.jsx(ke,{lengthMm:K,zoom:L,orientation:"h"}),e.jsx(ke,{lengthMm:ue,zoom:L,orientation:"v"})]}),e.jsx("div",{className:t.paperScroll,onClick:l=>l.stopPropagation(),children:e.jsxs("div",{className:t.paperShadow,style:{width:Fe,minHeight:He},children:[e.jsx("div",{className:t.marginGuide,style:{top:i.margins.top*L*G,right:i.margins.right*L*G,bottom:i.margins.bottom*L*G,left:i.margins.left*L*G}}),(i.watermarks??[]).map(l=>e.jsx("div",{className:t.watermark,style:{fontSize:(l.fontSize??60)*L,color:l.color??pe,opacity:l.opacity,transform:`translate(-50%, -50%) rotate(${l.angle}deg)`},children:l.type==="text"?l.text:e.jsx(_.NiceIcon,{name:"image",size:(l.fontSize??60)*L})},l.id)),i.sections.map(l=>e.jsx("div",{children:e.jsx(Bn,{section:l,zoom:L,paperWidthMm:K,selectedIds:a,sampleData:Pe,readOnly:f,showGrid:y,onFieldClick:Le,onFieldDragStart:Te,onResizeStart:ze,onSectionHeightChange:Me,onDropField:Be})},l.id))]})})]})})},An="_root_7m4s0_1",Mn="_dark_7m4s0_25",Pn="_topBar_7m4s0_39",Fn="_searchInput_7m4s0_69",Hn="_actionBtn_7m4s0_111",Gn="_categoryRow_7m4s0_157",On="_catChip_7m4s0_187",qn="_catChipActive_7m4s0_217",Wn="_grid_7m4s0_231",Yn="_card_7m4s0_253",Un="_cardSelected_7m4s0_285",Vn="_thumbnail_7m4s0_307",Xn="_thumbnailImg_7m4s0_321",Kn="_thumbnailPlaceholder_7m4s0_333",Jn="_paperMini_7m4s0_347",Qn="_paperLine_7m4s0_371",Zn="_cardOverlay_7m4s0_385",ea="_overlayBtn_7m4s0_405",ta="_overlayBtnDanger_7m4s0_441",sa="_cardBody_7m4s0_481",na="_cardName_7m4s0_489",aa="_cardDesc_7m4s0_517",ia="_cardMeta_7m4s0_539",ra="_cardSize_7m4s0_553",oa="_cardCat_7m4s0_569",la="_cardTags_7m4s0_585",ca="_cardTag_7m4s0_585",da="_emptyState_7m4s0_617",ma="_emptyIcon_7m4s0_639",D={root:An,dark:Mn,topBar:Pn,searchInput:Fn,actionBtn:Hn,categoryRow:Gn,catChip:On,catChipActive:qn,grid:Wn,card:Yn,cardSelected:Un,thumbnail:Vn,thumbnailImg:Xn,thumbnailPlaceholder:Kn,paperMini:Jn,paperLine:Qn,cardOverlay:Zn,overlayBtn:ea,overlayBtnDanger:ta,cardBody:sa,cardName:na,cardDesc:aa,cardMeta:ia,cardSize:ra,cardCat:oa,cardTags:la,cardTag:ca,emptyState:da,emptyIcon:ma},pa=[],ua=[{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 ha(s){return new Promise((r,d)=>{const o=new FileReader;o.onload=k=>{var f;try{r(JSON.parse((f=k.target)==null?void 0:f.result))}catch(g){d(g)}},o.readAsText(s)})}function _a(s){const r=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),d=URL.createObjectURL(r),o=document.createElement("a");o.href=d,o.download=`${s.name.replace(/\s+/g,"_")}.json`,o.click(),URL.revokeObjectURL(d)}const ga=({templates:s=pa,selectedId:r,onSelect:d,onImport:o,onExport:k,onDelete:f,onNew:g,className:h,style:b,theme:N="light"})=>{const{t:u}=_.useNiceTranslation(),[i,w]=j.useState(""),[I,B]=j.useState(null),[a,n]=j.useState(null),c=j.useRef(null),p=async x=>{var T;const $=(T=x.target.files)==null?void 0:T[0];if($){try{const z=await ha($);o==null||o(z)}catch{}x.target.value=""}},L=s.filter(x=>{const $=!i||x.name.toLowerCase().includes(i.toLowerCase())||(x.description??"").toLowerCase().includes(i.toLowerCase())||(x.tags??[]).some(z=>z.toLowerCase().includes(i.toLowerCase())),T=!I||x.category===I;return $&&T});return e.jsxs("div",{className:`${D.root} ${N==="dark"?D.dark:""} ${h??""}`,style:b,children:[e.jsxs("div",{className:D.topBar,children:[e.jsx("input",{type:"search",className:D.searchInput,placeholder:u("printing.searchTemplates","Search templates…"),value:i,onChange:x=>w(x.target.value)}),e.jsxs("button",{className:D.actionBtn,onClick:g,title:u("printing.newTemplate","New template"),children:[e.jsx(_.NiceIcon,{name:"plus",size:14})," ",u("printing.new","New")]}),e.jsxs("button",{className:D.actionBtn,onClick:()=>{var x;return(x=c.current)==null?void 0:x.click()},title:u("printing.importJson","Import JSON"),children:[e.jsx(_.NiceIcon,{name:"upload",size:14})," ",u("printing.import","Import")]}),e.jsx("input",{ref:c,type:"file",accept:".json",hidden:!0,onChange:p})]}),e.jsxs("div",{className:D.categoryRow,children:[e.jsx("button",{className:`${D.catChip} ${I?"":D.catChipActive}`,onClick:()=>B(null),children:u("printing.filter.all","All")}),ua.map(x=>e.jsx("button",{className:`${D.catChip} ${I===x.fallback?D.catChipActive:""}`,onClick:()=>B($=>$===x.fallback?null:x.fallback),children:u(x.key,x.fallback)},x.key))]}),e.jsxs("div",{className:D.grid,children:[L.map(x=>e.jsxs("div",{className:`${D.card} ${r===x.id?D.cardSelected:""}`,onClick:()=>d==null?void 0:d(x),onMouseEnter:()=>n(x.id),onMouseLeave:()=>n(null),children:[e.jsxs("div",{className:D.thumbnail,children:[x.previewImageUrl?e.jsx("img",{src:x.previewImageUrl,alt:x.name,className:D.thumbnailImg}):e.jsx("div",{className:D.thumbnailPlaceholder,children:e.jsxs("div",{className:D.paperMini,children:[e.jsx("div",{className:D.paperLine,style:{width:"80%"}}),e.jsx("div",{className:D.paperLine,style:{width:"60%"}}),e.jsx("div",{className:D.paperLine,style:{width:"90%"}}),e.jsx("div",{className:D.paperLine,style:{width:"50%"}})]})}),a===x.id&&e.jsxs("div",{className:D.cardOverlay,children:[e.jsx("button",{className:D.overlayBtn,onClick:$=>{$.stopPropagation(),k==null||k(x),_a(x)},title:u("printing.export","Export"),children:e.jsx(_.NiceIcon,{name:"download",size:14})}),f&&e.jsx("button",{className:D.overlayBtnDanger,onClick:$=>{$.stopPropagation(),f(x.id)},title:u("printing.action.remove","Remove"),children:e.jsx(_.NiceIcon,{name:"trash",size:14})})]})]}),e.jsxs("div",{className:D.cardBody,children:[e.jsx("div",{className:D.cardName,children:x.name}),x.description&&e.jsx("div",{className:D.cardDesc,children:x.description}),e.jsxs("div",{className:D.cardMeta,children:[e.jsxs("span",{className:D.cardSize,children:[x.paperSize," ",x.orientation==="landscape"?u("printing.orientation.landscape","landscape"):u("printing.orientation.portrait","portrait")]}),x.category&&e.jsx("span",{className:D.cardCat,children:x.category})]}),x.tags&&x.tags.length>0&&e.jsx("div",{className:D.cardTags,children:x.tags.slice(0,3).map($=>e.jsx("span",{className:D.cardTag,children:$},$))})]})]},x.id)),L.length===0&&e.jsxs("div",{className:D.emptyState,children:[e.jsx("span",{className:D.emptyIcon,children:e.jsx(_.NiceIcon,{name:"file",size:32})}),e.jsx("span",{children:i?`${u("printing.noMatches","No matches for")} "${i}"`:u("printing.noTemplates","No templates yet.")})]})]})]})},ba="_root_18ja1_1",xa="_dark_18ja1_19",ya="_headerBar_18ja1_31",fa="_entityNav_18ja1_59",ja="_navBtn_18ja1_69",va="_navLabel_18ja1_103",Na="_sampleBadge_18ja1_117",wa="_zoomBar_18ja1_135",ka="_zoomBtn_18ja1_147",Sa="_zoomLabel_18ja1_179",Ia="_printBtn_18ja1_193",Ca="_canvas_18ja1_223",Ba="_page_18ja1_243",La="_watermark_18ja1_269",Ta="_footerBar_18ja1_299",H={root:ba,dark:xa,headerBar:ya,entityNav:fa,navBtn:ja,navLabel:va,sampleBadge:Na,zoomBar:wa,zoomBtn:ka,zoomLabel:Sa,printBtn:Ia,canvas:Ca,page:Ba,watermark:La,footerBar:Ta},V=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 za(s,r){try{return s.split(".").reduce((d,o)=>d&&typeof d=="object"?d[o]:null,r)}catch{return null}}function Da(s,r,d){if(s==null)return"";if(r==="date"&&d)try{const o=new Date(s);if(d==="DD.MM.YYYY"){const k=String(o.getDate()).padStart(2,"0"),f=String(o.getMonth()+1).padStart(2,"0");return`${k}.${f}.${o.getFullYear()}`}return o.toLocaleDateString()}catch{return String(s)}if(r==="currency"&&d){const o=Number(s);if(!isNaN(o))return`${o.toFixed(2)} ${d}`}return r==="number"&&typeof s=="number"?s.toLocaleString("pl-PL"):String(s)}const $a=({field:s,data:r,zoom:d})=>{const o=s.dataPath?za(s.dataPath,r):null,k=o!=null?Da(o,s.type,s.format):s.fallback??"",f=h=>h*d*V,g={position:"absolute",left:f(s.position.x),top:f(s.position.y),width:f(s.position.width),height:f(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?f(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"&&o?e.jsx("div",{style:g,children:e.jsx("img",{src:String(o),alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}})}):s.type==="barcode"||s.type==="qr"?e.jsxs("div",{style:{...g,background:"var(--nice-bg-secondary, #f8fafc)",border:"1px dashed var(--nice-border-color, #e2e8f0)",alignItems:"center",justifyContent:"center",fontSize:10*d},children:[e.jsx(_.NiceIcon,{name:s.type==="qr"?"qr-code":"barcode",size:12*d})," ",k]}):s.type==="signature"?e.jsx("div",{style:{...g,borderBottom:"1px solid var(--nice-border-color, #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:{...g,borderBottom:`${s.style.borderWidth??1}px ${s.style.borderStyle??"solid"} ${s.style.borderColor??"var(--nice-text-primary, #0f172a)"}`}}):e.jsx("div",{style:g,children:k})},Ra=({template:s,data:r,zoom:d})=>{var h;const[o,k]=(()=>{const[b,N]=Se[s.paperSize]??Se.A4;return s.orientation==="landscape"?[N*V*d,b*V*d]:[b*V*d,N*V*d]})(),f=s.margins,g=s.sections.flatMap(b=>b.fields);return e.jsxs("div",{className:H.page,style:{width:o,minHeight:k},children:[e.jsx("div",{style:{position:"absolute",top:f.top*d*V,left:f.left*d*V,right:f.right*d*V,bottom:f.bottom*d*V},children:g.map(b=>e.jsx($a,{field:b,data:r,zoom:d},b.id))}),(h=s.watermarks)==null?void 0:h.map(b=>e.jsx("div",{className:H.watermark,style:{opacity:b.opacity,transform:`rotate(${b.angle}deg)`,fontSize:(b.fontSize??48)*d},children:b.type==="text"?b.text:e.jsx("img",{src:b.imageUrl,alt:"wm",style:{maxWidth:200*d}})},b.id))]})},Ea=({template:s,entities:r=[],sampleData:d,onPrint:o,className:k,style:f,theme:g="light",asPopup:h=!0,open:b,onClose:N})=>{const{t:u}=_.useNiceTranslation(),[i,w]=j.useState(0),[I,B]=j.useState(.8),[a,n]=j.useState(!0),c=b!==void 0,p=c?b:a,L=()=>{c||n(!1),N==null||N()};j.useEffect(()=>{if(!h||!p)return;const E=O=>{O.key==="Escape"&&L()};return document.addEventListener("keydown",E),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",E),document.body.style.overflow=""}},[h,p]);const x=j.useMemo(()=>r.length>0?r:d?[d.data]:[{}],[r,d]),$=x[i]??{};if(h&&!p)return null;const T=e.jsxs("div",{className:`${H.root} ${g==="dark"?H.dark:""} ${k??""}`,style:f,children:[e.jsxs("div",{className:H.headerBar,children:[e.jsxs("div",{className:H.entityNav,children:[x.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:H.navBtn,disabled:i===0,onClick:()=>w(E=>E-1),children:"‹"}),e.jsxs("span",{className:H.navLabel,children:[i+1," / ",x.length]}),e.jsx("button",{className:H.navBtn,disabled:i>=x.length-1,onClick:()=>w(E=>E+1),children:"›"})]}),r.length===0&&d&&e.jsx("span",{className:H.sampleBadge,children:u("printing.sampleData","Sample data")})]}),e.jsxs("div",{className:H.zoomBar,children:[e.jsx("button",{className:H.zoomBtn,onClick:()=>B(E=>Math.max(.3,E-.1)),children:"−"}),e.jsxs("span",{className:H.zoomLabel,children:[Math.round(I*100),"%"]}),e.jsx("button",{className:H.zoomBtn,onClick:()=>B(E=>Math.min(2.5,E+.1)),children:"+"}),e.jsx("button",{className:H.zoomBtn,onClick:()=>B(.8),title:u("printing.fit","Fit"),children:"⊡"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:H.printBtn,onClick:()=>o==null?void 0:o({copies:1,printerId:""}),children:u("printPreview.print","Print")}),h&&e.jsx("button",{type:"button",className:H.zoomBtn,onClick:L,"aria-label":u("close","Close"),title:u("close","Close"),children:e.jsx(_.NiceIcon,{name:"close",size:16})})]})]}),e.jsx("div",{className:H.canvas,children:e.jsx(Ra,{template:s,data:$,zoom:I})}),e.jsxs("div",{className:H.footerBar,children:[e.jsx("span",{children:s.name}),e.jsxs("span",{children:[s.paperSize," ·"," ",s.orientation==="portrait"?u("printing.portrait","Portrait"):u("printing.landscape","Landscape")]}),s.sections.reduce((E,O)=>E+O.fields.length,0)," ",u("printing.fields","fields")]})]});if(!h)return T;const z=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:E=>{E.target===E.currentTarget&&L()},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:T})});return Oe.createPortal(z,document.body)},Aa="_root_1f4bm_1",Ma="_dark_1f4bm_23",Pa="_statsBar_1f4bm_37",Fa="_stat_1f4bm_37",Ha="_dot_1f4bm_75",Ga="_statPrinting_1f4bm_87",Oa="_statQueued_1f4bm_93",qa="_statDone_1f4bm_99",Wa="_statError_1f4bm_105",Ya="_toolbar_1f4bm_115",Ua="_filterTabs_1f4bm_139",Va="_filterTab_1f4bm_139",Xa="_filterTabActive_1f4bm_177",Ka="_filterCount_1f4bm_187",Ja="_bulkActions_1f4bm_211",Qa="_bulkCount_1f4bm_223",Za="_bulkBtn_1f4bm_231",ei="_bulkBtnRemove_1f4bm_255",ti="_jobList_1f4bm_273",si="_listHeader_1f4bm_281",ni="_headerLabel_1f4bm_313",ai="_jobRow_1f4bm_323",ii="_jobRowSelected_1f4bm_359",ri="_jobCheckbox_1f4bm_373",oi="_statusBadge_1f4bm_387",li="_pulse_1f4bm_1",ci="_jobInfo_1f4bm_479",di="_jobName_1f4bm_485",mi="_jobMeta_1f4bm_497",pi="_jobTime_1f4bm_513",ui="_jobDuration_1f4bm_519",hi="_jobError_1f4bm_525",_i="_progressBar_1f4bm_539",gi="_progressFill_1f4bm_553",bi="_copiesEditor_1f4bm_569",xi="_copiesBtn_1f4bm_581",yi="_copiesValue_1f4bm_621",fi="_jobActions_1f4bm_635",ji="_actionBtn_1f4bm_645",vi="_removeBtn_1f4bm_677",Ni="_emptyState_1f4bm_695",v={root:Aa,dark:Ma,statsBar:Pa,stat:Fa,dot:Ha,statPrinting:Ga,statQueued:Oa,statDone:qa,statError:Wa,toolbar:Ya,filterTabs:Ua,filterTab:Va,filterTabActive:Xa,filterCount:Ka,bulkActions:Ja,bulkCount:Qa,bulkBtn:Za,bulkBtnRemove:ei,jobList:ti,listHeader:si,headerLabel:ni,jobRow:ai,jobRowSelected:ii,jobCheckbox:ri,statusBadge:oi,"badge-queued":"_badge-queued_1f4bm_405","badge-printing":"_badge-printing_1f4bm_413",pulse:li,"badge-done":"_badge-done_1f4bm_423","badge-error":"_badge-error_1f4bm_431","badge-paused":"_badge-paused_1f4bm_439","badge-cancelled":"_badge-cancelled_1f4bm_447",jobInfo:ci,jobName:di,jobMeta:mi,jobTime:pi,jobDuration:ui,jobError:hi,progressBar:_i,progressFill:gi,copiesEditor:bi,copiesBtn:xi,copiesValue:yi,jobActions:fi,actionBtn:ji,removeBtn:vi,emptyState:Ni},wi=[],Ie={queued:"Queued",printing:"Printing",done:"Printed",error:"Error",paused:"Paused",cancelled:"Cancelled"},xe=(s,r)=>Ie[r]?s(`printing.status.${r}`,Ie[r]):r;function ki(s,r){try{return new Date(r).toLocaleTimeString(s,{hour:"2-digit",minute:"2-digit"})}catch{return r}}function Si(s){const r=Math.floor((Date.now()-new Date(s).getTime())/1e3);if(r<60)return`${r}s`;const d=Math.floor(r/60);if(d<60)return`${d}m ${r%60}s`;const o=Math.floor(d/60);return o<24?`${o}h ${d%60}m`:`${Math.floor(o/24)}d ${o%24}h`}const Ii=({jobs:s})=>{const{t:r}=_.useNiceTranslation(),d=s.filter(g=>g.status==="printing").length,o=s.filter(g=>g.status==="queued").length,k=s.filter(g=>g.status==="done").length,f=s.filter(g=>g.status==="error").length;return e.jsxs("div",{className:v.statsBar,children:[e.jsxs("span",{className:`${v.stat} ${v.statPrinting}`,children:[e.jsx("span",{className:v.dot}),r("printing.stats.active","Printing"),": ",e.jsx("strong",{children:d})]}),e.jsxs("span",{className:`${v.stat} ${v.statQueued}`,children:[e.jsx("span",{className:v.dot}),r("printing.stats.queued","In queue"),": ",e.jsx("strong",{children:o})]}),e.jsxs("span",{className:`${v.stat} ${v.statDone}`,children:[e.jsx("span",{className:v.dot}),r("printing.stats.done","Done"),": ",e.jsx("strong",{children:k})]}),f>0&&e.jsxs("span",{className:`${v.stat} ${v.statError}`,children:[e.jsx("span",{className:v.dot}),r("printing.stats.errors","Errors"),": ",e.jsx("strong",{children:f})]})]})},Ci=({job:s,index:r,total:d,printers:o,selected:k,onSelect:f,onUpdate:g,onRemove:h,onPrint:b,onReorder:N})=>{const{t:u,lang:i}=_.useNiceTranslation(),w=o.find(a=>a.id===s.options.printerId),I=r>0&&s.status==="queued",B=r<d-1&&s.status==="queued";return e.jsxs("div",{className:`${v.jobRow} ${k?v.jobRowSelected:""} ${v[`status-${s.status}`]??""}`,children:[e.jsx("input",{type:"checkbox",className:v.jobCheckbox,checked:k,onChange:()=>f(s.id)}),e.jsx("span",{className:`${v.statusBadge} ${v[`badge-${s.status}`]}`,children:xe(u,s.status)}),e.jsxs("div",{className:v.jobInfo,children:[e.jsx("div",{className:v.jobName,children:s.templateName??s.templateId}),e.jsxs("div",{className:v.jobMeta,children:[s.entityLabel&&e.jsx("span",{children:s.entityLabel}),w&&e.jsxs("span",{children:[e.jsx(_.NiceIcon,{name:"printer",size:12})," ",w.name]}),e.jsxs("span",{children:["×",s.options.copies]}),s.createdAt&&e.jsx("span",{className:v.jobTime,children:ki(i,s.createdAt)}),s.startedAt&&s.status!=="done"&&e.jsx("span",{className:v.jobDuration,children:Si(s.startedAt)})]}),s.status==="printing"&&s.progress!=null&&e.jsx("div",{className:v.progressBar,children:e.jsx("div",{className:v.progressFill,style:{width:`${s.progress}%`}})}),s.status==="error"&&s.errorMessage&&e.jsx("div",{className:v.jobError,children:s.errorMessage})]}),e.jsxs("div",{className:v.copiesEditor,children:[e.jsx("button",{className:v.copiesBtn,disabled:s.options.copies<=1,"aria-label":u("printing.copies.decrease","One copy fewer"),onClick:()=>g(s.id,{options:{...s.options,copies:s.options.copies-1}}),children:e.jsx(_.NiceIcon,{name:"minus",size:12})}),e.jsx("span",{className:v.copiesValue,children:s.options.copies}),e.jsx("button",{className:v.copiesBtn,"aria-label":u("printing.copies.increase","One copy more"),onClick:()=>g(s.id,{options:{...s.options,copies:s.options.copies+1}}),children:e.jsx(_.NiceIcon,{name:"plus",size:12})})]}),e.jsxs("div",{className:v.jobActions,children:[I&&e.jsx("button",{className:v.actionBtn,title:u("printing.action.moveUp","Move up"),onClick:()=>N(r,r-1),children:e.jsx(_.NiceIcon,{name:"arrow-up",size:14})}),B&&e.jsx("button",{className:v.actionBtn,title:u("printing.action.moveDown","Move down"),onClick:()=>N(r,r+1),children:e.jsx(_.NiceIcon,{name:"arrow-down",size:14})}),s.status==="queued"&&e.jsx("button",{className:v.actionBtn,title:u("printing.action.printNow","Print now"),onClick:()=>b(s.id),children:e.jsx(_.NiceIcon,{name:"play",size:14})}),s.status==="printing"&&e.jsx("button",{className:v.actionBtn,title:u("printing.action.pause","Pause"),onClick:()=>g(s.id,{status:"paused"}),children:e.jsx(_.NiceIcon,{name:"pause",size:14})}),s.status==="paused"&&e.jsx("button",{className:v.actionBtn,title:u("printing.action.resume","Resume"),onClick:()=>g(s.id,{status:"queued"}),children:e.jsx(_.NiceIcon,{name:"play",size:14})}),e.jsx("button",{className:`${v.actionBtn} ${v.removeBtn}`,title:u("printing.action.remove","Remove"),onClick:()=>h(s.id),children:e.jsx(_.NiceIcon,{name:"close",size:14})})]})]})},Bi=({jobs:s=wi,printers:r=[],onJobUpdate:d,onJobRemove:o,onJobReorder:k,onJobPrint:f,onBulkRemove:g,onBulkPrint:h,maxHeight:b=500,className:N,style:u,theme:i="light"})=>{const{t:w}=_.useNiceTranslation(),[I,B]=j.useState(new Set),[a,n]=j.useState("all"),c=a==="all"?s:s.filter(T=>T.status===a),p=j.useCallback(T=>{B(z=>{const E=new Set(z);return E.has(T)?E.delete(T):E.add(T),E})},[]),L=j.useCallback(()=>{I.size===c.length?B(new Set):B(new Set(c.map(T=>T.id)))},[c,I.size]),x=j.useCallback(()=>{g==null||g(Array.from(I)),B(new Set)},[I,g]),$=j.useCallback(()=>{h==null||h(Array.from(I)),B(new Set)},[I,h]);return e.jsxs("div",{className:`${v.root} ${i==="dark"?v.dark:""} ${N??""}`,style:u,children:[e.jsx(Ii,{jobs:s}),e.jsxs("div",{className:v.toolbar,children:[e.jsx("div",{className:v.filterTabs,children:["all","queued","printing","done","error"].map(T=>e.jsxs("button",{className:`${v.filterTab} ${a===T?v.filterTabActive:""}`,onClick:()=>n(T),children:[T==="all"?w("printing.filter.all","All"):xe(w,T),e.jsx("span",{className:v.filterCount,children:T==="all"?s.length:s.filter(z=>z.status===T).length})]},T))}),I.size>0&&e.jsxs("div",{className:v.bulkActions,children:[e.jsxs("span",{className:v.bulkCount,children:[I.size," ",w("printing.bulk.selected","selected")]}),h&&e.jsxs("button",{className:v.bulkBtn,onClick:$,children:[e.jsx(_.NiceIcon,{name:"printer",size:14})," ",w("printing.bulk.print","Print selected")]}),g&&e.jsxs("button",{className:`${v.bulkBtn} ${v.bulkBtnRemove}`,onClick:x,children:[e.jsx(_.NiceIcon,{name:"trash",size:14})," ",w("printing.bulk.remove","Remove selected")]})]})]}),e.jsx("div",{className:v.jobList,style:{maxHeight:b},children:c.length===0?e.jsx("div",{className:v.emptyState,children:a==="all"?w("printing.empty.queue","No jobs in the queue"):`${w("printing.empty.filtered","No jobs with status")} "${xe(w,a)}"`}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:v.listHeader,children:[e.jsx("input",{type:"checkbox",onChange:L,checked:I.size===c.length&&c.length>0}),e.jsx("span",{className:v.headerLabel,children:w("printing.col.job","Job")}),e.jsx("span",{className:v.headerLabel,children:w("printing.col.copies","Copies")}),e.jsx("span",{className:v.headerLabel,children:w("printing.col.actions","Actions")})]}),c.map((T,z)=>e.jsx(Ci,{job:T,index:s.indexOf(T),total:s.length,printers:r,selected:I.has(T.id),onSelect:p,onUpdate:d,onRemove:o,onPrint:f,onReorder:k},T.id))]})})]})},Li="_container_1f76z_1",Ti="_buttonGroup_1f76z_19",zi="_trigger_1f76z_31",Di="_triggerDisabled_1f76z_57",$i="_mainAction_1f76z_151",Ri="_dropdownToggle_1f76z_175",Ei="_chevron_1f76z_201",Ai="_chevronUp_1f76z_211",Mi="_dropdown_1f76z_175",Pi="_dark_1f76z_245",Fi="_section_1f76z_257",Hi="_sectionLabel_1f76z_263",Gi="_divider_1f76z_283",Oi="_copiesRow_1f76z_301",qi="_copiesBtn_1f76z_311",Wi="_copiesValue_1f76z_351",Yi="_printerSelect_1f76z_375",Ui="_printerStatus_1f76z_415",Vi="_printerDot_1f76z_429",Xi="_printerStatusLabel_1f76z_463",Ki="_submitBtn_1f76z_473",Ji="_spinner_1f76z_515",Qi="_spin_1f76z_515",R={container:Li,buttonGroup:Ti,trigger:zi,triggerDisabled:Di,"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:$i,dropdownToggle:Ri,chevron:Ei,chevronUp:Ai,dropdown:Mi,dark:Pi,section:Fi,sectionLabel:Hi,divider:Gi,copiesRow:Oi,copiesBtn:qi,copiesValue:Wi,printerSelect:Yi,printerStatus:Ui,printerDot:Vi,"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:Xi,submitBtn:Ki,spinner:Ji,spin:Qi},Zi=({onPrint:s,printers:r=[],defaultPrinterId:d,defaultCopies:o=1,disabled:k=!1,loading:f=!1,variant:g="primary",size:h="md",label:b,className:N,style:u,theme:i="light"})=>{var X;const{t:w}=_.useNiceTranslation(),I=b??w("printing.print","Print"),[B,a]=j.useState(!1),[n,c]=j.useState(o),[p,L]=j.useState(d??((X=r[0])==null?void 0:X.id)??""),x=j.useRef(null);j.useEffect(()=>{if(!B)return;const y=Y=>{x.current&&!x.current.contains(Y.target)&&a(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[B]);const $=j.useCallback(()=>{s({copies:n,printerId:p}),a(!1)},[n,p,s]),T=j.useCallback(()=>c(y=>Math.min(99,y+1)),[]),z=j.useCallback(()=>c(y=>Math.max(1,y-1)),[]),E=[R.container,i==="dark"?R.dark:"",N??""].filter(Boolean).join(" "),O=[R.trigger,R[`variant-${g}`],R[`size-${h}`],k||f?R.triggerDisabled:""].filter(Boolean).join(" ");return e.jsxs("div",{ref:x,className:E,style:u,children:[e.jsxs("div",{className:R.buttonGroup,children:[e.jsxs("button",{className:`${O} ${R.mainAction}`,disabled:k||f,onClick:$,"aria-label":I,children:[f?e.jsx("span",{className:R.spinner}):e.jsx(_.NiceIcon,{name:"printer",size:16}),e.jsx("span",{children:I})]}),e.jsx("button",{className:`${O} ${R.dropdownToggle}`,disabled:k||f,onClick:()=>a(y=>!y),"aria-label":w("printing.options","Print options"),"aria-expanded":B,children:e.jsx("span",{className:`${R.chevron} ${B?R.chevronUp:""}`,children:e.jsx(_.NiceIcon,{name:"chevron-down",size:12})})})]}),B&&e.jsxs("div",{className:R.dropdown,children:[e.jsxs("div",{className:R.section,children:[e.jsx("label",{className:R.sectionLabel,children:w("printing.copies.label","Copies")}),e.jsxs("div",{className:R.copiesRow,children:[e.jsx("button",{className:R.copiesBtn,onClick:z,disabled:n<=1,"aria-label":w("printing.copies.decrease","One copy fewer"),children:e.jsx(_.NiceIcon,{name:"minus",size:12})}),e.jsx("span",{className:R.copiesValue,children:n}),e.jsx("button",{className:R.copiesBtn,onClick:T,disabled:n>=99,"aria-label":w("printing.copies.increase","One copy more"),children:e.jsx(_.NiceIcon,{name:"plus",size:12})})]})]}),e.jsx("div",{className:R.divider}),r.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:R.section,children:[e.jsx("label",{className:R.sectionLabel,children:w("printing.printer","Printer")}),e.jsx("select",{className:R.printerSelect,value:p,onChange:y=>L(y.target.value),children:r.map(y=>e.jsxs("option",{value:y.id,disabled:y.status==="offline"||!y.isOnline&&y.status==null,children:[y.name," ",y.status==="offline"||!y.isOnline&&y.status==null?w("printing.offline","(Offline)"):y.status==="busy"?`(${w("printing.printerBusyLabel","Busy")})`:""]},y.id))}),r.find(y=>y.id===p)&&e.jsx("div",{className:R.printerStatus,children:(()=>{const y=r.find(me=>me.id===p),Y=y.status??(y.isOnline?"ready":"offline");return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`${R.printerDot} ${R[`dot-${Y}`]}`}),e.jsx("span",{className:R.printerStatusLabel,children:Y==="ready"?w("printing.printerReady","Ready"):Y==="busy"?w("printing.printerBusyLabel","Busy"):Y==="offline"?w("printing.offline2","Offline"):w("printing.printerError","Error")})]})})()})]}),e.jsx("div",{className:R.divider})]}),e.jsx("div",{className:R.section,children:e.jsx("button",{className:R.submitBtn,onClick:$,disabled:k||f||r.length>0&&(()=>{const y=r.find(Y=>Y.id===p);return y!=null&&(y.status==="offline"||!y.isOnline&&y.status==null)})(),children:f?w("printing.printing","Printing…"):e.jsxs(e.Fragment,{children:[e.jsx(_.NiceIcon,{name:"printer",size:14})," ",I,n>1?` (${n})`:""]})})})]})]})};exports.NicePrintButton=Zi;exports.NicePrintPreview=Ea;exports.NicePrintQueue=Bi;exports.NiceTemplateBrowser=ga;exports.NiceTemplateEditor=En;
|