@nice2dev/ui-printing 1.0.28 → 1.0.29

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"),y=require("react"),Pe=require("@nice2dev/ui"),Ae=require("react-dom"),Me="_root_552wg_3",Ee="_dark_552wg_27",Fe="_toolbar_552wg_39",Ge="_toolbarGroup_552wg_75",He="_toolbarBtn_552wg_107",We="_toolbarBtnActive_552wg_167",Oe="_toolbarBtnDanger_552wg_191",Ue="_toolbarSelect_552wg_203",qe="_toolbarSep_552wg_233",Ye="_insertWrapper_552wg_259",Ke="_insertBtn_552wg_267",Ve="_insertDropdown_552wg_289",Ze="_insertCategory_552wg_329",Xe="_insertItem_552wg_347",Qe="_insertIcon_552wg_391",Je="_zoomSelect_552wg_405",et="_saveBtn_552wg_437",tt="_editorBody_552wg_473",st="_leftPanel_552wg_489",at="_leftTabs_552wg_519",nt="_leftTab_552wg_519",lt="_leftTabActive_552wg_591",rt="_leftTabIcon_552wg_611",it="_leftTabLabel_552wg_619",ot="_leftContent_552wg_629",ct="_panelHeader_552wg_643",dt="_panelHeaderIcon_552wg_667",ut="_panelHeaderName_552wg_675",pt="_searchBox_552wg_689",mt="_searchInput_552wg_697",ht="_fieldList_552wg_743",_t="_fieldItem_552wg_753",gt="_fieldItemIcon_552wg_797",yt="_fieldItemInfo_552wg_811",xt="_fieldItemLabel_552wg_821",bt="_fieldItemPath_552wg_837",wt="_fieldItemType_552wg_853",vt="_layerList_552wg_873",jt="_layerItem_552wg_885",Nt="_layerItemSelected_552wg_919",kt="_layerIcon_552wg_937",ft="_layerName_552wg_949",St="_layerActions_552wg_965",Ct="_layerBtn_552wg_987",Bt="_wmList_552wg_1019",It="_wmItem_552wg_1027",Lt="_wmRow_552wg_1053",zt="_wmLabel_552wg_1067",Dt="_wmInput_552wg_1079",Tt="_wmInputNum_552wg_1111",$t="_wmSelect_552wg_1131",Rt="_wmSlider_552wg_1163",Pt="_wmValue_552wg_1173",At="_wmUnit_552wg_1187",Mt="_wmDelete_552wg_1197",Et="_addBtn_552wg_1229",Ft="_settingsForm_552wg_1265",Gt="_settingsRow_552wg_1273",Ht="_settingsLabel_552wg_1287",Wt="_settingsInput_552wg_1299",Ot="_settingsInputNum_552wg_1331",Ut="_settingsTextarea_552wg_1363",qt="_settingsDivider_552wg_1397",Yt="_settingsUnit_552wg_1417",Kt="_emptyMsg_552wg_1429",Vt="_canvasArea_552wg_1447",Zt="_testDataBar_552wg_1473",Xt="_testDataLabel_552wg_1505",Qt="_testDataSelect_552wg_1515",Jt="_rulerWrapper_552wg_1535",es="_rulerCorner_552wg_1551",ts="_ruler_552wg_1535",ss="_ruler_h_552wg_1609",as="_ruler_v_552wg_1619",ns="_rulerTick_552wg_1639",ls="_rulerTickMajor_552wg_1679",rs="_rulerLabel_552wg_1699",is="_paperScroll_552wg_1737",os="_paperShadow_552wg_1755",cs="_marginGuide_552wg_1779",ds="_watermark_552wg_1795",us="_sectionCanvas_552wg_1821",ps="_sectionCanvasOver_552wg_1835",ms="_sectionTypeChip_552wg_1843",hs="_sectionResizeBar_552wg_1875",_s="_sectionResizeGrip_552wg_1909",gs="_fieldImagePlaceholder_552wg_1925",ys="_fieldBarcodePlaceholder_552wg_1947",xs="_fieldSignaturePlaceholder_552wg_1975",bs="_resizeHandle_552wg_2001",ws="_handle_n_552wg_2021",vs="_handle_s_552wg_2023",js="_handle_e_552wg_2025",Ns="_handle_w_552wg_2027",ks="_handle_ne_552wg_2029",fs="_handle_nw_552wg_2031",Ss="_handle_se_552wg_2033",Cs="_handle_sw_552wg_2035",Bs="_rightPanel_552wg_2041",Is="_rightTabs_552wg_2071",Ls="_rightTab_552wg_2071",zs="_rightTabActive_552wg_2135",Ds="_propsBody_552wg_2147",Ts="_propsEmpty_552wg_2159",$s="_propsEmptyIcon_552wg_2181",Rs="_propsEmptyText_552wg_2191",Ps="_posGrid_552wg_2203",As="_posCell_552wg_2217",Ms="_posLabel_552wg_2229",Es="_posInput_552wg_2241",Fs="_posUnit_552wg_2283",Gs="_snapSection_552wg_2295",Hs="_snapTitle_552wg_2303",Ws="_snapRow_552wg_2321",Os="_snapBtn_552wg_2331",Us="_styleGroup_552wg_2365",qs="_styleGroupTitle_552wg_2373",Ys="_styleRow_552wg_2403",Ks="_styleLabel_552wg_2417",Vs="_styleSelect_552wg_2431",Zs="_styleSelectFull_552wg_2461",Xs="_styleSelectSm_552wg_2493",Qs="_styleSelectXs_552wg_2513",Js="_styleInput_552wg_2545",ea="_styleInputFull_552wg_2577",ta="_styleUnit_552wg_2609",sa="_styleValue_552wg_2621",aa="_toggleGroup_552wg_2635",na="_toggleBtn_552wg_2645",la="_toggleBtnActive_552wg_2675",ra="_colorPicker_552wg_2689",ia="_colorHex_552wg_2707",oa="_clearBtn_552wg_2741",ca="_sliderInput_552wg_2773",da="_conditionalHint_552wg_2785",ua="_clearConditionalBtn_552wg_2817",pa="_shortcutGrid_552wg_2849",ma="_shortcutChip_552wg_2863",ha="_shortcutKeys_552wg_2895",_a="_shortcutLabel_552wg_2915",t={root:Me,dark:Ee,toolbar:Fe,toolbarGroup:Ge,toolbarBtn:He,toolbarBtnActive:We,toolbarBtnDanger:Oe,toolbarSelect:Ue,toolbarSep:qe,insertWrapper:Ye,insertBtn:Ke,insertDropdown:Ve,insertCategory:Ze,insertItem:Xe,insertIcon:Qe,zoomSelect:Je,saveBtn:et,editorBody:tt,leftPanel:st,leftTabs:at,leftTab:nt,leftTabActive:lt,leftTabIcon:rt,leftTabLabel:it,leftContent:ot,panelHeader:ct,panelHeaderIcon:dt,panelHeaderName:ut,searchBox:pt,searchInput:mt,fieldList:ht,fieldItem:_t,fieldItemIcon:gt,fieldItemInfo:yt,fieldItemLabel:xt,fieldItemPath:bt,fieldItemType:wt,layerList:vt,layerItem:jt,layerItemSelected:Nt,layerIcon:kt,layerName:ft,layerActions:St,layerBtn:Ct,wmList:Bt,wmItem:It,wmRow:Lt,wmLabel:zt,wmInput:Dt,wmInputNum:Tt,wmSelect:$t,wmSlider:Rt,wmValue:Pt,wmUnit:At,wmDelete:Mt,addBtn:Et,settingsForm:Ft,settingsRow:Gt,settingsLabel:Ht,settingsInput:Wt,settingsInputNum:Ot,settingsTextarea:Ut,settingsDivider:qt,settingsUnit:Yt,emptyMsg:Kt,canvasArea:Vt,testDataBar:Zt,testDataLabel:Xt,testDataSelect:Qt,rulerWrapper:Jt,rulerCorner:es,ruler:ts,ruler_h:ss,ruler_v:as,rulerTick:ns,rulerTickMajor:ls,rulerLabel:rs,paperScroll:is,paperShadow:os,marginGuide:cs,watermark:ds,sectionCanvas:us,sectionCanvasOver:ps,sectionTypeChip:ms,sectionResizeBar:hs,sectionResizeGrip:_s,fieldImagePlaceholder:gs,fieldBarcodePlaceholder:ys,fieldSignaturePlaceholder:xs,resizeHandle:bs,handle_n:ws,handle_s:vs,handle_e:js,handle_w:Ns,handle_ne:ks,handle_nw:fs,handle_se:Ss,handle_sw:Cs,rightPanel:Bs,rightTabs:Is,rightTab:Ls,rightTabActive:zs,propsBody:Ds,propsEmpty:Ts,propsEmptyIcon:$s,propsEmptyText:Rs,posGrid:Ps,posCell:As,posLabel:Ms,posInput:Es,posUnit:Fs,snapSection:Gs,snapTitle:Hs,snapRow:Ws,snapBtn:Os,styleGroup:Us,styleGroupTitle:qs,styleRow:Ys,styleLabel:Ks,styleSelect:Vs,styleSelectFull:Zs,styleSelectSm:Xs,styleSelectXs:Qs,styleInput:Js,styleInputFull:ea,styleUnit:ta,styleValue:sa,toggleGroup:aa,toggleBtn:na,toggleBtnActive:la,colorPicker:ra,colorHex:ia,clearBtn:oa,sliderInput:ca,conditionalHint:da,clearConditionalBtn:ua,shortcutGrid:pa,shortcutChip:ma,shortcutKeys:ha,shortcutLabel:_a},G=3.78,ge={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432],custom:[210,297]},ga=["sans-serif","serif","monospace","Arial","Times New Roman","Courier New","Georgia","Verdana","Tahoma"],ye=[6,7,8,9,10,11,12,14,16,18,20,24,28,32,36,48,60,72],le={text:"📝",number:"#",currency:"€",date:"📅",datetime:"🕐",boolean:"✓",image:"🖼",barcode:"▮▌▮",qr:"⬛",signature:"✍",static_text:"T",static_image:"🖼",line:"─",rect:"▭",page_number:"#p",total_pages:"#pp",print_date:"📅"},re={text:"Tekst",number:"Liczba",currency:"Waluta",date:"Data",datetime:"Data i czas",boolean:"Tak/Nie",image:"Obraz",barcode:"Kod kreskowy",qr:"QR",signature:"Podpis",static_text:"Tekst stały",static_image:"Obraz stały",line:"Linia",rect:"Prostokąt",page_number:"Numer strony",total_pages:"Liczba stron",print_date:"Data wydruku"};function ya(s,r){switch(r.type){case"UPDATE":return{past:[...s.past.slice(-50),s.present],present:r.payload,future:[]};case"UNDO":return s.past.length?{past:s.past.slice(0,-1),present:s.past[s.past.length-1],future:[s.present,...s.future]}:s;case"REDO":return s.future.length?{past:[...s.past,s.present],present:s.future[0],future:s.future.slice(1)}:s;default:return s}}function te(){return`f-${Date.now()}-${Math.floor(Math.random()*1e3)}`}function xe(s,r){const d={id:te(),name:(r==null?void 0:r.label)??re[s]??s,label:(r==null?void 0:r.label)??re[s]??s,type:s,dataPath:(r==null?void 0:r.path)??"",fallback:s==="static_text"?"Tekst statyczny":void 0,format:s==="date"||s==="datetime"?"DD.MM.YYYY":void 0,position:{x:15,y:15,width:s==="line"?80:60,height:s==="line"?1:s==="image"?30:8},style:{fontSize:10,color:"var(--nice-text, #000000)",fontFamily:"sans-serif"}};return s==="rect"&&(d.style.backgroundColor="var(--nice-bg-secondary, #f1f5f9)"),s==="line"&&(d.style={...d.style,borderWidth:.5,borderColor:"var(--nice-text, #000000)",borderStyle:"solid"}),d}const be=({lengthMm:s,zoom:r,orientation:d})=>{const l=[],N=r<.6?20:r<1?10:5;for(let m=0;m<=s;m+=N){const k=m*r*G,x=m%(N*2)===0;l.push(e.jsx("div",{className:`${t.rulerTick} ${x?t.rulerTickMajor:""}`,style:d==="h"?{left:k}:{top:k},children:x&&e.jsx("span",{className:t.rulerLabel,children:m})},m))}return e.jsx("div",{className:`${t.ruler} ${t[`ruler_${d}`]}`,children:l})},xa=["n","s","e","w","ne","nw","se","sw"],ba=({onResizeStart:s})=>e.jsx(e.Fragment,{children:xa.map(r=>e.jsx("div",{className:`${t.resizeHandle} ${t[`handle_${r}`]}`,onMouseDown:d=>{d.stopPropagation(),s(r,d)}},r))});function wa(s,r){if(s.type==="static_text")return s.fallback??"Tekst";if(s.type==="page_number")return"1";if(s.type==="total_pages")return"3";if(s.type==="print_date")return new Date().toLocaleDateString("pl-PL");if(r&&s.dataPath){const d=s.dataPath.split(".").reduce((l,N)=>l&&typeof l=="object"?l[N]:null,r);if(d!=null)return String(d)}return s.label?`{${s.label}}`:`{${s.dataPath}}`}const va=({field:s,zoom:r,selected:d,sampleData:l,onClick:N,onDragStart:m,onResizeStart:k,readOnly:x})=>{const _=s.position,w=s.style,o=u=>u*r*G,D=s.type==="line",v=s.type==="rect",n=s.type==="image"||s.type==="static_image",a=s.type==="barcode"||s.type==="qr",p={position:"absolute",left:o(_.x),top:o(_.y),width:o(_.width),height:o(_.height),zIndex:_.zIndex??1,transform:w.rotation?`rotate(${w.rotation}deg)`:void 0,boxSizing:"border-box",overflow:"hidden",...!D&&!v?{fontSize:(w.fontSize??10)*r,fontFamily:w.fontFamily??"sans-serif",fontWeight:w.fontWeight??"normal",fontStyle:w.fontStyle??"normal",color:w.color??"var(--nice-text, #000)",textAlign:w.textAlign??"left",lineHeight:w.lineHeight??1.4,letterSpacing:w.letterSpacing?`${w.letterSpacing}em`:void 0,padding:w.padding?o(w.padding):0}:{},backgroundColor:w.backgroundColor,borderWidth:w.borderWidth??0,borderColor:w.borderColor??"transparent",borderStyle:w.borderStyle??"solid",borderRadius:w.borderRadius,opacity:w.opacity,outline:d?"1.5px solid var(--nice-primary-hover, #2563eb)":"1px dashed transparent",outlineOffset:1,cursor:x?"default":"move"};return e.jsxs("div",{style:p,onClick:N,onMouseDown:x?void 0:m,children:[D?e.jsx("div",{style:{width:"100%",borderBottom:`${(w.borderWidth??.5)*r}px ${w.borderStyle??"solid"} ${w.borderColor??"var(--nice-text, #000)"}`}}):v?null:n?e.jsx("div",{className:t.fieldImagePlaceholder,children:"🖼"}):a?e.jsx("div",{className:t.fieldBarcodePlaceholder,children:s.type==="qr"?"⬛ QR":"▮▌▮ Barcode"}):s.type==="signature"?e.jsxs("div",{className:t.fieldSignaturePlaceholder,children:["✍ ",s.label]}):e.jsx("span",{style:{display:"block",width:"100%"},children:wa(s,l)}),d&&!x&&e.jsx(ba,{onResizeStart:k})]})},ja=({section:s,zoom:r,paperWidthMm:d,selectedIds:l,sampleData:N,readOnly:m,showGrid:k,onFieldClick:x,onFieldDragStart:_,onResizeStart:w,onSectionHeightChange:o,onDropField:D})=>{const v=(s.heightMm??(s.type==="body"?200:40))*r*G,n=d*r*G,[a,p]=y.useState(!1),u={header:"rgba(219,234,254,0.35)",footer:"rgba(220,252,231,0.35)",background:"rgba(254,249,195,0.35)",body:"transparent"};return e.jsxs("div",{className:`${t.sectionCanvas} ${a?t.sectionCanvasOver:""}`,style:{width:n,height:v,position:"relative",background:u[s.type]??"transparent",backgroundImage:k?`repeating-linear-gradient(0deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*r*G}px),
2
- repeating-linear-gradient(90deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*r*G}px)`:void 0},onDragOver:j=>{j.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:j=>{j.preventDefault(),p(!1);const z=j.dataTransfer.getData("fieldPath");if(!z)return;const g=j.currentTarget.getBoundingClientRect(),I=(j.clientX-g.left)/(r*G),C=(j.clientY-g.top)/(r*G);D(s.id,z,Math.max(0,I),Math.max(0,C))},children:[e.jsx("div",{className:t.sectionTypeChip,children:s.type}),s.fields.map(j=>e.jsx(va,{field:j,zoom:r,selected:l.has(j.id),sampleData:N,readOnly:m,onClick:z=>x(j.id,z),onDragStart:z=>_(j.id,z),onResizeStart:(z,g)=>w(j.id,z,g)},j.id)),!m&&s.type!=="body"&&e.jsx("div",{className:t.sectionResizeBar,onMouseDown:j=>{j.preventDefault();const z=j.clientY,g=s.heightMm??40,I=P=>{const A=(P.clientY-z)/(r*G);o(s.id,Math.max(10,g+A))},C=()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",I),document.addEventListener("mouseup",C)},children:e.jsx("div",{className:t.sectionResizeGrip})})]})},ee=({keys:s,label:r})=>e.jsxs("div",{className:t.shortcutChip,children:[e.jsx("span",{className:t.shortcutKeys,children:s}),e.jsx("span",{className:t.shortcutLabel,children:r})]}),Na=[{id:"fields",icon:"📝",label:"Pola"},{id:"layers",icon:"◧",label:"Warstwy"},{id:"watermarks",icon:"💧",label:"Znaki"},{id:"signatures",icon:"✍",label:"Podpisy"},{id:"settings",icon:"⚙",label:"Ustawienia"}],ka=[{id:"position",label:"Pozycja"},{id:"style",label:"Styl"},{id:"data",label:"Dane"},{id:"conditional",label:"Warunki"}],fa=({tpl:s,zoom:r,canUndo:d,canRedo:l,showGrid:N,showRulers:m,readOnly:k,selectedCount:x,onPaperChange:_,onZoom:w,onUndo:o,onRedo:D,onToggleGrid:v,onToggleRulers:n,onInsert:a,onDelete:p,onDuplicate:u,onAlignH:j,onAlignV:z,onBringForward:g,onSendBackward:I,onSave:C})=>{const[P,A]=y.useState(!1),R=[.5,.75,1,1.25,1.5,2];return e.jsxs("div",{className:t.toolbar,children:[e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("select",{className:t.toolbarSelect,value:s.paperSize,onChange:h=>_(h.target.value,s.orientation),children:["A4","A5","A3","Letter","Legal","Tabloid","custom"].map(h=>e.jsx("option",{value:h,children:h},h))}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="portrait"?t.toolbarBtnActive:""}`,onClick:()=>_(s.paperSize,"portrait"),title:"Pion",children:"⬜"}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="landscape"?t.toolbarBtnActive:""}`,onClick:()=>_(s.paperSize,"landscape"),title:"Poziom",children:"▭"})]}),!k&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,disabled:!d,onClick:o,title:"Cofnij (Ctrl+Z)",children:"↩"}),e.jsx("button",{className:t.toolbarBtn,disabled:!l,onClick:D,title:"Ponów (Ctrl+Y)",children:"↪"})]}),!k&&e.jsxs("div",{className:t.insertWrapper,children:[e.jsx("button",{className:`${t.toolbarBtn} ${t.insertBtn}`,onClick:()=>A(h=>!h),children:"+ Wstaw ▾"}),P&&e.jsxs("div",{className:t.insertDropdown,onMouseLeave:()=>A(!1),children:[e.jsx("div",{className:t.insertCategory,children:"Pola danych"}),["text","number","currency","date","image","barcode","qr"].map(h=>e.jsxs("button",{className:t.insertItem,onClick:()=>{a(h),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:le[h]}),re[h]]},h)),e.jsx("div",{className:t.insertCategory,children:"Elementy statyczne"}),["static_text","static_image","line","rect","page_number","total_pages","print_date"].map(h=>e.jsxs("button",{className:t.insertItem,onClick:()=>{a(h),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:le[h]}),re[h]]},h)),e.jsx("div",{className:t.insertCategory,children:"Specjalne"}),e.jsxs("button",{className:t.insertItem,onClick:()=>{a("watermark"),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:"💧"}),"Znak wodny"]}),e.jsxs("button",{className:t.insertItem,onClick:()=>{a("signature"),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:"✍"}),"Podpis"]})]})]}),!k&&x>0&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:u,title:"Duplikuj (Ctrl+D)",children:"⧉"}),e.jsx("button",{className:`${t.toolbarBtn} ${t.toolbarBtnDanger}`,onClick:p,title:"Usuń (Del)",children:"🗑"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j("left"),title:"Wyrównaj lewo",children:"⬛□□"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j("center"),title:"Wyśrodkuj",children:"□⬛□"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j("right"),title:"Wyrównaj prawo",children:"□□⬛"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("top"),title:"Góra",children:"⊤"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("center"),title:"Środek V",children:"⊕"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("bottom"),title:"Dół",children:"⊥"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:g,title:"Do przodu",children:"▲"}),e.jsx("button",{className:t.toolbarBtn,onClick:I,title:"Do tyłu",children:"▼"})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:`${t.toolbarBtn} ${N?t.toolbarBtnActive:""}`,onClick:v,title:"Siatka",children:"⊞"}),e.jsx("button",{className:`${t.toolbarBtn} ${m?t.toolbarBtnActive:""}`,onClick:n,title:"Linijki",children:"⊢"})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:()=>w(Math.max(.25,r-.1)),children:"−"}),e.jsx("select",{className:t.zoomSelect,value:R.includes(r)?r:"",onChange:h=>w(+h.target.value),children:R.map(h=>e.jsxs("option",{value:h,children:[Math.round(h*100),"%"]},h))}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>w(Math.min(3,r+.1)),children:"+"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>w(1),title:"100%",children:"⊡"})]}),!k&&C&&e.jsx("button",{className:t.saveBtn,onClick:C,children:"💾 Zapisz"})]})},Sa=({activeTab:s,onTabChange:r,schema:d,tpl:l,allFields:N,selectedIds:m,onInsertSchemaField:k,onSelectField:x,onUpdateTpl:_,onReorderField:w})=>{const[o,D]=y.useState(""),v=d==null?void 0:d.fields.filter(n=>n.label.toLowerCase().includes(o.toLowerCase())||n.path.toLowerCase().includes(o.toLowerCase()));return e.jsxs("div",{className:t.leftPanel,children:[e.jsx("div",{className:t.leftTabs,children:Na.map(n=>e.jsxs("button",{className:`${t.leftTab} ${s===n.id?t.leftTabActive:""}`,onClick:()=>r(n.id),title:n.label,children:[e.jsx("span",{className:t.leftTabIcon,children:n.icon}),e.jsx("span",{className:t.leftTabLabel,children:n.label})]},n.id))}),e.jsxs("div",{className:t.leftContent,children:[s==="fields"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Pola danych"}),e.jsx("div",{className:t.searchBox,children:e.jsx("input",{className:t.searchInput,placeholder:"Szukaj...",value:o,onChange:n=>D(n.target.value)})}),d?e.jsxs("div",{className:t.fieldList,children:[(v??[]).map(n=>e.jsxs("div",{className:t.fieldItem,draggable:!0,onDragStart:a=>{a.dataTransfer.setData("fieldPath",n.path),a.dataTransfer.setData("fieldLabel",n.label),a.dataTransfer.setData("fieldType",n.type)},onClick:()=>k(n),children:[e.jsx("span",{className:t.fieldItemIcon,children:le[n.type]??"📝"}),e.jsxs("div",{className:t.fieldItemInfo,children:[e.jsx("div",{className:t.fieldItemLabel,children:n.label}),e.jsx("div",{className:t.fieldItemPath,children:n.path})]}),e.jsx("span",{className:t.fieldItemType,children:n.type})]},n.path)),(v==null?void 0:v.length)===0&&e.jsx("div",{className:t.emptyMsg,children:"Brak wyników"})]}):e.jsx("div",{className:t.emptyMsg,children:"Brak schematu danych. Przypisz encję w zakładce Ustawienia."})]}),s==="layers"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.panelHeader,children:["Warstwy (",N.length,")"]}),e.jsxs("div",{className:t.layerList,children:[N.length===0&&e.jsx("div",{className:t.emptyMsg,children:"Brak elementów"}),N.slice().reverse().map(n=>e.jsxs("div",{className:`${t.layerItem} ${m.has(n.id)?t.layerItemSelected:""}`,onClick:()=>x(n.id),children:[e.jsx("span",{className:t.layerIcon,children:le[n.type]??"📝"}),e.jsx("span",{className:t.layerName,children:n.name||n.label}),e.jsxs("div",{className:t.layerActions,children:[e.jsx("button",{className:t.layerBtn,onClick:a=>{a.stopPropagation(),w(n.id,-1)},title:"Do przodu",children:"↑"}),e.jsx("button",{className:t.layerBtn,onClick:a=>{a.stopPropagation(),w(n.id,1)},title:"Do tyłu",children:"↓"})]})]},n.id))]})]}),s==="watermarks"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Znaki wodne"}),e.jsxs("div",{className:t.wmList,children:[(l.watermarks??[]).map(n=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Typ"}),e.jsxs("select",{className:t.wmSelect,value:n.type,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,type:a.target.value}:u)})},children:[e.jsx("option",{value:"text",children:"Tekst"}),e.jsx("option",{value:"image",children:"Obraz"})]})]}),n.type==="text"&&e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Tekst"}),e.jsx("input",{className:t.wmInput,value:n.text??"",onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,text:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.02,max:.5,step:.01,className:t.wmSlider,value:n.opacity,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,opacity:+a.target.value}:u)})}}),e.jsxs("span",{className:t.wmValue,children:[Math.round(n.opacity*100),"%"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Kąt"}),e.jsx("input",{type:"range",min:-90,max:90,step:5,className:t.wmSlider,value:n.angle,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,angle:+a.target.value}:u)})}}),e.jsxs("span",{className:t.wmValue,children:[n.angle,"°"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Rozmiar"}),e.jsx("input",{type:"number",min:8,max:200,className:t.wmInputNum,value:n.fontSize??48,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,fontSize:+a.target.value}:u)})}}),e.jsx("span",{className:t.wmUnit,children:"pt"})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Kolor"}),e.jsx("input",{type:"color",className:t.colorPicker,value:n.color??"var(--nice-text-muted, #94a3b8)",onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,color:a.target.value}:u)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var a;return _({watermarks:(a=l.watermarks)==null?void 0:a.filter(p=>p.id!==n.id)})},children:"Usuń"})]},n.id)),e.jsx("button",{className:t.addBtn,onClick:()=>_({watermarks:[...l.watermarks??[],{id:te(),type:"text",text:"KOPIA",opacity:.12,angle:-45,fontSize:60,color:"var(--nice-text-muted, #94a3b8)"}]}),children:"+ Dodaj znak wodny"})]})]}),s==="signatures"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Podpisy"}),e.jsxs("div",{className:t.wmList,children:[(l.signatures??[]).map(n=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Etykieta"}),e.jsx("input",{className:t.wmInput,value:n.label,onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,label:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Nazwisko"}),e.jsx("input",{className:t.wmInput,value:n.signerName??"",onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,signerName:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Linia"}),e.jsx("input",{type:"checkbox",checked:n.showLine??!0,onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,showLine:a.target.checked}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Pokaż datę"}),e.jsx("input",{type:"checkbox",checked:n.showDate??!1,onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,showDate:a.target.checked}:u)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var a;return _({signatures:(a=l.signatures)==null?void 0:a.filter(p=>p.id!==n.id)})},children:"Usuń"})]},n.id)),e.jsx("button",{className:t.addBtn,onClick:()=>_({signatures:[...l.signatures??[],{id:te(),label:"Podpis",position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),children:"+ Dodaj podpis"})]})]}),s==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Ustawienia szablonu"}),e.jsxs("div",{className:t.settingsForm,children:[e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Nazwa"}),e.jsx("input",{className:t.settingsInput,value:l.name,onChange:n=>_({name:n.target.value})})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Opis"}),e.jsx("textarea",{className:t.settingsTextarea,value:l.description??"",onChange:n=>_({description:n.target.value}),rows:2})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Kategoria"}),e.jsx("input",{className:t.settingsInput,value:l.category??"",onChange:n=>_({category:n.target.value})})]}),e.jsx("div",{className:t.settingsDivider,children:"Marginesy (mm)"}),["top","right","bottom","left"].map(n=>e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:n==="top"?"Góra":n==="right"?"Prawo":n==="bottom"?"Dół":"Lewo"}),e.jsx("input",{type:"number",min:0,max:50,step:1,className:t.settingsInputNum,value:l.margins[n],onChange:a=>_({margins:{...l.margins,[n]:+a.target.value}})}),e.jsx("span",{className:t.settingsUnit,children:"mm"})]},n))]})]})]})]})},Ca=({field:s,activeTab:r,onTabChange:d,onChange:l,paperWidthMm:N,paperHeightMm:m})=>{var o,D,v,n;const k=y.useCallback(a=>s&&l({position:{...s.position,...a}}),[s,l]),x=y.useCallback(a=>s&&l({style:{...(s==null?void 0:s.style)??{},...a}}),[s,l]);if(!s)return e.jsxs("div",{className:t.rightPanel,children:[e.jsx("div",{className:t.panelHeader,children:"Właściwości"}),e.jsxs("div",{className:t.propsEmpty,children:[e.jsx("div",{className:t.propsEmptyIcon,children:"⬚"}),e.jsx("div",{className:t.propsEmptyText,children:"Zaznacz element na szablonie"}),e.jsxs("div",{className:t.shortcutGrid,children:[e.jsx(ee,{keys:"Del",label:"Usuń"}),e.jsx(ee,{keys:"Ctrl+D",label:"Duplikuj"}),e.jsx(ee,{keys:"↑↓←→",label:"Przesuń"}),e.jsx(ee,{keys:"Ctrl+Z",label:"Cofnij"}),e.jsx(ee,{keys:"Ctrl+A",label:"Zaznacz wszystko"}),e.jsx(ee,{keys:"Shift+↑",label:"Przesuń 5mm"})]})]})]});const _=!["line","rect","image","static_image","barcode","qr","signature"].includes(s.type),w=!["static_text","static_image","line","rect","page_number","total_pages","print_date"].includes(s.type);return e.jsxs("div",{className:t.rightPanel,children:[e.jsxs("div",{className:t.panelHeader,children:[e.jsx("span",{className:t.panelHeaderIcon,children:le[s.type]}),e.jsx("span",{className:t.panelHeaderName,children:s.name})]}),e.jsx("div",{className:t.rightTabs,children:ka.map(a=>a.id==="data"&&!w?null:e.jsx("button",{className:`${t.rightTab} ${r===a.id?t.rightTabActive:""}`,onClick:()=>d(a.id),children:a.label},a.id))}),e.jsxs("div",{className:t.propsBody,children:[r==="position"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.posGrid,children:[[{key:"x",label:"X",unit:"mm"},{key:"y",label:"Y",unit:"mm"},{key:"width",label:"Szer.",unit:"mm"},{key:"height",label:"Wys.",unit:"mm"}].map(({key:a,label:p,unit:u})=>e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:p}),e.jsx("input",{type:"number",step:.5,className:t.posInput,value:Math.round(s.position[a]*10)/10,onChange:j=>k({[a]:+j.target.value})}),e.jsx("span",{className:t.posUnit,children:u})]},a)),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Obrót"}),e.jsx("input",{type:"number",step:5,className:t.posInput,value:s.style.rotation??0,onChange:a=>x({rotation:+a.target.value})}),e.jsx("span",{className:t.posUnit,children:"°"})]}),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Z-idx"}),e.jsx("input",{type:"number",step:1,min:1,className:t.posInput,value:s.position.zIndex??1,onChange:a=>k({zIndex:+a.target.value})})]})]}),e.jsxs("div",{className:t.snapSection,children:[e.jsx("div",{className:t.snapTitle,children:"Wyrównanie do strony"}),e.jsxs("div",{className:t.snapRow,children:[e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:0}),title:"Lewa krawędź",children:"⫷"}),e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:(N-s.position.width)/2}),title:"Środek poziomy",children:"⊕"}),e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:N-s.position.width}),title:"Prawa krawędź",children:"⫸"})]})]})]}),r==="style"&&e.jsxs(e.Fragment,{children:[_&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Czcionka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rodzina"}),e.jsx("select",{className:t.styleSelectFull,value:s.style.fontFamily??"sans-serif",onChange:a=>x({fontFamily:a.target.value}),children:ga.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rozmiar"}),e.jsx("select",{className:t.styleSelectSm,value:ye.includes(s.style.fontSize??10)?s.style.fontSize??10:"",onChange:a=>x({fontSize:+a.target.value}),children:ye.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("input",{type:"number",step:.5,min:4,max:200,className:t.styleInput,value:s.style.fontSize??10,onChange:a=>x({fontSize:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"pt"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Kolor"}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.color??"var(--nice-text, #000000)",onChange:a=>x({color:a.target.value})}),e.jsx("input",{className:t.colorHex,value:s.style.color??"var(--nice-text, #000000)",onChange:a=>x({color:a.target.value}),maxLength:7})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Styl"}),e.jsxs("div",{className:t.toggleGroup,children:[e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontWeight==="bold"?t.toggleBtnActive:""}`,onClick:()=>x({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:()=>x({fontStyle:s.style.fontStyle==="italic"?"normal":"italic"}),children:e.jsx("i",{children:"I"})})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Wyrówn."}),e.jsx("div",{className:t.toggleGroup,children:["left","center","right","justify"].map(a=>e.jsx("button",{title:a,className:`${t.toggleBtn} ${(s.style.textAlign??"left")===a?t.toggleBtnActive:""}`,onClick:()=>x({textAlign:a}),children:a==="left"?"≡L":a==="center"?"≡C":a==="right"?"≡R":"≡J"},a))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"W. linii"}),e.jsx("input",{type:"number",step:.1,min:1,max:4,className:t.styleInput,value:s.style.lineHeight??1.4,onChange:a=>x({lineHeight:+a.target.value})})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Odstępy"}),e.jsx("input",{type:"number",step:.01,min:-.1,max:.5,className:t.styleInput,value:s.style.letterSpacing??0,onChange:a=>x({letterSpacing:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"em"})]})]}),e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Tło i ramka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Tło"}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.backgroundColor??"var(--nice-bg, #fff)",onChange:a=>x({backgroundColor:a.target.value})}),e.jsx("button",{className:t.clearBtn,onClick:()=>x({backgroundColor:void 0}),title:"Wyczyść tło",children:"✕"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ramka"}),e.jsx("input",{type:"number",step:.5,min:0,max:10,className:t.styleInput,value:s.style.borderWidth??0,onChange:a=>x({borderWidth:+a.target.value})}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.borderColor??"var(--nice-text, #000000)",onChange:a=>x({borderColor:a.target.value})}),e.jsxs("select",{className:t.styleSelectXs,value:s.style.borderStyle??"solid",onChange:a=>x({borderStyle:a.target.value}),children:[e.jsx("option",{value:"solid",children:"─"}),e.jsx("option",{value:"dashed",children:"- -"}),e.jsx("option",{value:"dotted",children:"···"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Zaokr."}),e.jsx("input",{type:"number",step:1,min:0,max:50,className:t.styleInput,value:s.style.borderRadius??0,onChange:a=>x({borderRadius:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"px"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Padding"}),e.jsx("input",{type:"number",step:.5,min:0,max:20,className:t.styleInput,value:s.style.padding??0,onChange:a=>x({padding:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"mm"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.1,max:1,step:.05,className:t.sliderInput,value:s.style.opacity??1,onChange:a=>x({opacity:+a.target.value})}),e.jsxs("span",{className:t.styleValue,children:[Math.round((s.style.opacity??1)*100),"%"]})]})]})]}),r==="data"&&w&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Źródło danych"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ścieżka"}),e.jsx("input",{className:t.styleInputFull,value:s.dataPath,onChange:a=>l({dataPath:a.target.value}),placeholder:"np. invoice.number"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Format"}),e.jsx("input",{className:t.styleInputFull,value:s.format??"",onChange:a=>l({format:a.target.value}),placeholder:"DD.MM.YYYY / #,##0.00"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Domyślny"}),e.jsx("input",{className:t.styleInputFull,value:s.fallback??"",onChange:a=>l({fallback:a.target.value}),placeholder:"Gdy brak wartości"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Typ"}),e.jsx("select",{className:t.styleSelectFull,value:s.type,onChange:a=>l({type:a.target.value}),children:Object.entries(re).map(([a,p])=>e.jsx("option",{value:a,children:p},a))})]}),(s.type==="barcode"||s.type==="qr")&&e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Format kodu"}),e.jsx("select",{className:t.styleSelectFull,value:s.barcodeType??"code128",onChange:a=>l({barcodeType:a.target.value}),children:["ean13","ean8","code128","code39","upc","itf14","datamatrix"].map(a=>e.jsx("option",{value:a,children:a.toUpperCase()},a))})]})]}),r==="conditional"&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Widoczność warunkowa"}),e.jsx("div",{className:t.conditionalHint,children:"Element zostanie ukryty gdy warunek nie jest spełniony."}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Pole"}),e.jsx("input",{className:t.styleInputFull,value:((o=s.conditional)==null?void 0:o.field)??"",onChange:a=>{var p,u;return l({conditional:{field:a.target.value,operator:((p=s.conditional)==null?void 0:p.operator)??"eq",value:(u=s.conditional)==null?void 0:u.value}})},placeholder:"np. invoice.isPaid"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Operator"}),e.jsxs("select",{className:t.styleSelectFull,value:((D=s.conditional)==null?void 0:D.operator)??"eq",onChange:a=>{var p,u;return l({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:a.target.value,value:(u=s.conditional)==null?void 0:u.value}})},children:[e.jsx("option",{value:"eq",children:"= r�wne"}),e.jsx("option",{value:"neq",children:"≠ różne"}),e.jsx("option",{value:"gt",children:"> wieksze"}),e.jsx("option",{value:"lt",children:"< mniejsze"}),e.jsx("option",{value:"contains",children:"zawiera"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Wartosc"}),e.jsx("input",{className:t.styleInputFull,value:String(((v=s.conditional)==null?void 0:v.value)??""),onChange:a=>{var p,u;return l({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:((u=s.conditional)==null?void 0:u.operator)??"eq",value:a.target.value}})},placeholder:'np. true / "PAID"'})]}),((n=s.conditional)==null?void 0:n.field)&&e.jsx("button",{className:t.clearConditionalBtn,onClick:()=>l({conditional:void 0}),children:"Wyczyść warunek"})]})]})]})};function Ba(){return{id:`tpl-${Date.now()}`,name:"Nowy szablon",description:"",paperSize:"A4",orientation:"portrait",margins:{top:20,right:15,bottom:20,left:15},sections:[{id:"sec-header",type:"header",heightMm:35,fields:[]},{id:"sec-body",type:"body",fields:[]},{id:"sec-footer",type:"footer",heightMm:20,fields:[]}],watermarks:[],signatures:[]}}const Ia=({template:s,dataSchema:r,sampleData:d=[],onChange:l,onSave:N,readOnly:m=!1,className:k,style:x,theme:_="light"})=>{const[{past:w,present:o,future:D},v]=y.useReducer(ya,{past:[],present:s??Ba(),future:[]}),[n,a]=y.useState(new Set),[p,u]=y.useState("sec-body"),[j,z]=y.useState(1),[g,I]=y.useState(0),[C,P]=y.useState("fields"),[A,R]=y.useState("position"),[h,O]=y.useState(!1),[ie,ve]=y.useState(!0),T=y.useCallback(i=>{const c={...o,...i};v({type:"UPDATE",payload:c}),l==null||l(c)},[o,l]),[Y,oe]=y.useMemo(()=>{const[i,c]=ge[o.paperSize]??ge.A4;return o.orientation==="landscape"?[c,i]:[i,c]},[o.paperSize,o.orientation]),K=y.useMemo(()=>o.sections.flatMap(i=>i.fields),[o]),M=y.useMemo(()=>K.find(i=>n.has(i.id))??null,[K,n]),ce=y.useCallback((i,c)=>{T({sections:o.sections.map(S=>({...S,fields:S.fields.map(f=>f.id===i?{...f,...c,style:{...f.style,...c.style??{}}}:f)}))})},[o,T]),se=y.useCallback(i=>{T({sections:o.sections.map(c=>({...c,fields:c.fields.map(S=>n.has(S.id)?{...S,...i,style:{...S.style,...i.style??{}}}:S)}))})},[o,n,T]),me=y.useCallback((i,c)=>{if(i==="watermark"){T({watermarks:[...o.watermarks??[],{id:te(),type:"text",text:"KOPIA",opacity:.12,angle:-45,fontSize:60,color:"var(--nice-text-muted, #94a3b8)"}]}),P("watermarks");return}if(i==="signature"){T({signatures:[...o.signatures??[],{id:te(),label:"Podpis",position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),P("signatures");return}const S=o.sections.find(E=>E.id===p)??o.sections.find(E=>E.type==="body");if(!S)return;const f=xe(i,c),$={sections:o.sections.map(E=>E.id===S.id?{...E,fields:[...E.fields,f]}:E)};v({type:"UPDATE",payload:{...o,...$}}),l==null||l({...o,...$}),a(new Set([f.id]))},[o,p,l]),je=y.useCallback((i,c,S,f)=>{const $=r==null?void 0:r.fields.find(H=>H.path===c),E=xe(($==null?void 0:$.type)??"text",$);E.position.x=Math.round(S*2)/2,E.position.y=Math.round(f*2)/2;const V={sections:o.sections.map(H=>H.id===i?{...H,fields:[...H.fields,E]}:H)};v({type:"UPDATE",payload:{...o,...V}}),l==null||l({...o,...V}),a(new Set([E.id]))},[o,r,l]),Ne=y.useCallback((i,c)=>{c.ctrlKey||c.metaKey?a(S=>{const f=new Set(S);return f.has(i)?f.delete(i):f.add(i),f}):c.shiftKey?a(S=>new Set([...S,i])):a(new Set([i]))},[]),ke=y.useCallback((i,c)=>{if(m)return;c.preventDefault(),n.has(i)||a(new Set([i]));const S=c.clientX,f=c.clientY,$=o.sections.map(H=>({id:H.id,fields:H.fields.map(Z=>({id:Z.id,pos:{...Z.position}}))})),E=H=>{const Z=(H.clientX-S)/(j*G),Q=(H.clientY-f)/(j*G),ae=n.has(i)?n:new Set([i]),ne=o.sections.map(X=>{const U=$.find(W=>W.id===X.id);return{...X,fields:X.fields.map(W=>{var _e;if(!ae.has(W.id))return W;const he=((_e=U==null?void 0:U.fields.find(Re=>Re.id===W.id))==null?void 0:_e.pos)??W.position;return{...W,position:{...W.position,x:Math.max(0,Math.round((he.x+Z)*2)/2),y:Math.max(0,Math.round((he.y+Q)*2)/2)}}})}}),J={...o,sections:ne};l==null||l(J),v({type:"UPDATE",payload:J})},V=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",V)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",V)},[o,j,n,m,l]),fe=y.useCallback((i,c,S)=>{if(m)return;S.preventDefault();const f=K.find(Q=>Q.id===i);if(!f)return;const $={...f.position},E=S.clientX,V=S.clientY,H=Q=>{const ae=(Q.clientX-E)/(j*G),ne=(Q.clientY-V)/(j*G);let{x:J,y:X,width:U,height:W}=$;c.includes("e")&&(U=Math.max(5,U+ae)),c.includes("s")&&(W=Math.max(3,W+ne)),c.includes("w")&&(J=J+ae,U=Math.max(5,U-ae)),c.includes("n")&&(X=X+ne,W=Math.max(3,W-ne)),ce(i,{position:{...$,x:Math.round(J*2)/2,y:Math.round(X*2)/2,width:Math.round(U*2)/2,height:Math.round(W*2)/2}})},Z=()=>{document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",Z)};document.addEventListener("mousemove",H),document.addEventListener("mouseup",Z)},[K,j,m,ce]),de=y.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.filter(c=>!n.has(c.id))}))}),a(new Set)},[o,n,T]),ue=y.useCallback(()=>{const i=new Set;T({sections:o.sections.map(c=>{const S=c.fields.filter(f=>n.has(f.id)).map(f=>{const $={...f,id:te(),position:{...f.position,x:f.position.x+5,y:f.position.y+5}};return i.add($.id),$});return{...c,fields:[...c.fields,...S]}})}),a(i)},[o,n,T]),Se=y.useCallback(i=>{T({sections:o.sections.map(c=>({...c,fields:c.fields.map(S=>{if(!n.has(S.id))return S;const f=i==="left"?o.margins.left:i==="right"?Y-o.margins.right-S.position.width:(Y-S.position.width)/2;return{...S,position:{...S.position,x:f}}})}))})},[o,n,Y,T]),Ce=y.useCallback(i=>{const c=o.sections.find(f=>f.id===p);if(!c)return;const S=c.heightMm??200;T({sections:o.sections.map(f=>f.id!==p?f:{...f,fields:f.fields.map($=>{if(!n.has($.id))return $;const E=i==="top"?0:i==="bottom"?S-$.position.height:(S-$.position.height)/2;return{...$,position:{...$.position,y:E}}})})})},[o,n,p,T]),Be=y.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.map(c=>n.has(c.id)?{...c,position:{...c.position,zIndex:(c.position.zIndex??1)+1}}:c)}))})},[o,n,T]),Ie=y.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.map(c=>n.has(c.id)?{...c,position:{...c.position,zIndex:Math.max(1,(c.position.zIndex??1)-1)}}:c)}))})},[o,n,T]),Le=y.useCallback((i,c)=>{T({sections:o.sections.map(S=>({...S,fields:S.fields.map(f=>f.id===i?{...f,position:{...f.position,zIndex:Math.max(1,(f.position.zIndex??1)-c)}}:f)}))})},[o,T]);y.useEffect(()=>{const i=c=>{const S=c.target.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;const f=c.shiftKey?5:.5;c.key==="Delete"||c.key==="Backspace"?n.size&&(c.preventDefault(),de()):c.ctrlKey&&c.key==="z"?(c.preventDefault(),v({type:"UNDO"})):c.ctrlKey&&(c.key==="y"||c.key==="Y")?(c.preventDefault(),v({type:"REDO"})):c.ctrlKey&&(c.key==="d"||c.key==="D")?(c.preventDefault(),n.size&&ue()):c.ctrlKey&&c.key==="a"?(c.preventDefault(),a(new Set(K.map($=>$.id)))):c.key==="ArrowLeft"?(c.preventDefault(),se({position:{...M.position,x:((M==null?void 0:M.position.x)??0)-f}})):c.key==="ArrowRight"?(c.preventDefault(),se({position:{...M.position,x:((M==null?void 0:M.position.x)??0)+f}})):c.key==="ArrowUp"?(c.preventDefault(),se({position:{...M.position,y:((M==null?void 0:M.position.y)??0)-f}})):c.key==="ArrowDown"&&(c.preventDefault(),se({position:{...M.position,y:((M==null?void 0:M.position.y)??0)+f}}))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n,K,M,de,ue,se]);const ze=y.useCallback((i,c)=>{T({sections:o.sections.map(S=>S.id===i?{...S,heightMm:Math.round(c*2)/2}:S)})},[o,T]),De=y.useMemo(()=>{const i=Array.isArray(d)?d[g]:d;return i?"data"in i?i.data:i:{}},[d,g]),Te=Y*j*G,$e=oe*j*G;return e.jsxs("div",{className:`${t.root} ${_==="dark"?t.dark:""} ${k??""}`,style:x,onClick:()=>a(new Set),children:[e.jsx(fa,{tpl:o,zoom:j,canUndo:w.length>0,canRedo:D.length>0,showGrid:h,showRulers:ie,readOnly:m,selectedCount:n.size,onPaperChange:(i,c)=>T({paperSize:i,orientation:c}),onZoom:z,onUndo:()=>v({type:"UNDO"}),onRedo:()=>v({type:"REDO"}),onToggleGrid:()=>O(i=>!i),onToggleRulers:()=>ve(i=>!i),onInsert:me,onDelete:de,onDuplicate:ue,onAlignH:Se,onAlignV:Ce,onBringForward:Be,onSendBackward:Ie,onSave:N?()=>N(o):void 0}),e.jsxs("div",{className:t.editorBody,children:[e.jsx(Sa,{activeTab:C,onTabChange:P,schema:r,tpl:o,allFields:K,selectedIds:n,onInsertSchemaField:i=>me(i.type,i),onSelectField:i=>a(new Set([i])),onUpdateTpl:i=>T(i),onReorderField:Le}),e.jsxs("div",{className:t.canvasArea,children:[Array.isArray(d)&&d.length>0&&e.jsxs("div",{className:t.testDataBar,children:[e.jsx("span",{className:t.testDataLabel,children:"Dane testowe:"}),e.jsx("select",{className:t.testDataSelect,value:g,onChange:i=>I(+i.target.value),children:d.map((i,c)=>e.jsxs("option",{value:c,children:["Rekord ",c+1]},c))})]}),ie&&e.jsxs("div",{className:t.rulerWrapper,children:[e.jsx("div",{className:t.rulerCorner}),e.jsx(be,{lengthMm:Y,zoom:j,orientation:"h"}),e.jsx(be,{lengthMm:oe,zoom:j,orientation:"v"})]}),e.jsx("div",{className:t.paperScroll,onClick:i=>i.stopPropagation(),children:e.jsxs("div",{className:t.paperShadow,style:{width:Te,minHeight:$e},children:[e.jsx("div",{className:t.marginGuide,style:{top:o.margins.top*j*G,right:o.margins.right*j*G,bottom:o.margins.bottom*j*G,left:o.margins.left*j*G}}),(o.watermarks??[]).map(i=>e.jsx("div",{className:t.watermark,style:{fontSize:(i.fontSize??60)*j,color:i.color??"var(--nice-text-muted, #94a3b8)",opacity:i.opacity,transform:`translate(-50%, -50%) rotate(${i.angle}deg)`},children:i.type==="text"?i.text:"??"},i.id)),o.sections.map(i=>e.jsx("div",{children:e.jsx(ja,{section:i,zoom:j,paperWidthMm:Y,selectedIds:n,sampleData:De,readOnly:m,showGrid:h,onFieldClick:Ne,onFieldDragStart:ke,onResizeStart:fe,onSectionHeightChange:ze,onDropField:je})},i.id))]})})]}),e.jsx(Ca,{field:M,activeTab:A,onTabChange:R,onChange:i=>M&&ce(M.id,i),paperWidthMm:Y,paperHeightMm:oe})]})]})},La="_root_6hwvk_1",za="_dark_6hwvk_25",Da="_topBar_6hwvk_31",Ta="_searchInput_6hwvk_55",$a="_actionBtn_6hwvk_83",Ra="_categoryRow_6hwvk_117",Pa="_catChip_6hwvk_141",Aa="_catChipActive_6hwvk_167",Ma="_grid_6hwvk_181",Ea="_card_6hwvk_203",Fa="_cardSelected_6hwvk_235",Ga="_thumbnail_6hwvk_251",Ha="_thumbnailImg_6hwvk_265",Wa="_thumbnailPlaceholder_6hwvk_277",Oa="_paperMini_6hwvk_291",Ua="_paperLine_6hwvk_315",qa="_cardOverlay_6hwvk_329",Ya="_overlayBtn_6hwvk_349",Ka="_overlayBtnDanger_6hwvk_381",Va="_cardBody_6hwvk_411",Za="_cardName_6hwvk_415",Xa="_cardDesc_6hwvk_439",Qa="_cardMeta_6hwvk_461",Ja="_cardSize_6hwvk_475",en="_cardCat_6hwvk_491",tn="_cardTags_6hwvk_507",sn="_cardTag_6hwvk_507",an="_emptyState_6hwvk_531",nn="_emptyIcon_6hwvk_553",B={root:La,dark:za,topBar:Da,searchInput:Ta,actionBtn:$a,categoryRow:Ra,catChip:Pa,catChipActive:Aa,grid:Ma,card:Ea,cardSelected:Fa,thumbnail:Ga,thumbnailImg:Ha,thumbnailPlaceholder:Wa,paperMini:Oa,paperLine:Ua,cardOverlay:qa,overlayBtn:Ya,overlayBtnDanger:Ka,cardBody:Va,cardName:Za,cardDesc:Xa,cardMeta:Qa,cardSize:Ja,cardCat:en,cardTags:tn,cardTag:sn,emptyState:an,emptyIcon:nn},ln=["Faktury","Raporty","Etykiety","Listy","Umowy","Inne"];function rn(s){return new Promise((r,d)=>{const l=new FileReader;l.onload=N=>{var m;try{r(JSON.parse((m=N.target)==null?void 0:m.result))}catch(k){d(k)}},l.readAsText(s)})}function on(s){const r=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),d=URL.createObjectURL(r),l=document.createElement("a");l.href=d,l.download=`${s.name.replace(/\s+/g,"_")}.json`,l.click(),URL.revokeObjectURL(d)}const cn=({templates:s,selectedId:r,onSelect:d,onImport:l,onExport:N,onDelete:m,onNew:k,className:x,style:_,theme:w="light"})=>{const[o,D]=y.useState(""),[v,n]=y.useState(null),[a,p]=y.useState(null),u=y.useRef(null),j=async g=>{var C;const I=(C=g.target.files)==null?void 0:C[0];if(I){try{const P=await rn(I);l==null||l(P)}catch{}g.target.value=""}},z=s.filter(g=>{const I=!o||g.name.toLowerCase().includes(o.toLowerCase())||(g.description??"").toLowerCase().includes(o.toLowerCase())||(g.tags??[]).some(P=>P.toLowerCase().includes(o.toLowerCase())),C=!v||g.category===v;return I&&C});return e.jsxs("div",{className:`${B.root} ${w==="dark"?B.dark:""} ${x??""}`,style:_,children:[e.jsxs("div",{className:B.topBar,children:[e.jsx("input",{type:"search",className:B.searchInput,placeholder:"Szukaj szablonów…",value:o,onChange:g=>D(g.target.value)}),e.jsx("button",{className:B.actionBtn,onClick:k,title:"Nowy szablon",children:"+ Nowy"}),e.jsx("button",{className:B.actionBtn,onClick:()=>{var g;return(g=u.current)==null?void 0:g.click()},title:"Importuj JSON",children:"⬆ Import"}),e.jsx("input",{ref:u,type:"file",accept:".json",hidden:!0,onChange:j})]}),e.jsxs("div",{className:B.categoryRow,children:[e.jsx("button",{className:`${B.catChip} ${v?"":B.catChipActive}`,onClick:()=>n(null),children:"Wszystkie"}),ln.map(g=>e.jsx("button",{className:`${B.catChip} ${v===g?B.catChipActive:""}`,onClick:()=>n(I=>I===g?null:g),children:g},g))]}),e.jsxs("div",{className:B.grid,children:[z.map(g=>e.jsxs("div",{className:`${B.card} ${r===g.id?B.cardSelected:""}`,onClick:()=>d==null?void 0:d(g),onMouseEnter:()=>p(g.id),onMouseLeave:()=>p(null),children:[e.jsxs("div",{className:B.thumbnail,children:[g.previewImageUrl?e.jsx("img",{src:g.previewImageUrl,alt:g.name,className:B.thumbnailImg}):e.jsx("div",{className:B.thumbnailPlaceholder,children:e.jsxs("div",{className:B.paperMini,children:[e.jsx("div",{className:B.paperLine,style:{width:"80%"}}),e.jsx("div",{className:B.paperLine,style:{width:"60%"}}),e.jsx("div",{className:B.paperLine,style:{width:"90%"}}),e.jsx("div",{className:B.paperLine,style:{width:"50%"}})]})}),a===g.id&&e.jsxs("div",{className:B.cardOverlay,children:[e.jsx("button",{className:B.overlayBtn,onClick:I=>{I.stopPropagation(),N==null||N(g),on(g)},title:"Eksportuj",children:"⬇"}),m&&e.jsx("button",{className:B.overlayBtnDanger,onClick:I=>{I.stopPropagation(),m(g.id)},title:"Usuń",children:"✕"})]})]}),e.jsxs("div",{className:B.cardBody,children:[e.jsx("div",{className:B.cardName,children:g.name}),g.description&&e.jsx("div",{className:B.cardDesc,children:g.description}),e.jsxs("div",{className:B.cardMeta,children:[e.jsxs("span",{className:B.cardSize,children:[g.paperSize," ",g.orientation==="landscape"?"↔":"↕"]}),g.category&&e.jsx("span",{className:B.cardCat,children:g.category})]}),g.tags&&g.tags.length>0&&e.jsx("div",{className:B.cardTags,children:g.tags.slice(0,3).map(I=>e.jsx("span",{className:B.cardTag,children:I},I))})]})]},g.id)),z.length===0&&e.jsxs("div",{className:B.emptyState,children:[e.jsx("span",{className:B.emptyIcon,children:"📄"}),e.jsx("span",{children:o?`Brak wyników dla "${o}"`:"Brak szablonów. Utwórz pierwszy!"})]})]})]})},dn="_root_1grye_1",un="_dark_1grye_19",pn="_headerBar_1grye_25",mn="_entityNav_1grye_47",hn="_navBtn_1grye_49",_n="_navLabel_1grye_73",gn="_sampleBadge_1grye_77",yn="_zoomBar_1grye_95",xn="_zoomBtn_1grye_97",bn="_zoomLabel_1grye_119",wn="_printBtn_1grye_123",vn="_canvas_1grye_149",jn="_page_1grye_169",Nn="_watermark_1grye_191",kn="_footerBar_1grye_221",F={root:dn,dark:un,headerBar:pn,entityNav:mn,navBtn:hn,navLabel:_n,sampleBadge:gn,zoomBar:yn,zoomBtn:xn,zoomLabel:bn,printBtn:wn,canvas:vn,page:jn,watermark:Nn,footerBar:kn},q=3.78,we={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432]};function fn(s,r){try{return s.split(".").reduce((d,l)=>d&&typeof d=="object"?d[l]:null,r)}catch{return null}}function Sn(s,r,d){if(s==null)return"";if(r==="date"&&d)try{const l=new Date(s);if(d==="DD.MM.YYYY"){const N=String(l.getDate()).padStart(2,"0"),m=String(l.getMonth()+1).padStart(2,"0");return`${N}.${m}.${l.getFullYear()}`}return l.toLocaleDateString()}catch{return String(s)}if(r==="currency"&&d){const l=Number(s);if(!isNaN(l))return`${l.toFixed(2)} ${d}`}return r==="number"&&typeof s=="number"?s.toLocaleString("pl-PL"):String(s)}const Cn=({field:s,data:r,zoom:d})=>{const l=s.dataPath?fn(s.dataPath,r):null,N=l!=null?Sn(l,s.type,s.format):s.fallback??"",m=x=>x*d*q,k={position:"absolute",left:m(s.position.x),top:m(s.position.y),width:m(s.position.width),height:m(s.position.height),fontSize:(s.style.fontSize??10)*d,fontWeight:s.style.fontWeight??"normal",fontStyle:s.style.fontStyle??"normal",color:s.style.color??"var(--text-primary, #0f172a)",textAlign:s.style.textAlign??"left",backgroundColor:s.style.backgroundColor,transform:s.style.rotation?`rotate(${s.style.rotation}deg)`:void 0,overflow:"hidden",display:"flex",alignItems:s.style.verticalAlign==="middle"?"center":s.style.verticalAlign==="bottom"?"flex-end":"flex-start",lineHeight:s.style.lineHeight??1.4,padding:s.style.padding?m(s.style.padding):0,boxSizing:"border-box",borderWidth:s.style.borderWidth,borderColor:s.style.borderColor,borderStyle:s.style.borderStyle,borderRadius:s.style.borderRadius,zIndex:s.position.zIndex??1};return s.type==="image"&&l?e.jsx("div",{style:k,children:e.jsx("img",{src:String(l),alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}})}):s.type==="barcode"||s.type==="qr"?e.jsxs("div",{style:{...k,background:"var(--bg-secondary, #f8fafc)",border:"1px dashed var(--border-color, #e2e8f0)",alignItems:"center",justifyContent:"center",fontSize:10*d},children:[s.type==="qr"?"⬛":"▮▌▮"," ",N]}):s.type==="signature"?e.jsx("div",{style:{...k,borderBottom:"1px solid var(--text-primary, #0f172a)",alignItems:"flex-end"},children:e.jsx("span",{style:{fontSize:8*d,color:"var(--text-muted, #94a3b8)"},children:s.label})}):s.type==="line"?e.jsx("div",{style:{...k,borderBottom:`${s.style.borderWidth??1}px ${s.style.borderStyle??"solid"} ${s.style.borderColor??"var(--text-primary, #0f172a)"}`}}):e.jsx("div",{style:k,children:N})},Bn=({template:s,data:r,zoom:d})=>{var x;const[l,N]=(()=>{const[_,w]=we[s.paperSize]??we.A4;return s.orientation==="landscape"?[w*q*d,_*q*d]:[_*q*d,w*q*d]})(),m=s.margins,k=s.sections.flatMap(_=>_.fields);return e.jsxs("div",{className:F.page,style:{width:l,minHeight:N},children:[e.jsx("div",{style:{position:"absolute",top:m.top*d*q,left:m.left*d*q,right:m.right*d*q,bottom:m.bottom*d*q},children:k.map(_=>e.jsx(Cn,{field:_,data:r,zoom:d},_.id))}),(x=s.watermarks)==null?void 0:x.map(_=>e.jsx("div",{className:F.watermark,style:{opacity:_.opacity,transform:`rotate(${_.angle}deg)`,fontSize:(_.fontSize??48)*d},children:_.type==="text"?_.text:e.jsx("img",{src:_.imageUrl,alt:"wm",style:{maxWidth:200*d}})},_.id))]})},In=({template:s,entities:r=[],sampleData:d,onPrint:l,className:N,style:m,theme:k="light",asPopup:x=!0,open:_,onClose:w})=>{const{t:o}=Pe.useNiceTranslation(),[D,v]=y.useState(0),[n,a]=y.useState(.8),[p,u]=y.useState(!0),j=_!==void 0,z=j?_:p,g=()=>{j||u(!1),w==null||w()};y.useEffect(()=>{if(!x||!z)return;const R=h=>{h.key==="Escape"&&g()};return document.addEventListener("keydown",R),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=""}},[x,z]);const I=y.useMemo(()=>r.length>0?r:d?[d.data]:[{}],[r,d]),C=I[D]??{};if(x&&!z)return null;const P=e.jsxs("div",{className:`${F.root} ${k==="dark"?F.dark:""} ${N??""}`,style:m,children:[e.jsxs("div",{className:F.headerBar,children:[e.jsxs("div",{className:F.entityNav,children:[I.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:F.navBtn,disabled:D===0,onClick:()=>v(R=>R-1),children:"‹"}),e.jsxs("span",{className:F.navLabel,children:[D+1," / ",I.length]}),e.jsx("button",{className:F.navBtn,disabled:D>=I.length-1,onClick:()=>v(R=>R+1),children:"›"})]}),r.length===0&&d&&e.jsx("span",{className:F.sampleBadge,children:"Przykładowe dane"})]}),e.jsxs("div",{className:F.zoomBar,children:[e.jsx("button",{className:F.zoomBtn,onClick:()=>a(R=>Math.max(.3,R-.1)),children:"−"}),e.jsxs("span",{className:F.zoomLabel,children:[Math.round(n*100),"%"]}),e.jsx("button",{className:F.zoomBtn,onClick:()=>a(R=>Math.min(2.5,R+.1)),children:"+"}),e.jsx("button",{className:F.zoomBtn,onClick:()=>a(.8),title:"Dopasuj",children:"⊡"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:F.printBtn,onClick:()=>l==null?void 0:l({copies:1,printerId:""}),children:o("printPreview.print","Drukuj")}),x&&e.jsx("button",{type:"button",className:F.zoomBtn,onClick:g,"aria-label":o("common.close","Zamknij"),title:o("common.close","Zamknij"),children:"✕"})]})]}),e.jsx("div",{className:F.canvas,children:e.jsx(Bn,{template:s,data:C,zoom:n})}),e.jsxs("div",{className:F.footerBar,children:[e.jsx("span",{children:s.name}),e.jsxs("span",{children:[s.paperSize," · ",s.orientation==="portrait"?"Pion":"Poziom"]}),s.sections.reduce((R,h)=>R+h.fields.length,0)," pól"]})]});if(!x)return P;const A=e.jsx("div",{style:{position:"fixed",inset:0,background:"color-mix(in srgb, var(--text-primary, #000) 50%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:24},onMouseDown:R=>{R.target===R.currentTarget&&g()},role:"presentation",children:e.jsx("div",{role:"dialog","aria-modal":"true",style:{background:"var(--bg-elevated, var(--bg-primary, #ffffff))",borderRadius:12,boxShadow:"0 20px 60px color-mix(in srgb, var(--text-primary, #000) 30%, transparent)",maxWidth:"90vw",maxHeight:"90vh",overflow:"auto"},children:P})});return Ae.createPortal(A,document.body)},Ln="_root_18ftw_1",zn="_dark_18ftw_23",Dn="_statsBar_18ftw_29",Tn="_stat_18ftw_29",$n="_dot_18ftw_51",Rn="_statPrinting_18ftw_53",Pn="_statQueued_18ftw_55",An="_statDone_18ftw_57",Mn="_statError_18ftw_59",En="_toolbar_18ftw_65",Fn="_filterTabs_18ftw_85",Gn="_filterTab_18ftw_85",Hn="_filterTabActive_18ftw_109",Wn="_filterCount_18ftw_111",On="_bulkActions_18ftw_123",Un="_bulkCount_18ftw_125",qn="_bulkBtn_18ftw_127",Yn="_bulkBtnRemove_18ftw_147",Kn="_jobList_18ftw_155",Vn="_listHeader_18ftw_159",Zn="_headerLabel_18ftw_187",Xn="_jobRow_18ftw_193",Qn="_jobRowSelected_18ftw_217",Jn="_jobCheckbox_18ftw_223",el="_statusBadge_18ftw_229",tl="_pulse_18ftw_1",sl="_jobInfo_18ftw_267",al="_jobName_18ftw_269",nl="_jobMeta_18ftw_271",ll="_jobTime_18ftw_281",rl="_jobDuration_18ftw_283",il="_jobError_18ftw_285",ol="_progressBar_18ftw_291",cl="_progressFill_18ftw_305",dl="_copiesEditor_18ftw_321",ul="_copiesBtn_18ftw_333",pl="_copiesValue_18ftw_357",ml="_jobActions_18ftw_363",hl="_actionBtn_18ftw_365",_l="_removeBtn_18ftw_387",gl="_emptyState_18ftw_395",b={root:Ln,dark:zn,statsBar:Dn,stat:Tn,dot:$n,statPrinting:Rn,statQueued:Pn,statDone:An,statError:Mn,toolbar:En,filterTabs:Fn,filterTab:Gn,filterTabActive:Hn,filterCount:Wn,bulkActions:On,bulkCount:Un,bulkBtn:qn,bulkBtnRemove:Yn,jobList:Kn,listHeader:Vn,headerLabel:Zn,jobRow:Xn,jobRowSelected:Qn,jobCheckbox:Jn,statusBadge:el,"badge-queued":"_badge-queued_18ftw_247","badge-printing":"_badge-printing_18ftw_249",pulse:tl,"badge-done":"_badge-done_18ftw_251","badge-error":"_badge-error_18ftw_253","badge-paused":"_badge-paused_18ftw_255","badge-cancelled":"_badge-cancelled_18ftw_257",jobInfo:sl,jobName:al,jobMeta:nl,jobTime:ll,jobDuration:rl,jobError:il,progressBar:ol,progressFill:cl,copiesEditor:dl,copiesBtn:ul,copiesValue:pl,jobActions:ml,actionBtn:hl,removeBtn:_l,emptyState:gl},pe={queued:"Kolejka",printing:"Drukowanie",done:"Wydrukowano",error:"Błąd",paused:"Wstrzymano",cancelled:"Anulowano"};function yl(s){try{return new Date(s).toLocaleTimeString("pl-PL",{hour:"2-digit",minute:"2-digit"})}catch{return s}}function xl(s){const r=Date.now()-new Date(s).getTime(),d=Math.floor(r/1e3);return d<60?`${d}s`:`${Math.floor(d/60)}m ${d%60}s`}const bl=({jobs:s})=>{const r=s.filter(m=>m.status==="printing").length,d=s.filter(m=>m.status==="queued").length,l=s.filter(m=>m.status==="done").length,N=s.filter(m=>m.status==="error").length;return e.jsxs("div",{className:b.statsBar,children:[e.jsxs("span",{className:`${b.stat} ${b.statPrinting}`,children:[e.jsx("span",{className:b.dot}),"Drukuje: ",e.jsx("strong",{children:r})]}),e.jsxs("span",{className:`${b.stat} ${b.statQueued}`,children:[e.jsx("span",{className:b.dot}),"W kolejce: ",e.jsx("strong",{children:d})]}),e.jsxs("span",{className:`${b.stat} ${b.statDone}`,children:[e.jsx("span",{className:b.dot}),"Gotowe: ",e.jsx("strong",{children:l})]}),N>0&&e.jsxs("span",{className:`${b.stat} ${b.statError}`,children:[e.jsx("span",{className:b.dot}),"Błędy: ",e.jsx("strong",{children:N})]})]})},wl=({job:s,index:r,total:d,printers:l,selected:N,onSelect:m,onUpdate:k,onRemove:x,onPrint:_,onReorder:w})=>{const o=l.find(n=>n.id===s.options.printerId),D=r>0&&s.status==="queued",v=r<d-1&&s.status==="queued";return e.jsxs("div",{className:`${b.jobRow} ${N?b.jobRowSelected:""} ${b[`status-${s.status}`]??""}`,children:[e.jsx("input",{type:"checkbox",className:b.jobCheckbox,checked:N,onChange:()=>m(s.id)}),e.jsx("span",{className:`${b.statusBadge} ${b[`badge-${s.status}`]}`,children:pe[s.status]??s.status}),e.jsxs("div",{className:b.jobInfo,children:[e.jsx("div",{className:b.jobName,children:s.templateName??s.templateId}),e.jsxs("div",{className:b.jobMeta,children:[s.entityLabel&&e.jsx("span",{children:s.entityLabel}),o&&e.jsxs("span",{children:["🖨 ",o.name]}),e.jsxs("span",{children:["×",s.options.copies]}),s.createdAt&&e.jsx("span",{className:b.jobTime,children:yl(s.createdAt)}),s.startedAt&&s.status!=="done"&&e.jsx("span",{className:b.jobDuration,children:xl(s.startedAt)})]}),s.status==="printing"&&s.progress!=null&&e.jsx("div",{className:b.progressBar,children:e.jsx("div",{className:b.progressFill,style:{width:`${s.progress}%`}})}),s.status==="error"&&s.errorMessage&&e.jsx("div",{className:b.jobError,children:s.errorMessage})]}),e.jsxs("div",{className:b.copiesEditor,children:[e.jsx("button",{className:b.copiesBtn,disabled:s.options.copies<=1,onClick:()=>k(s.id,{options:{...s.options,copies:s.options.copies-1}}),children:"−"}),e.jsx("span",{className:b.copiesValue,children:s.options.copies}),e.jsx("button",{className:b.copiesBtn,onClick:()=>k(s.id,{options:{...s.options,copies:s.options.copies+1}}),children:"+"})]}),e.jsxs("div",{className:b.jobActions,children:[D&&e.jsx("button",{className:b.actionBtn,title:"Przesuń wyżej",onClick:()=>w(r,r-1),children:"↑"}),v&&e.jsx("button",{className:b.actionBtn,title:"Przesuń niżej",onClick:()=>w(r,r+1),children:"↓"}),s.status==="queued"&&e.jsx("button",{className:b.actionBtn,title:"Drukuj teraz",onClick:()=>_(s.id),children:"▶"}),s.status==="printing"&&e.jsx("button",{className:b.actionBtn,title:"Wstrzymaj",onClick:()=>k(s.id,{status:"paused"}),children:"⏸"}),s.status==="paused"&&e.jsx("button",{className:b.actionBtn,title:"Wznów",onClick:()=>k(s.id,{status:"queued"}),children:"▶"}),e.jsx("button",{className:`${b.actionBtn} ${b.removeBtn}`,title:"Usuń",onClick:()=>x(s.id),children:"✕"})]})]})},vl=({jobs:s,printers:r=[],onJobUpdate:d,onJobRemove:l,onJobReorder:N,onJobPrint:m,onBulkRemove:k,onBulkPrint:x,maxHeight:_=500,className:w,style:o,theme:D="light"})=>{const[v,n]=y.useState(new Set),[a,p]=y.useState("all"),u=a==="all"?s:s.filter(C=>C.status===a),j=y.useCallback(C=>{n(P=>{const A=new Set(P);return A.has(C)?A.delete(C):A.add(C),A})},[]),z=y.useCallback(()=>{v.size===u.length?n(new Set):n(new Set(u.map(C=>C.id)))},[u,v.size]),g=y.useCallback(()=>{k==null||k(Array.from(v)),n(new Set)},[v,k]),I=y.useCallback(()=>{x==null||x(Array.from(v)),n(new Set)},[v,x]);return e.jsxs("div",{className:`${b.root} ${D==="dark"?b.dark:""} ${w??""}`,style:o,children:[e.jsx(bl,{jobs:s}),e.jsxs("div",{className:b.toolbar,children:[e.jsx("div",{className:b.filterTabs,children:["all","queued","printing","done","error"].map(C=>e.jsxs("button",{className:`${b.filterTab} ${a===C?b.filterTabActive:""}`,onClick:()=>p(C),children:[C==="all"?"Wszystkie":pe[C],e.jsx("span",{className:b.filterCount,children:C==="all"?s.length:s.filter(P=>P.status===C).length})]},C))}),v.size>0&&e.jsxs("div",{className:b.bulkActions,children:[e.jsxs("span",{className:b.bulkCount,children:[v.size," zaznaczonych"]}),x&&e.jsx("button",{className:b.bulkBtn,onClick:I,children:"▶ Drukuj wybrane"}),k&&e.jsx("button",{className:`${b.bulkBtn} ${b.bulkBtnRemove}`,onClick:g,children:"✕ Usuń wybrane"})]})]}),e.jsx("div",{className:b.jobList,style:{maxHeight:_},children:u.length===0?e.jsx("div",{className:b.emptyState,children:a==="all"?"Brak zadań w kolejce":`Brak zadań ze statusem "${pe[a]}"`}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:b.listHeader,children:[e.jsx("input",{type:"checkbox",onChange:z,checked:v.size===u.length&&u.length>0}),e.jsx("span",{className:b.headerLabel,children:"Zadanie"}),e.jsx("span",{className:b.headerLabel,children:"Kopie"}),e.jsx("span",{className:b.headerLabel,children:"Akcje"})]}),u.map((C,P)=>e.jsx(wl,{job:C,index:s.indexOf(C),total:s.length,printers:r,selected:v.has(C.id),onSelect:j,onUpdate:d,onRemove:l,onPrint:m,onReorder:N},C.id))]})})]})},jl="_container_yzbyh_1",Nl="_buttonGroup_yzbyh_19",kl="_trigger_yzbyh_31",fl="_triggerDisabled_yzbyh_53",Sl="_mainAction_yzbyh_85",Cl="_dropdownToggle_yzbyh_95",Bl="_chevron_yzbyh_109",Il="_chevronUp_yzbyh_111",Ll="_dropdown_yzbyh_95",zl="_dark_yzbyh_141",Dl="_section_yzbyh_145",Tl="_sectionLabel_yzbyh_147",$l="_divider_yzbyh_167",Rl="_copiesRow_yzbyh_175",Pl="_copiesBtn_yzbyh_185",Al="_copiesValue_yzbyh_209",Ml="_printerSelect_yzbyh_229",El="_printerStatus_yzbyh_255",Fl="_printerDot_yzbyh_269",Gl="_printerStatusLabel_yzbyh_279",Hl="_submitBtn_yzbyh_285",Wl="_spinner_yzbyh_317",Ol="_spin_yzbyh_317",L={container:jl,buttonGroup:Nl,trigger:kl,triggerDisabled:fl,"variant-primary":"_variant-primary_yzbyh_59","variant-secondary":"_variant-secondary_yzbyh_63","variant-ghost":"_variant-ghost_yzbyh_67","size-sm":"_size-sm_yzbyh_75","size-md":"_size-md_yzbyh_77","size-lg":"_size-lg_yzbyh_79",mainAction:Sl,dropdownToggle:Cl,chevron:Bl,chevronUp:Il,dropdown:Ll,dark:zl,section:Dl,sectionLabel:Tl,divider:$l,copiesRow:Rl,copiesBtn:Pl,copiesValue:Al,printerSelect:Ml,printerStatus:El,printerDot:Fl,"dot-ready":"_dot-ready_yzbyh_271","dot-busy":"_dot-busy_yzbyh_273","dot-offline":"_dot-offline_yzbyh_275","dot-error":"_dot-error_yzbyh_277",printerStatusLabel:Gl,submitBtn:Hl,spinner:Wl,spin:Ol},Ul=({onPrint:s,printers:r=[],defaultPrinterId:d,defaultCopies:l=1,disabled:N=!1,loading:m=!1,variant:k="primary",size:x="md",label:_="Drukuj",className:w,style:o,theme:D="light"})=>{var R;const[v,n]=y.useState(!1),[a,p]=y.useState(l),[u,j]=y.useState(d??((R=r[0])==null?void 0:R.id)??""),z=y.useRef(null);y.useEffect(()=>{if(!v)return;const h=O=>{z.current&&!z.current.contains(O.target)&&n(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[v]);const g=y.useCallback(()=>{s({copies:a,printerId:u}),n(!1)},[a,u,s]),I=y.useCallback(()=>p(h=>Math.min(99,h+1)),[]),C=y.useCallback(()=>p(h=>Math.max(1,h-1)),[]),P=[L.container,D==="dark"?L.dark:"",w??""].filter(Boolean).join(" "),A=[L.trigger,L[`variant-${k}`],L[`size-${x}`],N||m?L.triggerDisabled:""].filter(Boolean).join(" ");return e.jsxs("div",{ref:z,className:P,style:o,children:[e.jsxs("div",{className:L.buttonGroup,children:[e.jsxs("button",{className:`${A} ${L.mainAction}`,disabled:N||m,onClick:g,"aria-label":_,children:[m?e.jsx("span",{className:L.spinner}):e.jsx("span",{children:"🖨"}),e.jsx("span",{children:_})]}),e.jsx("button",{className:`${A} ${L.dropdownToggle}`,disabled:N||m,onClick:()=>n(h=>!h),"aria-label":"Opcje druku","aria-expanded":v,children:e.jsx("span",{className:`${L.chevron} ${v?L.chevronUp:""}`,children:"▾"})})]}),v&&e.jsxs("div",{className:L.dropdown,children:[e.jsxs("div",{className:L.section,children:[e.jsx("label",{className:L.sectionLabel,children:"Liczba kopii"}),e.jsxs("div",{className:L.copiesRow,children:[e.jsx("button",{className:L.copiesBtn,onClick:C,disabled:a<=1,children:"−"}),e.jsx("span",{className:L.copiesValue,children:a}),e.jsx("button",{className:L.copiesBtn,onClick:I,disabled:a>=99,children:"+"})]})]}),e.jsx("div",{className:L.divider}),r.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:L.section,children:[e.jsx("label",{className:L.sectionLabel,children:"Drukarka"}),e.jsx("select",{className:L.printerSelect,value:u,onChange:h=>j(h.target.value),children:r.map(h=>e.jsxs("option",{value:h.id,disabled:h.status==="offline"||!h.isOnline&&h.status==null,children:[h.name," ",h.status==="offline"||!h.isOnline&&h.status==null?"(Offline)":h.status==="busy"?"(Zajęta)":""]},h.id))}),r.find(h=>h.id===u)&&e.jsx("div",{className:L.printerStatus,children:(()=>{const h=r.find(ie=>ie.id===u),O=h.status??(h.isOnline?"ready":"offline");return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`${L.printerDot} ${L[`dot-${O}`]}`}),e.jsx("span",{className:L.printerStatusLabel,children:O==="ready"?"Gotowa":O==="busy"?"Zajęta":O==="offline"?"Offline":"Błąd"})]})})()})]}),e.jsx("div",{className:L.divider})]}),e.jsx("div",{className:L.section,children:e.jsx("button",{className:L.submitBtn,onClick:g,disabled:N||m||r.length>0&&(()=>{const h=r.find(O=>O.id===u);return h!=null&&(h.status==="offline"||!h.isOnline&&h.status==null)})(),children:m?"Drukowanie...":`🖨 Drukuj${a>1?` (${a} kopie)`:""}`})})]})]})};exports.NicePrintButton=Ul;exports.NicePrintPreview=In;exports.NicePrintQueue=vl;exports.NiceTemplateBrowser=cn;exports.NiceTemplateEditor=Ia;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),y=require("react"),ve=require("@nice2dev/ui"),Ae=require("react-dom"),Me="_root_552wg_3",Ee="_dark_552wg_27",Fe="_toolbar_552wg_39",Ge="_toolbarGroup_552wg_75",He="_toolbarBtn_552wg_107",We="_toolbarBtnActive_552wg_167",Oe="_toolbarBtnDanger_552wg_191",Ue="_toolbarSelect_552wg_203",qe="_toolbarSep_552wg_233",Ye="_insertWrapper_552wg_259",Ke="_insertBtn_552wg_267",Ve="_insertDropdown_552wg_289",Ze="_insertCategory_552wg_329",Xe="_insertItem_552wg_347",Qe="_insertIcon_552wg_391",Je="_zoomSelect_552wg_405",et="_saveBtn_552wg_437",tt="_editorBody_552wg_473",st="_leftPanel_552wg_489",at="_leftTabs_552wg_519",nt="_leftTab_552wg_519",lt="_leftTabActive_552wg_591",rt="_leftTabIcon_552wg_611",it="_leftTabLabel_552wg_619",ot="_leftContent_552wg_629",ct="_panelHeader_552wg_643",dt="_panelHeaderIcon_552wg_667",ut="_panelHeaderName_552wg_675",pt="_searchBox_552wg_689",mt="_searchInput_552wg_697",ht="_fieldList_552wg_743",_t="_fieldItem_552wg_753",gt="_fieldItemIcon_552wg_797",yt="_fieldItemInfo_552wg_811",bt="_fieldItemLabel_552wg_821",xt="_fieldItemPath_552wg_837",wt="_fieldItemType_552wg_853",vt="_layerList_552wg_873",jt="_layerItem_552wg_885",Nt="_layerItemSelected_552wg_919",kt="_layerIcon_552wg_937",ft="_layerName_552wg_949",St="_layerActions_552wg_965",Ct="_layerBtn_552wg_987",Bt="_wmList_552wg_1019",It="_wmItem_552wg_1027",Lt="_wmRow_552wg_1053",zt="_wmLabel_552wg_1067",Dt="_wmInput_552wg_1079",Tt="_wmInputNum_552wg_1111",$t="_wmSelect_552wg_1131",Rt="_wmSlider_552wg_1163",Pt="_wmValue_552wg_1173",At="_wmUnit_552wg_1187",Mt="_wmDelete_552wg_1197",Et="_addBtn_552wg_1229",Ft="_settingsForm_552wg_1265",Gt="_settingsRow_552wg_1273",Ht="_settingsLabel_552wg_1287",Wt="_settingsInput_552wg_1299",Ot="_settingsInputNum_552wg_1331",Ut="_settingsTextarea_552wg_1363",qt="_settingsDivider_552wg_1397",Yt="_settingsUnit_552wg_1417",Kt="_emptyMsg_552wg_1429",Vt="_canvasArea_552wg_1447",Zt="_testDataBar_552wg_1473",Xt="_testDataLabel_552wg_1505",Qt="_testDataSelect_552wg_1515",Jt="_rulerWrapper_552wg_1535",es="_rulerCorner_552wg_1551",ts="_ruler_552wg_1535",ss="_ruler_h_552wg_1609",as="_ruler_v_552wg_1619",ns="_rulerTick_552wg_1639",ls="_rulerTickMajor_552wg_1679",rs="_rulerLabel_552wg_1699",is="_paperScroll_552wg_1737",os="_paperShadow_552wg_1755",cs="_marginGuide_552wg_1779",ds="_watermark_552wg_1795",us="_sectionCanvas_552wg_1821",ps="_sectionCanvasOver_552wg_1835",ms="_sectionTypeChip_552wg_1843",hs="_sectionResizeBar_552wg_1875",_s="_sectionResizeGrip_552wg_1909",gs="_fieldImagePlaceholder_552wg_1925",ys="_fieldBarcodePlaceholder_552wg_1947",bs="_fieldSignaturePlaceholder_552wg_1975",xs="_resizeHandle_552wg_2001",ws="_handle_n_552wg_2021",vs="_handle_s_552wg_2023",js="_handle_e_552wg_2025",Ns="_handle_w_552wg_2027",ks="_handle_ne_552wg_2029",fs="_handle_nw_552wg_2031",Ss="_handle_se_552wg_2033",Cs="_handle_sw_552wg_2035",Bs="_rightPanel_552wg_2041",Is="_rightTabs_552wg_2071",Ls="_rightTab_552wg_2071",zs="_rightTabActive_552wg_2135",Ds="_propsBody_552wg_2147",Ts="_propsEmpty_552wg_2159",$s="_propsEmptyIcon_552wg_2181",Rs="_propsEmptyText_552wg_2191",Ps="_posGrid_552wg_2203",As="_posCell_552wg_2217",Ms="_posLabel_552wg_2229",Es="_posInput_552wg_2241",Fs="_posUnit_552wg_2283",Gs="_snapSection_552wg_2295",Hs="_snapTitle_552wg_2303",Ws="_snapRow_552wg_2321",Os="_snapBtn_552wg_2331",Us="_styleGroup_552wg_2365",qs="_styleGroupTitle_552wg_2373",Ys="_styleRow_552wg_2403",Ks="_styleLabel_552wg_2417",Vs="_styleSelect_552wg_2431",Zs="_styleSelectFull_552wg_2461",Xs="_styleSelectSm_552wg_2493",Qs="_styleSelectXs_552wg_2513",Js="_styleInput_552wg_2545",ea="_styleInputFull_552wg_2577",ta="_styleUnit_552wg_2609",sa="_styleValue_552wg_2621",aa="_toggleGroup_552wg_2635",na="_toggleBtn_552wg_2645",la="_toggleBtnActive_552wg_2675",ra="_colorPicker_552wg_2689",ia="_colorHex_552wg_2707",oa="_clearBtn_552wg_2741",ca="_sliderInput_552wg_2773",da="_conditionalHint_552wg_2785",ua="_clearConditionalBtn_552wg_2817",pa="_shortcutGrid_552wg_2849",ma="_shortcutChip_552wg_2863",ha="_shortcutKeys_552wg_2895",_a="_shortcutLabel_552wg_2915",t={root:Me,dark:Ee,toolbar:Fe,toolbarGroup:Ge,toolbarBtn:He,toolbarBtnActive:We,toolbarBtnDanger:Oe,toolbarSelect:Ue,toolbarSep:qe,insertWrapper:Ye,insertBtn:Ke,insertDropdown:Ve,insertCategory:Ze,insertItem:Xe,insertIcon:Qe,zoomSelect:Je,saveBtn:et,editorBody:tt,leftPanel:st,leftTabs:at,leftTab:nt,leftTabActive:lt,leftTabIcon:rt,leftTabLabel:it,leftContent:ot,panelHeader:ct,panelHeaderIcon:dt,panelHeaderName:ut,searchBox:pt,searchInput:mt,fieldList:ht,fieldItem:_t,fieldItemIcon:gt,fieldItemInfo:yt,fieldItemLabel:bt,fieldItemPath:xt,fieldItemType:wt,layerList:vt,layerItem:jt,layerItemSelected:Nt,layerIcon:kt,layerName:ft,layerActions:St,layerBtn:Ct,wmList:Bt,wmItem:It,wmRow:Lt,wmLabel:zt,wmInput:Dt,wmInputNum:Tt,wmSelect:$t,wmSlider:Rt,wmValue:Pt,wmUnit:At,wmDelete:Mt,addBtn:Et,settingsForm:Ft,settingsRow:Gt,settingsLabel:Ht,settingsInput:Wt,settingsInputNum:Ot,settingsTextarea:Ut,settingsDivider:qt,settingsUnit:Yt,emptyMsg:Kt,canvasArea:Vt,testDataBar:Zt,testDataLabel:Xt,testDataSelect:Qt,rulerWrapper:Jt,rulerCorner:es,ruler:ts,ruler_h:ss,ruler_v:as,rulerTick:ns,rulerTickMajor:ls,rulerLabel:rs,paperScroll:is,paperShadow:os,marginGuide:cs,watermark:ds,sectionCanvas:us,sectionCanvasOver:ps,sectionTypeChip:ms,sectionResizeBar:hs,sectionResizeGrip:_s,fieldImagePlaceholder:gs,fieldBarcodePlaceholder:ys,fieldSignaturePlaceholder:bs,resizeHandle:xs,handle_n:ws,handle_s:vs,handle_e:js,handle_w:Ns,handle_ne:ks,handle_nw:fs,handle_se:Ss,handle_sw:Cs,rightPanel:Bs,rightTabs:Is,rightTab:Ls,rightTabActive:zs,propsBody:Ds,propsEmpty:Ts,propsEmptyIcon:$s,propsEmptyText:Rs,posGrid:Ps,posCell:As,posLabel:Ms,posInput:Es,posUnit:Fs,snapSection:Gs,snapTitle:Hs,snapRow:Ws,snapBtn:Os,styleGroup:Us,styleGroupTitle:qs,styleRow:Ys,styleLabel:Ks,styleSelect:Vs,styleSelectFull:Zs,styleSelectSm:Xs,styleSelectXs:Qs,styleInput:Js,styleInputFull:ea,styleUnit:ta,styleValue:sa,toggleGroup:aa,toggleBtn:na,toggleBtnActive:la,colorPicker:ra,colorHex:ia,clearBtn:oa,sliderInput:ca,conditionalHint:da,clearConditionalBtn:ua,shortcutGrid:pa,shortcutChip:ma,shortcutKeys:ha,shortcutLabel:_a},G=3.78,ge={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432],custom:[210,297]},ga=["sans-serif","serif","monospace","Arial","Times New Roman","Courier New","Georgia","Verdana","Tahoma"],ye=[6,7,8,9,10,11,12,14,16,18,20,24,28,32,36,48,60,72],le={text:"📝",number:"#",currency:"€",date:"📅",datetime:"🕐",boolean:"✓",image:"🖼",barcode:"▮▌▮",qr:"⬛",signature:"✍",static_text:"T",static_image:"🖼",line:"─",rect:"▭",page_number:"#p",total_pages:"#pp",print_date:"📅"},re={text:"Tekst",number:"Liczba",currency:"Waluta",date:"Data",datetime:"Data i czas",boolean:"Tak/Nie",image:"Obraz",barcode:"Kod kreskowy",qr:"QR",signature:"Podpis",static_text:"Tekst stały",static_image:"Obraz stały",line:"Linia",rect:"Prostokąt",page_number:"Numer strony",total_pages:"Liczba stron",print_date:"Data wydruku"};function ya(s,r){switch(r.type){case"UPDATE":return{past:[...s.past.slice(-50),s.present],present:r.payload,future:[]};case"UNDO":return s.past.length?{past:s.past.slice(0,-1),present:s.past[s.past.length-1],future:[s.present,...s.future]}:s;case"REDO":return s.future.length?{past:[...s.past,s.present],present:s.future[0],future:s.future.slice(1)}:s;default:return s}}function te(){return`f-${Date.now()}-${Math.floor(Math.random()*1e3)}`}function be(s,r){const d={id:te(),name:(r==null?void 0:r.label)??re[s]??s,label:(r==null?void 0:r.label)??re[s]??s,type:s,dataPath:(r==null?void 0:r.path)??"",fallback:s==="static_text"?"Tekst statyczny":void 0,format:s==="date"||s==="datetime"?"DD.MM.YYYY":void 0,position:{x:15,y:15,width:s==="line"?80:60,height:s==="line"?1:s==="image"?30:8},style:{fontSize:10,color:"var(--nice-text, #000000)",fontFamily:"sans-serif"}};return s==="rect"&&(d.style.backgroundColor="var(--nice-bg-secondary, #f1f5f9)"),s==="line"&&(d.style={...d.style,borderWidth:.5,borderColor:"var(--nice-text, #000000)",borderStyle:"solid"}),d}const xe=({lengthMm:s,zoom:r,orientation:d})=>{const l=[],N=r<.6?20:r<1?10:5;for(let m=0;m<=s;m+=N){const k=m*r*G,b=m%(N*2)===0;l.push(e.jsx("div",{className:`${t.rulerTick} ${b?t.rulerTickMajor:""}`,style:d==="h"?{left:k}:{top:k},children:b&&e.jsx("span",{className:t.rulerLabel,children:m})},m))}return e.jsx("div",{className:`${t.ruler} ${t[`ruler_${d}`]}`,children:l})},ba=["n","s","e","w","ne","nw","se","sw"],xa=({onResizeStart:s})=>e.jsx(e.Fragment,{children:ba.map(r=>e.jsx("div",{className:`${t.resizeHandle} ${t[`handle_${r}`]}`,onMouseDown:d=>{d.stopPropagation(),s(r,d)}},r))});function wa(s,r){if(s.type==="static_text")return s.fallback??"Tekst";if(s.type==="page_number")return"1";if(s.type==="total_pages")return"3";if(s.type==="print_date")return new Date().toLocaleDateString("pl-PL");if(r&&s.dataPath){const d=s.dataPath.split(".").reduce((l,N)=>l&&typeof l=="object"?l[N]:null,r);if(d!=null)return String(d)}return s.label?`{${s.label}}`:`{${s.dataPath}}`}const va=({field:s,zoom:r,selected:d,sampleData:l,onClick:N,onDragStart:m,onResizeStart:k,readOnly:b})=>{const _=s.position,w=s.style,o=u=>u*r*G,D=s.type==="line",v=s.type==="rect",n=s.type==="image"||s.type==="static_image",a=s.type==="barcode"||s.type==="qr",p={position:"absolute",left:o(_.x),top:o(_.y),width:o(_.width),height:o(_.height),zIndex:_.zIndex??1,transform:w.rotation?`rotate(${w.rotation}deg)`:void 0,boxSizing:"border-box",overflow:"hidden",...!D&&!v?{fontSize:(w.fontSize??10)*r,fontFamily:w.fontFamily??"sans-serif",fontWeight:w.fontWeight??"normal",fontStyle:w.fontStyle??"normal",color:w.color??"var(--nice-text, #000)",textAlign:w.textAlign??"left",lineHeight:w.lineHeight??1.4,letterSpacing:w.letterSpacing?`${w.letterSpacing}em`:void 0,padding:w.padding?o(w.padding):0}:{},backgroundColor:w.backgroundColor,borderWidth:w.borderWidth??0,borderColor:w.borderColor??"transparent",borderStyle:w.borderStyle??"solid",borderRadius:w.borderRadius,opacity:w.opacity,outline:d?"1.5px solid var(--nice-primary-hover, #2563eb)":"1px dashed transparent",outlineOffset:1,cursor:b?"default":"move"};return e.jsxs("div",{style:p,onClick:N,onMouseDown:b?void 0:m,children:[D?e.jsx("div",{style:{width:"100%",borderBottom:`${(w.borderWidth??.5)*r}px ${w.borderStyle??"solid"} ${w.borderColor??"var(--nice-text, #000)"}`}}):v?null:n?e.jsx("div",{className:t.fieldImagePlaceholder,children:"🖼"}):a?e.jsx("div",{className:t.fieldBarcodePlaceholder,children:s.type==="qr"?"⬛ QR":"▮▌▮ Barcode"}):s.type==="signature"?e.jsxs("div",{className:t.fieldSignaturePlaceholder,children:["✍ ",s.label]}):e.jsx("span",{style:{display:"block",width:"100%"},children:wa(s,l)}),d&&!b&&e.jsx(xa,{onResizeStart:k})]})},ja=({section:s,zoom:r,paperWidthMm:d,selectedIds:l,sampleData:N,readOnly:m,showGrid:k,onFieldClick:b,onFieldDragStart:_,onResizeStart:w,onSectionHeightChange:o,onDropField:D})=>{const v=(s.heightMm??(s.type==="body"?200:40))*r*G,n=d*r*G,[a,p]=y.useState(!1),u={header:"rgba(219,234,254,0.35)",footer:"rgba(220,252,231,0.35)",background:"rgba(254,249,195,0.35)",body:"transparent"};return e.jsxs("div",{className:`${t.sectionCanvas} ${a?t.sectionCanvasOver:""}`,style:{width:n,height:v,position:"relative",background:u[s.type]??"transparent",backgroundImage:k?`repeating-linear-gradient(0deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*r*G}px),
2
+ repeating-linear-gradient(90deg, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 0, var(--nice-overlay-15, rgba(148, 163, 184, 0.15)) 1px, transparent 1px, transparent ${5*r*G}px)`:void 0},onDragOver:j=>{j.preventDefault(),p(!0)},onDragLeave:()=>p(!1),onDrop:j=>{j.preventDefault(),p(!1);const z=j.dataTransfer.getData("fieldPath");if(!z)return;const g=j.currentTarget.getBoundingClientRect(),I=(j.clientX-g.left)/(r*G),C=(j.clientY-g.top)/(r*G);D(s.id,z,Math.max(0,I),Math.max(0,C))},children:[e.jsx("div",{className:t.sectionTypeChip,children:s.type}),s.fields.map(j=>e.jsx(va,{field:j,zoom:r,selected:l.has(j.id),sampleData:N,readOnly:m,onClick:z=>b(j.id,z),onDragStart:z=>_(j.id,z),onResizeStart:(z,g)=>w(j.id,z,g)},j.id)),!m&&s.type!=="body"&&e.jsx("div",{className:t.sectionResizeBar,onMouseDown:j=>{j.preventDefault();const z=j.clientY,g=s.heightMm??40,I=P=>{const A=(P.clientY-z)/(r*G);o(s.id,Math.max(10,g+A))},C=()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",C)};document.addEventListener("mousemove",I),document.addEventListener("mouseup",C)},children:e.jsx("div",{className:t.sectionResizeGrip})})]})},ee=({keys:s,label:r})=>e.jsxs("div",{className:t.shortcutChip,children:[e.jsx("span",{className:t.shortcutKeys,children:s}),e.jsx("span",{className:t.shortcutLabel,children:r})]}),Na=[{id:"fields",icon:"📝",label:"Pola"},{id:"layers",icon:"◧",label:"Warstwy"},{id:"watermarks",icon:"💧",label:"Znaki"},{id:"signatures",icon:"✍",label:"Podpisy"},{id:"settings",icon:"⚙",label:"Ustawienia"}],ka=[{id:"position",label:"Pozycja"},{id:"style",label:"Styl"},{id:"data",label:"Dane"},{id:"conditional",label:"Warunki"}],fa=({tpl:s,zoom:r,canUndo:d,canRedo:l,showGrid:N,showRulers:m,readOnly:k,selectedCount:b,onPaperChange:_,onZoom:w,onUndo:o,onRedo:D,onToggleGrid:v,onToggleRulers:n,onInsert:a,onDelete:p,onDuplicate:u,onAlignH:j,onAlignV:z,onBringForward:g,onSendBackward:I,onSave:C})=>{const[P,A]=y.useState(!1),R=[.5,.75,1,1.25,1.5,2];return e.jsxs("div",{className:t.toolbar,children:[e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("select",{className:t.toolbarSelect,value:s.paperSize,onChange:h=>_(h.target.value,s.orientation),children:["A4","A5","A3","Letter","Legal","Tabloid","custom"].map(h=>e.jsx("option",{value:h,children:h},h))}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="portrait"?t.toolbarBtnActive:""}`,onClick:()=>_(s.paperSize,"portrait"),title:"Pion",children:"⬜"}),e.jsx("button",{className:`${t.toolbarBtn} ${s.orientation==="landscape"?t.toolbarBtnActive:""}`,onClick:()=>_(s.paperSize,"landscape"),title:"Poziom",children:"▭"})]}),!k&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,disabled:!d,onClick:o,title:"Cofnij (Ctrl+Z)",children:"↩"}),e.jsx("button",{className:t.toolbarBtn,disabled:!l,onClick:D,title:"Ponów (Ctrl+Y)",children:"↪"})]}),!k&&e.jsxs("div",{className:t.insertWrapper,children:[e.jsx("button",{className:`${t.toolbarBtn} ${t.insertBtn}`,onClick:()=>A(h=>!h),children:"+ Wstaw ▾"}),P&&e.jsxs("div",{className:t.insertDropdown,onMouseLeave:()=>A(!1),children:[e.jsx("div",{className:t.insertCategory,children:"Pola danych"}),["text","number","currency","date","image","barcode","qr"].map(h=>e.jsxs("button",{className:t.insertItem,onClick:()=>{a(h),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:le[h]}),re[h]]},h)),e.jsx("div",{className:t.insertCategory,children:"Elementy statyczne"}),["static_text","static_image","line","rect","page_number","total_pages","print_date"].map(h=>e.jsxs("button",{className:t.insertItem,onClick:()=>{a(h),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:le[h]}),re[h]]},h)),e.jsx("div",{className:t.insertCategory,children:"Specjalne"}),e.jsxs("button",{className:t.insertItem,onClick:()=>{a("watermark"),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:"💧"}),"Znak wodny"]}),e.jsxs("button",{className:t.insertItem,onClick:()=>{a("signature"),A(!1)},children:[e.jsx("span",{className:t.insertIcon,children:"✍"}),"Podpis"]})]})]}),!k&&b>0&&e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:u,title:"Duplikuj (Ctrl+D)",children:"⧉"}),e.jsx("button",{className:`${t.toolbarBtn} ${t.toolbarBtnDanger}`,onClick:p,title:"Usuń (Del)",children:"🗑"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j("left"),title:"Wyrównaj lewo",children:"⬛□□"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j("center"),title:"Wyśrodkuj",children:"□⬛□"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>j("right"),title:"Wyrównaj prawo",children:"□□⬛"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("top"),title:"Góra",children:"⊤"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("center"),title:"Środek V",children:"⊕"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>z("bottom"),title:"Dół",children:"⊥"}),e.jsx("span",{className:t.toolbarSep}),e.jsx("button",{className:t.toolbarBtn,onClick:g,title:"Do przodu",children:"▲"}),e.jsx("button",{className:t.toolbarBtn,onClick:I,title:"Do tyłu",children:"▼"})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:`${t.toolbarBtn} ${N?t.toolbarBtnActive:""}`,onClick:v,title:"Siatka",children:"⊞"}),e.jsx("button",{className:`${t.toolbarBtn} ${m?t.toolbarBtnActive:""}`,onClick:n,title:"Linijki",children:"⊢"})]}),e.jsxs("div",{className:t.toolbarGroup,children:[e.jsx("button",{className:t.toolbarBtn,onClick:()=>w(Math.max(.25,r-.1)),children:"−"}),e.jsx("select",{className:t.zoomSelect,value:R.includes(r)?r:"",onChange:h=>w(+h.target.value),children:R.map(h=>e.jsxs("option",{value:h,children:[Math.round(h*100),"%"]},h))}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>w(Math.min(3,r+.1)),children:"+"}),e.jsx("button",{className:t.toolbarBtn,onClick:()=>w(1),title:"100%",children:"⊡"})]}),!k&&C&&e.jsx("button",{className:t.saveBtn,onClick:C,children:"💾 Zapisz"})]})},Sa=({activeTab:s,onTabChange:r,schema:d,tpl:l,allFields:N,selectedIds:m,onInsertSchemaField:k,onSelectField:b,onUpdateTpl:_,onReorderField:w})=>{const[o,D]=y.useState(""),v=d==null?void 0:d.fields.filter(n=>n.label.toLowerCase().includes(o.toLowerCase())||n.path.toLowerCase().includes(o.toLowerCase()));return e.jsxs("div",{className:t.leftPanel,children:[e.jsx("div",{className:t.leftTabs,children:Na.map(n=>e.jsxs("button",{className:`${t.leftTab} ${s===n.id?t.leftTabActive:""}`,onClick:()=>r(n.id),title:n.label,children:[e.jsx("span",{className:t.leftTabIcon,children:n.icon}),e.jsx("span",{className:t.leftTabLabel,children:n.label})]},n.id))}),e.jsxs("div",{className:t.leftContent,children:[s==="fields"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Pola danych"}),e.jsx("div",{className:t.searchBox,children:e.jsx("input",{className:t.searchInput,placeholder:"Szukaj...",value:o,onChange:n=>D(n.target.value)})}),d?e.jsxs("div",{className:t.fieldList,children:[(v??[]).map(n=>e.jsxs("div",{className:t.fieldItem,draggable:!0,onDragStart:a=>{a.dataTransfer.setData("fieldPath",n.path),a.dataTransfer.setData("fieldLabel",n.label),a.dataTransfer.setData("fieldType",n.type)},onClick:()=>k(n),children:[e.jsx("span",{className:t.fieldItemIcon,children:le[n.type]??"📝"}),e.jsxs("div",{className:t.fieldItemInfo,children:[e.jsx("div",{className:t.fieldItemLabel,children:n.label}),e.jsx("div",{className:t.fieldItemPath,children:n.path})]}),e.jsx("span",{className:t.fieldItemType,children:n.type})]},n.path)),(v==null?void 0:v.length)===0&&e.jsx("div",{className:t.emptyMsg,children:"Brak wyników"})]}):e.jsx("div",{className:t.emptyMsg,children:"Brak schematu danych. Przypisz encję w zakładce Ustawienia."})]}),s==="layers"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.panelHeader,children:["Warstwy (",N.length,")"]}),e.jsxs("div",{className:t.layerList,children:[N.length===0&&e.jsx("div",{className:t.emptyMsg,children:"Brak elementów"}),N.slice().reverse().map(n=>e.jsxs("div",{className:`${t.layerItem} ${m.has(n.id)?t.layerItemSelected:""}`,onClick:()=>b(n.id),children:[e.jsx("span",{className:t.layerIcon,children:le[n.type]??"📝"}),e.jsx("span",{className:t.layerName,children:n.name||n.label}),e.jsxs("div",{className:t.layerActions,children:[e.jsx("button",{className:t.layerBtn,onClick:a=>{a.stopPropagation(),w(n.id,-1)},title:"Do przodu",children:"↑"}),e.jsx("button",{className:t.layerBtn,onClick:a=>{a.stopPropagation(),w(n.id,1)},title:"Do tyłu",children:"↓"})]})]},n.id))]})]}),s==="watermarks"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Znaki wodne"}),e.jsxs("div",{className:t.wmList,children:[(l.watermarks??[]).map(n=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Typ"}),e.jsxs("select",{className:t.wmSelect,value:n.type,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,type:a.target.value}:u)})},children:[e.jsx("option",{value:"text",children:"Tekst"}),e.jsx("option",{value:"image",children:"Obraz"})]})]}),n.type==="text"&&e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Tekst"}),e.jsx("input",{className:t.wmInput,value:n.text??"",onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,text:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.02,max:.5,step:.01,className:t.wmSlider,value:n.opacity,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,opacity:+a.target.value}:u)})}}),e.jsxs("span",{className:t.wmValue,children:[Math.round(n.opacity*100),"%"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Kąt"}),e.jsx("input",{type:"range",min:-90,max:90,step:5,className:t.wmSlider,value:n.angle,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,angle:+a.target.value}:u)})}}),e.jsxs("span",{className:t.wmValue,children:[n.angle,"°"]})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Rozmiar"}),e.jsx("input",{type:"number",min:8,max:200,className:t.wmInputNum,value:n.fontSize??48,onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,fontSize:+a.target.value}:u)})}}),e.jsx("span",{className:t.wmUnit,children:"pt"})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Kolor"}),e.jsx("input",{type:"color",className:t.colorPicker,value:n.color??"var(--nice-text-muted, #94a3b8)",onChange:a=>{var p;return _({watermarks:(p=l.watermarks)==null?void 0:p.map(u=>u.id===n.id?{...u,color:a.target.value}:u)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var a;return _({watermarks:(a=l.watermarks)==null?void 0:a.filter(p=>p.id!==n.id)})},children:"Usuń"})]},n.id)),e.jsx("button",{className:t.addBtn,onClick:()=>_({watermarks:[...l.watermarks??[],{id:te(),type:"text",text:"KOPIA",opacity:.12,angle:-45,fontSize:60,color:"var(--nice-text-muted, #94a3b8)"}]}),children:"+ Dodaj znak wodny"})]})]}),s==="signatures"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Podpisy"}),e.jsxs("div",{className:t.wmList,children:[(l.signatures??[]).map(n=>e.jsxs("div",{className:t.wmItem,children:[e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Etykieta"}),e.jsx("input",{className:t.wmInput,value:n.label,onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,label:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Nazwisko"}),e.jsx("input",{className:t.wmInput,value:n.signerName??"",onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,signerName:a.target.value}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Linia"}),e.jsx("input",{type:"checkbox",checked:n.showLine??!0,onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,showLine:a.target.checked}:u)})}})]}),e.jsxs("div",{className:t.wmRow,children:[e.jsx("span",{className:t.wmLabel,children:"Pokaż datę"}),e.jsx("input",{type:"checkbox",checked:n.showDate??!1,onChange:a=>{var p;return _({signatures:(p=l.signatures)==null?void 0:p.map(u=>u.id===n.id?{...u,showDate:a.target.checked}:u)})}})]}),e.jsx("button",{className:t.wmDelete,onClick:()=>{var a;return _({signatures:(a=l.signatures)==null?void 0:a.filter(p=>p.id!==n.id)})},children:"Usuń"})]},n.id)),e.jsx("button",{className:t.addBtn,onClick:()=>_({signatures:[...l.signatures??[],{id:te(),label:"Podpis",position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),children:"+ Dodaj podpis"})]})]}),s==="settings"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:t.panelHeader,children:"Ustawienia szablonu"}),e.jsxs("div",{className:t.settingsForm,children:[e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Nazwa"}),e.jsx("input",{className:t.settingsInput,value:l.name,onChange:n=>_({name:n.target.value})})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Opis"}),e.jsx("textarea",{className:t.settingsTextarea,value:l.description??"",onChange:n=>_({description:n.target.value}),rows:2})]}),e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:"Kategoria"}),e.jsx("input",{className:t.settingsInput,value:l.category??"",onChange:n=>_({category:n.target.value})})]}),e.jsx("div",{className:t.settingsDivider,children:"Marginesy (mm)"}),["top","right","bottom","left"].map(n=>e.jsxs("div",{className:t.settingsRow,children:[e.jsx("label",{className:t.settingsLabel,children:n==="top"?"Góra":n==="right"?"Prawo":n==="bottom"?"Dół":"Lewo"}),e.jsx("input",{type:"number",min:0,max:50,step:1,className:t.settingsInputNum,value:l.margins[n],onChange:a=>_({margins:{...l.margins,[n]:+a.target.value}})}),e.jsx("span",{className:t.settingsUnit,children:"mm"})]},n))]})]})]})]})},Ca=({field:s,activeTab:r,onTabChange:d,onChange:l,paperWidthMm:N,paperHeightMm:m})=>{var o,D,v,n;const k=y.useCallback(a=>s&&l({position:{...s.position,...a}}),[s,l]),b=y.useCallback(a=>s&&l({style:{...(s==null?void 0:s.style)??{},...a}}),[s,l]);if(!s)return e.jsxs("div",{className:t.rightPanel,children:[e.jsx("div",{className:t.panelHeader,children:"Właściwości"}),e.jsxs("div",{className:t.propsEmpty,children:[e.jsx("div",{className:t.propsEmptyIcon,children:"⬚"}),e.jsx("div",{className:t.propsEmptyText,children:"Zaznacz element na szablonie"}),e.jsxs("div",{className:t.shortcutGrid,children:[e.jsx(ee,{keys:"Del",label:"Usuń"}),e.jsx(ee,{keys:"Ctrl+D",label:"Duplikuj"}),e.jsx(ee,{keys:"↑↓←→",label:"Przesuń"}),e.jsx(ee,{keys:"Ctrl+Z",label:"Cofnij"}),e.jsx(ee,{keys:"Ctrl+A",label:"Zaznacz wszystko"}),e.jsx(ee,{keys:"Shift+↑",label:"Przesuń 5mm"})]})]})]});const _=!["line","rect","image","static_image","barcode","qr","signature"].includes(s.type),w=!["static_text","static_image","line","rect","page_number","total_pages","print_date"].includes(s.type);return e.jsxs("div",{className:t.rightPanel,children:[e.jsxs("div",{className:t.panelHeader,children:[e.jsx("span",{className:t.panelHeaderIcon,children:le[s.type]}),e.jsx("span",{className:t.panelHeaderName,children:s.name})]}),e.jsx("div",{className:t.rightTabs,children:ka.map(a=>a.id==="data"&&!w?null:e.jsx("button",{className:`${t.rightTab} ${r===a.id?t.rightTabActive:""}`,onClick:()=>d(a.id),children:a.label},a.id))}),e.jsxs("div",{className:t.propsBody,children:[r==="position"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:t.posGrid,children:[[{key:"x",label:"X",unit:"mm"},{key:"y",label:"Y",unit:"mm"},{key:"width",label:"Szer.",unit:"mm"},{key:"height",label:"Wys.",unit:"mm"}].map(({key:a,label:p,unit:u})=>e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:p}),e.jsx("input",{type:"number",step:.5,className:t.posInput,value:Math.round(s.position[a]*10)/10,onChange:j=>k({[a]:+j.target.value})}),e.jsx("span",{className:t.posUnit,children:u})]},a)),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Obrót"}),e.jsx("input",{type:"number",step:5,className:t.posInput,value:s.style.rotation??0,onChange:a=>b({rotation:+a.target.value})}),e.jsx("span",{className:t.posUnit,children:"°"})]}),e.jsxs("div",{className:t.posCell,children:[e.jsx("label",{className:t.posLabel,children:"Z-idx"}),e.jsx("input",{type:"number",step:1,min:1,className:t.posInput,value:s.position.zIndex??1,onChange:a=>k({zIndex:+a.target.value})})]})]}),e.jsxs("div",{className:t.snapSection,children:[e.jsx("div",{className:t.snapTitle,children:"Wyrównanie do strony"}),e.jsxs("div",{className:t.snapRow,children:[e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:0}),title:"Lewa krawędź",children:"⫷"}),e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:(N-s.position.width)/2}),title:"Środek poziomy",children:"⊕"}),e.jsx("button",{className:t.snapBtn,onClick:()=>k({x:N-s.position.width}),title:"Prawa krawędź",children:"⫸"})]})]})]}),r==="style"&&e.jsxs(e.Fragment,{children:[_&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Czcionka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rodzina"}),e.jsx("select",{className:t.styleSelectFull,value:s.style.fontFamily??"sans-serif",onChange:a=>b({fontFamily:a.target.value}),children:ga.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Rozmiar"}),e.jsx("select",{className:t.styleSelectSm,value:ye.includes(s.style.fontSize??10)?s.style.fontSize??10:"",onChange:a=>b({fontSize:+a.target.value}),children:ye.map(a=>e.jsx("option",{value:a,children:a},a))}),e.jsx("input",{type:"number",step:.5,min:4,max:200,className:t.styleInput,value:s.style.fontSize??10,onChange:a=>b({fontSize:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"pt"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Kolor"}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.color??"var(--nice-text, #000000)",onChange:a=>b({color:a.target.value})}),e.jsx("input",{className:t.colorHex,value:s.style.color??"var(--nice-text, #000000)",onChange:a=>b({color:a.target.value}),maxLength:7})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Styl"}),e.jsxs("div",{className:t.toggleGroup,children:[e.jsx("button",{className:`${t.toggleBtn} ${s.style.fontWeight==="bold"?t.toggleBtnActive:""}`,onClick:()=>b({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:()=>b({fontStyle:s.style.fontStyle==="italic"?"normal":"italic"}),children:e.jsx("i",{children:"I"})})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Wyrówn."}),e.jsx("div",{className:t.toggleGroup,children:["left","center","right","justify"].map(a=>e.jsx("button",{title:a,className:`${t.toggleBtn} ${(s.style.textAlign??"left")===a?t.toggleBtnActive:""}`,onClick:()=>b({textAlign:a}),children:a==="left"?"≡L":a==="center"?"≡C":a==="right"?"≡R":"≡J"},a))})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"W. linii"}),e.jsx("input",{type:"number",step:.1,min:1,max:4,className:t.styleInput,value:s.style.lineHeight??1.4,onChange:a=>b({lineHeight:+a.target.value})})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Odstępy"}),e.jsx("input",{type:"number",step:.01,min:-.1,max:.5,className:t.styleInput,value:s.style.letterSpacing??0,onChange:a=>b({letterSpacing:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"em"})]})]}),e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Tło i ramka"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Tło"}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.backgroundColor??"var(--nice-bg, #fff)",onChange:a=>b({backgroundColor:a.target.value})}),e.jsx("button",{className:t.clearBtn,onClick:()=>b({backgroundColor:void 0}),title:"Wyczyść tło",children:"✕"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ramka"}),e.jsx("input",{type:"number",step:.5,min:0,max:10,className:t.styleInput,value:s.style.borderWidth??0,onChange:a=>b({borderWidth:+a.target.value})}),e.jsx("input",{type:"color",className:t.colorPicker,value:s.style.borderColor??"var(--nice-text, #000000)",onChange:a=>b({borderColor:a.target.value})}),e.jsxs("select",{className:t.styleSelectXs,value:s.style.borderStyle??"solid",onChange:a=>b({borderStyle:a.target.value}),children:[e.jsx("option",{value:"solid",children:"─"}),e.jsx("option",{value:"dashed",children:"- -"}),e.jsx("option",{value:"dotted",children:"···"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Zaokr."}),e.jsx("input",{type:"number",step:1,min:0,max:50,className:t.styleInput,value:s.style.borderRadius??0,onChange:a=>b({borderRadius:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"px"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Padding"}),e.jsx("input",{type:"number",step:.5,min:0,max:20,className:t.styleInput,value:s.style.padding??0,onChange:a=>b({padding:+a.target.value})}),e.jsx("span",{className:t.styleUnit,children:"mm"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Krycie"}),e.jsx("input",{type:"range",min:.1,max:1,step:.05,className:t.sliderInput,value:s.style.opacity??1,onChange:a=>b({opacity:+a.target.value})}),e.jsxs("span",{className:t.styleValue,children:[Math.round((s.style.opacity??1)*100),"%"]})]})]})]}),r==="data"&&w&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Źródło danych"}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Ścieżka"}),e.jsx("input",{className:t.styleInputFull,value:s.dataPath,onChange:a=>l({dataPath:a.target.value}),placeholder:"np. invoice.number"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Format"}),e.jsx("input",{className:t.styleInputFull,value:s.format??"",onChange:a=>l({format:a.target.value}),placeholder:"DD.MM.YYYY / #,##0.00"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Domyślny"}),e.jsx("input",{className:t.styleInputFull,value:s.fallback??"",onChange:a=>l({fallback:a.target.value}),placeholder:"Gdy brak wartości"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Typ"}),e.jsx("select",{className:t.styleSelectFull,value:s.type,onChange:a=>l({type:a.target.value}),children:Object.entries(re).map(([a,p])=>e.jsx("option",{value:a,children:p},a))})]}),(s.type==="barcode"||s.type==="qr")&&e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Format kodu"}),e.jsx("select",{className:t.styleSelectFull,value:s.barcodeType??"code128",onChange:a=>l({barcodeType:a.target.value}),children:["ean13","ean8","code128","code39","upc","itf14","datamatrix"].map(a=>e.jsx("option",{value:a,children:a.toUpperCase()},a))})]})]}),r==="conditional"&&e.jsxs("div",{className:t.styleGroup,children:[e.jsx("div",{className:t.styleGroupTitle,children:"Widoczność warunkowa"}),e.jsx("div",{className:t.conditionalHint,children:"Element zostanie ukryty gdy warunek nie jest spełniony."}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Pole"}),e.jsx("input",{className:t.styleInputFull,value:((o=s.conditional)==null?void 0:o.field)??"",onChange:a=>{var p,u;return l({conditional:{field:a.target.value,operator:((p=s.conditional)==null?void 0:p.operator)??"eq",value:(u=s.conditional)==null?void 0:u.value}})},placeholder:"np. invoice.isPaid"})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Operator"}),e.jsxs("select",{className:t.styleSelectFull,value:((D=s.conditional)==null?void 0:D.operator)??"eq",onChange:a=>{var p,u;return l({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:a.target.value,value:(u=s.conditional)==null?void 0:u.value}})},children:[e.jsx("option",{value:"eq",children:"= r�wne"}),e.jsx("option",{value:"neq",children:"≠ różne"}),e.jsx("option",{value:"gt",children:"> wieksze"}),e.jsx("option",{value:"lt",children:"< mniejsze"}),e.jsx("option",{value:"contains",children:"zawiera"})]})]}),e.jsxs("div",{className:t.styleRow,children:[e.jsx("label",{className:t.styleLabel,children:"Wartosc"}),e.jsx("input",{className:t.styleInputFull,value:String(((v=s.conditional)==null?void 0:v.value)??""),onChange:a=>{var p,u;return l({conditional:{field:((p=s.conditional)==null?void 0:p.field)??"",operator:((u=s.conditional)==null?void 0:u.operator)??"eq",value:a.target.value}})},placeholder:'np. true / "PAID"'})]}),((n=s.conditional)==null?void 0:n.field)&&e.jsx("button",{className:t.clearConditionalBtn,onClick:()=>l({conditional:void 0}),children:"Wyczyść warunek"})]})]})]})};function Ba(){return{id:`tpl-${Date.now()}`,name:"Nowy szablon",description:"",paperSize:"A4",orientation:"portrait",margins:{top:20,right:15,bottom:20,left:15},sections:[{id:"sec-header",type:"header",heightMm:35,fields:[]},{id:"sec-body",type:"body",fields:[]},{id:"sec-footer",type:"footer",heightMm:20,fields:[]}],watermarks:[],signatures:[]}}const Ia=({template:s,dataSchema:r,sampleData:d=[],onChange:l,onSave:N,readOnly:m=!1,className:k,style:b,theme:_="light"})=>{const[{past:w,present:o,future:D},v]=y.useReducer(ya,{past:[],present:s??Ba(),future:[]}),[n,a]=y.useState(new Set),[p,u]=y.useState("sec-body"),[j,z]=y.useState(1),[g,I]=y.useState(0),[C,P]=y.useState("fields"),[A,R]=y.useState("position"),[h,O]=y.useState(!1),[ie,je]=y.useState(!0),T=y.useCallback(i=>{const c={...o,...i};v({type:"UPDATE",payload:c}),l==null||l(c)},[o,l]),[Y,oe]=y.useMemo(()=>{const[i,c]=ge[o.paperSize]??ge.A4;return o.orientation==="landscape"?[c,i]:[i,c]},[o.paperSize,o.orientation]),K=y.useMemo(()=>o.sections.flatMap(i=>i.fields),[o]),M=y.useMemo(()=>K.find(i=>n.has(i.id))??null,[K,n]),ce=y.useCallback((i,c)=>{T({sections:o.sections.map(S=>({...S,fields:S.fields.map(f=>f.id===i?{...f,...c,style:{...f.style,...c.style??{}}}:f)}))})},[o,T]),se=y.useCallback(i=>{T({sections:o.sections.map(c=>({...c,fields:c.fields.map(S=>n.has(S.id)?{...S,...i,style:{...S.style,...i.style??{}}}:S)}))})},[o,n,T]),me=y.useCallback((i,c)=>{if(i==="watermark"){T({watermarks:[...o.watermarks??[],{id:te(),type:"text",text:"KOPIA",opacity:.12,angle:-45,fontSize:60,color:"var(--nice-text-muted, #94a3b8)"}]}),P("watermarks");return}if(i==="signature"){T({signatures:[...o.signatures??[],{id:te(),label:"Podpis",position:{x:10,y:5,width:70,height:22},showLine:!0,showDate:!1}]}),P("signatures");return}const S=o.sections.find(E=>E.id===p)??o.sections.find(E=>E.type==="body");if(!S)return;const f=be(i,c),$={sections:o.sections.map(E=>E.id===S.id?{...E,fields:[...E.fields,f]}:E)};v({type:"UPDATE",payload:{...o,...$}}),l==null||l({...o,...$}),a(new Set([f.id]))},[o,p,l]),Ne=y.useCallback((i,c,S,f)=>{const $=r==null?void 0:r.fields.find(H=>H.path===c),E=be(($==null?void 0:$.type)??"text",$);E.position.x=Math.round(S*2)/2,E.position.y=Math.round(f*2)/2;const V={sections:o.sections.map(H=>H.id===i?{...H,fields:[...H.fields,E]}:H)};v({type:"UPDATE",payload:{...o,...V}}),l==null||l({...o,...V}),a(new Set([E.id]))},[o,r,l]),ke=y.useCallback((i,c)=>{c.ctrlKey||c.metaKey?a(S=>{const f=new Set(S);return f.has(i)?f.delete(i):f.add(i),f}):c.shiftKey?a(S=>new Set([...S,i])):a(new Set([i]))},[]),fe=y.useCallback((i,c)=>{if(m)return;c.preventDefault(),n.has(i)||a(new Set([i]));const S=c.clientX,f=c.clientY,$=o.sections.map(H=>({id:H.id,fields:H.fields.map(Z=>({id:Z.id,pos:{...Z.position}}))})),E=H=>{const Z=(H.clientX-S)/(j*G),Q=(H.clientY-f)/(j*G),ae=n.has(i)?n:new Set([i]),ne=o.sections.map(X=>{const U=$.find(W=>W.id===X.id);return{...X,fields:X.fields.map(W=>{var _e;if(!ae.has(W.id))return W;const he=((_e=U==null?void 0:U.fields.find(Pe=>Pe.id===W.id))==null?void 0:_e.pos)??W.position;return{...W,position:{...W.position,x:Math.max(0,Math.round((he.x+Z)*2)/2),y:Math.max(0,Math.round((he.y+Q)*2)/2)}}})}}),J={...o,sections:ne};l==null||l(J),v({type:"UPDATE",payload:J})},V=()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",V)};document.addEventListener("mousemove",E),document.addEventListener("mouseup",V)},[o,j,n,m,l]),Se=y.useCallback((i,c,S)=>{if(m)return;S.preventDefault();const f=K.find(Q=>Q.id===i);if(!f)return;const $={...f.position},E=S.clientX,V=S.clientY,H=Q=>{const ae=(Q.clientX-E)/(j*G),ne=(Q.clientY-V)/(j*G);let{x:J,y:X,width:U,height:W}=$;c.includes("e")&&(U=Math.max(5,U+ae)),c.includes("s")&&(W=Math.max(3,W+ne)),c.includes("w")&&(J=J+ae,U=Math.max(5,U-ae)),c.includes("n")&&(X=X+ne,W=Math.max(3,W-ne)),ce(i,{position:{...$,x:Math.round(J*2)/2,y:Math.round(X*2)/2,width:Math.round(U*2)/2,height:Math.round(W*2)/2}})},Z=()=>{document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",Z)};document.addEventListener("mousemove",H),document.addEventListener("mouseup",Z)},[K,j,m,ce]),de=y.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.filter(c=>!n.has(c.id))}))}),a(new Set)},[o,n,T]),ue=y.useCallback(()=>{const i=new Set;T({sections:o.sections.map(c=>{const S=c.fields.filter(f=>n.has(f.id)).map(f=>{const $={...f,id:te(),position:{...f.position,x:f.position.x+5,y:f.position.y+5}};return i.add($.id),$});return{...c,fields:[...c.fields,...S]}})}),a(i)},[o,n,T]),Ce=y.useCallback(i=>{T({sections:o.sections.map(c=>({...c,fields:c.fields.map(S=>{if(!n.has(S.id))return S;const f=i==="left"?o.margins.left:i==="right"?Y-o.margins.right-S.position.width:(Y-S.position.width)/2;return{...S,position:{...S.position,x:f}}})}))})},[o,n,Y,T]),Be=y.useCallback(i=>{const c=o.sections.find(f=>f.id===p);if(!c)return;const S=c.heightMm??200;T({sections:o.sections.map(f=>f.id!==p?f:{...f,fields:f.fields.map($=>{if(!n.has($.id))return $;const E=i==="top"?0:i==="bottom"?S-$.position.height:(S-$.position.height)/2;return{...$,position:{...$.position,y:E}}})})})},[o,n,p,T]),Ie=y.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.map(c=>n.has(c.id)?{...c,position:{...c.position,zIndex:(c.position.zIndex??1)+1}}:c)}))})},[o,n,T]),Le=y.useCallback(()=>{T({sections:o.sections.map(i=>({...i,fields:i.fields.map(c=>n.has(c.id)?{...c,position:{...c.position,zIndex:Math.max(1,(c.position.zIndex??1)-1)}}:c)}))})},[o,n,T]),ze=y.useCallback((i,c)=>{T({sections:o.sections.map(S=>({...S,fields:S.fields.map(f=>f.id===i?{...f,position:{...f.position,zIndex:Math.max(1,(f.position.zIndex??1)-c)}}:f)}))})},[o,T]);y.useEffect(()=>{const i=c=>{const S=c.target.tagName;if(S==="INPUT"||S==="TEXTAREA"||S==="SELECT")return;const f=c.shiftKey?5:.5;c.key==="Delete"||c.key==="Backspace"?n.size&&(c.preventDefault(),de()):c.ctrlKey&&c.key==="z"?(c.preventDefault(),v({type:"UNDO"})):c.ctrlKey&&(c.key==="y"||c.key==="Y")?(c.preventDefault(),v({type:"REDO"})):c.ctrlKey&&(c.key==="d"||c.key==="D")?(c.preventDefault(),n.size&&ue()):c.ctrlKey&&c.key==="a"?(c.preventDefault(),a(new Set(K.map($=>$.id)))):c.key==="ArrowLeft"?(c.preventDefault(),se({position:{...M.position,x:((M==null?void 0:M.position.x)??0)-f}})):c.key==="ArrowRight"?(c.preventDefault(),se({position:{...M.position,x:((M==null?void 0:M.position.x)??0)+f}})):c.key==="ArrowUp"?(c.preventDefault(),se({position:{...M.position,y:((M==null?void 0:M.position.y)??0)-f}})):c.key==="ArrowDown"&&(c.preventDefault(),se({position:{...M.position,y:((M==null?void 0:M.position.y)??0)+f}}))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n,K,M,de,ue,se]);const De=y.useCallback((i,c)=>{T({sections:o.sections.map(S=>S.id===i?{...S,heightMm:Math.round(c*2)/2}:S)})},[o,T]),Te=y.useMemo(()=>{const i=Array.isArray(d)?d[g]:d;return i?"data"in i?i.data:i:{}},[d,g]),$e=Y*j*G,Re=oe*j*G;return e.jsx(ve.NiceAppShell,{flush:!0,className:`${t.root} ${_==="dark"?t.dark:""} ${k??""}`,style:b,toolbar:e.jsx(fa,{tpl:o,zoom:j,canUndo:w.length>0,canRedo:D.length>0,showGrid:h,showRulers:ie,readOnly:m,selectedCount:n.size,onPaperChange:(i,c)=>T({paperSize:i,orientation:c}),onZoom:z,onUndo:()=>v({type:"UNDO"}),onRedo:()=>v({type:"REDO"}),onToggleGrid:()=>O(i=>!i),onToggleRulers:()=>je(i=>!i),onInsert:me,onDelete:de,onDuplicate:ue,onAlignH:Ce,onAlignV:Be,onBringForward:Ie,onSendBackward:Le,onSave:N?()=>N(o):void 0}),sidebar:e.jsx(Sa,{activeTab:C,onTabChange:P,schema:r,tpl:o,allFields:K,selectedIds:n,onInsertSchemaField:i=>me(i.type,i),onSelectField:i=>a(new Set([i])),onUpdateTpl:i=>T(i),onReorderField:ze}),rightSidebar:e.jsx(Ca,{field:M,activeTab:A,onTabChange:R,onChange:i=>M&&ce(M.id,i),paperWidthMm:Y,paperHeightMm:oe}),children:e.jsxs("div",{className:t.canvasArea,onClick:()=>a(new Set),children:[Array.isArray(d)&&d.length>0&&e.jsxs("div",{className:t.testDataBar,children:[e.jsx("span",{className:t.testDataLabel,children:"Dane testowe:"}),e.jsx("select",{className:t.testDataSelect,value:g,onChange:i=>I(+i.target.value),children:d.map((i,c)=>e.jsxs("option",{value:c,children:["Rekord ",c+1]},c))})]}),ie&&e.jsxs("div",{className:t.rulerWrapper,children:[e.jsx("div",{className:t.rulerCorner}),e.jsx(xe,{lengthMm:Y,zoom:j,orientation:"h"}),e.jsx(xe,{lengthMm:oe,zoom:j,orientation:"v"})]}),e.jsx("div",{className:t.paperScroll,onClick:i=>i.stopPropagation(),children:e.jsxs("div",{className:t.paperShadow,style:{width:$e,minHeight:Re},children:[e.jsx("div",{className:t.marginGuide,style:{top:o.margins.top*j*G,right:o.margins.right*j*G,bottom:o.margins.bottom*j*G,left:o.margins.left*j*G}}),(o.watermarks??[]).map(i=>e.jsx("div",{className:t.watermark,style:{fontSize:(i.fontSize??60)*j,color:i.color??"var(--nice-text-muted, #94a3b8)",opacity:i.opacity,transform:`translate(-50%, -50%) rotate(${i.angle}deg)`},children:i.type==="text"?i.text:"??"},i.id)),o.sections.map(i=>e.jsx("div",{children:e.jsx(ja,{section:i,zoom:j,paperWidthMm:Y,selectedIds:n,sampleData:Te,readOnly:m,showGrid:h,onFieldClick:ke,onFieldDragStart:fe,onResizeStart:Se,onSectionHeightChange:De,onDropField:Ne})},i.id))]})})]})})},La="_root_6hwvk_1",za="_dark_6hwvk_25",Da="_topBar_6hwvk_31",Ta="_searchInput_6hwvk_55",$a="_actionBtn_6hwvk_83",Ra="_categoryRow_6hwvk_117",Pa="_catChip_6hwvk_141",Aa="_catChipActive_6hwvk_167",Ma="_grid_6hwvk_181",Ea="_card_6hwvk_203",Fa="_cardSelected_6hwvk_235",Ga="_thumbnail_6hwvk_251",Ha="_thumbnailImg_6hwvk_265",Wa="_thumbnailPlaceholder_6hwvk_277",Oa="_paperMini_6hwvk_291",Ua="_paperLine_6hwvk_315",qa="_cardOverlay_6hwvk_329",Ya="_overlayBtn_6hwvk_349",Ka="_overlayBtnDanger_6hwvk_381",Va="_cardBody_6hwvk_411",Za="_cardName_6hwvk_415",Xa="_cardDesc_6hwvk_439",Qa="_cardMeta_6hwvk_461",Ja="_cardSize_6hwvk_475",en="_cardCat_6hwvk_491",tn="_cardTags_6hwvk_507",sn="_cardTag_6hwvk_507",an="_emptyState_6hwvk_531",nn="_emptyIcon_6hwvk_553",B={root:La,dark:za,topBar:Da,searchInput:Ta,actionBtn:$a,categoryRow:Ra,catChip:Pa,catChipActive:Aa,grid:Ma,card:Ea,cardSelected:Fa,thumbnail:Ga,thumbnailImg:Ha,thumbnailPlaceholder:Wa,paperMini:Oa,paperLine:Ua,cardOverlay:qa,overlayBtn:Ya,overlayBtnDanger:Ka,cardBody:Va,cardName:Za,cardDesc:Xa,cardMeta:Qa,cardSize:Ja,cardCat:en,cardTags:tn,cardTag:sn,emptyState:an,emptyIcon:nn},ln=["Faktury","Raporty","Etykiety","Listy","Umowy","Inne"];function rn(s){return new Promise((r,d)=>{const l=new FileReader;l.onload=N=>{var m;try{r(JSON.parse((m=N.target)==null?void 0:m.result))}catch(k){d(k)}},l.readAsText(s)})}function on(s){const r=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),d=URL.createObjectURL(r),l=document.createElement("a");l.href=d,l.download=`${s.name.replace(/\s+/g,"_")}.json`,l.click(),URL.revokeObjectURL(d)}const cn=({templates:s,selectedId:r,onSelect:d,onImport:l,onExport:N,onDelete:m,onNew:k,className:b,style:_,theme:w="light"})=>{const[o,D]=y.useState(""),[v,n]=y.useState(null),[a,p]=y.useState(null),u=y.useRef(null),j=async g=>{var C;const I=(C=g.target.files)==null?void 0:C[0];if(I){try{const P=await rn(I);l==null||l(P)}catch{}g.target.value=""}},z=s.filter(g=>{const I=!o||g.name.toLowerCase().includes(o.toLowerCase())||(g.description??"").toLowerCase().includes(o.toLowerCase())||(g.tags??[]).some(P=>P.toLowerCase().includes(o.toLowerCase())),C=!v||g.category===v;return I&&C});return e.jsxs("div",{className:`${B.root} ${w==="dark"?B.dark:""} ${b??""}`,style:_,children:[e.jsxs("div",{className:B.topBar,children:[e.jsx("input",{type:"search",className:B.searchInput,placeholder:"Szukaj szablonów…",value:o,onChange:g=>D(g.target.value)}),e.jsx("button",{className:B.actionBtn,onClick:k,title:"Nowy szablon",children:"+ Nowy"}),e.jsx("button",{className:B.actionBtn,onClick:()=>{var g;return(g=u.current)==null?void 0:g.click()},title:"Importuj JSON",children:"⬆ Import"}),e.jsx("input",{ref:u,type:"file",accept:".json",hidden:!0,onChange:j})]}),e.jsxs("div",{className:B.categoryRow,children:[e.jsx("button",{className:`${B.catChip} ${v?"":B.catChipActive}`,onClick:()=>n(null),children:"Wszystkie"}),ln.map(g=>e.jsx("button",{className:`${B.catChip} ${v===g?B.catChipActive:""}`,onClick:()=>n(I=>I===g?null:g),children:g},g))]}),e.jsxs("div",{className:B.grid,children:[z.map(g=>e.jsxs("div",{className:`${B.card} ${r===g.id?B.cardSelected:""}`,onClick:()=>d==null?void 0:d(g),onMouseEnter:()=>p(g.id),onMouseLeave:()=>p(null),children:[e.jsxs("div",{className:B.thumbnail,children:[g.previewImageUrl?e.jsx("img",{src:g.previewImageUrl,alt:g.name,className:B.thumbnailImg}):e.jsx("div",{className:B.thumbnailPlaceholder,children:e.jsxs("div",{className:B.paperMini,children:[e.jsx("div",{className:B.paperLine,style:{width:"80%"}}),e.jsx("div",{className:B.paperLine,style:{width:"60%"}}),e.jsx("div",{className:B.paperLine,style:{width:"90%"}}),e.jsx("div",{className:B.paperLine,style:{width:"50%"}})]})}),a===g.id&&e.jsxs("div",{className:B.cardOverlay,children:[e.jsx("button",{className:B.overlayBtn,onClick:I=>{I.stopPropagation(),N==null||N(g),on(g)},title:"Eksportuj",children:"⬇"}),m&&e.jsx("button",{className:B.overlayBtnDanger,onClick:I=>{I.stopPropagation(),m(g.id)},title:"Usuń",children:"✕"})]})]}),e.jsxs("div",{className:B.cardBody,children:[e.jsx("div",{className:B.cardName,children:g.name}),g.description&&e.jsx("div",{className:B.cardDesc,children:g.description}),e.jsxs("div",{className:B.cardMeta,children:[e.jsxs("span",{className:B.cardSize,children:[g.paperSize," ",g.orientation==="landscape"?"↔":"↕"]}),g.category&&e.jsx("span",{className:B.cardCat,children:g.category})]}),g.tags&&g.tags.length>0&&e.jsx("div",{className:B.cardTags,children:g.tags.slice(0,3).map(I=>e.jsx("span",{className:B.cardTag,children:I},I))})]})]},g.id)),z.length===0&&e.jsxs("div",{className:B.emptyState,children:[e.jsx("span",{className:B.emptyIcon,children:"📄"}),e.jsx("span",{children:o?`Brak wyników dla "${o}"`:"Brak szablonów. Utwórz pierwszy!"})]})]})]})},dn="_root_1grye_1",un="_dark_1grye_19",pn="_headerBar_1grye_25",mn="_entityNav_1grye_47",hn="_navBtn_1grye_49",_n="_navLabel_1grye_73",gn="_sampleBadge_1grye_77",yn="_zoomBar_1grye_95",bn="_zoomBtn_1grye_97",xn="_zoomLabel_1grye_119",wn="_printBtn_1grye_123",vn="_canvas_1grye_149",jn="_page_1grye_169",Nn="_watermark_1grye_191",kn="_footerBar_1grye_221",F={root:dn,dark:un,headerBar:pn,entityNav:mn,navBtn:hn,navLabel:_n,sampleBadge:gn,zoomBar:yn,zoomBtn:bn,zoomLabel:xn,printBtn:wn,canvas:vn,page:jn,watermark:Nn,footerBar:kn},q=3.78,we={A3:[297,420],A4:[210,297],A5:[148,210],A6:[105,148],Letter:[216,279],Legal:[216,356],Tabloid:[279,432]};function fn(s,r){try{return s.split(".").reduce((d,l)=>d&&typeof d=="object"?d[l]:null,r)}catch{return null}}function Sn(s,r,d){if(s==null)return"";if(r==="date"&&d)try{const l=new Date(s);if(d==="DD.MM.YYYY"){const N=String(l.getDate()).padStart(2,"0"),m=String(l.getMonth()+1).padStart(2,"0");return`${N}.${m}.${l.getFullYear()}`}return l.toLocaleDateString()}catch{return String(s)}if(r==="currency"&&d){const l=Number(s);if(!isNaN(l))return`${l.toFixed(2)} ${d}`}return r==="number"&&typeof s=="number"?s.toLocaleString("pl-PL"):String(s)}const Cn=({field:s,data:r,zoom:d})=>{const l=s.dataPath?fn(s.dataPath,r):null,N=l!=null?Sn(l,s.type,s.format):s.fallback??"",m=b=>b*d*q,k={position:"absolute",left:m(s.position.x),top:m(s.position.y),width:m(s.position.width),height:m(s.position.height),fontSize:(s.style.fontSize??10)*d,fontWeight:s.style.fontWeight??"normal",fontStyle:s.style.fontStyle??"normal",color:s.style.color??"var(--text-primary, #0f172a)",textAlign:s.style.textAlign??"left",backgroundColor:s.style.backgroundColor,transform:s.style.rotation?`rotate(${s.style.rotation}deg)`:void 0,overflow:"hidden",display:"flex",alignItems:s.style.verticalAlign==="middle"?"center":s.style.verticalAlign==="bottom"?"flex-end":"flex-start",lineHeight:s.style.lineHeight??1.4,padding:s.style.padding?m(s.style.padding):0,boxSizing:"border-box",borderWidth:s.style.borderWidth,borderColor:s.style.borderColor,borderStyle:s.style.borderStyle,borderRadius:s.style.borderRadius,zIndex:s.position.zIndex??1};return s.type==="image"&&l?e.jsx("div",{style:k,children:e.jsx("img",{src:String(l),alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}})}):s.type==="barcode"||s.type==="qr"?e.jsxs("div",{style:{...k,background:"var(--bg-secondary, #f8fafc)",border:"1px dashed var(--border-color, #e2e8f0)",alignItems:"center",justifyContent:"center",fontSize:10*d},children:[s.type==="qr"?"⬛":"▮▌▮"," ",N]}):s.type==="signature"?e.jsx("div",{style:{...k,borderBottom:"1px solid var(--text-primary, #0f172a)",alignItems:"flex-end"},children:e.jsx("span",{style:{fontSize:8*d,color:"var(--text-muted, #94a3b8)"},children:s.label})}):s.type==="line"?e.jsx("div",{style:{...k,borderBottom:`${s.style.borderWidth??1}px ${s.style.borderStyle??"solid"} ${s.style.borderColor??"var(--text-primary, #0f172a)"}`}}):e.jsx("div",{style:k,children:N})},Bn=({template:s,data:r,zoom:d})=>{var b;const[l,N]=(()=>{const[_,w]=we[s.paperSize]??we.A4;return s.orientation==="landscape"?[w*q*d,_*q*d]:[_*q*d,w*q*d]})(),m=s.margins,k=s.sections.flatMap(_=>_.fields);return e.jsxs("div",{className:F.page,style:{width:l,minHeight:N},children:[e.jsx("div",{style:{position:"absolute",top:m.top*d*q,left:m.left*d*q,right:m.right*d*q,bottom:m.bottom*d*q},children:k.map(_=>e.jsx(Cn,{field:_,data:r,zoom:d},_.id))}),(b=s.watermarks)==null?void 0:b.map(_=>e.jsx("div",{className:F.watermark,style:{opacity:_.opacity,transform:`rotate(${_.angle}deg)`,fontSize:(_.fontSize??48)*d},children:_.type==="text"?_.text:e.jsx("img",{src:_.imageUrl,alt:"wm",style:{maxWidth:200*d}})},_.id))]})},In=({template:s,entities:r=[],sampleData:d,onPrint:l,className:N,style:m,theme:k="light",asPopup:b=!0,open:_,onClose:w})=>{const{t:o}=ve.useNiceTranslation(),[D,v]=y.useState(0),[n,a]=y.useState(.8),[p,u]=y.useState(!0),j=_!==void 0,z=j?_:p,g=()=>{j||u(!1),w==null||w()};y.useEffect(()=>{if(!b||!z)return;const R=h=>{h.key==="Escape"&&g()};return document.addEventListener("keydown",R),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",R),document.body.style.overflow=""}},[b,z]);const I=y.useMemo(()=>r.length>0?r:d?[d.data]:[{}],[r,d]),C=I[D]??{};if(b&&!z)return null;const P=e.jsxs("div",{className:`${F.root} ${k==="dark"?F.dark:""} ${N??""}`,style:m,children:[e.jsxs("div",{className:F.headerBar,children:[e.jsxs("div",{className:F.entityNav,children:[I.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:F.navBtn,disabled:D===0,onClick:()=>v(R=>R-1),children:"‹"}),e.jsxs("span",{className:F.navLabel,children:[D+1," / ",I.length]}),e.jsx("button",{className:F.navBtn,disabled:D>=I.length-1,onClick:()=>v(R=>R+1),children:"›"})]}),r.length===0&&d&&e.jsx("span",{className:F.sampleBadge,children:"Przykładowe dane"})]}),e.jsxs("div",{className:F.zoomBar,children:[e.jsx("button",{className:F.zoomBtn,onClick:()=>a(R=>Math.max(.3,R-.1)),children:"−"}),e.jsxs("span",{className:F.zoomLabel,children:[Math.round(n*100),"%"]}),e.jsx("button",{className:F.zoomBtn,onClick:()=>a(R=>Math.min(2.5,R+.1)),children:"+"}),e.jsx("button",{className:F.zoomBtn,onClick:()=>a(.8),title:"Dopasuj",children:"⊡"})]}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx("button",{className:F.printBtn,onClick:()=>l==null?void 0:l({copies:1,printerId:""}),children:o("printPreview.print","Drukuj")}),b&&e.jsx("button",{type:"button",className:F.zoomBtn,onClick:g,"aria-label":o("common.close","Zamknij"),title:o("common.close","Zamknij"),children:"✕"})]})]}),e.jsx("div",{className:F.canvas,children:e.jsx(Bn,{template:s,data:C,zoom:n})}),e.jsxs("div",{className:F.footerBar,children:[e.jsx("span",{children:s.name}),e.jsxs("span",{children:[s.paperSize," · ",s.orientation==="portrait"?"Pion":"Poziom"]}),s.sections.reduce((R,h)=>R+h.fields.length,0)," pól"]})]});if(!b)return P;const A=e.jsx("div",{style:{position:"fixed",inset:0,background:"color-mix(in srgb, var(--text-primary, #000) 50%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:24},onMouseDown:R=>{R.target===R.currentTarget&&g()},role:"presentation",children:e.jsx("div",{role:"dialog","aria-modal":"true",style:{background:"var(--bg-elevated, var(--bg-primary, #ffffff))",borderRadius:12,boxShadow:"0 20px 60px color-mix(in srgb, var(--text-primary, #000) 30%, transparent)",maxWidth:"90vw",maxHeight:"90vh",overflow:"auto"},children:P})});return Ae.createPortal(A,document.body)},Ln="_root_18ftw_1",zn="_dark_18ftw_23",Dn="_statsBar_18ftw_29",Tn="_stat_18ftw_29",$n="_dot_18ftw_51",Rn="_statPrinting_18ftw_53",Pn="_statQueued_18ftw_55",An="_statDone_18ftw_57",Mn="_statError_18ftw_59",En="_toolbar_18ftw_65",Fn="_filterTabs_18ftw_85",Gn="_filterTab_18ftw_85",Hn="_filterTabActive_18ftw_109",Wn="_filterCount_18ftw_111",On="_bulkActions_18ftw_123",Un="_bulkCount_18ftw_125",qn="_bulkBtn_18ftw_127",Yn="_bulkBtnRemove_18ftw_147",Kn="_jobList_18ftw_155",Vn="_listHeader_18ftw_159",Zn="_headerLabel_18ftw_187",Xn="_jobRow_18ftw_193",Qn="_jobRowSelected_18ftw_217",Jn="_jobCheckbox_18ftw_223",el="_statusBadge_18ftw_229",tl="_pulse_18ftw_1",sl="_jobInfo_18ftw_267",al="_jobName_18ftw_269",nl="_jobMeta_18ftw_271",ll="_jobTime_18ftw_281",rl="_jobDuration_18ftw_283",il="_jobError_18ftw_285",ol="_progressBar_18ftw_291",cl="_progressFill_18ftw_305",dl="_copiesEditor_18ftw_321",ul="_copiesBtn_18ftw_333",pl="_copiesValue_18ftw_357",ml="_jobActions_18ftw_363",hl="_actionBtn_18ftw_365",_l="_removeBtn_18ftw_387",gl="_emptyState_18ftw_395",x={root:Ln,dark:zn,statsBar:Dn,stat:Tn,dot:$n,statPrinting:Rn,statQueued:Pn,statDone:An,statError:Mn,toolbar:En,filterTabs:Fn,filterTab:Gn,filterTabActive:Hn,filterCount:Wn,bulkActions:On,bulkCount:Un,bulkBtn:qn,bulkBtnRemove:Yn,jobList:Kn,listHeader:Vn,headerLabel:Zn,jobRow:Xn,jobRowSelected:Qn,jobCheckbox:Jn,statusBadge:el,"badge-queued":"_badge-queued_18ftw_247","badge-printing":"_badge-printing_18ftw_249",pulse:tl,"badge-done":"_badge-done_18ftw_251","badge-error":"_badge-error_18ftw_253","badge-paused":"_badge-paused_18ftw_255","badge-cancelled":"_badge-cancelled_18ftw_257",jobInfo:sl,jobName:al,jobMeta:nl,jobTime:ll,jobDuration:rl,jobError:il,progressBar:ol,progressFill:cl,copiesEditor:dl,copiesBtn:ul,copiesValue:pl,jobActions:ml,actionBtn:hl,removeBtn:_l,emptyState:gl},pe={queued:"Kolejka",printing:"Drukowanie",done:"Wydrukowano",error:"Błąd",paused:"Wstrzymano",cancelled:"Anulowano"};function yl(s){try{return new Date(s).toLocaleTimeString("pl-PL",{hour:"2-digit",minute:"2-digit"})}catch{return s}}function bl(s){const r=Date.now()-new Date(s).getTime(),d=Math.floor(r/1e3);return d<60?`${d}s`:`${Math.floor(d/60)}m ${d%60}s`}const xl=({jobs:s})=>{const r=s.filter(m=>m.status==="printing").length,d=s.filter(m=>m.status==="queued").length,l=s.filter(m=>m.status==="done").length,N=s.filter(m=>m.status==="error").length;return e.jsxs("div",{className:x.statsBar,children:[e.jsxs("span",{className:`${x.stat} ${x.statPrinting}`,children:[e.jsx("span",{className:x.dot}),"Drukuje: ",e.jsx("strong",{children:r})]}),e.jsxs("span",{className:`${x.stat} ${x.statQueued}`,children:[e.jsx("span",{className:x.dot}),"W kolejce: ",e.jsx("strong",{children:d})]}),e.jsxs("span",{className:`${x.stat} ${x.statDone}`,children:[e.jsx("span",{className:x.dot}),"Gotowe: ",e.jsx("strong",{children:l})]}),N>0&&e.jsxs("span",{className:`${x.stat} ${x.statError}`,children:[e.jsx("span",{className:x.dot}),"Błędy: ",e.jsx("strong",{children:N})]})]})},wl=({job:s,index:r,total:d,printers:l,selected:N,onSelect:m,onUpdate:k,onRemove:b,onPrint:_,onReorder:w})=>{const o=l.find(n=>n.id===s.options.printerId),D=r>0&&s.status==="queued",v=r<d-1&&s.status==="queued";return e.jsxs("div",{className:`${x.jobRow} ${N?x.jobRowSelected:""} ${x[`status-${s.status}`]??""}`,children:[e.jsx("input",{type:"checkbox",className:x.jobCheckbox,checked:N,onChange:()=>m(s.id)}),e.jsx("span",{className:`${x.statusBadge} ${x[`badge-${s.status}`]}`,children:pe[s.status]??s.status}),e.jsxs("div",{className:x.jobInfo,children:[e.jsx("div",{className:x.jobName,children:s.templateName??s.templateId}),e.jsxs("div",{className:x.jobMeta,children:[s.entityLabel&&e.jsx("span",{children:s.entityLabel}),o&&e.jsxs("span",{children:["🖨 ",o.name]}),e.jsxs("span",{children:["×",s.options.copies]}),s.createdAt&&e.jsx("span",{className:x.jobTime,children:yl(s.createdAt)}),s.startedAt&&s.status!=="done"&&e.jsx("span",{className:x.jobDuration,children:bl(s.startedAt)})]}),s.status==="printing"&&s.progress!=null&&e.jsx("div",{className:x.progressBar,children:e.jsx("div",{className:x.progressFill,style:{width:`${s.progress}%`}})}),s.status==="error"&&s.errorMessage&&e.jsx("div",{className:x.jobError,children:s.errorMessage})]}),e.jsxs("div",{className:x.copiesEditor,children:[e.jsx("button",{className:x.copiesBtn,disabled:s.options.copies<=1,onClick:()=>k(s.id,{options:{...s.options,copies:s.options.copies-1}}),children:"−"}),e.jsx("span",{className:x.copiesValue,children:s.options.copies}),e.jsx("button",{className:x.copiesBtn,onClick:()=>k(s.id,{options:{...s.options,copies:s.options.copies+1}}),children:"+"})]}),e.jsxs("div",{className:x.jobActions,children:[D&&e.jsx("button",{className:x.actionBtn,title:"Przesuń wyżej",onClick:()=>w(r,r-1),children:"↑"}),v&&e.jsx("button",{className:x.actionBtn,title:"Przesuń niżej",onClick:()=>w(r,r+1),children:"↓"}),s.status==="queued"&&e.jsx("button",{className:x.actionBtn,title:"Drukuj teraz",onClick:()=>_(s.id),children:"▶"}),s.status==="printing"&&e.jsx("button",{className:x.actionBtn,title:"Wstrzymaj",onClick:()=>k(s.id,{status:"paused"}),children:"⏸"}),s.status==="paused"&&e.jsx("button",{className:x.actionBtn,title:"Wznów",onClick:()=>k(s.id,{status:"queued"}),children:"▶"}),e.jsx("button",{className:`${x.actionBtn} ${x.removeBtn}`,title:"Usuń",onClick:()=>b(s.id),children:"✕"})]})]})},vl=({jobs:s,printers:r=[],onJobUpdate:d,onJobRemove:l,onJobReorder:N,onJobPrint:m,onBulkRemove:k,onBulkPrint:b,maxHeight:_=500,className:w,style:o,theme:D="light"})=>{const[v,n]=y.useState(new Set),[a,p]=y.useState("all"),u=a==="all"?s:s.filter(C=>C.status===a),j=y.useCallback(C=>{n(P=>{const A=new Set(P);return A.has(C)?A.delete(C):A.add(C),A})},[]),z=y.useCallback(()=>{v.size===u.length?n(new Set):n(new Set(u.map(C=>C.id)))},[u,v.size]),g=y.useCallback(()=>{k==null||k(Array.from(v)),n(new Set)},[v,k]),I=y.useCallback(()=>{b==null||b(Array.from(v)),n(new Set)},[v,b]);return e.jsxs("div",{className:`${x.root} ${D==="dark"?x.dark:""} ${w??""}`,style:o,children:[e.jsx(xl,{jobs:s}),e.jsxs("div",{className:x.toolbar,children:[e.jsx("div",{className:x.filterTabs,children:["all","queued","printing","done","error"].map(C=>e.jsxs("button",{className:`${x.filterTab} ${a===C?x.filterTabActive:""}`,onClick:()=>p(C),children:[C==="all"?"Wszystkie":pe[C],e.jsx("span",{className:x.filterCount,children:C==="all"?s.length:s.filter(P=>P.status===C).length})]},C))}),v.size>0&&e.jsxs("div",{className:x.bulkActions,children:[e.jsxs("span",{className:x.bulkCount,children:[v.size," zaznaczonych"]}),b&&e.jsx("button",{className:x.bulkBtn,onClick:I,children:"▶ Drukuj wybrane"}),k&&e.jsx("button",{className:`${x.bulkBtn} ${x.bulkBtnRemove}`,onClick:g,children:"✕ Usuń wybrane"})]})]}),e.jsx("div",{className:x.jobList,style:{maxHeight:_},children:u.length===0?e.jsx("div",{className:x.emptyState,children:a==="all"?"Brak zadań w kolejce":`Brak zadań ze statusem "${pe[a]}"`}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:x.listHeader,children:[e.jsx("input",{type:"checkbox",onChange:z,checked:v.size===u.length&&u.length>0}),e.jsx("span",{className:x.headerLabel,children:"Zadanie"}),e.jsx("span",{className:x.headerLabel,children:"Kopie"}),e.jsx("span",{className:x.headerLabel,children:"Akcje"})]}),u.map((C,P)=>e.jsx(wl,{job:C,index:s.indexOf(C),total:s.length,printers:r,selected:v.has(C.id),onSelect:j,onUpdate:d,onRemove:l,onPrint:m,onReorder:N},C.id))]})})]})},jl="_container_yzbyh_1",Nl="_buttonGroup_yzbyh_19",kl="_trigger_yzbyh_31",fl="_triggerDisabled_yzbyh_53",Sl="_mainAction_yzbyh_85",Cl="_dropdownToggle_yzbyh_95",Bl="_chevron_yzbyh_109",Il="_chevronUp_yzbyh_111",Ll="_dropdown_yzbyh_95",zl="_dark_yzbyh_141",Dl="_section_yzbyh_145",Tl="_sectionLabel_yzbyh_147",$l="_divider_yzbyh_167",Rl="_copiesRow_yzbyh_175",Pl="_copiesBtn_yzbyh_185",Al="_copiesValue_yzbyh_209",Ml="_printerSelect_yzbyh_229",El="_printerStatus_yzbyh_255",Fl="_printerDot_yzbyh_269",Gl="_printerStatusLabel_yzbyh_279",Hl="_submitBtn_yzbyh_285",Wl="_spinner_yzbyh_317",Ol="_spin_yzbyh_317",L={container:jl,buttonGroup:Nl,trigger:kl,triggerDisabled:fl,"variant-primary":"_variant-primary_yzbyh_59","variant-secondary":"_variant-secondary_yzbyh_63","variant-ghost":"_variant-ghost_yzbyh_67","size-sm":"_size-sm_yzbyh_75","size-md":"_size-md_yzbyh_77","size-lg":"_size-lg_yzbyh_79",mainAction:Sl,dropdownToggle:Cl,chevron:Bl,chevronUp:Il,dropdown:Ll,dark:zl,section:Dl,sectionLabel:Tl,divider:$l,copiesRow:Rl,copiesBtn:Pl,copiesValue:Al,printerSelect:Ml,printerStatus:El,printerDot:Fl,"dot-ready":"_dot-ready_yzbyh_271","dot-busy":"_dot-busy_yzbyh_273","dot-offline":"_dot-offline_yzbyh_275","dot-error":"_dot-error_yzbyh_277",printerStatusLabel:Gl,submitBtn:Hl,spinner:Wl,spin:Ol},Ul=({onPrint:s,printers:r=[],defaultPrinterId:d,defaultCopies:l=1,disabled:N=!1,loading:m=!1,variant:k="primary",size:b="md",label:_="Drukuj",className:w,style:o,theme:D="light"})=>{var R;const[v,n]=y.useState(!1),[a,p]=y.useState(l),[u,j]=y.useState(d??((R=r[0])==null?void 0:R.id)??""),z=y.useRef(null);y.useEffect(()=>{if(!v)return;const h=O=>{z.current&&!z.current.contains(O.target)&&n(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[v]);const g=y.useCallback(()=>{s({copies:a,printerId:u}),n(!1)},[a,u,s]),I=y.useCallback(()=>p(h=>Math.min(99,h+1)),[]),C=y.useCallback(()=>p(h=>Math.max(1,h-1)),[]),P=[L.container,D==="dark"?L.dark:"",w??""].filter(Boolean).join(" "),A=[L.trigger,L[`variant-${k}`],L[`size-${b}`],N||m?L.triggerDisabled:""].filter(Boolean).join(" ");return e.jsxs("div",{ref:z,className:P,style:o,children:[e.jsxs("div",{className:L.buttonGroup,children:[e.jsxs("button",{className:`${A} ${L.mainAction}`,disabled:N||m,onClick:g,"aria-label":_,children:[m?e.jsx("span",{className:L.spinner}):e.jsx("span",{children:"🖨"}),e.jsx("span",{children:_})]}),e.jsx("button",{className:`${A} ${L.dropdownToggle}`,disabled:N||m,onClick:()=>n(h=>!h),"aria-label":"Opcje druku","aria-expanded":v,children:e.jsx("span",{className:`${L.chevron} ${v?L.chevronUp:""}`,children:"▾"})})]}),v&&e.jsxs("div",{className:L.dropdown,children:[e.jsxs("div",{className:L.section,children:[e.jsx("label",{className:L.sectionLabel,children:"Liczba kopii"}),e.jsxs("div",{className:L.copiesRow,children:[e.jsx("button",{className:L.copiesBtn,onClick:C,disabled:a<=1,children:"−"}),e.jsx("span",{className:L.copiesValue,children:a}),e.jsx("button",{className:L.copiesBtn,onClick:I,disabled:a>=99,children:"+"})]})]}),e.jsx("div",{className:L.divider}),r.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:L.section,children:[e.jsx("label",{className:L.sectionLabel,children:"Drukarka"}),e.jsx("select",{className:L.printerSelect,value:u,onChange:h=>j(h.target.value),children:r.map(h=>e.jsxs("option",{value:h.id,disabled:h.status==="offline"||!h.isOnline&&h.status==null,children:[h.name," ",h.status==="offline"||!h.isOnline&&h.status==null?"(Offline)":h.status==="busy"?"(Zajęta)":""]},h.id))}),r.find(h=>h.id===u)&&e.jsx("div",{className:L.printerStatus,children:(()=>{const h=r.find(ie=>ie.id===u),O=h.status??(h.isOnline?"ready":"offline");return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`${L.printerDot} ${L[`dot-${O}`]}`}),e.jsx("span",{className:L.printerStatusLabel,children:O==="ready"?"Gotowa":O==="busy"?"Zajęta":O==="offline"?"Offline":"Błąd"})]})})()})]}),e.jsx("div",{className:L.divider})]}),e.jsx("div",{className:L.section,children:e.jsx("button",{className:L.submitBtn,onClick:g,disabled:N||m||r.length>0&&(()=>{const h=r.find(O=>O.id===u);return h!=null&&(h.status==="offline"||!h.isOnline&&h.status==null)})(),children:m?"Drukowanie...":`🖨 Drukuj${a>1?` (${a} kopie)`:""}`})})]})]})};exports.NicePrintButton=Ul;exports.NicePrintPreview=In;exports.NicePrintQueue=vl;exports.NiceTemplateBrowser=cn;exports.NiceTemplateEditor=Ia;