@nice2dev/ui-enterprise 1.0.23 → 1.0.25

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.
@@ -0,0 +1,696 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),G=require("./index-DYmRgxid.cjs"),i=require("react"),_e=require("./NiceForm-BrBaLUkv-RLFZ6sNy.cjs");function On(t,n=30){switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-n,180+n];case"analogous":return[0,-n,n];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270];case"shade-chain":return[];case"custom":return[0,60,200];default:return[0]}}function Et(t,n={}){const a=n.size??16,r="currentColor",o="currentColor";if(n.rectangle||t==="shade-chain"||t==="monochromatic"){const H=Math.max(3,Math.min(7,n.count??5)),D=a*.1,f=a-D*2,j=Math.max(1.2,a/14),R=a/2,Q=Array.from({length:H},(q,Z)=>{const y=D+f*Z/(H-1),T=.25+.75*Z/(H-1);return e.jsx("circle",{cx:y,cy:R,r:j,fill:o,opacity:T},Z)});return e.jsxs("svg",{width:a,height:a,viewBox:`0 0 ${a} ${a}`,"aria-hidden":!0,children:[e.jsx("rect",{x:1,y:a/2-a/6,width:a-2,height:a/3,rx:a/6,fill:"none",stroke:r,strokeOpacity:.25}),Q]})}const p=n.angles??On(t),v=a/2,C=a/2,M=a/2-2,E=Math.max(1.4,a/9);return e.jsxs("svg",{width:a,height:a,viewBox:`0 0 ${a} ${a}`,"aria-hidden":!0,children:[e.jsx("circle",{cx:v,cy:C,r:M,fill:"none",stroke:r,strokeOpacity:.25}),p.map((H,D)=>{const f=(H-90)*Math.PI/180,j=v+M*Math.cos(f),R=C+M*Math.sin(f);return e.jsx("circle",{cx:j,cy:R,r:E,fill:o},D)})]})}function Dt(t,n,a){return Math.max(n,Math.min(a,t))}function Jt({h:t,s:n,v:a}){t=(t%360+360)%360;const r=a*n,o=r*(1-Math.abs(t/60%2-1)),p=a-r;let v=0,C=0,M=0;return t<60?(v=r,C=o):t<120?(v=o,C=r):t<180?(C=r,M=o):t<240?(C=o,M=r):t<300?(v=o,M=r):(v=r,M=o),{r:Math.round((v+p)*255),g:Math.round((C+p)*255),b:Math.round((M+p)*255)}}function Ct({r:t,g:n,b:a}){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),o=Math.min(t,n,a),p=r-o;let v=0;return p!==0&&(r===t?v=(n-a)/p%6:r===n?v=(a-t)/p+2:v=(t-n)/p+4,v=(v*60+360)%360),{h:v,s:r===0?0:p/r,v:r}}function en({r:t,g:n,b:a}){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),o=Math.min(t,n,a),p=(r+o)/2;if(r===o)return{h:0,s:0,l:p};const v=r-o,C=p>.5?v/(2-r-o):v/(r+o);let M=0;return r===t?M=((n-a)/v+(n<a?6:0))/6:r===n?M=((a-t)/v+2)/6:M=((t-n)/v+4)/6,{h:M*360,s:C,l:p}}function lt(t){const n=t.replace("#",""),a=n.length===3?n[0]+n[0]+n[1]+n[1]+n[2]+n[2]:n,r=parseInt(a,16);return{r:r>>16&255,g:r>>8&255,b:r&255}}function tn({r:t,g:n,b:a}){return"#"+[t,n,a].map(r=>r.toString(16).padStart(2,"0")).join("")}function Le(t){return tn(Jt(t))}function He(t){return Ct(lt(t))}function nn(t,n){const a=[];for(let r=0;r<n;r++){const o=n<=1?.5:r/(n-1),p=Dt(t.s*(.3+o*.7),0,1),v=Dt(t.v*(1.2-o*.7),0,1);a.push(Le({h:t.h,s:p,v}))}return a}function Nt(t,n){if(t==="custom"||t==="shade-chain")return[0];const a=n??30;switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-a,180+a];case"analogous":return[0,-a,a];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270]}return[0]}function rt(t,n,a){return Nt(n,a).map(r=>((t+r)%360+360)%360)}function Tt(t,n,a=.12){const r=Math.max(2,n),o=(r-1)/2,p=[];for(let v=0;v<r;v++){const C=(v-o)*a,M=Math.max(.05,Math.min(.98,t.v+C)),E=Math.max(.05,Math.min(1,t.s-Math.abs(C)*.25));p.push(Le({h:t.h,s:E,v:M}))}return p}function zt({r:t,g:n,b:a}){const[r,o,p]=[t,n,a].map(v=>{const C=v/255;return C<=.03928?C/12.92:Math.pow((C+.055)/1.055,2.4)});return .2126*r+.7152*o+.0722*p}function pt(t,n){const a=zt(lt(t)),r=zt(lt(n)),o=Math.max(a,r),p=Math.min(a,r);return(o+.05)/(p+.05)}function ht(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"AA-lg":"Fail"}const an={"lightest-pastel":{sRange:[.1,.25],vRange:[.92,1]},"bright-pastel":{sRange:[.25,.45],vRange:[.9,1]},shiny:{sRange:[.7,.95],vRange:[.9,1]},pastel:{sRange:[.3,.55],vRange:[.75,.92]},full:{sRange:[.75,1],vRange:[.75,1]},dark:{sRange:[.6,.9],vRange:[.3,.55]},deep:{sRange:[.85,1],vRange:[.45,.65]},muted:{sRange:[.15,.35],vRange:[.5,.7]},earth:{sRange:[.3,.6],vRange:[.4,.65]}};function mt(t,n){const a=an[n];return t.map(r=>{const o=(a.sRange[0]+a.sRange[1])/2,p=(a.vRange[0]+a.vRange[1])/2;return Le({h:r,s:o,v:p})})}function Fn(){return Math.floor(Math.random()*360)}function rn(t,n,a){const r=Fn(),o=rt(r,t,a),p=[];for(let v=0;v<n;v++){const C=o[v%o.length],M=.55+Math.random()*.4,E=.5+Math.random()*.45;p.push(Le({h:C+(Math.random()-.5)*8,s:M,v:E}))}return p}const Un=({hues:t,baseHue:n,onBaseHueChange:a,mode:r,distance:o,disabled:p})=>{const v=i.useCallback(D=>{if(p)return;const f=D.currentTarget.getBoundingClientRect(),j=D.clientX-f.left-120,R=D.clientY-f.top-120,Q=(Math.atan2(R,j)*180/Math.PI+360)%360;a(Math.round(Q))},[120,120,p,a]),C=[];for(let D=0;D<360;D+=2){const f=(D-1)*Math.PI/180,j=(D+1)*Math.PI/180,R=Le({h:D,s:1,v:1});C.push(e.jsx("path",{d:`M${120+55*Math.cos(f)},${120+55*Math.sin(f)} L${120+110*Math.cos(f)},${120+110*Math.sin(f)} A110,110 0 0,1 ${120+110*Math.cos(j)},${120+110*Math.sin(j)} L${120+55*Math.cos(j)},${120+55*Math.sin(j)} A55,55 0 0,0 ${120+55*Math.cos(f)},${120+55*Math.sin(f)} Z`,fill:R},D))}const M=`wheel-center-${r}`,E=t.map((D,f)=>{const j=D*Math.PI/180;return e.jsx("circle",{cx:120+82.5*Math.cos(j),cy:120+82.5*Math.sin(j),r:f===0?8:6,fill:Le({h:D,s:.85,v:.9}),stroke:f===0?"var(--bg-primary, #fff)":"var(--border-color, #ccc)",strokeWidth:f===0?3:2},f)});let H=null;if(r==="analogous"||r==="split-complementary"){const D=Nt(r,o).slice(1).map((f,j)=>{const R=(n+f)*Math.PI/180;return e.jsx("line",{x1:120,y1:120,x2:120+82.5*Math.cos(R),y2:120+82.5*Math.sin(R),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${j}`)});H=e.jsx(e.Fragment,{children:D})}return e.jsxs("svg",{className:"nice-palette__wheel",viewBox:"0 0 240 240",width:240,height:240,onClick:v,style:{cursor:p?"default":"crosshair"},children:[e.jsx("defs",{children:e.jsxs("radialGradient",{id:M,children:[e.jsx("stop",{offset:"0%",stopColor:"var(--nice-bg, #fff)"}),e.jsx("stop",{offset:"100%",stopColor:"transparent"})]})}),C,e.jsx("circle",{cx:120,cy:120,r:53,fill:Le({h:n,s:.6,v:.85})}),e.jsx("circle",{cx:120,cy:120,r:53,fill:`url(#${M})`,opacity:.4}),H,E]})},qn=({colors:t})=>{if(t.length<2)return null;const n=[];for(let a=0;a<t.length;a++){const r=pt(t[a],"var(--bg-primary, #ffffff)"),o=pt(t[a],"var(--text-primary, #000000)");n.push({a:t[a],b:"var(--bg-primary, #ffffff)",ratio:r,level:ht(r)}),n.push({a:t[a],b:"var(--text-primary, #000000)",ratio:o,level:ht(o)});for(let p=a+1;p<t.length;p++){const v=pt(t[a],t[p]);n.push({a:t[a],b:t[p],ratio:v,level:ht(v)})}}return e.jsxs("div",{className:"nice-palette__contrast",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Contrast Analysis (WCAG 2.1)"}),e.jsx("div",{className:"nice-palette__contrast-grid",children:n.map((a,r)=>e.jsxs("div",{className:"nice-palette__contrast-pair",children:[e.jsxs("div",{className:"nice-palette__contrast-swatches",children:[e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:a.a}}),e.jsx("span",{className:"nice-palette__contrast-vs",children:"vs"}),e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:a.b}})]}),e.jsxs("span",{className:"nice-palette__contrast-ratio",children:[a.ratio.toFixed(1),":1"]}),e.jsx("span",{className:`nice-palette__contrast-level nice-palette__contrast-level--${a.level.toLowerCase().replace("-","")}`,children:a.level})]},r))})]})},Xn=({hex:t})=>{const n=lt(t),a=en(n),r=Ct(n);return e.jsxs("div",{className:"nice-palette__color-info",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"HEX"})," ",t.toUpperCase()]}),e.jsxs("div",{children:[e.jsx("strong",{children:"RGB"})," ",n.r,", ",n.g,", ",n.b]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSL"})," ",Math.round(a.h),"°, ",Math.round(a.s*100),"%,"," ",Math.round(a.l*100),"%"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSV"})," ",Math.round(r.h),"°, ",Math.round(r.s*100),"%,"," ",Math.round(r.v*100),"%"]})]})},Kn={monochromatic:"Monochromatic",complementary:"Complementary","split-complementary":"Split-Complementary",analogous:"Analogous",triadic:"Triadic",tetradic:"Tetradic (Rectangle)",square:"Square","shade-chain":"Shade chain",custom:"Custom"},Zn={"lightest-pastel":"Lightest Pastel","bright-pastel":"Bright Pastel",shiny:"Shiny",pastel:"Pastel",full:"Full Colors",dark:"Dark",deep:"Deep Colors",muted:"Muted",earth:"Earth Tones"},Vn=["monochromatic","shade-chain","complementary","split-complementary","analogous","triadic","tetradic","square","custom"],ln="nice-palette-custom-schemes";function Yn(){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(ln);if(!t)return[];const n=JSON.parse(t);if(Array.isArray(n))return n}catch{}return[]}function Gn(t){if(!(typeof window>"u"))try{window.localStorage.setItem(ln,JSON.stringify(t))}catch{}}const sn=i.forwardRef(({id:t,className:n,style:a,accessMode:r,value:o,onChange:p,minColors:v=1,maxColors:C=8,harmonyMode:M,onHarmonyModeChange:E,distance:H,onDistanceChange:D,preset:f,onPresetChange:j,showWheel:R=!0,showContrast:Q=!0,showInfo:q=!0,showPresets:Z=!0,presets:y=[],showVariations:T=!0,showRandom:A=!0,variationCount:k=5,label:z,disabled:S,colorCount:x,shadeStep:m,onShadeStepChange:N,customSchemes:$,onCustomSchemesChange:L,persistCustomSchemes:u=!0},d)=>{const I=G.Nl(r,t),w=I==="hidden";(I==="disabled"||I==="readOnly")&&(S=!0);const _=G.hl(t),{t:g}=G.ce(),[l,h]=i.useState("analogous"),[c,s]=i.useState(30),[F,O]=i.useState(""),[Y,J]=i.useState(0),[me,de]=i.useState(.12),[P,B]=i.useState(null),[re,ue]=i.useState(()=>$??(u?Yn():[])),[fe,V]=i.useState(null),ne=M??l,oe=H??c,xe=f??F,le=m??me,U=$??re;i.useEffect(()=>{!$&&u&&Gn(re)},[re,$,u]);const K=i.useCallback(ae=>{ue(ae),L==null||L(ae)},[L]),W=i.useCallback(ae=>{h(ae),E==null||E(ae)},[E]),se=i.useCallback(ae=>{s(ae),D==null||D(ae)},[D]),be=i.useCallback(ae=>{O(ae),ae&&(j==null||j(ae))},[j]),ie=i.useMemo(()=>["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)"],[]),ce=o&&o.length>0?o:ie,he=ce[0],ke=i.useMemo(()=>He(he),[he]),$e=i.useMemo(()=>rt(ke.h,ne,oe),[ke.h,ne,oe]),Ee=i.useCallback((ae,ge,Ce,ze)=>{var Te;const X=x??P??void 0,pe=X!==void 0?Math.max(v,Math.min(C,X)):void 0;if(ge==="shade-chain"){const je=pe??Math.max(v,5),Re=Tt({h:ae,s:ke.s||.7,v:ke.v||.6},je,le);p==null||p(Re);return}let ve;const Ne=ge==="custom"&&fe?U.find(je=>je.id===fe):null;Ne&&Ne.angles.length>0?ve=Ne.angles.map(je=>((ae+je)%360+360)%360):ve=rt(ae,ge,Ce);let ye;if(ze&&an[ze]?ye=mt(ve,ze):ye=ve.map(je=>Le({h:je,s:ke.s||.7,v:ke.v||.85})),(Te=Ne==null?void 0:Ne.lightnessOffsets)!=null&&Te.length&&(ye=ye.map((je,Re)=>{var Pe;const Ie=(Pe=Ne.lightnessOffsets)==null?void 0:Pe[Re];if(Ie==null)return je;const Ae=He(je);return Le({h:Ae.h,s:Ae.s,v:Math.max(.05,Math.min(.98,Ae.v+Ie))})})),pe!==void 0){for(;ye.length<pe;){const je=ye[ye.length-1]||"#888888",Re=He(je);ye.push(Le({h:(Re.h+18)%360,s:Re.s,v:Re.v}))}ye=ye.slice(0,pe)}else{for(;ye.length<v;)ye.push(ye[ye.length-1]||"var(--nice-text-secondary, #888888)");ye.length>C&&(ye=ye.slice(0,C))}p==null||p(ye)},[ke.s,ke.v,v,C,p,x,P,le,fe,U]),Me=i.useCallback(ae=>{if(!S){if(ne==="custom"){const ge=Le({h:ae,s:ke.s||.7,v:ke.v||.85}),Ce=[...ce];Ce[Y]=ge,p==null||p(Ce);return}Ee(ae,ne,oe,xe)}},[S,ne,oe,xe,Ee,ke.s,ke.v,ce,Y,p]),qe=i.useCallback(ae=>{S||(W(ae),ae!=="custom"&&Ee(ke.h,ae,oe,xe))},[S,ke.h,oe,xe,W,Ee]),Qe=i.useCallback(ae=>{S||(se(ae),Ee(ke.h,ne,ae,xe))},[S,ke.h,ne,xe,se,Ee]),We=i.useCallback(ae=>{if(S)return;be(ae);const ge=rt(ke.h,ne,oe),Ce=mt(ge,ae);p==null||p(Ce.slice(0,C))},[S,ke.h,ne,oe,C,be,p]),Oe=i.useCallback((ae,ge)=>{if(S)return;const Ce=[...ce];Ce[ae]=ge,p==null||p(Ce)},[S,ce,p]),Be=i.useCallback(()=>{if(S||ce.length>=C)return;const ae=He(ce[ce.length-1]),ge=Le({h:(ae.h+30)%360,s:ae.s,v:ae.v});p==null||p([...ce,ge])},[S,ce,C,p]),Je=i.useCallback(ae=>{if(S||ce.length<=v)return;const ge=ce.filter((Ce,ze)=>ze!==ae);p==null||p(ge),Y>=ge.length&&J(Math.max(0,ge.length-1))},[S,ce,v,p,Y]),et=i.useCallback(()=>{if(S)return;const ae=Math.max(v,Math.min(C,Nt(ne).length)),ge=rn(ne,ae,oe);p==null||p(ge)},[S,v,C,ne,oe,p]),Xe=i.useMemo(()=>{if(!T)return[];const ae=ce[Y]||ce[0];return nn(He(ae),k)},[T,ce,Y,k]),Fe=ce[Y]||ce[0],Ke=i.useMemo(()=>{const ae=He(Fe);return Le({h:(ae.h+180)%360,s:ae.s,v:ae.v})},[Fe]);return w?null:e.jsxs("div",{ref:d,id:_,className:`nice-palette ${S?"nice-palette--disabled":""} ${n||""}`,style:a,children:[z&&e.jsx("div",{className:"nice-palette__label",children:z}),e.jsxs("div",{className:"nice-palette__modes",style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[e.jsx(_e.Ze,{label:g("colorPalette.harmony","Harmony"),labelPlacement:"left",size:"sm",disabled:S,value:ne==="custom"&&fe?`custom:${fe}`:ne,onChange:ae=>{const ge=Array.isArray(ae)?ae[0]:ae;if(typeof ge=="string")if(ge.startsWith("custom:")){const Ce=ge.slice(7);V(Ce),qe("custom")}else V(null),qe(ge)},options:[...Vn.map(ae=>({value:ae,label:Kn[ae]})),...U.map(ae=>({value:`custom:${ae.id}`,label:`★ ${ae.name}`}))],renderOption:(ae,ge)=>{const Ce=String(ae.value),ze=Ce.startsWith("custom:"),X=ze?U.find(ve=>ve.id===Ce.slice(7)):null,pe=X?X.angles:void 0;return e.jsxs("span",{style:{display:"inline-flex",gap:8,alignItems:"center"},children:[e.jsx("span",{style:{width:16,height:16,display:"inline-flex",color:"currentColor"},children:Et(ze?"custom":Ce,{angles:pe,size:16,count:x})}),e.jsx("span",{style:{fontWeight:ge?600:400},children:ae.label})]})}}),ne==="shade-chain"&&e.jsx(_e.Qe,{label:g("colorPalette.step","Step"),labelPlacement:"left",size:"sm",min:.02,max:.5,step:.02,precision:2,value:le,onChange:ae=>{const ge=typeof ae=="number"?ae:Number(ae);Number.isNaN(ge)||(de(ge),N==null||N(ge),Ee(ke.h,ne,oe,xe))},showStepper:!0,disabled:S}),e.jsx(_e.Qe,{label:g("colorPalette.colors","Colors"),labelPlacement:"left",size:"sm",min:Math.max(2,v),max:Math.min(12,C),step:1,precision:0,value:x??P??ce.length,onChange:ae=>{const ge=typeof ae=="number"?ae:Number(ae);if(!Number.isFinite(ge))return;const Ce=Math.max(Math.max(2,v),Math.min(Math.min(12,C),Math.round(ge)));B(Ce),ne==="shade-chain"?p==null||p(Tt({h:ke.h,s:ke.s||.7,v:ke.v||.6},Ce,le)):setTimeout(()=>Ee(ke.h,ne,oe,xe),0)},showStepper:!0,disabled:S})]}),e.jsxs("div",{className:"nice-palette__main",children:[R&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Un,{hues:$e,baseHue:ke.h,onBaseHueChange:Me,mode:ne,distance:oe,disabled:S}),(ne==="analogous"||ne==="split-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsxs("label",{children:["Distance: ",oe,"°"]}),e.jsx("input",{type:"range",min:10,max:90,value:oe,onChange:ae=>Qe(Number(ae.target.value)),disabled:S,className:"nice-palette__distance-slider"})]})]}),e.jsxs("div",{className:"nice-palette__strips",children:[e.jsxs("div",{className:"nice-palette__swatches",children:[ce.map((ae,ge)=>e.jsxs("div",{className:`nice-palette__swatch-wrapper ${Y===ge?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>J(ge),children:[e.jsx("div",{className:"nice-palette__swatch",style:{background:ae},children:ce.length>v&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:Ce=>{Ce.stopPropagation(),Je(ge)},disabled:S,"aria-label":"Remove color",children:"×"})}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:ae.toUpperCase(),maxLength:7,disabled:S,onChange:Ce=>Oe(ge,Ce.target.value)})]},ge)),ce.length<C&&e.jsx("button",{type:"button",className:"nice-palette__add-btn",onClick:Be,disabled:S,title:"Add color",children:"+"})]}),e.jsxs("div",{className:"nice-palette__complementary",children:[e.jsx("span",{className:"nice-palette__section-tag",children:"Complementary"}),e.jsx("div",{className:"nice-palette__swatch nice-palette__swatch--sm",style:{background:Ke},title:Ke.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:Ke.toUpperCase()})]}),T&&Xe.length>0&&e.jsxs("div",{className:"nice-palette__variations",children:[e.jsx("span",{className:"nice-palette__section-tag",children:"Tints & Shades"}),e.jsx("div",{className:"nice-palette__variation-strip",children:Xe.map((ae,ge)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:ae},title:ae.toUpperCase(),onClick:()=>{S||Oe(Y,ae)},role:"button",tabIndex:0},ge))})]}),A&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:et,disabled:S,title:"Random palette","aria-label":"Random palette",children:"🎲 Random Palette"})]})]}),Z&&y.length>0&&e.jsxs("div",{className:"nice-palette__presets",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Style Presets"}),e.jsx("div",{className:"nice-palette__preset-grid",children:y.map(ae=>{const ge=mt($e,ae);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${xe===ae?"nice-palette__preset-card--active":""}`,onClick:()=>We(ae),disabled:S,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:ge.map((Ce,ze)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:Ce}},ze))}),e.jsx("span",{className:"nice-palette__preset-label",children:Zn[ae]})]},ae)})})]}),q&&e.jsxs("div",{className:"nice-palette__info-panel",children:[e.jsx("div",{className:"nice-palette__section-title",children:"Selected Color Info"}),e.jsx(Xn,{hex:Fe})]}),e.jsxs("details",{className:"nice-palette__custom-schemes",style:{marginTop:8},children:[e.jsxs("summary",{style:{cursor:"pointer",padding:"6px 10px",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border-color)",borderRadius:4,display:"inline-block",fontSize:12,userSelect:"none"},children:["Custom schemes (",U.length,")"]}),e.jsxs("div",{style:{marginTop:8,display:"flex",flexDirection:"column",gap:6},children:[U.length===0&&e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)"},children:g("colorPalette.schemes.empty","Save the current palette as a reusable scheme.")}),U.map(ae=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12},children:[e.jsx("span",{style:{width:16,height:16,display:"inline-flex"},children:Et("custom",{angles:ae.angles,size:16})}),e.jsx("span",{style:{flex:1},children:ae.name}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>{V(ae.id),qe("custom")},disabled:S,children:"Use"}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>K(U.filter(ge=>ge.id!==ae.id)),disabled:S,"aria-label":`Delete ${ae.name}`,children:"×"})]},ae.id)),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:S,onClick:()=>{const ae=typeof window<"u"?window.prompt("Scheme name?",`Scheme ${U.length+1}`):null;if(!ae)return;const ge=He(ce[0]).h,Ce=ce.map(X=>(He(X).h-ge+540)%360-180),ze={id:`cs-${Date.now()}`,name:ae,angles:Ce};K([...U,ze])},children:"+ Save current as scheme"}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:S||U.length===0,onClick:()=>{var ae;typeof navigator>"u"||((ae=navigator.clipboard)==null||ae.writeText(JSON.stringify(U,null,2)))},children:g("colorPalette.exportJson","Export JSON")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:S,onClick:()=>{if(typeof window>"u")return;const ae=window.prompt("Paste schemes JSON");if(ae)try{const ge=JSON.parse(ae);Array.isArray(ge)&&K(ge)}catch{}},children:g("colorPalette.importJson","Import JSON")})]})]})]}),Q&&e.jsxs("details",{className:"nice-palette__contrast-popup",style:{marginTop:8},children:[e.jsx("summary",{style:{cursor:"pointer",padding:"6px 10px",background:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border-color)",borderRadius:4,display:"inline-block",fontSize:12,userSelect:"none"},children:"Contrast Analysis (WCAG 2.1)"}),e.jsx("div",{style:{marginTop:8},children:e.jsx(qn,{colors:ce})})]})]})});sn.displayName="NiceColorPalette";function vt(){return{type:"linear",angle:90,stops:[{color:"var(--nice-primary, #3b82f6)",position:0},{color:"var(--nice-accent, #8b5cf6)",position:100}]}}function _t(t){const n=t.stops.slice().sort((r,o)=>r.position-o.position).map(r=>`${r.color} ${r.position}%`).join(", "),a=t.repeating?"repeating-":"";switch(t.type){case"linear":return`${a}linear-gradient(${t.angle}deg, ${n})`;case"radial":{const r=t.shape||"ellipse",o=t.size||"farthest-corner",p=t.positionX??50,v=t.positionY??50;return`${a}radial-gradient(${r} ${o} at ${p}% ${v}%, ${n})`}case"conic":{const r=t.angle??0,o=t.positionX??50,p=t.positionY??50;return`${a}conic-gradient(from ${r}deg at ${o}% ${p}%, ${n})`}}}function on(t){var r,o,p;const n=t.trim(),a=n.startsWith("repeating-");if(n.includes("linear-gradient")){const v=(r=n.match(/linear-gradient\((.+)\)/))==null?void 0:r[1];if(!v)return null;const C=v.split(",").map(f=>f.trim());let M=90,E=0;const H=C[0].match(/^(\d+)deg$/);H&&(M=parseInt(H[1]),E=1);const D=xt(C.slice(E));return{type:"linear",angle:M,repeating:a,stops:D}}if(n.includes("radial-gradient")){const v=(o=n.match(/radial-gradient\((.+)\)/))==null?void 0:o[1];if(!v)return null;const C=v.split(",").map(E=>E.trim()),M=xt(C.filter(E=>E.includes("#")||E.includes("rgb")));return{type:"radial",angle:0,repeating:a,stops:M.length>=2?M:vt().stops}}if(n.includes("conic-gradient")){const v=(p=n.match(/conic-gradient\((.+)\)/))==null?void 0:p[1];if(!v)return null;const C=v.split(",").map(E=>E.trim()),M=xt(C.filter(E=>E.includes("#")||E.includes("rgb")));return{type:"conic",angle:0,repeating:a,stops:M.length>=2?M:vt().stops}}return null}function xt(t){return t.map((n,a,r)=>{const o=n.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(o){const p=o[2]?parseFloat(o[2]):a/Math.max(1,r.length-1)*100;return{color:o[1],position:p}}return{color:n,position:a/Math.max(1,r.length-1)*100}})}function Qn(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function Bn(t=2){const n=["linear","radial","conic"],a=n[Math.floor(Math.random()*n.length)],r=[];for(let o=0;o<t;o++)r.push({color:Qn(),position:Math.round(o/(t-1)*100)});return{type:a,angle:Math.floor(Math.random()*360),stops:r,shape:a==="radial"?Math.random()>.5?"circle":"ellipse":void 0,positionX:a!=="linear"?Math.round(Math.random()*100):void 0,positionY:a!=="linear"?Math.round(Math.random()*100):void 0}}const cn=[{name:"Sunset",value:{type:"linear",angle:135,stops:[{color:"var(--nice-danger, #ff6b6b)",position:0},{color:"#feca57",position:100}]}},{name:"Ocean",value:{type:"linear",angle:180,stops:[{color:"#667eea",position:0},{color:"#764ba2",position:100}]}},{name:"Forest",value:{type:"linear",angle:120,stops:[{color:"#11998e",position:0},{color:"#38ef7d",position:100}]}},{name:"Fire",value:{type:"linear",angle:90,stops:[{color:"#f12711",position:0},{color:"#f5af19",position:100}]}},{name:"Aurora",value:{type:"linear",angle:135,stops:[{color:"#a18cd1",position:0},{color:"#fbc2eb",position:50},{color:"#a6c1ee",position:100}]}},{name:"Midnight",value:{type:"linear",angle:180,stops:[{color:"#0f0c29",position:0},{color:"#302b63",position:50},{color:"#24243e",position:100}]}},{name:"Candy",value:{type:"linear",angle:45,stops:[{color:"#fc5c7d",position:0},{color:"#6a82fb",position:100}]}},{name:"Radial Glow",value:{type:"radial",angle:0,shape:"circle",stops:[{color:"var(--nice-warning-bg, #ffecd2)",position:0},{color:"#fcb69f",position:100}],positionX:50,positionY:50}},{name:"Rainbow",value:{type:"conic",angle:0,stops:[{color:"var(--nice-danger, #ff0000)",position:0},{color:"#ff8800",position:17},{color:"var(--nice-warning, #ffff00)",position:33},{color:"var(--nice-success, #00ff00)",position:50},{color:"#0088ff",position:67},{color:"#8800ff",position:83},{color:"var(--nice-danger, #ff0000)",position:100}],positionX:50,positionY:50}}],dn=i.forwardRef(({id:t,className:n,style:a,accessMode:r,value:o,onChange:p,showCssOutput:v=!0,showPresets:C=!0,showEditor:M=!0,showRandom:E=!0,maxStops:H=10,label:D,disabled:f,width:j},R)=>{const Q=G.Nl(r,t),q=Q==="hidden";(Q==="disabled"||Q==="readOnly")&&(f=!0);const Z=G.hl(t),y=o??vt(),T=i.useMemo(()=>_t(y),[y]),[A,k]=i.useState(0),[z,S]=i.useState(""),x=i.useRef(null),m=i.useCallback(c=>{p==null||p(c)},[p]),N=i.useCallback(c=>{f||m({...y,type:c})},[f,y,m]),$=i.useCallback(c=>{f||m({...y,angle:c})},[f,y,m]),L=i.useCallback(c=>{f||m({...y,repeating:c})},[f,y,m]),u=i.useCallback(c=>{f||m({...y,shape:c})},[f,y,m]),d=i.useCallback((c,s)=>{if(f)return;const F=y.stops.map((O,Y)=>Y===c?{...O,...s}:O);m({...y,stops:F})},[f,y,m]),I=i.useCallback(()=>{if(f||y.stops.length>=H)return;const c=y.stops.slice().sort((J,me)=>J.position-me.position);let s=0,F=c[0];for(let J=0;J<c.length-1;J++){const me=c[J+1].position-c[J].position;me>s&&(s=me,F=c[J])}const O=Math.round(F.position+s/2),Y="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");m({...y,stops:[...y.stops,{color:Y,position:O}]})},[f,y,H,m]),w=i.useCallback(c=>{if(f||y.stops.length<=2)return;const s=y.stops.filter((F,O)=>O!==c);m({...y,stops:s}),A>=s.length&&k(s.length-1)},[f,y,A,m]),_=i.useCallback(()=>{if(f)return;const c=2+Math.floor(Math.random()*3);m(Bn(c))},[f,m]),g=i.useCallback(()=>{if(f||!z.trim())return;const c=on(z);c&&m(c)},[f,z,m]),l=i.useCallback(c=>{if(f||!x.current||y.stops.length>=H)return;const s=x.current.getBoundingClientRect(),F=Math.round((c.clientX-s.left)/s.width*100),O="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),Y=[...y.stops,{color:O,position:F}];m({...y,stops:Y}),k(Y.length-1)},[f,y,H,m]),h=i.useMemo(()=>y.stops.slice().sort((c,s)=>c.position-s.position),[y.stops]);return q?null:e.jsxs("div",{ref:R,id:Z,className:`nice-gradient ${f?"nice-gradient--disabled":""} ${n||""}`,style:{width:j!=null?typeof j=="number"?`${j}px`:j:320,boxSizing:"border-box",...a},children:[D&&e.jsx("div",{className:"nice-gradient__label",children:D}),e.jsx("div",{className:"nice-gradient__preview",style:{background:T}}),M&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-gradient__type-row",children:[["linear","radial","conic"].map(c=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${y.type===c?"nice-gradient__type-btn--active":""}`,onClick:()=>N(c),disabled:f,children:c.charAt(0).toUpperCase()+c.slice(1)},c)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:y.repeating??!1,onChange:c=>L(c.target.checked),disabled:f}),"Repeating"]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[y.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Angle: ",y.angle,"°"]}),e.jsx("input",{type:"range",min:0,max:360,value:y.angle,onChange:c=>$(Number(c.target.value)),disabled:f,className:"nice-gradient__slider"}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(c=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${y.angle===c?"nice-gradient__angle-btn--active":""}`,onClick:()=>$(c),disabled:f,title:`${c}°`,children:e.jsx("span",{style:{transform:`rotate(${c}deg)`,display:"inline-block"},children:"→"})},c))})]}),y.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:"Shape:"}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(c=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(y.shape||"ellipse")===c?"nice-gradient__shape-btn--active":""}`,onClick:()=>u(c),disabled:f,children:c},c))})]}),(y.type==="radial"||y.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Center: ",y.positionX??50,"%, ",y.positionY??50,"%"]}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:y.positionX??50,onChange:c=>m({...y,positionX:Number(c.target.value)}),disabled:f,className:"nice-gradient__slider"}),e.jsx("input",{type:"range",min:0,max:100,value:y.positionY??50,onChange:c=>m({...y,positionY:Number(c.target.value)}),disabled:f,className:"nice-gradient__slider"})]})]}),y.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsxs("label",{children:["Start angle: ",y.angle,"°"]}),e.jsx("input",{type:"range",min:0,max:360,value:y.angle,onChange:c=>$(Number(c.target.value)),disabled:f,className:"nice-gradient__slider"})]})]}),e.jsxs("div",{className:"nice-gradient__bar-container",children:[e.jsx("div",{ref:x,className:"nice-gradient__bar",style:{background:T},onClick:l,children:y.stops.map((c,s)=>e.jsx("div",{className:`nice-gradient__stop-marker ${A===s?"nice-gradient__stop-marker--active":""}`,style:{left:`${c.position}%`},onClick:F=>{F.stopPropagation(),k(s)},title:`${c.color} @ ${c.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:c.color}})},s))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:I,disabled:f||y.stops.length>=H,title:"Add stop",children:"+"})]}),e.jsx("div",{className:"nice-gradient__stop-editor",children:e.jsx("div",{className:"nice-gradient__stop-list",children:h.map((c,s)=>{const F=y.stops.indexOf(c);return e.jsxs("div",{className:`nice-gradient__stop-row ${A===F?"nice-gradient__stop-row--active":""}`,onClick:()=>k(F),children:[e.jsx("input",{type:"color",value:c.color,onChange:O=>d(F,{color:O.target.value}),disabled:f,className:"nice-gradient__stop-color"}),e.jsx("input",{type:"text",value:c.color.toUpperCase(),maxLength:7,onChange:O=>d(F,{color:O.target.value}),disabled:f,className:"nice-gradient__stop-hex"}),e.jsx("input",{type:"number",min:0,max:100,value:c.position,onChange:O=>d(F,{position:Number(O.target.value)}),disabled:f,className:"nice-gradient__stop-pos"}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),y.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>w(F),disabled:f,"aria-label":"Remove stop",children:"×"})]},F)})})})]}),E&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:_,disabled:f,title:"Random gradient","aria-label":"Random gradient",children:"🎲 Random Gradient"}),C&&e.jsxs("div",{className:"nice-gradient__presets",children:[e.jsx("div",{className:"nice-gradient__section-title",children:"Presets"}),e.jsx("div",{className:"nice-gradient__preset-grid",children:cn.map((c,s)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{f||m(c.value)},disabled:f,title:c.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:_t(c.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:c.name})]},s))})]}),v&&e.jsxs("div",{className:"nice-gradient__css",children:[e.jsx("div",{className:"nice-gradient__section-title",children:"CSS Output"}),e.jsxs("div",{className:"nice-gradient__css-output",children:[e.jsx("code",{children:`background: ${T};`}),e.jsx("button",{type:"button",className:"nice-gradient__copy-btn",onClick:()=>{var c;return(c=navigator.clipboard)==null?void 0:c.writeText(`background: ${T};`)},title:"Copy CSS",children:"📋"})]}),e.jsxs("div",{className:"nice-gradient__css-import",children:[e.jsx("input",{type:"text",className:"nice-gradient__css-input",placeholder:"Paste CSS gradient to import...",value:z,onChange:c=>S(c.target.value),disabled:f}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:g,disabled:f,children:"Import"})]})]})]})});dn.displayName="NiceGradientPicker";const Jn=({options:t,value:n,onChange:a,searchable:r=!0,clearable:o,loading:p,placeholder:v,label:C,error:M,helperText:E,required:H,disabled:D,size:f="md",id:j,className:R,style:Q,data:q,columns:Z,valueField:y="id",displayField:T,dropdownWidth:A,controlWidth:k})=>{var h;const z=G.hl(j),{t:S}=G.ce(),[x,m]=i.useState(!1),[N,$]=i.useState(""),L=i.useRef(null);G.bl(L,()=>m(!1));const u=!!(q&&Z&&Z.length>0),d=T??(Z&&((h=Z[0])==null?void 0:h.key)),I=i.useMemo(()=>!u||!q?[]:q.map(c=>({value:String(c[y]??""),label:d?String(c[d]??""):""})),[u,q,y,d]),w=u?I:t??[],_=w.find(c=>String(c.value)===n),g=i.useMemo(()=>{if(!u||!q)return[];if(!N)return q;const c=N.toLowerCase();return q.filter(s=>Z.some(F=>String(s[F.key]??"").toLowerCase().includes(c)))},[u,q,Z,N]),l=i.useMemo(()=>{if(u||!N)return w;const c=N.toLowerCase();return w.filter(s=>s.label.toLowerCase().includes(c))},[w,N,u]);return e.jsxs("div",{className:`nice-field nice-field--${f} ${M?"nice-field--error":""} ${R||""}`,style:{width:k!=null?typeof k=="number"?`${k}px`:k:"fit-content",...Q},ref:L,children:[C&&e.jsxs("label",{className:"nice-field__label",htmlFor:z,children:[C,H&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{className:"nice-field__input-wrap",style:{position:"relative"},children:[e.jsxs("button",{type:"button",id:z,className:"nice-select__trigger",onClick:()=>!D&&m(!x),disabled:D,children:[e.jsx("span",{children:(_==null?void 0:_.label)||v||S("controls.select","Select...")}),e.jsx("span",{className:"nice-select__arrow",children:"▾"})]}),o&&n&&!D&&e.jsx("button",{type:"button",className:"nice-field__clear",onClick:()=>a(""),"aria-label":S("controls.clear","Clear"),children:"✕"}),x&&e.jsxs("div",{className:"nice-dropdown nice-lookup__dropdown",style:{position:"absolute",top:"100%",left:0,zIndex:50,marginTop:4,background:"var(--bg-primary)",border:"1px solid var(--border-color)",borderRadius:"var(--nice-radius-md)",boxShadow:"0 4px 16px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",minWidth:"100%",width:A!=null?typeof A=="number"?`${A}px`:A:u?"max-content":"100%"},children:[r&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:N,onChange:c=>$(c.target.value),placeholder:S("controls.search","Search..."),autoFocus:!0,style:{width:"100%",padding:"4px 8px",border:"1px solid var(--border-color)",borderRadius:4,background:"var(--bg-primary)",color:"var(--text-primary)"}})}),u?e.jsxs("table",{className:"nice-lookup__grid",role:"listbox",style:{width:"100%",borderCollapse:"collapse",color:"var(--text-primary)"},children:[e.jsx("thead",{children:e.jsx("tr",{children:Z.map(c=>e.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontSize:12,fontWeight:600,color:"var(--text-secondary)",background:"var(--bg-secondary)",borderBottom:"1px solid var(--border-color)",width:c.width!=null?typeof c.width=="number"?`${c.width}px`:c.width:void 0},children:c.header},c.key))})}),e.jsx("tbody",{children:g.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Z.length,style:{padding:12,textAlign:"center",color:"var(--text-muted)"},children:S("controls.noResults","No results")})}):g.map(c=>{const s=String(c[y]??""),F=s===n;return e.jsx("tr",{role:"option","aria-selected":F,onClick:()=>{a(s),m(!1),$("")},style:{cursor:"pointer",background:F?"var(--hover-bg)":"transparent"},onMouseEnter:O=>{F||(O.currentTarget.style.background="var(--hover-bg)")},onMouseLeave:O=>{F||(O.currentTarget.style.background="transparent")},children:Z.map(O=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--border-color)"},children:String(c[O.key]??"")},O.key))},s)})})]}):e.jsx("ul",{className:"nice-dropdown__list",role:"listbox",style:{listStyle:"none",margin:0,padding:4,maxHeight:240,overflowY:"auto"},children:l.length===0?e.jsx("li",{className:"nice-dropdown__empty",style:{padding:8,color:"var(--text-muted)"},children:S("controls.noResults","No results")}):l.map(c=>e.jsx("li",{role:"option",className:`nice-dropdown__option ${String(c.value)===n?"nice-dropdown__option--selected":""}`,onClick:()=>{a(String(c.value)),m(!1),$("")},"aria-selected":String(c.value)===n,children:c.label},String(c.value)))})]})]}),M&&e.jsx("div",{className:"nice-field__error",children:M}),E&&!M&&e.jsx("div",{className:"nice-field__hint",children:E})]})},ei=["Su","Mo","Tu","We","Th","Fr","Sa"];function ti(t,n){return new Date(t,n+1,0).getDate()}function ni(t,n){return new Date(t,n,1).getDay()}function Rt(t,n,a){return`${t}-${String(n+1).padStart(2,"0")}-${String(a).padStart(2,"0")}`}function ii(t){const n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate()));n.setUTCDate(n.getUTCDate()+4-(n.getUTCDay()||7));const a=new Date(Date.UTC(n.getUTCFullYear(),0,1));return Math.ceil(((n.getTime()-a.getTime())/864e5+1)/7)}const Lt=["January","February","March","April","May","June","July","August","September","October","November","December"],un=({value:t,onChange:n,min:a,max:r,disabledDates:o=[],firstDayOfWeek:p=1,size:v="md",showWeekNumbers:C,onMonthChange:M,className:E,style:H,accessMode:D,id:f,multiple:j,selectedDates:R=[],onSelectedDatesChange:Q,renderDay:q,showKeyboardHints:Z,persistPreferences:y=!1,fullWidth:T=!1,cookies:A=!1,localStorage:k=!0,sessionStorage:z=!1,storageMode:S,storageKey:x})=>{const m=G.Nl(D,f),N=m==="hidden",$=m==="disabled"||m==="readOnly",{t:L}=G.ce(),u=new Date,d=t?new Date(t):u,I=G.ht(x??"nice-calendar"),w=i.useMemo(()=>y?I.get("prefs")??{}:{},[y,I]),_=w.firstDayOfWeek??p,[g,l]=i.useState(w.lastViewYear??d.getFullYear()),[h,c]=i.useState(w.lastViewMonth??d.getMonth()),[s,F]=i.useState(w.preferredView??"days"),O=i.useCallback(ie=>{if(!y)return;const ce=I.get("prefs")??{};I.set("prefs",{...ce,...ie})},[y,I]),Y=i.useCallback(ie=>{F(ie),O({preferredView:ie})},[O]),J=i.useCallback((ie,ce)=>{O({lastViewYear:ie,lastViewMonth:ce})},[O]),me=i.useMemo(()=>[G.Zl.moveUp,G.Zl.moveDown,G.Zl.moveLeft,G.Zl.moveRight,{key:"Enter",description:L("shortcuts.selectDate","Select date")},G.Zl.pageUp,G.Zl.pageDown],[L]),de=i.useMemo(()=>ti(g,h),[g,h]),P=i.useMemo(()=>(ni(g,h)-_+7)%7,[g,h,_]),B=i.useMemo(()=>{const ie=[...ei];for(let ce=0;ce<_;ce++)ie.push(ie.shift());return ie},[_]),re=i.useCallback(ie=>a&&ie<a||r&&ie>r?!0:o.includes(ie),[a,r,o]),ue=i.useCallback(ie=>{if(s==="years"){l(ke=>ke+ie*10);return}if(s==="months"){l(ke=>ke+ie);return}let ce=h+ie,he=g;ce<0&&(ce=11,he--),ce>11&&(ce=0,he++),c(ce),l(he),J(he,ce),M==null||M(he,ce)},[h,g,M,s,J]),fe=Rt(u.getFullYear(),u.getMonth(),u.getDate()),V=i.useCallback(ie=>j?R.includes(ie):ie===t,[j,R,t]),ne=i.useCallback(ie=>{if(!$){if(j){const ce=R.includes(ie)?R.filter(he=>he!==ie):[...R,ie];Q==null||Q(ce)}n==null||n(ie)}},[j,R,n,Q]),oe=i.useCallback(()=>{s==="days"?Y("months"):s==="months"&&Y("years")},[s,Y]),xe=i.useCallback(ie=>{c(ie),Y("days"),J(g,ie),M==null||M(g,ie)},[g,M,Y,J]),le=i.useCallback(ie=>{l(ie),Y("months")},[Y]),U=s==="years"?`${g-g%10} – ${g-g%10+9}`:s==="months"?`${g}`:`${Lt[h]} ${g}`,K=s==="years"?"decade":s==="months"?"year":"month",W=[];for(let ie=0;ie<P;ie++)W.push(null);for(let ie=1;ie<=de;ie++)W.push(ie);for(;W.length%7!==0;)W.push(null);const se=[];for(let ie=0;ie<W.length;ie+=7)se.push(W.slice(ie,ie+7));const be=g-g%10;return N?null:e.jsxs("div",{className:`nice-calendar nice-calendar--${v}${T?" nice-calendar--full-width":""} ${E||""}`,style:H,children:[e.jsxs("div",{className:"nice-calendar__header",children:[e.jsx("button",{type:"button",className:"nice-calendar__nav",onClick:()=>ue(-1),"aria-label":`Previous ${K}`,children:"‹"}),e.jsx("button",{type:"button",className:"nice-calendar__title",onClick:oe,"aria-label":s==="days"?"Show month picker":s==="months"?"Show year picker":void 0,disabled:s==="years",children:U}),e.jsx("button",{type:"button",className:"nice-calendar__nav",onClick:()=>ue(1),"aria-label":`Next ${K}`,children:"›"}),Z&&e.jsx(G.qo,{shortcuts:me,size:"sm"})]}),s==="days"&&e.jsxs("table",{className:"nice-calendar__grid",role:"grid",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[C&&e.jsx("th",{className:"nice-calendar__wk",children:"W"}),B.map(ie=>e.jsx("th",{children:ie},ie))]})}),e.jsx("tbody",{children:se.map((ie,ce)=>e.jsxs("tr",{children:[C&&e.jsx("td",{className:"nice-calendar__wk",children:ie.find(he=>he!=null)?ii(new Date(g,h,ie.find(he=>he!=null))):""}),ie.map((he,ke)=>{if(he==null)return e.jsx("td",{className:"nice-calendar__empty-cell"},ke);const $e=Rt(g,h,he),Ee=re($e),Me=V($e);return e.jsx("td",{className:`nice-calendar__day${Me?" nice-calendar__day--selected":""}${$e===fe?" nice-calendar__day--today":""}${Ee?" nice-calendar__day--disabled":""}`,onClick:()=>!Ee&&ne($e),role:"gridcell","aria-selected":Me,"aria-disabled":Ee,children:q?q($e,he):he},ke)})]},ce))})]}),s==="months"&&e.jsx("div",{className:"nice-calendar__picker-grid",children:Lt.map((ie,ce)=>e.jsx("button",{type:"button",className:`nice-calendar__picker-cell${ce===h&&g===d.getFullYear()?" nice-calendar__picker-cell--selected":""}`,onClick:()=>xe(ce),children:ie.slice(0,3)},ce))}),s==="years"&&e.jsx("div",{className:"nice-calendar__picker-grid",children:Array.from({length:12},(ie,ce)=>be-1+ce).map(ie=>e.jsx("button",{type:"button",className:`nice-calendar__picker-cell${ie===g?" nice-calendar__picker-cell--selected":""}${ie<be||ie>be+9?" nice-calendar__picker-cell--other":""}`,onClick:()=>le(ie),children:ie},ie))})]})};un.displayName="NiceCalendar";const ai=({startDate:t,endDate:n,onStartChange:a,onEndChange:r,min:o,max:p,clearable:v,startPlaceholder:C,endPlaceholder:M,startLabel:E,endLabel:H,layout:D="horizontal",separator:f="–",gap:j=12,fullWidth:R=!1,label:Q,error:q,helperText:Z,required:y,disabled:T,size:A="md",id:k,className:z,style:S,accessMode:x,showKeyboardHints:m,labelPlacement:N,errorPlacement:$,labelWidth:L,controlWidth:u,loading:d})=>{const I=G.Nl(x,k),w=G.hl(k),{t:_}=G.ce(),g=I==="disabled"||I==="readOnly"||!!T,l=i.useMemo(()=>[{key:"Tab",description:_("shortcuts.switchField","Switch between start/end")},G.Zl.cancel],[_]);if(I==="hidden")return null;const h=s=>{a(s),s&&n&&s>n&&r(s)},c=D==="horizontal";return e.jsxs("div",{className:`nice-field nice-field--${A} nice-daterange nice-daterange--${D} ${N==="left"?"nice-field--label-left":""} ${q?"nice-field--error":""} ${d?"nice-field--loading":""} ${z||""}`,style:{...S,...L!=null&&{"--nice-field-label-width":typeof L=="number"?`${L}px`:L},...u!=null&&{"--nice-field-control-width":typeof u=="number"?`${u}px`:u}},"aria-busy":d||void 0,children:[Q&&e.jsxs("label",{className:"nice-field__label",htmlFor:w,children:[Q,y&&e.jsx("span",{className:"nice-field__required",children:"*"}),m&&e.jsx(G.qo,{shortcuts:l,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:c?"row":"column",alignItems:c?"flex-end":"stretch",gap:j,flexWrap:"wrap"},children:[e.jsx("div",{style:{flex:R?"1 1 0":void 0,minWidth:0},children:e.jsx(_e.sn,{id:w,label:E,value:t,onChange:h,min:o,max:n||p,placeholder:C||_("controls.startDate","Start date"),disabled:g,size:A,clearable:v,labelPlacement:N,labelWidth:L})}),c&&f!==""&&f!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--text-secondary, #666)"},"aria-hidden":"true",children:f}),e.jsx("div",{style:{flex:R?"1 1 0":void 0,minWidth:0},children:e.jsx(_e.sn,{label:H,value:n,onChange:r,min:t||o,max:p,placeholder:M||_("controls.endDate","End date"),disabled:g,size:A,clearable:v,labelPlacement:N,labelWidth:L})})]}),d&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),$==="right"&&q&&e.jsx("div",{className:"nice-field__error",role:"alert",children:q}),$==="right"&&!q&&Z&&e.jsx("div",{className:"nice-field__helper",children:Z})]}),$!=="right"&&q&&e.jsx("div",{className:"nice-field__error",children:q}),$!=="right"&&!q&&Z&&e.jsx("div",{className:"nice-field__hint",children:Z})]})},ri=({min:t=0,max:n=100,step:a=1,startValue:r,endValue:o,onChange:p,showLabels:v=!0,formatLabel:C,valuePlacement:M="none",label:E,error:H,helperText:D,required:f,disabled:j,readOnly:R,loading:Q,size:q="md",id:Z,className:y,style:T,accessMode:A,showKeyboardHints:k,labelPlacement:z,errorPlacement:S,labelWidth:x,controlWidth:m})=>{const N=G.Nl(A,Z),$=N==="hidden";(N==="disabled"||N==="readOnly")&&(j=!0);const{t:L}=G.ce(),u=G.hl(Z),d=i.useRef(null),I=i.useMemo(()=>[G.Zl.increment,G.Zl.decrement,G.Zl.first,G.Zl.last,{key:"Tab",description:L("shortcuts.switchThumb","Switch thumb")}],[L]),w=h=>(h-t)/(n-t)*100,_=h=>C?C(h):String(h),g=h=>{const c=Math.round(h/a)*a;return Math.max(t,Math.min(n,c))},l=i.useCallback((h,c)=>{h.preventDefault();const s=d.current;if(!s||j)return;const F=Y=>{const J=s.getBoundingClientRect(),me=Math.max(0,Math.min(1,(Y.clientX-J.left)/J.width)),de=g(t+me*(n-t));c==="start"?p(Math.min(de,o),o):p(r,Math.max(de,r))},O=()=>{document.removeEventListener("pointermove",F),document.removeEventListener("pointerup",O)};document.addEventListener("pointermove",F),document.addEventListener("pointerup",O)},[t,n,a,r,o,p,j]);return $?null:e.jsxs("div",{className:`nice-field nice-field--${q} nice-field--rangeslider ${z==="left"?"nice-field--label-left":""} ${S==="right"?"nice-field--error-right":""} ${H?"nice-field--error":""} ${Q?"nice-field--loading":""} ${y||""}`,style:{...T,...x!=null&&{"--nice-field-label-width":typeof x=="number"?`${x}px`:x},...m!=null&&{"--nice-field-control-width":typeof m=="number"?`${m}px`:m}},"aria-busy":Q||void 0,children:[E&&e.jsxs("label",{className:"nice-field__label nice-field__label--with-value",htmlFor:u,children:[e.jsxs("span",{className:"nice-field__label-text",children:[E,f&&e.jsx("span",{className:"nice-field__required",children:"*"}),k&&e.jsx(G.qo,{shortcuts:I,size:"sm"})]}),M==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[_(r)," – ",_(o)]})]}),e.jsxs("div",{className:"nice-field__control",children:[M==="right"&&!E&&e.jsxs("span",{className:"nice-range-slider__value",children:[_(r)," – ",_(o)]}),e.jsxs("div",{className:"nice-range-slider__stack",children:[e.jsxs("div",{className:`nice-range-slider ${v?"nice-range-slider--with-labels":""} ${E?"nice-range-slider--has-field-label":""}`,ref:d,children:[e.jsx("div",{className:"nice-range-slider__track",children:e.jsx("div",{className:"nice-range-slider__fill",style:{left:`${w(r)}%`,width:`${w(o)-w(r)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${w(r)}%`},onPointerDown:h=>R?void 0:l(h,"start"),role:"slider","aria-valuemin":t,"aria-valuemax":o,"aria-valuenow":r,tabIndex:j?-1:0,id:u}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${w(o)}%`},onPointerDown:h=>R?void 0:l(h,"end"),role:"slider","aria-valuemin":r,"aria-valuemax":n,"aria-valuenow":o,tabIndex:j?-1:0})]}),v&&e.jsxs("div",{className:"nice-range-slider__values",children:[e.jsx("span",{className:"nice-range-slider__values-start",style:{left:`${w(r)}%`},children:_(r)}),e.jsx("span",{className:"nice-range-slider__values-end",style:{left:`${w(o)}%`},children:_(o)})]}),M==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[_(r)," – ",_(o)]})]}),Q&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),S==="right"&&H&&e.jsx("div",{className:"nice-field__error",role:"alert",children:H}),S==="right"&&!H&&D&&e.jsx("div",{className:"nice-field__helper",children:D})]}),S!=="right"&&H&&e.jsx("div",{className:"nice-field__error",role:"alert",children:H}),S!=="right"&&!H&&D&&e.jsx("div",{className:"nice-field__helper",children:D})]})},li=({displayValue:t,placeholder:n,clearable:a,children:r,onClear:o,open:p,onOpenChange:v,dropdownWidth:C,label:M,error:E,helperText:H,required:D,disabled:f,size:j="md",id:R,className:Q,style:q,accessMode:Z,showKeyboardHints:y,displayStyle:T})=>{G.rl("input",T),G.ol("input",T);const A=G.Nl(Z,R),k=A==="hidden";(A==="disabled"||A==="readOnly")&&(f=!0);const z=G.hl(R),{t:S}=G.ce(),[x,m]=i.useState(!1),N=i.useRef(null),$=p??x,L=i.useMemo(()=>[{key:"Enter",description:S("shortcuts.openDropdown","Open dropdown")},G.Zl.cancel],[S]),u=d=>{v?v(d):m(d)};return G.bl(N,()=>u(!1)),k?null:e.jsxs("div",{className:`nice-field nice-field--${j} ${E?"nice-field--error":""} ${Q||""}`,style:q,ref:N,children:[M&&e.jsxs("label",{className:"nice-field__label",htmlFor:z,children:[M,D&&e.jsx("span",{className:"nice-field__required",children:"*"}),y&&e.jsx(G.qo,{shortcuts:L,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",children:[e.jsxs("button",{type:"button",id:z,className:"nice-select__trigger",onClick:()=>!f&&u(!$),disabled:f,children:[e.jsx("span",{children:t||n||S("controls.select","Select...")}),e.jsx("span",{className:"nice-select__arrow",children:"▾"})]}),a&&t&&!f&&e.jsx("button",{type:"button",className:"nice-field__clear",onClick:()=>o==null?void 0:o(),"aria-label":S("controls.clear","Clear"),children:"✕"})]}),$&&e.jsx("div",{className:"nice-dropdown",style:{width:C},children:r}),E&&e.jsx("div",{className:"nice-field__error",children:E}),H&&!E&&e.jsx("div",{className:"nice-field__hint",children:H})]})};function At(t){const n=t.trim().toLowerCase();return n.startsWith("http://")||n.startsWith("https://")||n.startsWith("/")||n.startsWith("./")||n.startsWith("../")?!0:!(n.startsWith("javascript:")||n.startsWith("vbscript:")||n.startsWith("data:text"))}const si=[{target:".nice-htmleditor",titleKey:"tutorial.htmlEditor.intro.title",title:"Rich text editor",contentKey:"tutorial.htmlEditor.intro.content",content:"Format text with the toolbar, insert links, images and tables, and switch to HTML or Markdown source when you need it.",placement:"auto"}],oi=["bold","italic","underline","strikethrough","h1","h2","h3","ul","ol","blockquote","hr","link","unlink","image","table","code","alignLeft","alignCenter","alignRight","fontSize","fontColor","undo","redo","clear","findReplace","emoji","source","fullscreen","markdown"],Se=({d:t,viewBox:n="0 0 24 24"})=>e.jsx("svg",{width:"16",height:"16",viewBox:n,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:t})}),ci={bold:e.jsx("strong",{style:{fontFamily:"serif"},children:"B"}),italic:e.jsx("em",{style:{fontFamily:"serif"},children:"I"}),underline:e.jsx("span",{style:{textDecoration:"underline"},children:"U"}),strikethrough:e.jsx("span",{style:{textDecoration:"line-through"},children:"S"}),h1:"H1",h2:"H2",h3:"H3",ul:e.jsx(Se,{d:"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"}),ol:e.jsx(Se,{d:"M10 6h11M10 12h11M10 18h11M4 6h1v4M4 10h2M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"}),link:e.jsx(Se,{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"}),unlink:e.jsx(Se,{d:"M18.84 12.25l1.72-1.71a5 5 0 0 0-7.07-7.07L11 5.78M3 3l18 18M9 15l3-3M14 11l3 3M14 21l-1.72-1.72a5 5 0 0 1-7.07-7.07L7 10.49"}),undo:e.jsx(Se,{d:"M3 7v6h6M3 13a9 9 0 1 0 3-7.7L3 13"}),redo:e.jsx(Se,{d:"M21 7v6h-6M21 13a9 9 0 1 1-3-7.7L21 13"}),clear:e.jsx(Se,{d:"M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),table:e.jsx(Se,{d:"M3 3h18v18H3zM3 9h18M3 15h18M9 3v18M15 3v18"}),image:e.jsx(Se,{d:"M3 3h18v18H3zM3 16l5-5 4 4 3-3 6 6M9 9a2 2 0 1 1-4 0 2 2 0 0 1 4 0z"}),code:e.jsx(Se,{d:"M16 18l6-6-6-6M8 6l-6 6 6 6"}),markdown:"MD",blockquote:e.jsx(Se,{d:"M3 21c3-3 3-9 0-12M21 21c-3-3-3-9 0-12M9 7h6v6H9zM15 7h6v6h-6z"}),hr:e.jsx(Se,{d:"M5 12h14"}),subscript:"X₂",superscript:"X²",indent:e.jsx(Se,{d:"M3 8l4 4-4 4M7 6h14M7 12h14M3 18h18"}),outdent:e.jsx(Se,{d:"M7 8l-4 4 4 4M21 6H3M21 12H7M21 18H3"}),alignLeft:e.jsx(Se,{d:"M3 6h18M3 12h12M3 18h18"}),alignCenter:e.jsx(Se,{d:"M3 6h18M6 12h12M3 18h18"}),alignRight:e.jsx(Se,{d:"M3 6h18M9 12h12M3 18h18"}),alignJustify:e.jsx(Se,{d:"M3 6h18M3 12h18M3 18h18"}),fullscreen:e.jsx(Se,{d:"M3 9V3h6M21 9V3h-6M3 15v6h6M21 15v6h-6"}),removeFormat:e.jsx(Se,{d:"M4 7V4h16v3M5 20h6M13 4 8 20"}),print:e.jsx(Se,{d:"M6 9V2h12v7M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2M6 14h12v8H6z"}),source:e.jsx(Se,{d:"M16 18l6-6-6-6M8 6l-6 6 6 6"}),emoji:e.jsx(Se,{d:"M12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20zM8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01"}),findReplace:e.jsx(Se,{d:"M11 19a8 8 0 1 1 0-16 8 8 0 0 1 0 16zM21 21l-4.35-4.35"}),fontSize:e.jsx(Se,{d:"M4 7V4h16v3M9 20h6M12 4v16"}),fontColor:e.jsx(Se,{d:"M4 21h16M5 17l7-12 7 12M8 13h8"})},di=[{value:"1",label:"8pt"},{value:"2",label:"10pt"},{value:"3",label:"12pt"},{value:"4",label:"14pt"},{value:"5",label:"18pt"},{value:"6",label:"24pt"},{value:"7",label:"36pt"}],ui=[{label:"Faces",emojis:["??","??","??","??","??","??","??","??","??","??","??","??"]},{label:"Hands",emojis:["??","??","??","??","??","??","??","??","??","??"]},{label:"Symbols",emojis:["??","?","??","?","?","?","??","??","??","??","??","??"]},{label:"Arrows",emojis:["??","??","??","??","??","??","??","??","??","?"]}];function pi(t){let n=t;return n=n.replace(/<h1[^>]*>(.*?)<\/h1>/gi,`# $1
2
+ `),n=n.replace(/<h2[^>]*>(.*?)<\/h2>/gi,`## $1
3
+ `),n=n.replace(/<h3[^>]*>(.*?)<\/h3>/gi,`### $1
4
+ `),n=n.replace(/<strong[^>]*>(.*?)<\/strong>/gi,"**$1**"),n=n.replace(/<b[^>]*>(.*?)<\/b>/gi,"**$1**"),n=n.replace(/<em[^>]*>(.*?)<\/em>/gi,"*$1*"),n=n.replace(/<i[^>]*>(.*?)<\/i>/gi,"*$1*"),n=n.replace(/<code[^>]*>(.*?)<\/code>/gi,"`$1`"),n=n.replace(/<pre[^>]*>(.*?)<\/pre>/gis,"```\n$1\n```\n"),n=n.replace(/<br\s*\/?>/gi,`
5
+ `),n=n.replace(/<li[^>]*>(.*?)<\/li>/gi,`- $1
6
+ `),n=n.replace(/<\/?(?:ul|ol|p|div)[^>]*>/gi,`
7
+ `),n=n.replace(/<[^>]+>/g,""),n=n.replace(/\n{3,}/g,`
8
+
9
+ `),n.trim()}function hi(t){let n=t;return n=n.replace(/^### (.+)$/gm,"<h3>$1</h3>"),n=n.replace(/^## (.+)$/gm,"<h2>$1</h2>"),n=n.replace(/^# (.+)$/gm,"<h1>$1</h1>"),n=n.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),n=n.replace(/\*(.+?)\*/g,"<em>$1</em>"),n=n.replace(/`([^`]+)`/g,"<code>$1</code>"),n=n.replace(/```\n?([\s\S]*?)\n?```/g,"<pre>$1</pre>"),n=n.replace(/^- (.+)$/gm,"<li>$1</li>"),n=n.replace(/(<li>.*<\/li>)/gs,"<ul>$1</ul>"),n=n.replace(/\n/g,"<br>"),n}const wt=({value:t,onChange:n,placeholder:a,height:r=200,toolbar:o=oi,readOnly:p,onImageUpload:v,mentionTrigger:C,mentionSuggestions:M,onMentionSearch:E,onFileDrop:H,pasteCleanup:D=!0,maxLength:f=0,showWordCount:j=!1,templates:R,label:Q,error:q,helperText:Z,required:y,disabled:T,size:A="md",id:k,className:z,style:S,accessMode:x,tutorial:m})=>{const N=G.Nl(x,k),$=N==="hidden";N==="disabled"&&(T=!0),N==="readOnly"&&(p=!0);const L=G.hl(k),u=i.useRef(null),d=i.useRef(null),I=i.useRef(null),[w,_]=i.useState(!1),[g,l]=i.useState(""),[h,c]=i.useState(!1),[s,F]=i.useState(""),[O,Y]=i.useState(!1),[J,me]=i.useState(""),[de,P]=i.useState(0),[B,re]=i.useState(!1),[ue,fe]=i.useState("var(--nice-text, #000000)"),[V,ne]=i.useState("var(--nice-warning, #ffff00)"),[oe,xe]=i.useState(0),[le,U]=i.useState(0),[K,W]=i.useState(!1),[se,be]=i.useState(""),[ie,ce]=i.useState(""),[he,ke]=i.useState(!1),[$e,Ee]=i.useState(!1),Me=i.useCallback((X,pe)=>{var Ne,ye,Te;if(p||T)return;const ve=u.current;if(ve){if(X==="markdown"){if(!w)l(pi(t)),_(!0),c(!1);else{const je=hi(g);n(je),_(!1)}return}if(X==="source"){h?(n(s),c(!1)):(F(t),c(!0),_(!1));return}if(X==="fullscreen"){re(je=>!je);return}if(X==="emoji"){ke(je=>!je);return}if(X==="findReplace"){W(je=>!je);return}if(X==="image"){if(v)(Ne=d.current)==null||Ne.click();else{const je=prompt("Image URL:");je&&At(je)&&(ve.focus(),document.execCommand("insertImage",!1,je),n(G.dl(ve.innerHTML)))}return}switch(ve.focus(),X){case"bold":document.execCommand("bold");break;case"italic":document.execCommand("italic");break;case"underline":document.execCommand("underline");break;case"strikethrough":document.execCommand("strikeThrough");break;case"h1":document.execCommand("formatBlock",!1,"h1");break;case"h2":document.execCommand("formatBlock",!1,"h2");break;case"h3":document.execCommand("formatBlock",!1,"h3");break;case"ul":document.execCommand("insertUnorderedList");break;case"ol":document.execCommand("insertOrderedList");break;case"blockquote":document.execCommand("formatBlock",!1,"blockquote");break;case"hr":document.execCommand("insertHorizontalRule");break;case"subscript":document.execCommand("subscript");break;case"superscript":document.execCommand("superscript");break;case"indent":document.execCommand("indent");break;case"outdent":document.execCommand("outdent");break;case"alignLeft":document.execCommand("justifyLeft");break;case"alignCenter":document.execCommand("justifyCenter");break;case"alignRight":document.execCommand("justifyRight");break;case"alignJustify":document.execCommand("justifyFull");break;case"removeFormat":document.execCommand("removeFormat");break;case"print":window.print();return;case"link":{const je=prompt("URL:");je&&At(je)&&document.execCommand("createLink",!1,je);break}case"unlink":document.execCommand("unlink");break;case"undo":document.execCommand("undo");break;case"redo":document.execCommand("redo");break;case"clear":document.execCommand("removeFormat");break;case"fontSize":{pe&&document.execCommand("fontSize",!1,pe);break}case"fontColor":{pe&&document.execCommand("foreColor",!1,pe);break}case"bgColor":{pe&&document.execCommand("hiliteColor",!1,pe);break}case"table":{document.execCommand("insertHTML",!1,'<table class="nice-htmleditor__table"><thead><tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr></thead><tbody><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></tbody></table><p>&nbsp;</p>');break}case"code":{const je=((ye=window.getSelection())==null?void 0:ye.toString())||"";je.includes(`
10
+ `)||je.length>60?document.execCommand("insertHTML",!1,`<pre class="nice-htmleditor__code-block">${je||"// code"}</pre>`):document.execCommand("insertHTML",!1,`<code>${je||"code"}</code>`);break}}n(G.dl(ve.innerHTML)),xe(((Te=ve.textContent)==null?void 0:Te.length)??0)}},[n,p,T,w,g,t,v,h,s]),qe=i.useCallback(async X=>{var ye;const pe=(ye=X.target.files)==null?void 0:ye[0];if(!pe||!v)return;const ve=await v(pe),Ne=u.current;Ne&&ve&&(Ne.focus(),document.execCommand("insertImage",!1,ve),n(Ne.innerHTML)),X.target.value=""},[v,n]),Qe=i.useCallback(()=>{var ve;const X=u.current;if(!X)return;const pe=((ve=X.textContent)==null?void 0:ve.length)??0;if(f>0&&pe>f&&(X.textContent=(X.textContent??"").slice(0,f)),xe(pe),U((X.textContent??"").trim().split(/\s+/).filter(Boolean).length),n(X.innerHTML),C){const Ne=window.getSelection();if(Ne&&Ne.rangeCount>0){const ye=Ne.getRangeAt(0),Te=ye.startContainer;if(Te.nodeType===Node.TEXT_NODE){const je=Te.textContent||"",Re=ye.startOffset,Ie=je.slice(0,Re),Ae=Ie.lastIndexOf(C);if(Ae>=0&&(Ae===0||/\s/.test(Ie[Ae-1]))){const Pe=Ie.slice(Ae+C.length);if(!/\s/.test(Pe)){Y(!0),me(Pe),P(0),E==null||E(Pe);return}}}}Y(!1)}},[n,C,E]),We=(M==null?void 0:M.filter(X=>X.label.toLowerCase().includes(J.toLowerCase())).slice(0,8))??[],Oe=i.useCallback(X=>{var Te;const pe=u.current;if(!pe)return;const ve=window.getSelection();if(!ve||ve.rangeCount===0)return;const Ne=ve.getRangeAt(0),ye=Ne.startContainer;if(ye.nodeType===Node.TEXT_NODE&&C){const je=ye.textContent||"",Re=Ne.startOffset,Ie=je.slice(0,Re).lastIndexOf(C);if(Ie>=0){const Ae=je.slice(0,Ie),Pe=je.slice(Re),ot=`<span class="nice-htmleditor__mention" data-mention="${X.key}" contenteditable="false">${C}${X.label}</span>&nbsp;`;ye.textContent=Ae;const Ve=document.createRange();Ve.setStartAfter(ye),Ve.collapse(!0);const ct=Ve.createContextualFragment(ot+Pe);(Te=ye.parentNode)==null||Te.insertBefore(ct,ye.nextSibling),ve.collapseToEnd(),n(pe.innerHTML)}}Y(!1)},[C,n]),Be=i.useCallback(X=>{if(O&&We.length>0){X.key==="ArrowDown"?(X.preventDefault(),P(pe=>Math.min(pe+1,We.length-1))):X.key==="ArrowUp"?(X.preventDefault(),P(pe=>Math.max(pe-1,0))):X.key==="Enter"?(X.preventDefault(),Oe(We[de])):X.key==="Escape"&&Y(!1);return}(X.ctrlKey||X.metaKey)&&X.key==="b"?(X.preventDefault(),Me("bold")):(X.ctrlKey||X.metaKey)&&X.key==="i"?(X.preventDefault(),Me("italic")):(X.ctrlKey||X.metaKey)&&X.key==="u"?(X.preventDefault(),Me("underline")):(X.ctrlKey||X.metaKey)&&X.key==="f"?(X.preventDefault(),W(pe=>!pe)):(X.ctrlKey||X.metaKey)&&X.key==="z"&&!X.shiftKey?(X.preventDefault(),Me("undo")):(X.ctrlKey||X.metaKey)&&(X.key==="y"||X.key==="z"&&X.shiftKey)&&(X.preventDefault(),Me("redo"))},[O,We,de,Oe,Me]),Je=i.useCallback(X=>{var ye;if(!D)return;X.preventDefault();const pe=X.clipboardData.getData("text/html"),ve=X.clipboardData.getData("text/plain");if(pe){const Te=pe.replace(/<style[\s\S]*?<\/style>/gi,"").replace(/<script[\s\S]*?<\/script>/gi,"").replace(/class="[^"]*"/gi,"").replace(/style="[^"]*"/gi,"").replace(/<o:[^>]*>[\s\S]*?<\/o:[^>]*>/gi,"").replace(/<!--[\s\S]*?-->/g,"").replace(/<\/?(?:xml|meta|link|font|span)[^>]*>/gi,"");document.execCommand("insertHTML",!1,Te)}else ve&&document.execCommand("insertText",!1,ve);const Ne=u.current;Ne&&(n(Ne.innerHTML),xe(((ye=Ne.textContent)==null?void 0:ye.length)??0))},[D,n]),et=i.useCallback(async X=>{if(!H)return;X.preventDefault();const pe=Array.from(X.dataTransfer.files);if(pe.length===0)return;const ve=await H(pe),Ne=u.current;if(Ne){Ne.focus();for(const ye of ve)if(/\.(png|jpe?g|gif|webp|svg|bmp|ico)$/i.test(ye)||ye.startsWith("data:image/"))document.execCommand("insertImage",!1,ye);else{const Te=`<a href="${ye}">${ye.split("/").pop()??ye}</a>`;document.execCommand("insertHTML",!1,Te)}n(Ne.innerHTML)}},[H,n]),Xe=i.useCallback(X=>{H&&X.preventDefault()},[H]),Fe=i.useCallback(X=>{var Te;const pe=u.current;if(!pe||!se)return;const ve=pe.textContent??"",Ne=se.toLowerCase(),ye=ve.toLowerCase();(X===1?ye.indexOf(Ne):ye.lastIndexOf(Ne))!==-1&&(pe.focus(),(Te=window.find)==null||Te.call(window,se))},[se]),Ke=i.useCallback(()=>{const X=u.current;!X||!se||(X.innerHTML=X.innerHTML.split(se).join(ie),n(X.innerHTML))},[se,ie,n]),ae=i.useCallback(()=>{if(!se)return;const X=t.split(se).join(ie);n(X);const pe=u.current;pe&&(pe.innerHTML=X)},[se,ie,t,n]),ge=i.useCallback(X=>{const pe=u.current;pe&&(pe.focus(),document.execCommand("insertText",!1,X),n(pe.innerHTML),ke(!1))},[n]),Ce=i.useCallback(X=>{const pe=u.current;pe&&(pe.focus(),document.execCommand("insertHTML",!1,X),n(pe.innerHTML),Ee(!1))},[n]),ze=i.useCallback(X=>{const pe=T||p;return X==="fontSize"?e.jsx(_e.Ze,{size:"sm",value:"",onChange:ve=>Me("fontSize",String(ve)),disabled:pe,placeholder:"Size",options:di.map(ve=>({value:ve.value,label:ve.label})),style:{minWidth:70,maxWidth:80}},X):X==="fontColor"?e.jsx(_e.Xe,{value:ue,onChange:ve=>{fe(ve),Me("fontColor",ve)},disabled:pe,size:"sm",label:"",title:"Text color"},X):X==="bgColor"?e.jsx(_e.Xe,{value:V,onChange:ve=>{ne(ve),Me("bgColor",ve)},disabled:pe,size:"sm",label:"",title:"Highlight color"},X):e.jsx(_e.hn,{size:"sm",variant:X==="markdown"&&w||X==="fullscreen"&&B||X==="source"&&h||X==="findReplace"&&K||X==="emoji"&&he?"primary":"ghost",onClick:()=>Me(X),title:X,disabled:pe,children:ci[X]||X},X)},[T,p,Me,w,B,ue,V,h,K,he]);return $?null:e.jsxs("div",{className:`nice-field nice-field--${A} ${q?"nice-field--error":""} ${z||""}`,style:S,children:[Q&&e.jsxs("label",{className:"nice-field__label",htmlFor:L,children:[Q,y&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{ref:I,className:`nice-htmleditor${B?" nice-htmleditor--fullscreen":""}`,style:{position:"relative"},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(m,si)})}),e.jsxs("div",{className:"nice-htmleditor__toolbar",style:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center"},children:[o.map(ze),R&&R.length>0&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(_e.hn,{size:"sm",variant:$e?"primary":"ghost",onClick:()=>Ee(X=>!X),title:"Insert template",children:"??"}),$e&&e.jsx("ul",{style:{position:"absolute",top:"100%",right:0,zIndex:200,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",listStyle:"none",margin:0,padding:4,minWidth:160,maxHeight:200,overflow:"auto"},children:R.map((X,pe)=>e.jsx("li",{style:{padding:"6px 10px",cursor:"pointer",borderRadius:4},onMouseDown:ve=>{ve.preventDefault(),Ce(X.html)},children:X.label},pe))})]})]}),K&&e.jsxs("div",{className:"nice-htmleditor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--bg-secondary, #f8f9fa)",borderBottom:"1px solid var(--border-color, #ddd)",fontSize:"0.875em"},children:[e.jsx("input",{type:"text",placeholder:"Find...",value:se,onChange:X=>be(X.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--border-color, #ccc)",borderRadius:4,background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)"}}),e.jsx("input",{type:"text",placeholder:"Replace...",value:ie,onChange:X=>ce(X.target.value),style:{flex:1,maxWidth:180,padding:"2px 6px",border:"1px solid var(--border-color, #ccc)",borderRadius:4,background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)"}}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>Fe(1),title:"Find next",children:"?"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>Fe(-1),title:"Find previous",children:"?"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:Ke,disabled:T||p,children:"Replace"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:ae,disabled:T||p,children:"All"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>W(!1),children:"?"})]}),he&&e.jsx("div",{className:"nice-htmleditor__emoji-picker",style:{padding:8,background:"var(--bg-primary, #fff)",borderBottom:"1px solid var(--border-color, #ddd)",maxHeight:180,overflowY:"auto"},children:ui.map(X=>e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"0.7em",fontWeight:600,color:"var(--text-muted, #999)",padding:"4px 0"},children:X.label}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:2},children:X.emojis.map(pe=>e.jsx("span",{style:{cursor:"pointer",fontSize:"1.2em",padding:2,borderRadius:4},onClick:()=>ge(pe),title:pe,children:pe},pe))})]},X.label))}),e.jsx("input",{ref:d,type:"file",accept:"image/*",style:{display:"none"},onChange:qe}),h?e.jsx("textarea",{className:"nice-htmleditor__source",value:s,onChange:X=>F(X.target.value),style:{minHeight:r,width:"100%",fontFamily:"monospace",resize:"vertical",whiteSpace:"pre",fontSize:"0.85em",background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:T||p}):w?e.jsx("textarea",{className:"nice-htmleditor__markdown",value:g,onChange:X=>l(X.target.value),style:{minHeight:r,width:"100%",fontFamily:"monospace",resize:"vertical",background:"var(--bg-primary, #fff)",color:"var(--text-primary, #1f2937)",border:"none",padding:12,boxSizing:"border-box",outline:"none"},disabled:T||p}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:u,id:L,className:"nice-htmleditor__content",contentEditable:!T&&!p,dangerouslySetInnerHTML:{__html:t},onInput:Qe,onKeyDown:Be,onPaste:Je,onDrop:et,onDragOver:Xe,style:{minHeight:r},"data-placeholder":a,role:"textbox","aria-multiline":"true",suppressContentEditableWarning:!0}),O&&We.length>0&&e.jsx("ul",{className:"nice-htmleditor__mention-list",children:We.map((X,pe)=>e.jsx("li",{className:`nice-htmleditor__mention-item ${pe===de?"nice-htmleditor__mention-item--active":""}`,onMouseDown:ve=>{ve.preventDefault(),Oe(X)},children:X.label},X.key))})]}),e.jsxs("div",{className:"nice-htmleditor__statusbar",style:{display:"flex",gap:12,padding:"2px 8px",fontSize:"0.75em",color:"var(--text-muted, #666)",borderTop:"1px solid var(--border-color, #eee)"},children:[f>0&&e.jsxs("span",{children:[oe," / ",f]}),j&&e.jsxs("span",{children:[le," words"]}),j&&e.jsxs("span",{children:[oe," chars"]}),h&&e.jsx("span",{style:{fontWeight:600},children:"HTML Source"}),w&&e.jsx("span",{style:{fontWeight:600},children:"Markdown"})]})]}),q&&e.jsx("div",{className:"nice-field__error",children:q}),Z&&!q&&e.jsx("div",{className:"nice-field__hint",children:Z})]})},mi=Object.freeze(Object.defineProperty({__proto__:null,NiceHtmlEditor:wt},Symbol.toStringTag,{value:"Module"})),gi=[{code:"en",label:"English"},{code:"es",label:"Spanish"},{code:"fr",label:"French"},{code:"de",label:"German"},{code:"it",label:"Italian"},{code:"pt",label:"Portuguese"},{code:"pl",label:"Polish"},{code:"ru",label:"Russian"},{code:"zh",label:"Chinese"},{code:"ja",label:"Japanese"},{code:"ko",label:"Korean"},{code:"ar",label:"Arabic"}],fi=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}];i.forwardRef(function(t,n){var xe,le;const{enableAI:a=!0,aiModel:r,enableImprove:o=!0,enableTranslate:p=!0,enableGenerate:v=!0,toolbar:C,languages:M=gi,textStyles:E=fi,onImprove:H,onTranslate:D,onGenerate:f,showAIToolbar:j=!0,value:R,onChange:Q,...q}=t,Z=i.useRef(null),[y,T]=i.useState(!1),[A,k]=i.useState(!1),[z,S]=i.useState(!1),[x,m]=i.useState(""),[N,$]=i.useState(""),[L,u]=i.useState("professional"),[d,I]=i.useState(""),[w,_]=i.useState(((xe=M[0])==null?void 0:xe.code)||"en"),[g,l]=i.useState(""),[h,c]=i.useState(""),{t:s}=G.ce(),F=G.ge(),{improveText:O,translate:Y,generateHtml:J,isLoading:me}=G.ic(),de=a&&F.isConfigured,P=i.useCallback(()=>{const U=window.getSelection();return U&&U.toString().trim()?U.toString():""},[]),B=i.useCallback(U=>{const K=window.getSelection();if(K&&K.rangeCount>0){const W=K.getRangeAt(0);W.deleteContents();const se=document.createElement("div");se.innerHTML=U;const be=document.createDocumentFragment();for(;se.firstChild;)be.appendChild(se.firstChild);if(W.insertNode(be),Z.current){const ie=Z.current.innerHTML;Q(ie)}}},[Q]),re=i.useCallback(async(U="professional")=>{if(!de||!o)return"";const K=P();if(!K)return"";m(K),u(U),T(!0),$("");try{const W=await O(K,U);return $(W),H==null||H(K,W,U),W}catch{return $(s("htmlEditorAI.improveFailed","Failed to improve text")),""}},[de,o,P,O,H,s]),ue=i.useCallback(async U=>{var W;if(!de||!p)return"";const K=P();if(!K)return"";m(K),_(U),k(!0),I("");try{const se=((W=M.find(ie=>ie.code===U))==null?void 0:W.label)||U,be=await Y(K,se);return I(be),D==null||D(K,be,U),be}catch{return I(s("htmlEditorAI.translateFailed","Failed to translate text")),""}},[de,p,P,Y,M,D,s]),fe=i.useCallback(async U=>{if(!de||!v||!U.trim())return"";l(U),c("");try{const K=await J(U);return c(K),f==null||f(U,K),K}catch{return c(s("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[de,v,J,f,s]),V=i.useCallback(()=>{N&&B(N),T(!1),$("")},[N,B]),ne=i.useCallback(()=>{d&&B(d),k(!1),I("")},[d,B]),oe=i.useCallback(()=>{if(h&&Z.current){document.execCommand("insertHTML",!1,h);const U=Z.current.innerHTML;Q(U)}S(!1),c(""),l("")},[h,Q]);return i.useImperativeHandle(n,()=>({getEditor:()=>Z.current,focus:()=>{var U;return(U=Z.current)==null?void 0:U.focus()},getValue:()=>{var U;return((U=Z.current)==null?void 0:U.innerHTML)||""},setValue:U=>{Z.current&&(Z.current.innerHTML=U,Q(U))},getSelection:P,insertHtml:U=>{document.execCommand("insertHTML",!1,U),Z.current&&Q(Z.current.innerHTML)},improveSelection:re,translateSelection:ue,generateHtml:fe})),i.useCallback(U=>{Z.current=U},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":t["data-testid"],children:[j&&de&&e.jsxs("div",{className:"nice-html-editor-ai__toolbar",children:[e.jsxs("div",{className:"nice-html-editor-ai__toolbar-left",children:[e.jsx("span",{className:"nice-html-editor-ai__badge",children:"AI"}),me&&e.jsx("span",{className:"nice-html-editor-ai__loading",children:s("htmlEditorAI.processing","Processing...")})]}),e.jsxs("div",{className:"nice-html-editor-ai__toolbar-right",children:[o&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>re(),disabled:me,title:s("htmlEditorAI.improveText","Improve selected text"),children:["✨ ",s("htmlEditorAI.improve","Improve")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu",children:E.map(({style:U,label:K})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>re(U),children:K},U))})]}),p&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",disabled:me,title:s("htmlEditorAI.translateText","Translate selected text"),children:["🌐 ",s("htmlEditorAI.translate","Translate")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu nice-html-editor-ai__dropdown-menu--languages",children:M.map(({code:U,label:K})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>ue(U),children:K},U))})]}),v&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>S(!0),disabled:me,title:s("htmlEditorAI.generateHtml","Generate HTML from description"),children:["⚡ ",s("htmlEditorAI.generate","Generate")]})]})]}),e.jsx("div",{className:"nice-html-editor-ai__editor-wrapper",children:e.jsx(wt,{value:R,onChange:Q,toolbar:C,...q})}),y&&e.jsxs("div",{className:"nice-html-editor-ai__panel",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["✨ ",s("htmlEditorAI.improveText","Improve Text")]}),e.jsx("div",{className:"nice-html-editor-ai__style-selector",children:E.map(({style:U,label:K})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${L===U?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{u(U),re(U)},children:K},U))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>T(!1),children:"✕"})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:me?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:s("htmlEditorAI.improving","Improving text...")}):e.jsxs("div",{className:"nice-html-editor-ai__comparison",children:[e.jsxs("div",{className:"nice-html-editor-ai__text-block",children:[e.jsx("h5",{children:s("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:x})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--improved",children:[e.jsx("h5",{children:s("htmlEditorAI.improved","Improved")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:N})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:V,disabled:!N||me,children:["✓ ",s("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{T(!1),$("")},children:s("htmlEditorAI.cancel","Cancel")})]})]}),A&&e.jsxs("div",{className:"nice-html-editor-ai__panel",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["🌐 ",s("htmlEditorAI.translateText","Translate Text")]}),e.jsx("div",{className:"nice-html-editor-ai__language-selector",children:e.jsx("select",{value:w,onChange:U=>{_(U.target.value),ue(U.target.value)},className:"nice-html-editor-ai__language-select",children:M.map(({code:U,label:K})=>e.jsx("option",{value:U,children:K},U))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>k(!1),children:"✕"})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:me?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:s("htmlEditorAI.translating","Translating...")}):e.jsxs("div",{className:"nice-html-editor-ai__comparison",children:[e.jsxs("div",{className:"nice-html-editor-ai__text-block",children:[e.jsx("h5",{children:s("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:x})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:((le=M.find(U=>U.code===w))==null?void 0:le.label)||w}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:d})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ne,disabled:!d||me,children:["✓ ",s("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{k(!1),I("")},children:s("htmlEditorAI.cancel","Cancel")})]})]}),z&&e.jsxs("div",{className:"nice-html-editor-ai__panel nice-html-editor-ai__panel--generate",children:[e.jsxs("div",{className:"nice-html-editor-ai__panel-header",children:[e.jsxs("h4",{children:["⚡ ",s("htmlEditorAI.generateHtml","Generate HTML")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close",onClick:()=>{S(!1),c(""),l("")},children:"✕"})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-body",children:[e.jsxs("div",{className:"nice-html-editor-ai__generate-input",children:[e.jsx("textarea",{placeholder:s("htmlEditorAI.generatePlaceholder",'Describe what you want to create (e.g., "A pricing table with 3 tiers", "A contact form with name, email, and message")'),value:g,onChange:U=>l(U.target.value),className:"nice-html-editor-ai__generate-textarea",rows:3}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__generate-btn",onClick:()=>fe(g),disabled:me||!g.trim(),children:me?s("htmlEditorAI.generating","Generating..."):s("htmlEditorAI.generate","Generate")})]}),h&&e.jsxs("div",{className:"nice-html-editor-ai__generate-result",children:[e.jsx("h5",{children:s("htmlEditorAI.preview","Preview")}),e.jsx("div",{className:"nice-html-editor-ai__preview",dangerouslySetInnerHTML:{__html:h}}),e.jsx("h5",{children:s("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:h})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:oe,disabled:!h||me,children:["✓ ",s("htmlEditorAI.insert","Insert")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{S(!1),c(""),l("")},children:s("htmlEditorAI.cancel","Cancel")})]})]})]})});const pn=i.forwardRef(({length:t=6,value:n="",onChange:a,masked:r=!1,onComplete:o,label:p,helperText:v,error:C,required:M,disabled:E,readOnly:H,size:D="md",name:f,id:j,className:R,style:Q,autoFocus:q,labelPlacement:Z,errorPlacement:y,labelWidth:T,controlWidth:A,loading:k,cellWidth:z,...S},x)=>{const m=G.hl(j),N=i.useRef([]),$=n.padEnd(t,"").slice(0,t).split(""),L=i.useCallback(_=>{var l;const g=Math.max(0,Math.min(t-1,_));(l=N.current[g])==null||l.focus()},[t]),u=i.useCallback(_=>{const g=_.join("");a==null||a(g),g.length===t&&g.indexOf("")===-1&&/^\d+$/.test(g)&&(o==null||o(g))},[a,o,t]),d=i.useCallback((_,g)=>{const l=g.target.value.replace(/\D/g,"").slice(-1);if(!l)return;const h=[...$];h[_]=l,u(h),L(_+1)},[$,u,L]),I=i.useCallback((_,g)=>{if(g.key==="Backspace"){g.preventDefault();const l=[...$];$[_]?(l[_]="",u(l)):_>0&&(l[_-1]="",u(l),L(_-1))}else g.key==="ArrowLeft"?(g.preventDefault(),L(_-1)):g.key==="ArrowRight"&&(g.preventDefault(),L(_+1))},[$,u,L]),w=i.useCallback(_=>{_.preventDefault();const g=_.clipboardData.getData("text").replace(/\D/g,"").slice(0,t);if(!g)return;const l=g.padEnd(t,"").slice(0,t).split("");for(let h=g.length;h<t;h++)l[h]=$[h]||"";u(l),L(Math.min(g.length,t-1))},[t,$,u,L]);return e.jsxs("div",{className:`nice-field nice-field--${D} nice-field--otp${Z?` nice-field--label-${Z}`:""}${y==="right"?" nice-field--error-right":""} ${k?"nice-field--loading":""} ${R||""}`,style:{...Q,...T!=null&&{"--nice-field-label-width":typeof T=="number"?`${T}px`:T},...A!=null&&{"--nice-field-control-width":typeof A=="number"?`${A}px`:A},...z!=null&&{"--nice-otp-cell-width":typeof z=="number"?`${z}px`:z}},"aria-busy":k||void 0,...S,children:[p&&e.jsx("label",{htmlFor:`${m}-0`,className:`nice-field__label ${M?"nice-field__label--required":""}`,children:p}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{ref:x,className:`nice-otp nice-otp--${D} ${C?"nice-otp--error":""} ${E?"nice-otp--disabled":""}`,onPaste:w,children:[Array.from({length:t},(_,g)=>e.jsx("input",{ref:l=>{N.current[g]=l},id:g===0?`${m}-0`:void 0,className:"nice-otp__digit",type:r?"password":"text",inputMode:"numeric",maxLength:2,value:$[g]||"",disabled:E,readOnly:H,autoFocus:q&&g===0,"aria-invalid":!!C,"aria-label":`${g+1}`,onChange:l=>d(g,l),onKeyDown:l=>I(g,l),onFocus:l=>l.target.select()},g)),f&&e.jsx("input",{type:"hidden",name:f,value:n})]}),y==="right"&&C&&e.jsx("div",{id:`${m}-error`,className:"nice-field__error",role:"alert",children:C}),y==="right"&&!C&&v&&e.jsx("div",{id:`${m}-helper`,className:"nice-field__helper",children:v}),k&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]}),y!=="right"&&C&&e.jsx("div",{id:`${m}-error`,className:"nice-field__error",role:"alert",children:C}),y!=="right"&&!C&&v&&e.jsx("div",{id:`${m}-helper`,className:"nice-field__helper",children:v})]})});pn.displayName="NiceInputOtp";const xi={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160,small:64,medium:80,large:100},dt=6,at=135,hn=405,tt=hn-at;function kt(t,n,a,r){const o=(r-90)*(Math.PI/180);return{x:t+a*Math.cos(o),y:n+a*Math.sin(o)}}function It(t,n,a,r,o){const p=kt(t,n,a,r),v=kt(t,n,a,o),C=o-r>180?1:0;return`M ${p.x} ${p.y} A ${a} ${a} 0 ${C} 1 ${v.x} ${v.y}`}const mn=i.forwardRef(({value:t=0,onChange:n,min:a=0,max:r=100,step:o=1,showValue:p=!0,valueTemplate:v="{value}",label:C,helperText:M,error:E,required:H,disabled:D,readOnly:f,size:j="md",name:R,id:Q,className:q,style:Z,labelPlacement:y="top",errorPlacement:T,labelWidth:A,controlWidth:k,loading:z,isLabelCentered:S=!0,...x},m)=>{const N=G.hl(Q),$=i.useRef(!1),L=i.useRef(null),u=typeof j=="number"?j:xi[j],d=u/2,I=u/2,w=(u-dt*2)/2,_=r>a?(t-a)/(r-a):0,g=at+_*tt,l=i.useCallback(O=>{let Y=O-at;Y<0&&(Y+=360),Y>tt&&(Y=Y-tt<360-Y?tt:0);const J=Math.max(0,Math.min(1,Y/tt)),me=a+J*(r-a),de=Math.round(me/o)*o;return Math.max(a,Math.min(r,de))},[a,r,o]),h=i.useCallback(O=>{if(D||f)return;const Y=L.current;if(!Y)return;const J=Y.getBoundingClientRect(),me=O.clientX-J.left-J.width/2,de=O.clientY-J.top-J.height/2;let P=Math.atan2(me,-de)*(180/Math.PI);P<0&&(P+=360);const B=l(P);n==null||n(B)},[l,D,f,n]);i.useEffect(()=>{const O=J=>{$.current&&h(J)},Y=()=>{$.current=!1};return window.addEventListener("pointermove",O),window.addEventListener("pointerup",Y),()=>{window.removeEventListener("pointermove",O),window.removeEventListener("pointerup",Y)}},[h]);const c=i.useCallback(O=>{if(D||f)return;let Y=t;O.key==="ArrowUp"||O.key==="ArrowRight"?(O.preventDefault(),Y=Math.min(r,t+o)):(O.key==="ArrowDown"||O.key==="ArrowLeft")&&(O.preventDefault(),Y=Math.max(a,t-o)),Y!==t&&(n==null||n(Y))},[t,n,a,r,o,D,f]),s=v.replace("{value}",String(t)),F=kt(d,I,w,g);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${T||"bottom"} nice-field--${typeof j=="string"?j:"md"} ${z?"nice-field--loading":""} ${q||""}`,style:{...Z,...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...k!=null&&{"--nice-field-control-width":typeof k=="number"?`${k}px`:k}},"aria-busy":z||void 0,...x,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${y} ${S?"nice-knob-field--label-centered":""}`,children:[C&&e.jsx("label",{htmlFor:N,className:`nice-field__label ${H?"nice-field__label--required":""}`,children:C}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:O=>{L.current=O,typeof m=="function"?m(O):m&&(m.current=O)},className:`nice-knob nice-knob--${j} ${D?"nice-knob--disabled":""} ${E?"nice-knob--error":""}`,role:"slider",id:N,tabIndex:D?-1:0,"aria-valuenow":t,"aria-valuemin":a,"aria-valuemax":r,"aria-disabled":D,"aria-invalid":!!E,onPointerDown:O=>{D||f||($.current=!0,h(O))},onKeyDown:c,children:[e.jsxs("svg",{width:u,height:u,viewBox:`0 0 ${u} ${u}`,children:[e.jsx("path",{d:It(d,I,w,at,hn),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:dt,strokeLinecap:"round"}),_>0&&e.jsx("path",{d:It(d,I,w,at,g),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:dt,strokeLinecap:"round"}),e.jsx("circle",{cx:F.x,cy:F.y,r:dt,fill:"var(--nice-primary, #3b82f6)"})]}),p&&e.jsx("span",{className:"nice-knob__value",children:s}),R&&e.jsx("input",{type:"hidden",name:R,value:t}),z&&e.jsx("span",{className:"nice-knob__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]})})]}),E&&e.jsx("div",{className:"nice-field__error",role:"alert",children:E}),!E&&M&&e.jsx("div",{className:"nice-field__helper",children:M})]})});mn.displayName="NiceKnob";const gn=i.forwardRef(({value:t="",onChange:n,suggestions:a=[],onSearch:r,trigger:o="@",renderSuggestion:p,placeholder:v,rows:C=3,label:M,helperText:E,error:H,required:D,disabled:f,readOnly:j,size:R="md",name:Q,id:q,className:Z,style:y,...T},A)=>{const k=G.hl(q),[z,S]=i.useState(!1),[x,m]=i.useState(""),[N,$]=i.useState(0),[L,u]=i.useState({top:0,left:0}),d=i.useRef(null),I=i.useRef(-1),w=a.map(c=>typeof c=="string"?{key:c,label:c}:c).filter(c=>c.label.toLowerCase().includes(x.toLowerCase())),_=i.useCallback(()=>{S(!1),m(""),$(0),I.current=-1},[]),g=i.useCallback(c=>{const s=d.current;if(!s||I.current<0)return;const F=t.slice(0,I.current),O=t.slice(s.selectionStart),Y=`${o}${c.label} `,J=F+Y+O;n==null||n(J),_(),requestAnimationFrame(()=>{const me=F.length+Y.length;s.setSelectionRange(me,me),s.focus()})},[t,n,o,_]),l=i.useCallback(c=>{const s=c.target.value;n==null||n(s);const F=c.target.selectionStart,O=s.slice(0,F),Y=O.lastIndexOf(o);if(Y>=0){const J=Y>0?O[Y-1]:" ",me=O.slice(Y+o.length);if(/\s/.test(J)&&!/\s/.test(me)){I.current=Y;const de=me;m(de),S(!0),$(0),r==null||r(de);const P=c.target,B=P.getBoundingClientRect(),re=parseInt(getComputedStyle(P).lineHeight)||20,ue=O.split(`
11
+ `);u({top:B.top+ue.length*re+4-P.scrollTop,left:B.left+8});return}}_()},[n,o,r,_]),h=i.useCallback(c=>{!z||w.length===0||(c.key==="ArrowDown"?(c.preventDefault(),$(s=>(s+1)%w.length)):c.key==="ArrowUp"?(c.preventDefault(),$(s=>(s-1+w.length)%w.length)):c.key==="Enter"?(c.preventDefault(),w[N]&&g(w[N])):c.key==="Escape"&&_())},[z,w,N,g,_]);return i.useEffect(()=>{if(!z)return;const c=s=>{const F=d.current;F&&!F.contains(s.target)&&_()};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[z,_]),e.jsxs("div",{className:`nice-field ${Z||""}`,style:y,...T,children:[M&&e.jsx("label",{htmlFor:k,className:`nice-field__label ${D?"nice-field__label--required":""}`,children:M}),e.jsxs("div",{className:`nice-mention nice-mention--${R} ${H?"nice-mention--error":""} ${f?"nice-mention--disabled":""}`,children:[e.jsx("textarea",{ref:c=>{d.current=c,typeof A=="function"?A(c):A&&(A.current=c)},id:k,name:Q,className:"nice-mention__input",value:t,onChange:l,onKeyDown:h,placeholder:v,rows:C,disabled:f,readOnly:j,"aria-invalid":!!H,"aria-describedby":H?`${k}-error`:E?`${k}-helper`:void 0,"aria-autocomplete":"list","aria-expanded":z}),z&&w.length>0&&e.jsx("ul",{className:"nice-mention__suggestions",role:"listbox",style:{position:"fixed",top:L.top,left:L.left},children:w.map((c,s)=>e.jsx("li",{role:"option","aria-selected":s===N,className:`nice-mention__suggestion ${s===N?"nice-mention__suggestion--active":""}`,onMouseDown:F=>{F.preventDefault(),g(c)},onMouseEnter:()=>$(s),children:p?p(c):e.jsxs(e.Fragment,{children:[c.icon&&e.jsx("span",{className:"nice-mention__suggestion-icon",children:c.icon}),e.jsx("span",{children:c.label})]})},c.key))})]}),H&&e.jsx("div",{id:`${k}-error`,className:"nice-field__error",role:"alert",children:H}),!H&&E&&e.jsx("div",{id:`${k}-helper`,className:"nice-field__helper",children:E})]})});gn.displayName="NiceMention";function bi(t){const n=[],a=r=>{for(const o of r)n.push(o),o.children&&a(o.children)};return a(t),n}function fn(t,n){const a=n.toLowerCase();return t.reduce((r,o)=>{const p=o.children?fn(o.children,n):[];return(o.label.toLowerCase().includes(a)||p.length>0)&&r.push({...o,children:p.length>0?p:o.children}),r},[])}const xn=({node:t,level:n,selectedKeys:a,expandedKeys:r,onToggleExpand:o,onSelect:p,selectableLeafsOnly:v,maxDepth:C})=>{const M=typeof C=="number"?Math.min(10,Math.max(1,C)):1/0,E=!(n+1>=M)&&t.children&&t.children.length>0,H=r.has(t.key),D=a.has(t.key),f=!E,j=!t.disabled&&(!v||f),R=Math.min(n+1,10),Q={paddingLeft:n*16+8,"--nice-row-bg":`var(--nice-tree-level-${R}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${R}-text, inherit)`,"--nice-row-hover-bg":`var(--nice-tree-level-${R}-hover-bg, var(--bg-secondary, #f3f4f6))`,"--nice-row-active-bg":`var(--nice-tree-level-${R}-active-bg, var(--nice-primary-tint-10, rgba(59,130,246,0.1)))`};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`nice-tree-select__node ${D?"nice-tree-select__node--selected":""} ${t.disabled?"nice-tree-select__node--disabled":""}`,style:Q,"data-nice-depth":R,onClick:()=>j&&p(t.key),role:"treeitem","aria-selected":D,"aria-expanded":E?H:void 0,"aria-disabled":t.disabled,children:[E?e.jsx("button",{type:"button",className:"nice-tree-select__toggle",onClick:q=>{q.stopPropagation(),o(t.key)},"aria-label":"Toggle",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor",style:{transform:H?"rotate(90deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M4.5 2l4 4-4 4"})})}):e.jsx("span",{style:{width:12,display:"inline-block"}}),(t.icon==null,null),e.jsx("span",{className:"nice-tree-select__node-label",children:t.label})]}),E&&H&&t.children.map(q=>e.jsx(xn,{node:q,level:n+1,selectedKeys:a,expandedKeys:r,onToggleExpand:o,onSelect:p,selectableLeafsOnly:v,maxDepth:C},q.key))]})},bn=i.forwardRef(({nodes:t,value:n,onChange:a,multiple:r=!1,searchable:o=!1,placeholder:p,selectableLeafsOnly:v=!1,clearable:C=!1,maxDepth:M,label:E,helperText:H,error:D,required:f,disabled:j,readOnly:R,size:Q="md",name:q,id:Z,className:y,style:T,controlWidth:A,...k},z)=>{const{t:S}=G.ce(),x=G.hl(Z),[m,N]=i.useState(!1),[$,L]=i.useState(""),[u,d]=i.useState(new Set),I=i.useRef(null);G.bl(I,()=>N(!1));const w=i.useMemo(()=>n==null?new Set:new Set(Array.isArray(n)?n:[n]),[n]),_=i.useMemo(()=>$?fn(t,$):t,[t,$]),g=i.useMemo(()=>{const s=bi(t);return Array.from(w).map(F=>{var O;return(O=s.find(Y=>Y.key===F))==null?void 0:O.label}).filter(Boolean)},[w,t]),l=i.useCallback(s=>{d(F=>{const O=new Set(F);return O.has(s)?O.delete(s):O.add(s),O})},[]),h=i.useCallback(s=>{if(r){const F=new Set(w);F.has(s)?F.delete(s):F.add(s),a==null||a(Array.from(F))}else a==null||a(s),N(!1)},[r,w,a]),c=i.useCallback(s=>{s.stopPropagation(),a==null||a(r?[]:"")},[a,r]);return e.jsxs("div",{className:`nice-field nice-field--${Q} ${y||""}`,style:{width:"fit-content",maxWidth:"100%",...T},...k,children:[E&&e.jsx("label",{htmlFor:x,className:`nice-field__label ${f?"nice-field__label--required":""}`,children:E}),e.jsxs("div",{ref:I,className:"nice-tree-select",style:{position:"relative",width:A!=null?typeof A=="number"?`${A}px`:A:240},children:[e.jsxs("div",{ref:z,id:x,className:`nice-input nice-input--${Q} ${D?"nice-input--error":""} ${j?"nice-input--disabled":""} ${R?"nice-input--readonly":""}`,role:"combobox","aria-expanded":m,"aria-haspopup":"tree","aria-invalid":!!D,tabIndex:j?-1:0,onClick:()=>!j&&!R&&N(!m),onKeyDown:s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),!j&&!R&&N(!m))},children:[e.jsx("span",{className:"nice-tree-select__display",children:g.length>0?g.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:p??S("controls.select","Select...")})}),C&&w.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:c,"aria-label":S("controls.clear","Clear"),children:"✕"}),e.jsx("svg",{className:"nice-tree-select__arrow",width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",style:{transform:m?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx("path",{d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"})})]}),m&&e.jsxs("div",{className:"nice-tree-select__dropdown",role:"tree",children:[o&&e.jsx("div",{className:"nice-tree-select__search",children:e.jsx("input",{className:"nice-input__native",type:"text",placeholder:S("controls.search","Search..."),value:$,onChange:s=>L(s.target.value),autoFocus:!0,onClick:s=>s.stopPropagation()})}),e.jsx("div",{className:"nice-tree-select__list",children:_.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:S("controls.noResults","No results")}):_.map(s=>e.jsx(xn,{node:s,level:0,selectedKeys:w,expandedKeys:u,onToggleExpand:l,onSelect:h,selectableLeafsOnly:v,maxDepth:M},s.key))})]})]}),q&&e.jsx("input",{type:"hidden",name:q,value:Array.isArray(n)?n.join(","):n??""}),D&&e.jsx("div",{id:`${x}-error`,className:"nice-field__error",role:"alert",children:D}),!D&&H&&e.jsx("div",{id:`${x}-helper`,className:"nice-field__helper",children:H})]})});bn.displayName="NiceTreeSelect";function Ze(t,n){return String(t[n])}const yn=i.forwardRef(({source:t,target:n,onChange:a,keyField:r="id",labelField:o="label",renderItem:p,filterable:v=!1,searchable:C,groupBy:M,sortable:E=!1,bulkActions:H=!0,maxRight:D,sourceHeader:f,targetHeader:j,disabled:R=!1,size:Q="md",className:q,style:Z,id:y,...T},A)=>{const{t:k}=G.ce(),[z,S]=i.useState(new Set),[x,m]=i.useState(new Set),[N,$]=i.useState(""),[L,u]=i.useState(""),d=i.useCallback((s,F,O)=>{F(Y=>{const J=new Set(Y);return J.has(O)?J.delete(O):J.add(O),J})},[]),I=i.useCallback(()=>{const s=t.filter(J=>z.has(Ze(J,r))),F=t.filter(J=>!z.has(Ze(J,r))),O=typeof D=="number"?s.slice(0,Math.max(0,D-n.length)):s,Y=s.slice(O.length);a([...F,...Y],[...n,...O]),S(new Set)},[t,n,z,r,a,D]),w=i.useCallback(()=>{const s=n.filter(O=>x.has(Ze(O,r))),F=n.filter(O=>!x.has(Ze(O,r)));a([...t,...s],F),m(new Set)},[t,n,x,r,a]),_=i.useCallback(()=>{if(typeof D=="number"){const s=Math.max(0,D-n.length),F=t.slice(0,s),O=t.slice(s);a(O,[...n,...F])}else a([],[...n,...t]);S(new Set)},[t,n,a,D]),g=i.useCallback(()=>{a([...t,...n],[]),m(new Set)},[t,n,a]),l=(s,F)=>{if(!F)return s;const O=F.toLowerCase();return s.filter(Y=>String(Y[o]).toLowerCase().includes(O))},h=H===!1?{moveAll:!1,removeAll:!1}:H===!0||H===void 0?{moveAll:!0,removeAll:!0}:{moveAll:H.moveAll??!0,removeAll:H.removeAll??!0},c=(s,F,O,Y,J,me,de)=>{const P=l(s,Y),B=C===!0||v&&C===void 0?"both":C??!1,re=B==="both"||B==="left"&&de==="left"||B==="right"&&de==="right",ue=(()=>{if(!M)return[{label:"",items:P}];const ne=new Map;for(const oe of P){const xe=String(M(oe));let le=ne.get(xe);le||(le=[],ne.set(xe,le)),le.push(oe)}return[...ne.entries()].map(([oe,xe])=>({label:oe,items:xe}))})(),fe=(ne,oe)=>{ne.dataTransfer.setData("text/plain",oe),ne.dataTransfer.effectAllowed="move"},V=(ne,oe)=>{ne.preventDefault();const xe=ne.dataTransfer.getData("text/plain");if(!xe||xe===oe||de!=="right"||!E)return;const le=[...n],U=le.findIndex(se=>Ze(se,r)===xe),K=le.findIndex(se=>Ze(se,r)===oe);if(U===-1||K===-1)return;const[W]=le.splice(U,1);le.splice(K,0,W),a(t,le)};return e.jsxs("div",{className:"nice-picklist__panel",children:[me&&e.jsx("div",{className:"nice-picklist__header",children:me}),re&&e.jsx("div",{className:"nice-picklist__filter",children:e.jsx("input",{className:"nice-input__native",type:"text",placeholder:k("controls.search","Search..."),value:Y,onChange:ne=>J(ne.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true",children:[ue.map(ne=>e.jsxs(i.Fragment,{children:[ne.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:ne.label}),ne.items.map(oe=>{const xe=Ze(oe,r),le=F.has(xe);return e.jsx("div",{className:`nice-picklist__item ${le?"nice-picklist__item--selected":""}`,role:"option","aria-selected":le,draggable:E&&de==="right",onDragStart:E&&de==="right"?U=>fe(U,xe):void 0,onDragOver:E&&de==="right"?U=>U.preventDefault():void 0,onDrop:E&&de==="right"?U=>V(U,xe):void 0,onClick:()=>!R&&d(F,O,xe),children:p?p(oe,de):String(oe[o])},xe)})]},ne.label||"__none__")),P.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:k("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:A,id:y,className:`nice-picklist nice-picklist--${Q} ${R?"nice-picklist--disabled":""} ${q||""}`,style:Z,...T,children:[c(t,z,S,N,$,f??k("picklist.source","Available"),"left"),e.jsxs("div",{className:"nice-picklist__controls",children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R||z.size===0,onClick:I,"aria-label":k("picklist.moveRight","Move right"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"})})}),h.moveAll&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R||t.length===0,onClick:_,"aria-label":k("picklist.moveAllRight","Move all right"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M4.293 14.707a1 1 0 010-1.414L7.586 10 4.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"}),e.jsx("path",{d:"M10.293 14.707a1 1 0 010-1.414L13.586 10 10.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"})]})}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R||x.size===0,onClick:w,"aria-label":k("picklist.moveLeft","Move left"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"})})}),h.removeAll&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R||n.length===0,onClick:g,"aria-label":k("picklist.moveAllLeft","Move all left"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M15.707 5.293a1 1 0 010 1.414L12.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"}),e.jsx("path",{d:"M9.707 5.293a1 1 0 010 1.414L6.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"})]})})]}),c(n,x,m,L,u,j??k("picklist.target","Selected"),"right")]})});yn.displayName="NicePickList";const yi=[{target:".nice-code-editor-wrap",titleKey:"tutorial.codeEditor.intro.title",title:"Code editor",contentKey:"tutorial.codeEditor.intro.content",content:"Edit code with syntax highlighting, IntelliSense and the toolbar. Ctrl+S saves; the status bar shows the cursor position and any problems.",placement:"auto"}];let nt=null,it=null;const vi="0.45.0",gt=`https://cdn.jsdelivr.net/npm/monaco-editor@${vi}/min/vs`,Pt=15e3;function Wt(){var r;const t=window;if((r=t.MonacoEnvironment)!=null&&r.getWorkerUrl)return;const n=`self.MonacoEnvironment={baseUrl:'${gt}/'};importScripts('${gt}/base/worker/workerMain.js');`,a=URL.createObjectURL(new Blob([n],{type:"text/javascript"}));t.MonacoEnvironment={getWorkerUrl:()=>a}}function Ge(t){var a;if(t!=="auto")return t;if(typeof document>"u")return"vs";const n=document.documentElement.dataset.theme;return n==="dark"?"vs-dark":n==="light"?"vs":(a=window.matchMedia)!=null&&a.call(window,"(prefers-color-scheme: dark)").matches?"vs-dark":"vs"}function vn(){return it?Promise.resolve(it):nt||(nt=new Promise((t,n)=>{if(window.monaco){Wt(),it=window.monaco,t(it);return}let a=!1;const r=window.setTimeout(()=>{a||(a=!0,nt=null,n(new Error(`Monaco editor failed to load within ${Pt}ms`)))},Pt),o=document.createElement("script");o.src=`${gt}/loader.min.js`,o.async=!0,o.onload=()=>{const p=window.require;p.config({paths:{vs:gt}}),Wt(),p(["vs/editor/editor.main"],v=>{a||(a=!0,window.clearTimeout(r),it=v,t(v))})},o.onerror=()=>{a||(a=!0,window.clearTimeout(r),nt=null,n(new Error("Failed to load Monaco Editor loader script")))},document.head.appendChild(o)}),nt)}const st=i.forwardRef(function(t,n){const{value:a,onChange:r,language:o="plaintext",theme:p="auto",options:v={},height:C=400,width:M="100%",markers:E=[],decorations:H=[],completionProvider:D,onMount:f,onCursorPositionChange:j,onSelectionChange:R,onSave:Q,loading:q,disabled:Z=!1,showToolbar:y=!1,showStatusBar:T=!1,editorSize:A="standard",className:k,"data-testid":z,lsp:S,extraLibs:x,tutorial:m}=t,N=i.useRef(null),$=i.useRef(null),L=i.useRef(null),u=i.useRef([]),d=i.useRef(null),[I,w]=i.useState(!0),[_,g]=i.useState(null),[l,h]=i.useState({lineNumber:1,column:1}),[c,s]=i.useState(""),[F,O]=i.useState(v.wordWrap==="on"),Y=i.useMemo(()=>({automaticLayout:!0,readOnly:Z||v.readOnly,minimap:{enabled:v.minimap??!0},lineNumbers:v.lineNumbers??"on",wordWrap:v.wordWrap??"off",tabSize:v.tabSize??2,insertSpaces:v.insertSpaces??!0,fontSize:v.fontSize??14,fontFamily:v.fontFamily??"'Fira Code', 'Consolas', 'Monaco', monospace",fontLigatures:v.fontLigatures??!0,cursorStyle:v.cursorStyle??"line",cursorBlinking:v.cursorBlinking??"blink",autoClosingBrackets:v.autoClosingBrackets??"languageDefined",autoClosingQuotes:v.autoClosingQuotes??"languageDefined",formatOnPaste:v.formatOnPaste??!1,formatOnType:v.formatOnType??!1,renderWhitespace:v.renderWhitespace??"selection",renderControlCharacters:v.renderControlCharacters??!1,scrollBeyondLastLine:v.scrollBeyondLastLine??!0,smoothScrolling:v.smoothScrolling??!0,folding:v.folding??!0,showFoldingControls:v.showFoldingControls??"mouseover","bracketPairColorization.enabled":v.bracketPairColorization??!0,guides:v.guides??{bracketPairs:!0,indentation:!0,highlightActiveIndentation:!0},stickyScroll:{enabled:v.stickyScroll??!1},quickSuggestions:v.quickSuggestions??!0,suggestOnTriggerCharacters:v.suggestOnTriggerCharacters??!0,acceptSuggestionOnEnter:v.acceptSuggestionOnEnter??"on",inlayHints:{enabled:v.inlayHints?"on":"off"}}),[v,Z]);i.useEffect(()=>{if(!N.current)return;let P=!0;return vn().then(async B=>{if(!P||!N.current)return;L.current=B;const re=B.editor.create(N.current,{value:a,language:o,theme:Ge(p),...Y});if($.current=re,w(!1),re.onDidChangeModelContent(()=>{const ue=re.getValue();r==null||r(ue)}),re.onDidChangeCursorPosition(ue=>{h({lineNumber:ue.position.lineNumber,column:ue.position.column}),j==null||j({lineNumber:ue.position.lineNumber,column:ue.position.column})}),re.onDidChangeCursorSelection(ue=>{var ne;const fe=ue.selection,V=((ne=re.getModel())==null?void 0:ne.getValueInRange(fe))??"";s(V),R==null||R({startLineNumber:fe.startLineNumber,startColumn:fe.startColumn,endLineNumber:fe.endLineNumber,endColumn:fe.endColumn})}),re.addCommand(B.KeyMod.CtrlCmd|B.KeyCode.KeyS,()=>{Q==null||Q(re.getValue())}),S&&typeof window<"u")try{await ft("https://cdn.jsdelivr.net/npm/vscode-ws-jsonrpc@1.0.2/lib/browser/index.min.js"),await ft("https://cdn.jsdelivr.net/npm/monaco-languageclient@0.15.0/lib/monaco-languageclient.min.js");const ue=window,fe=ue.ReconnectingWebSocket,{MonacoLanguageClient:V,CloseAction:ne,ErrorAction:oe,createConnection:xe}=ue.monacoLanguageClient||{};if(V&&xe){const le=S.url,U=S.language,K=new fe(le),W=new ue.VSCodeWebSocketMessageReader(K),se=new ue.VSCodeWebSocketMessageWriter(K),be=xe(W,se),ie=new V({name:"LSP Client",clientOptions:{documentSelector:[U],initializationOptions:S.initOptions,errorHandler:{error:()=>oe.Continue,closed:()=>ne.Restart}},connectionProvider:{get:()=>Promise.resolve(be)}});ie.start(),$.current.__lspClient=ie}}catch(ue){console.warn("LSP bridge failed to load:",ue)}f==null||f(re,B)}).catch(B=>{P&&(g(B.message??"Failed to load editor"),w(!1))}),()=>{var B,re;if(P=!1,(B=$.current)==null||B.dispose(),(re=d.current)==null||re.dispose(),$.current&&$.current.__lspClient)try{$.current.__lspClient.stop()}catch{}}},[S]),i.useEffect(()=>{const P=$.current;if(P&&a!==P.getValue()){const B=P.getPosition();P.setValue(a),B&&P.setPosition(B)}},[a]),i.useEffect(()=>{const P=$.current,B=L.current;if(P&&B){const re=P.getModel();re&&B.editor.setModelLanguage(re,o)}},[o]),i.useEffect(()=>{var ue;const P=L.current;if(!P||I||!x||x.length===0||o!=="javascript"&&o!=="typescript")return;const B=(ue=P.languages)==null?void 0:ue.typescript;if(!B)return;const re=[];try{x.forEach((fe,V)=>{var le,U;const ne=fe.filePath??`inmemory://model/nice-extralib-${V}.d.ts`,oe=(le=B.typescriptDefaults)==null?void 0:le.addExtraLib(fe.content,ne);oe&&re.push(oe);const xe=(U=B.javascriptDefaults)==null?void 0:U.addExtraLib(fe.content,ne);xe&&re.push(xe)})}catch(fe){console.warn("Failed to register extraLibs:",fe)}return()=>{re.forEach(fe=>{try{fe.dispose()}catch{}})}},[x,o,I]),i.useEffect(()=>{var fe,V;const P=L.current;if(!P||(P.editor.setTheme(Ge(p)),p!=="auto"||typeof document>"u"))return;const B=()=>{var ne;(ne=L.current)==null||ne.editor.setTheme(Ge("auto"))},re=new MutationObserver(B);re.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const ue=(fe=window.matchMedia)==null?void 0:fe.call(window,"(prefers-color-scheme: dark)");return(V=ue==null?void 0:ue.addEventListener)==null||V.call(ue,"change",B),()=>{var ne;re.disconnect(),(ne=ue==null?void 0:ue.removeEventListener)==null||ne.call(ue,"change",B)}},[p]),i.useEffect(()=>{const P=$.current;P&&P.updateOptions(Y)},[Y]),i.useEffect(()=>{const P=$.current,B=L.current;if(P&&B){const re=P.getModel();if(re){const ue=E.map(fe=>({startLineNumber:fe.startLineNumber,startColumn:fe.startColumn,endLineNumber:fe.endLineNumber,endColumn:fe.endColumn,message:fe.message,severity:fe.severity}));B.editor.setModelMarkers(re,"owner",ue)}}},[E]),i.useEffect(()=>{const P=$.current;if(P&&H.length>0){const B=H.map(re=>({range:{startLineNumber:re.range.startLineNumber,startColumn:re.range.startColumn,endLineNumber:re.range.endLineNumber,endColumn:re.range.endColumn},options:{className:re.className,glyphMarginClassName:re.glyphMarginClassName,hoverMessage:re.hoverMessage?{value:re.hoverMessage}:void 0,isWholeLine:re.isWholeLine}}));u.current=P.deltaDecorations(u.current,B)}},[H]),i.useEffect(()=>{var re;const P=L.current;if(!P||!D)return;(re=d.current)==null||re.dispose();const B={text:0,method:1,function:2,constructor:3,field:4,variable:5,class:6,interface:7,module:8,property:9,keyword:13,snippet:14,color:15,file:16,reference:17,folder:18};return d.current=P.languages.registerCompletionItemProvider(o,{provideCompletionItems:async(ue,fe)=>({suggestions:(await D(ue,fe)).map(V=>({label:V.label,kind:B[V.kind]??0,insertText:V.insertText,insertTextRules:V.insertTextRules==="insertAsSnippet"?4:void 0,documentation:V.documentation,detail:V.detail,range:{startLineNumber:fe.lineNumber,startColumn:fe.column,endLineNumber:fe.lineNumber,endColumn:fe.column}}))})}),()=>{var ue;(ue=d.current)==null||ue.dispose()}},[o,D]),i.useImperativeHandle(n,()=>({getEditor:()=>$.current,getMonaco:()=>L.current,focus:()=>{var P;return(P=$.current)==null?void 0:P.focus()},getValue:()=>{var P;return((P=$.current)==null?void 0:P.getValue())??""},setValue:P=>{var B;return(B=$.current)==null?void 0:B.setValue(P)},getSelection:()=>{var re;const P=$.current;if(!P)return"";const B=P.getSelection();return B?((re=P.getModel())==null?void 0:re.getValueInRange(B))??"":""},insertText:P=>{const B=$.current;if(!B)return;const re=B.getSelection();re&&B.executeEdits("",[{range:re,text:P}])},formatDocument:()=>{var P,B;(B=(P=$.current)==null?void 0:P.getAction("editor.action.formatDocument"))==null||B.run()},goToLine:(P,B=1)=>{const re=$.current;re&&(re.setPosition({lineNumber:P,column:B}),re.revealLineInCenter(P),re.focus())},findReplace:()=>{var P,B;(B=(P=$.current)==null?void 0:P.getAction("editor.action.startFindReplaceAction"))==null||B.run()},undo:()=>{var P;(P=$.current)==null||P.trigger("keyboard","undo",null)},redo:()=>{var P;(P=$.current)==null||P.trigger("keyboard","redo",null)},getCursorPosition:()=>{var B;const P=(B=$.current)==null?void 0:B.getPosition();return{lineNumber:(P==null?void 0:P.lineNumber)??1,column:(P==null?void 0:P.column)??1}},setMarkers:P=>{const B=$.current,re=L.current;if(B&&re){const ue=B.getModel();if(ue){const fe=P.map(V=>({startLineNumber:V.startLineNumber,startColumn:V.startColumn,endLineNumber:V.endLineNumber,endColumn:V.endColumn,message:V.message,severity:V.severity}));re.editor.setModelMarkers(ue,"owner",fe)}}}}),[]);const J=i.useMemo(()=>({format:()=>{var P,B;return(B=(P=$.current)==null?void 0:P.getAction("editor.action.formatDocument"))==null?void 0:B.run()},undo:()=>{var P;return(P=$.current)==null?void 0:P.trigger("keyboard","undo",null)},redo:()=>{var P;return(P=$.current)==null?void 0:P.trigger("keyboard","redo",null)},find:()=>{var P,B;return(B=(P=$.current)==null?void 0:P.getAction("editor.action.startFindReplaceAction"))==null?void 0:B.run()},toggleWordWrap:()=>{var B;const P=!F;O(P),(B=$.current)==null||B.updateOptions({wordWrap:P?"on":"off"})},toggleMinimap:()=>{var B,re,ue,fe,V,ne;const P=(V=(B=$.current)==null?void 0:B.getOption)==null?void 0:V.call(B,(fe=(ue=(re=L.current)==null?void 0:re.editor)==null?void 0:ue.EditorOption)==null?void 0:fe.minimap);(ne=$.current)==null||ne.updateOptions({minimap:{enabled:!(P!=null&&P.enabled)}})},foldAll:()=>{var P,B;return(B=(P=$.current)==null?void 0:P.getAction("editor.foldAll"))==null?void 0:B.run()},unfoldAll:()=>{var P,B;return(B=(P=$.current)==null?void 0:P.getAction("editor.unfoldAll"))==null?void 0:B.run()}}),[F]),me=a.split(`
12
+ `).length,de=a.length;return e.jsxs("div",{className:`nice-code-editor-wrap nice-editor--${A} ${k??""}`,style:{height:C,width:M,display:"flex",flexDirection:"column",position:"relative"},"data-testid":z,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(m,yi)})}),_&&e.jsxs("div",{className:"nice-code-editor__error",style:{position:"absolute",inset:0,zIndex:2,background:"var(--nice-bg-primary, #fff)"},children:[e.jsxs("span",{children:["⚠️ ",_]}),e.jsx("textarea",{value:a,onChange:P=>r==null?void 0:r(P.target.value),readOnly:Z||v.readOnly,style:{width:"100%",height:"100%",fontFamily:"monospace"}})]}),I&&!_&&e.jsx("div",{className:"nice-code-editor__loader-overlay",style:{position:"absolute",inset:0,zIndex:2,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)"},children:q??e.jsx("div",{className:"nice-code-editor__loader",children:"Loading editor..."})}),y&&e.jsxs("div",{className:"nice-code-editor__toolbar",children:[e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.undo,title:"Undo (Ctrl+Z)",children:"↶"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.redo,title:"Redo (Ctrl+Y)",children:"↷"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.format,title:"Format (Shift+Alt+F)",children:"⎘"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.find,title:"Find & Replace (Ctrl+H)",children:"🔍"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:`nice-code-editor__toolbar-btn${F?" nice-code-editor__toolbar-btn--active":""}`,onClick:J.toggleWordWrap,title:"Toggle Word Wrap",children:"↩"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.toggleMinimap,title:"Toggle Minimap",children:"▥"}),e.jsx("span",{className:"nice-code-editor__toolbar-sep"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.foldAll,title:"Fold All",children:"⊟"}),e.jsx("button",{className:"nice-code-editor__toolbar-btn",onClick:J.unfoldAll,title:"Unfold All",children:"⊞"})]}),e.jsx("div",{ref:N,className:"nice-code-editor",style:{flex:1,minHeight:0}}),T&&e.jsxs("div",{className:"nice-code-editor__statusbar",children:[e.jsxs("span",{children:["Ln ",l.lineNumber,", Col ",l.column]}),c.length>0&&e.jsxs("span",{children:["(",c.length," selected)"]}),e.jsx("span",{className:"nice-code-editor__statusbar-spacer"}),e.jsxs("span",{children:[me," lines · ",de," chars"]}),e.jsx("span",{className:"nice-code-editor__statusbar-lang",children:o}),E.length>0&&e.jsxs("span",{className:"nice-code-editor__statusbar-markers",children:["⚠ ",E.length]})]})]})});function _n(t){const{original:n,modified:a,language:r="plaintext",theme:o="auto",height:p=400,width:v="100%",inline:C=!1,renderSideBySide:M=!0,originalEditable:E=!1,modifiedEditable:H=!1,onOriginalChange:D,onModifiedChange:f,loading:j,className:R,"data-testid":Q}=t,q=i.useRef(null),Z=i.useRef(null),y=i.useRef(null),[T,A]=i.useState(!0),[k,z]=i.useState(null);return i.useEffect(()=>{if(!q.current)return;let S=!0;return vn().then(x=>{if(!S||!q.current)return;y.current=x;const m=x.editor.createModel(n,r),N=x.editor.createModel(a,r),$=x.editor.createDiffEditor(q.current,{automaticLayout:!0,theme:Ge(o),renderSideBySide:!C&&M,originalEditable:E,readOnly:!H});$.setModel({original:m,modified:N}),Z.current=$,A(!1),E&&m.onDidChangeContent(()=>{D==null||D(m.getValue())}),H&&N.onDidChangeContent(()=>{f==null||f(N.getValue())})}).catch(x=>{S&&(z(x.message??"Failed to load diff editor"),A(!1))}),()=>{var x;S=!1,(x=Z.current)==null||x.dispose()}},[]),i.useEffect(()=>{const S=Z.current;if(!S)return;const x=S.getModel();x&&(x.original.getValue()!==n&&x.original.setValue(n),x.modified.getValue()!==a&&x.modified.setValue(a))},[n,a]),i.useEffect(()=>{var $,L;const S=y.current;if(!S||(S.editor.setTheme(Ge(o)),o!=="auto"||typeof document>"u"))return;const x=()=>{var u;(u=y.current)==null||u.editor.setTheme(Ge("auto"))},m=new MutationObserver(x);m.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const N=($=window.matchMedia)==null?void 0:$.call(window,"(prefers-color-scheme: dark)");return(L=N==null?void 0:N.addEventListener)==null||L.call(N,"change",x),()=>{var u;m.disconnect(),(u=N==null?void 0:N.removeEventListener)==null||u.call(N,"change",x)}},[o,T]),k?e.jsx("div",{className:`nice-code-diff-editor nice-code-diff-editor--error ${R??""}`,style:{height:p,width:v},"data-testid":Q,children:e.jsx("div",{className:"nice-code-editor__error",children:e.jsxs("span",{children:["⚠️ ",k]})})}):e.jsxs("div",{className:`nice-code-diff-editor ${R??""}`,style:{height:p,width:v,position:"relative"},"data-testid":Q,children:[e.jsx("div",{ref:q,style:{position:"absolute",inset:0}}),T&&e.jsx("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-primary, #fff)",zIndex:2},children:j??e.jsx("div",{className:"nice-code-editor__loader",children:"Loading diff editor..."})})]})}const _i="1.29.0",Ht=`https://cdn.jsdelivr.net/npm/prismjs@${_i}`;let bt=null;const jt={javascript:"javascript",typescript:"typescript",json:"json",html:"markup",css:"css",scss:"scss",less:"less",markdown:"markdown",xml:"markup",yaml:"yaml",sql:"sql",python:"python",csharp:"csharp",java:"java",cpp:"cpp",c:"c",go:"go",rust:"rust",php:"php",ruby:"ruby",shell:"bash",powershell:"powershell",plaintext:"plain"};function ft(t){return new Promise((n,a)=>{if(document.querySelector(`script[data-prism-src="${t}"]`)){n();return}const r=document.createElement("script");r.src=t,r.async=!0,r.dataset.prismSrc=t,r.onload=()=>n(),r.onerror=()=>a(new Error(`Failed to load ${t}`)),document.head.appendChild(r)})}function ki(t){if(typeof window>"u")return Promise.resolve(null);const n=window,a=jt[t]??"plain",r=async()=>{var o,p;if(a!=="plain"&&!((p=(o=n.Prism)==null?void 0:o.languages)!=null&&p[a]))try{await ft(`${Ht}/components/prism-${a}.min.js`)}catch{}};return n.Prism?r().then(()=>n.Prism):(bt||(bt=(async()=>(window.Prism={manual:!0},await ft(`${Ht}/prism.min.js`),window.Prism))()),bt.then(async()=>(await r(),window.Prism)))}function yt(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function kn(t){const{value:n,onChange:a,language:r="plaintext",height:o=300,width:p="100%",readOnly:v=!1,tabSize:C=2,lineNumbers:M=!0,placeholder:E,theme:H="auto",className:D,"data-testid":f}=t,j=i.useRef(null),R=i.useRef(null),[Q,q]=i.useState(()=>yt(n)),[Z,y]=i.useState("light");i.useEffect(()=>{var $,L;const S=()=>{var d;if(H!=="auto")return H;if(typeof document>"u")return"light";const u=document.documentElement.dataset.theme;return u==="dark"?"dark":u==="light"?"light":(d=window.matchMedia)!=null&&d.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light"};if(y(S()),H!=="auto"||typeof document>"u")return;const x=()=>y(S()),m=new MutationObserver(x);m.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"]});const N=($=window.matchMedia)==null?void 0:$.call(window,"(prefers-color-scheme: dark)");return(L=N==null?void 0:N.addEventListener)==null||L.call(N,"change",x),()=>{var u;m.disconnect(),(u=N==null?void 0:N.removeEventListener)==null||u.call(N,"change",x)}},[H]),i.useEffect(()=>{let S=!0;return ki(r).then(x=>{var N;if(!S)return;const m=jt[r]??"plain";if((N=x==null?void 0:x.languages)!=null&&N[m])try{const $=x.highlight(n,x.languages[m],m);q($);return}catch{}q(yt(n))}).catch(()=>{S&&q(yt(n))}),()=>{S=!1}},[n,r]);const T=i.useCallback(()=>{!R.current||!j.current||(R.current.scrollTop=j.current.scrollTop,R.current.scrollLeft=j.current.scrollLeft)},[]),A=i.useCallback(S=>{var x;if(S.key==="Tab"){S.preventDefault();const m=S.currentTarget,N=m.selectionStart,$=m.selectionEnd,L=" ".repeat(C);if(S.shiftKey){const u=n.substring(0,N).lastIndexOf(`
13
+ `)+1;if((((x=n.substring(u,N).match(/^(\s*)/))==null?void 0:x[1])??"").length>=C){const d=n.substring(0,u)+n.substring(u+C);a==null||a(d),setTimeout(()=>{m.selectionStart=m.selectionEnd=N-C},0)}}else{const u=n.substring(0,N)+L+n.substring($);a==null||a(u),setTimeout(()=>{m.selectionStart=m.selectionEnd=N+C},0)}}},[n,a,C]),k=n.split(`
14
+ `).length,z=jt[r]??"plain";return e.jsxs("div",{className:`nice-simple-code-editor nice-simple-code-editor--${Z} ${D??""}`,style:{height:o,width:p},"data-testid":f,"data-language":r,"data-theme":Z,children:[M&&e.jsx("div",{className:"nice-simple-code-editor__line-numbers",children:Array.from({length:k},(S,x)=>e.jsx("div",{className:"nice-simple-code-editor__line-number",children:x+1},x))}),e.jsxs("div",{className:"nice-simple-code-editor__editor-area",children:[e.jsx("pre",{ref:R,"aria-hidden":"true",className:`nice-simple-code-editor__highlight language-${z}`,children:e.jsx("code",{className:`language-${z}`,dangerouslySetInnerHTML:{__html:Q+(n.endsWith(`
15
+ `)?`
16
+ `:"")}})}),e.jsx("textarea",{ref:j,className:"nice-simple-code-editor__textarea",value:n,onChange:S=>a==null?void 0:a(S.target.value),onKeyDown:A,onScroll:T,readOnly:v,placeholder:E,spellCheck:!1,autoCapitalize:"off",autoCorrect:"off"})]})]})}const Ot="nice-code-editor-styles";if(typeof document<"u"&&!document.getElementById(Ot)){const t=document.createElement("style");t.id=Ot,t.textContent=`
17
+ .nice-code-editor,
18
+ .nice-code-diff-editor {
19
+ border: 1px solid var(--nice-border, #e0e0e0);
20
+ border-radius: var(--nice-radius-sm, 4px);
21
+ overflow: hidden;
22
+ }
23
+
24
+ .nice-code-editor--loading,
25
+ .nice-code-editor--error,
26
+ .nice-code-diff-editor--loading {
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ background: var(--nice-bg-muted, #f5f5f5);
31
+ }
32
+
33
+ .nice-code-editor__loader {
34
+ color: var(--nice-text-secondary, #666);
35
+ font-size: 14px;
36
+ }
37
+
38
+ .nice-code-editor__error {
39
+ display: flex;
40
+ flex-direction: column;
41
+ width: 100%;
42
+ height: 100%;
43
+ padding: var(--nice-space-2, 8px);
44
+ gap: var(--nice-space-2, 8px);
45
+ }
46
+
47
+ .nice-code-editor__error span {
48
+ color: var(--nice-error, #d32f2f);
49
+ }
50
+
51
+ /* Simple code editor */
52
+ .nice-simple-code-editor {
53
+ display: flex;
54
+ border: 1px solid var(--border-color, var(--nice-border, #e0e0e0));
55
+ border-radius: var(--nice-radius-sm, 4px);
56
+ overflow: hidden;
57
+ font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
58
+ font-size: 14px;
59
+ line-height: 1.5;
60
+ background: var(--bg-primary, var(--nice-bg-surface, #fff));
61
+ color: var(--text-primary, var(--nice-text-primary, #333));
62
+ }
63
+ .nice-simple-code-editor--dark {
64
+ background: var(--nice-bg, #1e1e1e);
65
+ color: var(--nice-text, #d4d4d4);
66
+ }
67
+
68
+ .nice-simple-code-editor__line-numbers {
69
+ padding: var(--nice-space-2, 8px) 0;
70
+ background: var(--bg-secondary, var(--nice-bg-muted, #f5f5f5));
71
+ border-right: 1px solid var(--border-color, var(--nice-border, #e0e0e0));
72
+ user-select: none;
73
+ text-align: right;
74
+ color: var(--text-secondary, var(--nice-text-secondary, #999));
75
+ overflow: hidden;
76
+ }
77
+ .nice-simple-code-editor--dark .nice-simple-code-editor__line-numbers {
78
+ background: var(--nice-bg-secondary, #252526);
79
+ border-right-color: var(--nice-border, #3c3c3c);
80
+ color: var(--nice-text-muted, #858585);
81
+ }
82
+
83
+ .nice-simple-code-editor__line-number {
84
+ padding: 0 var(--nice-space-3, 12px);
85
+ min-width: 40px;
86
+ }
87
+
88
+ .nice-simple-code-editor__editor-area {
89
+ position: relative;
90
+ flex: 1;
91
+ overflow: hidden;
92
+ }
93
+
94
+ .nice-simple-code-editor__highlight,
95
+ .nice-simple-code-editor__textarea {
96
+ position: absolute;
97
+ inset: 0;
98
+ margin: 0;
99
+ padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
100
+ border: 0;
101
+ font: inherit;
102
+ line-height: inherit;
103
+ white-space: pre;
104
+ overflow: auto;
105
+ tab-size: 2;
106
+ }
107
+
108
+ .nice-simple-code-editor__highlight {
109
+ pointer-events: none;
110
+ background: transparent;
111
+ color: inherit;
112
+ }
113
+ .nice-simple-code-editor__highlight code {
114
+ font: inherit;
115
+ background: transparent;
116
+ }
117
+
118
+ .nice-simple-code-editor__textarea {
119
+ background: transparent;
120
+ color: transparent;
121
+ caret-color: var(--text-primary, var(--nice-text-primary, #333));
122
+ resize: none;
123
+ outline: none;
124
+ -webkit-text-fill-color: transparent;
125
+ }
126
+ .nice-simple-code-editor--dark .nice-simple-code-editor__textarea {
127
+ caret-color: var(--nice-text, #d4d4d4);
128
+ }
129
+
130
+ .nice-simple-code-editor__textarea::placeholder {
131
+ color: var(--text-secondary, var(--nice-text-secondary, #999));
132
+ -webkit-text-fill-color: var(--text-secondary, var(--nice-text-secondary, #999));
133
+ }
134
+ .nice-simple-code-editor--dark .nice-simple-code-editor__textarea::placeholder {
135
+ color: var(--nice-text-muted, #858585);
136
+ -webkit-text-fill-color: var(--nice-text-muted, #858585);
137
+ }
138
+
139
+ /* Prism token colors — light */
140
+ .nice-simple-code-editor .token.comment,
141
+ .nice-simple-code-editor .token.prolog,
142
+ .nice-simple-code-editor .token.doctype,
143
+ .nice-simple-code-editor .token.cdata { color: #6a737d; font-style: italic; }
144
+ .nice-simple-code-editor .token.punctuation { color: #586069; }
145
+ .nice-simple-code-editor .token.property,
146
+ .nice-simple-code-editor .token.tag,
147
+ .nice-simple-code-editor .token.boolean,
148
+ .nice-simple-code-editor .token.number,
149
+ .nice-simple-code-editor .token.constant,
150
+ .nice-simple-code-editor .token.symbol,
151
+ .nice-simple-code-editor .token.deleted { color: #005cc5; }
152
+ .nice-simple-code-editor .token.selector,
153
+ .nice-simple-code-editor .token.attr-name,
154
+ .nice-simple-code-editor .token.string,
155
+ .nice-simple-code-editor .token.char,
156
+ .nice-simple-code-editor .token.builtin,
157
+ .nice-simple-code-editor .token.inserted { color: #032f62; }
158
+ .nice-simple-code-editor .token.operator,
159
+ .nice-simple-code-editor .token.entity,
160
+ .nice-simple-code-editor .token.url,
161
+ .nice-simple-code-editor .token.variable { color: var(--nice-danger, #d73a49); }
162
+ .nice-simple-code-editor .token.atrule,
163
+ .nice-simple-code-editor .token.attr-value,
164
+ .nice-simple-code-editor .token.keyword { color: var(--nice-danger, #d73a49); font-weight: 600; }
165
+ .nice-simple-code-editor .token.function,
166
+ .nice-simple-code-editor .token.class-name { color: #6f42c1; }
167
+ .nice-simple-code-editor .token.regex,
168
+ .nice-simple-code-editor .token.important { color: #e36209; }
169
+
170
+ /* Prism token colors — dark */
171
+ .nice-simple-code-editor--dark .token.comment,
172
+ .nice-simple-code-editor--dark .token.prolog,
173
+ .nice-simple-code-editor--dark .token.doctype,
174
+ .nice-simple-code-editor--dark .token.cdata { color: var(--nice-success, #6a9955); font-style: italic; }
175
+ .nice-simple-code-editor--dark .token.punctuation { color: var(--nice-text, #d4d4d4); }
176
+ .nice-simple-code-editor--dark .token.property,
177
+ .nice-simple-code-editor--dark .token.tag,
178
+ .nice-simple-code-editor--dark .token.boolean,
179
+ .nice-simple-code-editor--dark .token.number,
180
+ .nice-simple-code-editor--dark .token.constant,
181
+ .nice-simple-code-editor--dark .token.symbol,
182
+ .nice-simple-code-editor--dark .token.deleted { color: var(--nice-success-light, #b5cea8); }
183
+ .nice-simple-code-editor--dark .token.selector,
184
+ .nice-simple-code-editor--dark .token.attr-name,
185
+ .nice-simple-code-editor--dark .token.string,
186
+ .nice-simple-code-editor--dark .token.char,
187
+ .nice-simple-code-editor--dark .token.builtin,
188
+ .nice-simple-code-editor--dark .token.inserted { color: var(--nice-warning, #ce9178); }
189
+ .nice-simple-code-editor--dark .token.operator,
190
+ .nice-simple-code-editor--dark .token.entity,
191
+ .nice-simple-code-editor--dark .token.url,
192
+ .nice-simple-code-editor--dark .token.variable { color: var(--nice-primary, #569cd6); }
193
+ .nice-simple-code-editor--dark .token.atrule,
194
+ .nice-simple-code-editor--dark .token.attr-value,
195
+ .nice-simple-code-editor--dark .token.keyword { color: #c586c0; font-weight: 600; }
196
+ .nice-simple-code-editor--dark .token.function,
197
+ .nice-simple-code-editor--dark .token.class-name { color: #dcdcaa; }
198
+ .nice-simple-code-editor--dark .token.regex,
199
+ .nice-simple-code-editor--dark .token.important { color: #d7ba7d; }
200
+
201
+ /* Toolbar */
202
+ .nice-code-editor-wrap {
203
+ border: 1px solid var(--nice-border, #e0e0e0);
204
+ border-radius: var(--nice-radius-sm, 4px);
205
+ overflow: hidden;
206
+ }
207
+ .nice-code-editor-wrap .nice-code-editor {
208
+ border: none;
209
+ border-radius: 0;
210
+ }
211
+ .nice-code-editor__toolbar {
212
+ display: flex;
213
+ align-items: center;
214
+ gap: var(--nice-space-0-5, 2px);
215
+ padding: var(--nice-space-0-75, 3px) var(--nice-space-1-5, 6px);
216
+ background: var(--nice-bg-muted, #f5f5f5);
217
+ border-bottom: 1px solid var(--nice-border, #e0e0e0);
218
+ }
219
+ .nice-code-editor__toolbar-btn {
220
+ display: inline-flex;
221
+ align-items: center;
222
+ justify-content: center;
223
+ width: 26px;
224
+ height: 26px;
225
+ border: none;
226
+ border-radius: var(--nice-radius-sm, 3px);
227
+ background: transparent;
228
+ color: var(--nice-text-secondary, #666);
229
+ cursor: pointer;
230
+ font-size: 14px;
231
+ transition: background 0.15s, color 0.15s;
232
+ }
233
+ .nice-code-editor__toolbar-btn:hover {
234
+ background: var(--nice-hover, #e0e0e0);
235
+ color: var(--nice-text-primary, #333);
236
+ }
237
+ .nice-code-editor__toolbar-btn--active {
238
+ background: var(--nice-accent, #1976d2);
239
+ color: var(--nice-bg, #FFF);
240
+ }
241
+ .nice-code-editor__toolbar-sep {
242
+ width: 1px;
243
+ height: 18px;
244
+ background: var(--nice-border, #e0e0e0);
245
+ margin: 0 var(--nice-space-1, 4px);
246
+ }
247
+
248
+ /* Status bar */
249
+ .nice-code-editor__statusbar {
250
+ display: flex;
251
+ align-items: center;
252
+ gap: var(--nice-space-3, 12px);
253
+ padding: var(--nice-space-0-5, 2px) var(--nice-space-2-5, 10px);
254
+ background: var(--nice-bg-muted, #f5f5f5);
255
+ border-top: 1px solid var(--nice-border, #e0e0e0);
256
+ font-size: 12px;
257
+ color: var(--nice-text-secondary, #666);
258
+ user-select: none;
259
+ }
260
+ .nice-code-editor__statusbar-spacer { flex: 1; }
261
+ .nice-code-editor__statusbar-lang {
262
+ text-transform: uppercase;
263
+ font-weight: 600;
264
+ font-size: 11px;
265
+ }
266
+ .nice-code-editor__statusbar-markers {
267
+ color: var(--nice-warning, #f39c12);
268
+ font-weight: 600;
269
+ }
270
+ `,document.head.appendChild(t)}const ji=Object.freeze(Object.defineProperty({__proto__:null,NiceCodeDiffEditor:_n,NiceCodeEditor:st,NiceSimpleCodeEditor:kn},Symbol.toStringTag,{value:"Module"}));i.forwardRef(function(t,n){const{enableAI:a=!0,aiModel:r,enableInlineCompletion:o=!0,completionDelay:p=500,enableExplain:v=!0,enableRefactor:C=!0,enableGenerate:M=!0,systemPrompt:E,onExplain:H,onRefactor:D,showAIToolbar:f=!0,aiShortcutKey:j="Ctrl",language:R="plaintext",value:Q,onChange:q,...Z}=t,y=i.useRef(null),[T,A]=i.useState(null),[k,z]=i.useState(!1),[S,x]=i.useState(""),[m,N]=i.useState(!1),[$,L]=i.useState(""),[u,d]=i.useState(""),[I,w]=i.useState(""),_=i.useRef(),{t:g}=G.ce(),l=G.ge(),{complete:h,explain:c,refactor:s,generateFromComment:F,isLoading:O}=G.tc({language:R,model:r}),Y=a&&l.isConfigured,J=i.useCallback(async()=>{if(!Y||!o||!y.current||!y.current.getEditor())return;const V=y.current.getCursorPosition(),ne=y.current.getValue().split(`
271
+ `),oe=ne.slice(0,V.lineNumber-1),xe=ne[V.lineNumber-1]||"",le=[...oe,xe.slice(0,V.column-1)].join(`
272
+ `),U=[xe.slice(V.column-1),...ne.slice(V.lineNumber)].join(`
273
+ `);try{const K=await h(le,U);K&&A({lineNumber:V.lineNumber,column:V.column,text:K})}catch{}},[Y,o,h]),me=i.useCallback(async()=>{if(!Y||!v||!y.current)return"";const V=y.current.getSelection();if(!V)return"";w(V),z(!0),x("");try{const ne=await c(V);return x(ne),H==null||H(V,ne),ne}catch{return x(g("codeEditorAI.explanationFailed","Failed to explain code")),""}},[Y,v,c,H,g]),de=i.useCallback(async V=>{if(!Y||!C||!y.current)return"";const ne=y.current.getSelection();if(!ne)return"";try{const oe=await s(ne,V);return d(oe),D==null||D(ne,oe),oe}catch{return""}},[Y,C,s,D]),P=i.useCallback(async()=>{var xe;if(!Y||!M||!y.current)return;const V=y.current.getCursorPosition(),ne=y.current.getValue().split(`
274
+ `);let oe="";for(let le=V.lineNumber-1;le>=0&&le>=V.lineNumber-3;le--){const U=((xe=ne[le])==null?void 0:xe.trim())||"";if(U.startsWith("//")||U.startsWith("#")||U.startsWith("/*")||U.startsWith("*")){oe=U.replace(/^\/\/\s*|^#\s*|^\/\*\s*|\*\/\s*$|^\*\s*/g,"").trim();break}}if(oe)try{const le=await F(oe);le&&y.current&&y.current.insertText(`
275
+ `+le)}catch{}},[Y,M,F]),B=i.useCallback(()=>{!T||!y.current||(y.current.insertText(T.text),A(null))},[T]),re=i.useCallback(()=>{A(null)},[]),ue=i.useCallback(V=>{var ne;(ne=t.onCursorPositionChange)==null||ne.call(t,V),!(!Y||!o)&&(_.current&&clearTimeout(_.current),A(null),_.current=setTimeout(()=>{J()},p))},[t.onCursorPositionChange,Y,o,p,J]);i.useEffect(()=>{var ne;if(!((ne=y.current)!=null&&ne.getEditor())||!Y)return;const V=oe=>{var xe;if(j==="Ctrl"&&oe.ctrlKey||j==="Alt"&&oe.altKey||j==="Meta"&&oe.metaKey){if(oe.key===" "&&o&&(oe.preventDefault(),J()),oe.key==="e"&&v&&(oe.preventDefault(),me()),oe.key==="r"&&C){oe.preventDefault();const le=(xe=y.current)==null?void 0:xe.getSelection();le&&(w(le),N(!0))}oe.key==="g"&&M&&(oe.preventDefault(),P())}oe.key==="Tab"&&T&&(oe.preventDefault(),B()),oe.key==="Escape"&&T&&re()};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[Y,j,o,v,C,M,J,me,P,T,B,re]),i.useEffect(()=>()=>{_.current&&clearTimeout(_.current)},[]);const fe=i.useCallback(()=>{if(!u||!y.current)return;const V=y.current.getEditor();if(V!=null&&V.executeEdits&&(V!=null&&V.getSelection)){const ne=V.getSelection();V.executeEdits("ai-refactor",[{range:ne,text:u}])}N(!1),d(""),L("")},[u]);return i.useImperativeHandle(n,()=>({...y.current,getEditor:()=>{var V;return(V=y.current)==null?void 0:V.getEditor()},getMonaco:()=>{var V;return(V=y.current)==null?void 0:V.getMonaco()},focus:()=>{var V;return(V=y.current)==null?void 0:V.focus()},getValue:()=>{var V;return((V=y.current)==null?void 0:V.getValue())||""},setValue:V=>{var ne;return(ne=y.current)==null?void 0:ne.setValue(V)},getSelection:()=>{var V;return((V=y.current)==null?void 0:V.getSelection())||""},insertText:V=>{var ne;return(ne=y.current)==null?void 0:ne.insertText(V)},formatDocument:()=>{var V;return(V=y.current)==null?void 0:V.formatDocument()},goToLine:(V,ne)=>{var oe;return(oe=y.current)==null?void 0:oe.goToLine(V,ne)},findReplace:()=>{var V;return(V=y.current)==null?void 0:V.findReplace()},undo:()=>{var V;return(V=y.current)==null?void 0:V.undo()},redo:()=>{var V;return(V=y.current)==null?void 0:V.redo()},getCursorPosition:()=>{var V;return((V=y.current)==null?void 0:V.getCursorPosition())||{lineNumber:1,column:1}},setMarkers:V=>{var ne;return(ne=y.current)==null?void 0:ne.setMarkers(V)},triggerCompletion:J,explainSelection:me,refactorSelection:de,generateFromComment:P,acceptCompletion:B,dismissCompletion:re})),e.jsxs("div",{className:"nice-code-editor-ai","data-testid":t["data-testid"],children:[f&&Y&&e.jsxs("div",{className:"nice-code-editor-ai__toolbar",children:[e.jsxs("div",{className:"nice-code-editor-ai__toolbar-left",children:[e.jsx("span",{className:"nice-code-editor-ai__toolbar-badge",children:"AI"}),O&&e.jsx("span",{className:"nice-code-editor-ai__loading",children:g("codeEditorAI.loading","Thinking...")})]}),e.jsxs("div",{className:"nice-code-editor-ai__toolbar-right",children:[o&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>J(),disabled:O,title:`${g("codeEditorAI.complete","Complete")} (${j}+Space)`,children:["💡 ",g("codeEditorAI.complete","Complete")]}),v&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>me(),disabled:O,title:`${g("codeEditorAI.explain","Explain")} (${j}+E)`,children:["📖 ",g("codeEditorAI.explain","Explain")]}),C&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>{var ne;const V=(ne=y.current)==null?void 0:ne.getSelection();V&&(w(V),N(!0))},disabled:O,title:`${g("codeEditorAI.refactor","Refactor")} (${j}+R)`,children:["🔧 ",g("codeEditorAI.refactor","Refactor")]}),M&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>P(),disabled:O,title:`${g("codeEditorAI.generate","Generate")} (${j}+G)`,children:["⚡ ",g("codeEditorAI.generate","Generate")]})]})]}),e.jsxs("div",{className:"nice-code-editor-ai__editor-wrapper",children:[e.jsx(st,{ref:y,value:Q,onChange:q,language:R,onCursorPositionChange:ue,...Z}),T&&e.jsxs("div",{className:"nice-code-editor-ai__ghost-text",style:{top:`calc(${(T.lineNumber-1)*19}px + 4px)`,left:`calc(${(T.column-1)*7.8}px + 60px)`},children:[e.jsx("span",{className:"nice-code-editor-ai__ghost-text-content",children:T.text}),e.jsxs("span",{className:"nice-code-editor-ai__ghost-text-hint",children:["Tab ",g("codeEditorAI.toAccept","to accept")]})]})]}),k&&e.jsxs("div",{className:"nice-code-editor-ai__panel nice-code-editor-ai__panel--explain",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("h4",{children:["📖 ",g("codeEditorAI.explanation","Explanation")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>z(!1),children:"✕"})]}),e.jsx("div",{className:"nice-code-editor-ai__panel-body",children:O?e.jsx("div",{className:"nice-code-editor-ai__panel-loading",children:g("codeEditorAI.analyzing","Analyzing code...")}):e.jsxs("div",{className:"nice-code-editor-ai__explanation",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:I}),e.jsx("div",{className:"nice-code-editor-ai__explanation-text",children:S||g("codeEditorAI.noExplanation","Select code and click Explain")})]})})]}),m&&e.jsxs("div",{className:"nice-code-editor-ai__panel nice-code-editor-ai__panel--refactor",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("h4",{children:["🔧 ",g("codeEditorAI.refactorCode","Refactor Code")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>{N(!1),d(""),L("")},children:"✕"})]}),e.jsxs("div",{className:"nice-code-editor-ai__panel-body",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:I}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-input",children:[e.jsx("input",{type:"text",placeholder:g("codeEditorAI.refactorInstruction",'Describe how to refactor (e.g., "extract function", "add error handling")'),value:$,onChange:V=>L(V.target.value),onKeyDown:V=>{V.key==="Enter"&&$&&de($)}}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__refactor-btn",onClick:()=>de($),disabled:O||!$,children:O?g("codeEditorAI.refactoring","Refactoring..."):g("codeEditorAI.refactor","Refactor")})]}),u&&e.jsxs("div",{className:"nice-code-editor-ai__refactor-result",children:[e.jsx("h5",{children:g("codeEditorAI.refactoredCode","Refactored Code")}),e.jsx("pre",{className:"nice-code-editor-ai__code-preview nice-code-editor-ai__code-preview--result",children:u}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-actions",children:[e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-apply",onClick:fe,children:["✓ ",g("codeEditorAI.apply","Apply")]}),e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-discard",onClick:()=>{d(""),L("")},children:["✕ ",g("codeEditorAI.discard","Discard")]})]})]})]})]})]})});function Ci(t){const n=t instanceof Date?t:new Date(t),a=(r,o=2)=>String(r).padStart(o,"0");return`${a(n.getHours())}:${a(n.getMinutes())}:${a(n.getSeconds())}.${a(n.getMilliseconds(),3)}`}function Ni(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}const jn=i.forwardRef(function(t,n){const{entries:a,maxHeight:r=240,autoScroll:o=!0,showTimestamps:p=!0,levelFilter:v,onClear:C,title:M,emptyText:E="No output",clearLabel:H="Clear",fontFamily:D,className:f,style:j,id:R,"data-testid":Q}=t,q=i.useRef(null),Z=i.useMemo(()=>{if(!v||v.length===0)return a;const A=new Set(v);return a.filter(k=>A.has(k.level??"log"))},[a,v]);i.useEffect(()=>{o&&q.current&&(q.current.scrollTop=q.current.scrollHeight)},[Z.length,o]);const y=!!M||!!C,T="nice-log-console"+(f?` ${f}`:"");return e.jsxs("div",{ref:n,id:R,className:T,style:{...D?{fontFamily:D}:null,...j},"data-testid":Q,children:[y&&e.jsxs("div",{className:"nice-log-console__header",children:[e.jsx("span",{className:"nice-log-console__title",children:M}),C&&e.jsx("button",{type:"button",className:"nice-log-console__clear",onClick:C,"aria-label":H,children:H})]}),e.jsx("div",{ref:q,className:"nice-log-console__body",style:{maxHeight:typeof r=="number"?`${r}px`:r},role:"log","aria-live":"polite","aria-relevant":"additions",children:Z.length===0?e.jsx("div",{className:"nice-log-console__empty",children:E}):Z.map((A,k)=>{const z=A.level??"log";return e.jsxs("div",{className:`nice-log-console__entry nice-log-console__entry--${z}`,children:[p&&A.timestamp!=null&&e.jsx("span",{className:"nice-log-console__time",children:Ci(A.timestamp)}),e.jsx("span",{className:"nice-log-console__level",children:z}),A.source&&e.jsx("span",{className:"nice-log-console__source",children:A.source}),e.jsx("span",{className:"nice-log-console__message",children:A.message}),A.data!==void 0&&e.jsx("pre",{className:"nice-log-console__data",children:Ni(A.data)})]},k)})})]})}),Ft="nice-log-console-styles";if(typeof document<"u"&&!document.getElementById(Ft)){const t=document.createElement("style");t.id=Ft,t.textContent=`
276
+ .nice-log-console {
277
+ display: flex;
278
+ flex-direction: column;
279
+ border: 1px solid var(--nice-border, #e0e0e0);
280
+ border-radius: var(--nice-radius-sm, 4px);
281
+ background: var(--nice-surface, #fff);
282
+ color: var(--nice-text-primary, #1f2937);
283
+ overflow: hidden;
284
+ font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
285
+ font-size: 12px;
286
+ line-height: 1.55;
287
+ }
288
+ .nice-log-console__header {
289
+ display: flex;
290
+ align-items: center;
291
+ justify-content: space-between;
292
+ gap: var(--nice-space-2, 8px);
293
+ padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
294
+ border-bottom: 1px solid var(--nice-border, #e0e0e0);
295
+ background: var(--nice-bg-secondary, #f5f5f5);
296
+ }
297
+ .nice-log-console__title {
298
+ font-weight: 600;
299
+ font-size: 12px;
300
+ }
301
+ .nice-log-console__clear {
302
+ border: 1px solid var(--nice-border, #e0e0e0);
303
+ background: var(--nice-surface, #fff);
304
+ color: var(--nice-text-secondary, #6b7280);
305
+ border-radius: var(--nice-radius-sm, 4px);
306
+ padding: 2px 8px;
307
+ font: inherit;
308
+ font-size: 11px;
309
+ cursor: pointer;
310
+ }
311
+ .nice-log-console__clear:hover {
312
+ color: var(--nice-text-primary, #1f2937);
313
+ border-color: var(--nice-text-secondary, #9ca3af);
314
+ }
315
+ .nice-log-console__body {
316
+ flex: 1;
317
+ overflow: auto;
318
+ padding: var(--nice-space-2, 8px);
319
+ }
320
+ .nice-log-console__empty {
321
+ color: var(--nice-text-muted, #9ca3af);
322
+ font-style: italic;
323
+ padding: var(--nice-space-2, 8px) 0;
324
+ }
325
+ .nice-log-console__entry {
326
+ display: flex;
327
+ flex-wrap: wrap;
328
+ align-items: baseline;
329
+ gap: var(--nice-space-2, 8px);
330
+ padding: 1px 0;
331
+ white-space: pre-wrap;
332
+ word-break: break-word;
333
+ }
334
+ .nice-log-console__time {
335
+ color: var(--nice-text-muted, #9ca3af);
336
+ flex: 0 0 auto;
337
+ }
338
+ .nice-log-console__level {
339
+ flex: 0 0 auto;
340
+ text-transform: uppercase;
341
+ font-size: 10px;
342
+ font-weight: 700;
343
+ letter-spacing: 0.04em;
344
+ opacity: 0.8;
345
+ min-width: 38px;
346
+ }
347
+ .nice-log-console__source {
348
+ flex: 0 0 auto;
349
+ color: var(--nice-primary, #2563eb);
350
+ }
351
+ .nice-log-console__message {
352
+ flex: 1 1 auto;
353
+ }
354
+ .nice-log-console__data {
355
+ flex: 1 0 100%;
356
+ margin: 2px 0 4px;
357
+ padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
358
+ background: var(--nice-bg-secondary, #f5f5f5);
359
+ border-radius: var(--nice-radius-sm, 4px);
360
+ overflow: auto;
361
+ font: inherit;
362
+ }
363
+ .nice-log-console__entry--info .nice-log-console__level { color: var(--nice-primary, #2563eb); }
364
+ .nice-log-console__entry--warn { color: var(--nice-warning-text, #92400e); }
365
+ .nice-log-console__entry--warn .nice-log-console__level { color: var(--nice-warning, #d97706); }
366
+ .nice-log-console__entry--error { color: var(--nice-danger, #dc2626); }
367
+ .nice-log-console__entry--error .nice-log-console__level { color: var(--nice-danger, #dc2626); }
368
+ .nice-log-console__entry--debug { color: var(--nice-text-muted, #9ca3af); }
369
+ .nice-log-console__entry--trace { color: var(--nice-text-disabled, #b8bfc9); }
370
+ .nice-log-console__entry--trace .nice-log-console__level { color: var(--nice-text-disabled, #b8bfc9); }
371
+ `,document.head.appendChild(t)}const wi=[{target:".nice-script-runner",titleKey:"tutorial.scriptRunner.intro.title",title:"Script runner",contentKey:"tutorial.scriptRunner.intro.content",content:"Write a script and sample input, click Run, then inspect the result and captured logs below.",placement:"auto"}];function Ut(t){if(t===void 0)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function qt(t){const n=t.trim();if(n==="")return{value:void 0,error:null};try{return{value:JSON.parse(n),error:null}}catch(a){return{value:t,error:a instanceof Error?a.message:"Invalid JSON"}}}function $i(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}i.forwardRef(function(t,n){const{value:a,onChange:r,language:o="javascript",onRun:p,input:v,onInputChange:C,showInputPanel:M,extraLibs:E,height:H=260,running:D,autoRun:f=!1,autoRunDelay:j=600,layout:R="vertical",runLabel:Q="Run",theme:q="auto",tutorial:Z,className:y,style:T,id:A,"data-testid":k}=t,z=M??v!==void 0,[S,x]=i.useState(()=>Ut(v)),[m,N]=i.useState(null),[$,L]=i.useState(!1),[u,d]=i.useState(null),I=D??$,w=q==="light"?"vs":q==="dark"?"vs-dark":q;i.useEffect(()=>{x(Ut(v))},[v]);const _=i.useCallback(async()=>{const s=qt(S),F=typeof performance<"u"?performance.now():Date.now();D===void 0&&L(!0);try{const O=await p(a,s.value),Y=O.durationMs??Math.round((typeof performance<"u"?performance.now():Date.now())-F);d({...O,durationMs:Y})}catch(O){d({ok:!1,error:O instanceof Error?O.message:String(O),durationMs:Math.round((typeof performance<"u"?performance.now():Date.now())-F)})}finally{D===void 0&&L(!1)}},[S,p,a,D]),g=i.useRef(_);g.current=_,i.useEffect(()=>{if(!f)return;const s=setTimeout(()=>{g.current()},j);return()=>clearTimeout(s)},[f,j,a,S]);const l=i.useCallback(s=>{x(s);const F=qt(s);N(F.error),C==null||C(F.value)},[C]),h=typeof H=="number"?`${H}px`:H,c=`nice-script-runner nice-script-runner--${R}`+(y?` ${y}`:"");return e.jsxs("div",{ref:n,id:A,className:c,style:T,"data-testid":k,children:[e.jsxs("div",{className:"nice-script-runner__toolbar",children:[e.jsxs("button",{type:"button",className:"nice-script-runner__run",onClick:()=>void _(),disabled:I,children:[I?"…":"▶"," ",Q]}),(u==null?void 0:u.durationMs)!=null&&e.jsxs("span",{className:"nice-script-runner__status",children:[e.jsx("span",{className:"nice-script-runner__badge nice-script-runner__badge--"+(u.ok?"ok":"error"),children:u.ok?"OK":"Failed"}),e.jsxs("span",{className:"nice-script-runner__duration",children:[u.durationMs," ms"]})]}),Z&&e.jsx("span",{style:{marginLeft:"auto"},children:e.jsx(G.Ud,{steps:G.Kd(Z,wi)})})]}),e.jsxs("div",{className:"nice-script-runner__panes",children:[e.jsxs("div",{className:"nice-script-runner__editors",children:[e.jsx(st,{value:a,onChange:r,language:o,theme:w,height:h,extraLibs:E,options:{minimap:!1}}),z&&e.jsxs("div",{className:"nice-script-runner__input",children:[e.jsxs("div",{className:"nice-script-runner__pane-label",children:["Input (JSON)",m&&e.jsxs("span",{className:"nice-script-runner__input-error",children:[" — ",m]})]}),e.jsx(st,{value:S,onChange:l,language:"json",theme:w,height:120,options:{minimap:!1,lineNumbers:"off"}})]})]}),e.jsxs("div",{className:"nice-script-runner__output",children:[(u==null?void 0:u.error)&&e.jsx("div",{className:"nice-script-runner__error",children:u.error}),u&&u.result!==void 0&&e.jsxs("div",{className:"nice-script-runner__result",children:[e.jsx("div",{className:"nice-script-runner__pane-label",children:"Result"}),e.jsx("pre",{className:"nice-script-runner__result-body",children:$i(u.result)})]}),e.jsx(jn,{title:"Logs",entries:(u==null?void 0:u.logs)??[],maxHeight:160,emptyText:"Run the script to see logs"})]})]})]})});const Xt="nice-script-runner-styles";if(typeof document<"u"&&!document.getElementById(Xt)){const t=document.createElement("style");t.id=Xt,t.textContent=`
372
+ .nice-script-runner {
373
+ display: flex;
374
+ flex-direction: column;
375
+ gap: var(--nice-space-2, 8px);
376
+ border: 1px solid var(--nice-border, #e0e0e0);
377
+ border-radius: var(--nice-radius-md, 6px);
378
+ padding: var(--nice-space-2, 8px);
379
+ background: var(--nice-surface, #fff);
380
+ }
381
+ .nice-script-runner__toolbar {
382
+ display: flex;
383
+ align-items: center;
384
+ gap: var(--nice-space-2, 8px);
385
+ }
386
+ .nice-script-runner__run {
387
+ border: 0;
388
+ background: var(--nice-primary, #2563eb);
389
+ color: var(--nice-text-inverse, #fff);
390
+ border-radius: var(--nice-radius-sm, 4px);
391
+ padding: 6px 14px;
392
+ font: inherit;
393
+ font-weight: 600;
394
+ cursor: pointer;
395
+ }
396
+ .nice-script-runner__run:disabled {
397
+ opacity: 0.6;
398
+ cursor: default;
399
+ }
400
+ .nice-script-runner__status {
401
+ display: inline-flex;
402
+ align-items: center;
403
+ gap: var(--nice-space-2, 8px);
404
+ font-size: 12px;
405
+ }
406
+ .nice-script-runner__badge {
407
+ padding: 1px 8px;
408
+ border-radius: 999px;
409
+ font-size: 11px;
410
+ font-weight: 700;
411
+ }
412
+ .nice-script-runner__badge--ok {
413
+ background: var(--nice-success-bg, #dcfce7);
414
+ color: var(--nice-success-text, #166534);
415
+ }
416
+ .nice-script-runner__badge--error {
417
+ background: var(--nice-danger-bg, #fee2e2);
418
+ color: var(--nice-danger-text, #991b1b);
419
+ }
420
+ .nice-script-runner__duration {
421
+ color: var(--nice-text-muted, #9ca3af);
422
+ }
423
+ .nice-script-runner__panes {
424
+ display: grid;
425
+ gap: var(--nice-space-2, 8px);
426
+ }
427
+ .nice-script-runner--horizontal .nice-script-runner__panes {
428
+ grid-template-columns: 1fr 1fr;
429
+ }
430
+ .nice-script-runner__editors,
431
+ .nice-script-runner__output {
432
+ display: flex;
433
+ flex-direction: column;
434
+ gap: var(--nice-space-2, 8px);
435
+ min-width: 0;
436
+ }
437
+ .nice-script-runner__pane-label {
438
+ font-size: 11px;
439
+ font-weight: 600;
440
+ text-transform: uppercase;
441
+ letter-spacing: 0.04em;
442
+ color: var(--nice-text-secondary, #6b7280);
443
+ }
444
+ .nice-script-runner__input-error {
445
+ color: var(--nice-danger, #dc2626);
446
+ text-transform: none;
447
+ font-weight: 400;
448
+ }
449
+ .nice-script-runner__error {
450
+ padding: var(--nice-space-2, 8px);
451
+ border-radius: var(--nice-radius-sm, 4px);
452
+ background: var(--nice-danger-bg, #fee2e2);
453
+ color: var(--nice-danger-text, #991b1b);
454
+ font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
455
+ font-size: 12px;
456
+ white-space: pre-wrap;
457
+ }
458
+ .nice-script-runner__result-body {
459
+ margin: 4px 0 0;
460
+ padding: var(--nice-space-2, 8px);
461
+ border: 1px solid var(--nice-border, #e0e0e0);
462
+ border-radius: var(--nice-radius-sm, 4px);
463
+ background: var(--nice-bg-secondary, #f9fafb);
464
+ max-height: 200px;
465
+ overflow: auto;
466
+ font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
467
+ font-size: 12px;
468
+ }
469
+ `,document.head.appendChild(t)}const Mi=[{target:".nice-key-value-editor",titleKey:"tutorial.keyValueEditor.intro.title",title:"Key/value editor",contentKey:"tutorial.keyValueEditor.intro.content",content:"Add key/value rows for headers, params, env vars or config; mask secret values, toggle rows on/off, and watch for duplicate keys.",placement:"auto"}];i.forwardRef(function(t,n){const{value:a,onChange:r,allowSecret:o=!1,allowToggle:p=!1,allowDescription:v=!1,keySuggestions:C,keyPlaceholder:M="Key",valuePlaceholder:E="Value",addLabel:H="Add",readOnly:D=!1,duplicateKeyWarning:f=!0,tutorial:j,className:R,style:Q,id:q,"data-testid":Z}=t,y=i.useMemo(()=>`nice-kv-keys-${Math.random().toString(36).slice(2,9)}`,[]),T=i.useMemo(()=>{const x=new Map,m=new Set;if(f){for(const N of a){const $=N.key.trim();$!==""&&x.set($,(x.get($)??0)+1)}x.forEach((N,$)=>{N>1&&m.add($)})}return m},[a,f]),A=(x,m)=>{r(a.map((N,$)=>$===x?{...N,...m}:N))},k=x=>{r(a.filter((m,N)=>N!==x))},z=()=>{r([...a,{key:"",value:"",type:"text",enabled:!0}])},S="nice-key-value-editor"+(R?` ${R}`:"");return e.jsxs("div",{ref:n,id:q,className:S,style:{position:"relative",...Q},"data-testid":Z,children:[e.jsx("span",{style:{position:"absolute",top:0,right:0,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(j,Mi)})}),C&&C.length>0&&e.jsx("datalist",{id:y,children:C.map(x=>e.jsx("option",{value:x},x))}),e.jsx("div",{className:"nice-key-value-editor__rows",children:a.map((x,m)=>{const N=x.type==="secret",$=x.key.trim()!==""&&T.has(x.key.trim()),L=p&&x.enabled===!1;return e.jsxs("div",{className:"nice-key-value-editor__row"+(L?" nice-key-value-editor__row--disabled":""),children:[p&&e.jsx("input",{type:"checkbox",className:"nice-key-value-editor__toggle",checked:x.enabled!==!1,onChange:u=>A(m,{enabled:u.target.checked}),disabled:D,"aria-label":"Enabled"}),e.jsx("input",{type:"text",className:"nice-key-value-editor__key"+($?" nice-key-value-editor__key--dup":""),value:x.key,list:C?y:void 0,placeholder:M,onChange:u=>A(m,{key:u.target.value}),readOnly:D,"aria-label":M,title:$?"Duplicate key":void 0}),e.jsx("input",{type:N?"password":"text",className:"nice-key-value-editor__value",value:x.value,placeholder:E,onChange:u=>A(m,{value:u.target.value}),readOnly:D,autoComplete:N?"new-password":"off","aria-label":E}),o&&e.jsx("button",{type:"button",className:"nice-key-value-editor__secret"+(N?" nice-key-value-editor__secret--on":""),onClick:()=>A(m,{type:N?"text":"secret"}),disabled:D,title:N?"Secret (click to reveal as text)":"Mark as secret","aria-pressed":N,"aria-label":"Toggle secret",children:N?"🔒":"🔓"}),v&&e.jsx("input",{type:"text",className:"nice-key-value-editor__desc",value:x.description??"",placeholder:"Description",onChange:u=>A(m,{description:u.target.value}),readOnly:D,"aria-label":"Description"}),!D&&e.jsx("button",{type:"button",className:"nice-key-value-editor__remove",onClick:()=>k(m),title:"Remove row","aria-label":"Remove row",children:"✕"})]},x.id??m)})}),!D&&e.jsxs("button",{type:"button",className:"nice-key-value-editor__add",onClick:z,children:["+ ",H]})]})});const Kt="nice-key-value-editor-styles";if(typeof document<"u"&&!document.getElementById(Kt)){const t=document.createElement("style");t.id=Kt,t.textContent=`
470
+ .nice-key-value-editor {
471
+ display: flex;
472
+ flex-direction: column;
473
+ gap: var(--nice-space-2, 8px);
474
+ }
475
+ .nice-key-value-editor__rows {
476
+ display: flex;
477
+ flex-direction: column;
478
+ gap: var(--nice-space-1, 4px);
479
+ }
480
+ .nice-key-value-editor__row {
481
+ display: flex;
482
+ align-items: center;
483
+ gap: var(--nice-space-1, 4px);
484
+ }
485
+ .nice-key-value-editor__row--disabled {
486
+ opacity: 0.55;
487
+ }
488
+ .nice-key-value-editor__key,
489
+ .nice-key-value-editor__value,
490
+ .nice-key-value-editor__desc {
491
+ flex: 1 1 0;
492
+ min-width: 0;
493
+ padding: 6px 8px;
494
+ border: 1px solid var(--nice-border, #d1d5db);
495
+ border-radius: var(--nice-radius-sm, 4px);
496
+ background: var(--nice-bg, #fff);
497
+ color: var(--nice-text-primary, #1f2937);
498
+ font: inherit;
499
+ font-size: 13px;
500
+ }
501
+ .nice-key-value-editor__key {
502
+ flex-basis: 30%;
503
+ font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
504
+ }
505
+ .nice-key-value-editor__key--dup {
506
+ border-color: var(--nice-danger, #dc2626);
507
+ background: var(--nice-danger-bg, #fee2e2);
508
+ }
509
+ .nice-key-value-editor__key:focus,
510
+ .nice-key-value-editor__value:focus,
511
+ .nice-key-value-editor__desc:focus {
512
+ outline: none;
513
+ border-color: var(--nice-primary, #2563eb);
514
+ }
515
+ .nice-key-value-editor__toggle {
516
+ flex: 0 0 auto;
517
+ }
518
+ .nice-key-value-editor__secret,
519
+ .nice-key-value-editor__remove {
520
+ flex: 0 0 auto;
521
+ border: 1px solid var(--nice-border, #d1d5db);
522
+ background: var(--nice-surface, #fff);
523
+ border-radius: var(--nice-radius-sm, 4px);
524
+ padding: 5px 8px;
525
+ font-size: 13px;
526
+ line-height: 1;
527
+ cursor: pointer;
528
+ }
529
+ .nice-key-value-editor__secret--on {
530
+ border-color: var(--nice-warning, #d97706);
531
+ background: var(--nice-warning-bg, #fef3c7);
532
+ }
533
+ .nice-key-value-editor__remove:hover {
534
+ border-color: var(--nice-danger, #dc2626);
535
+ color: var(--nice-danger, #dc2626);
536
+ }
537
+ .nice-key-value-editor__add {
538
+ align-self: flex-start;
539
+ border: 1px dashed var(--nice-border, #d1d5db);
540
+ background: transparent;
541
+ color: var(--nice-primary, #2563eb);
542
+ border-radius: var(--nice-radius-sm, 4px);
543
+ padding: 5px 12px;
544
+ font: inherit;
545
+ font-size: 13px;
546
+ font-weight: 600;
547
+ cursor: pointer;
548
+ }
549
+ .nice-key-value-editor__add:hover {
550
+ background: var(--nice-bg-secondary, #f5f5f5);
551
+ }
552
+ `,document.head.appendChild(t)}function Zt(t,n){const a=n.getBoundingClientRect();let r,o,p;if("touches"in t){const v=t.touches[0];r=v.clientX-a.left,o=v.clientY-a.top,p=v.force}else"pressure"in t?(r=t.clientX-a.left,o=t.clientY-a.top,p=t.pressure):(r=t.clientX-a.left,o=t.clientY-a.top);return{x:r,y:o,time:Date.now(),pressure:p!==void 0?p:.5}}function Vt(t,n,a,r,o){if(!n)return(a+r)/2;const p=Math.sqrt(Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2))/Math.max(1,t.time-n.time),v=Math.min(p/5,1),C=r-v*(r-a),M=t.pressure??.5,E=a+M*(r-a);return C*.7+E*.3}function Yt(t,n,a,r){t.beginPath(),t.moveTo(n.x,n.y),t.lineTo(a.x,a.y),t.lineWidth=r,t.lineCap="round",t.lineJoin="round",t.stroke()}i.forwardRef(function(t,n){const{value:a,onChange:r,width:o="100%",height:p=200,penColor:v="var(--text-primary, #000000)",penWidth:C=2,minWidth:M=.5,maxWidth:E=4,backgroundColor:H="var(--bg-primary, #ffffff)",placeholder:D="Sign here",showClearButton:f=!0,showUndoButton:j=!0,showColorPicker:R=!1,showSizeSlider:Q=!1,velocityFilterWeight:q=.7,throttle:Z=16,disabled:y=!1,readOnly:T=!1,displayMode:A=!1,onBegin:k,onEnd:z,className:S,"data-testid":x}=t,m=T||A,N=A?!1:f,$=A?!1:j,L=A?!1:R,u=A?!1:Q,d=i.useRef(null),[I,w]=i.useState((a==null?void 0:a.strokes)??[]),[_,g]=i.useState([]),[l,h]=i.useState(!1),[c,s]=i.useState(v),[F,O]=i.useState(C),Y=i.useRef(null),J=i.useRef(0),me=I.length===0&&_.length===0;i.useEffect(()=>{const le=d.current;if(!le)return;const U=le.getContext("2d");if(!U)return;const K=le.getBoundingClientRect(),W=window.devicePixelRatio||1;le.width=K.width*W,le.height=K.height*W,U.scale(W,W),de()},[o,p]);const de=i.useCallback(()=>{const le=d.current;if(!le)return;const U=le.getContext("2d");if(!U)return;const K=le.getBoundingClientRect();U.fillStyle=H,U.fillRect(0,0,K.width,K.height),I.forEach(W=>{if(U.strokeStyle=W.color,!(W.points.length<2))for(let se=1;se<W.points.length;se++){const be=W.points[se-1],ie=W.points[se],ce=Vt(ie,be,M,E);Yt(U,be,ie,ce)}})},[I,H,M,E,q]);i.useEffect(()=>{de()},[de]),i.useEffect(()=>{a!=null&&a.strokes&&w(a.strokes)},[a]),i.useEffect(()=>{const le=d.current;if(le)if(I.length===0)r==null||r(null);else{const U=le.getBoundingClientRect();r==null||r({strokes:I,width:U.width,height:U.height,timestamp:Date.now()})}},[I,r]);const P=i.useCallback(le=>{if(y||m)return;const U=d.current;if(!U)return;U.setPointerCapture(le.pointerId);const K=Zt(le.nativeEvent,U);h(!0),g([K]),Y.current=K,J.current=K.time,k==null||k()},[y,m,k]),B=i.useCallback(le=>{if(!l||y||m)return;const U=d.current;if(!U)return;const K=U.getContext("2d");if(!K)return;const W=Date.now();if(W-J.current<Z)return;const se=Zt(le.nativeEvent,U),be=Y.current;if(be){K.strokeStyle=c;const ie=Vt(se,be,M,E);Yt(K,be,se,ie)}g(ie=>[...ie,se]),Y.current=se,J.current=W},[l,y,m,c,M,E,q,Z]),re=i.useCallback(le=>{if(!l)return;const U=d.current;if(U&&U.releasePointerCapture(le.pointerId),_.length>0){const K={points:_,color:c,width:F};w(W=>[...W,K])}h(!1),g([]),Y.current=null,z==null||z()},[l,_,c,F,z]),ue=i.useCallback(()=>{w([]),g([]),de()},[de]),fe=i.useCallback(()=>{w(le=>le.slice(0,-1))},[]),V=i.useCallback((le="png",U=.92)=>{const K=d.current;if(!K)return"";const W=le==="jpeg"?"image/jpeg":"image/png";return K.toDataURL(W,U)},[]),ne=i.useCallback(async(le="png",U=.92)=>{const K=d.current;return K?new Promise(W=>{const se=le==="jpeg"?"image/jpeg":"image/png";K.toBlob(be=>W(be),se,U)}):null},[]),oe=i.useCallback(()=>{const le=d.current;if(!le)return"";const U=le.getBoundingClientRect(),K=I.map(W=>W.points.length<2?"":`<path d="${W.points.reduce((se,be,ie)=>ie===0?`M ${be.x} ${be.y}`:`${se} L ${be.x} ${be.y}`,"")}" stroke="${W.color}" stroke-width="${W.width}" fill="none" stroke-linecap="round" stroke-linejoin="round"/>`).join(`
553
+ `);return`<svg xmlns="http://www.w3.org/2000/svg" width="${U.width}" height="${U.height}" viewBox="0 0 ${le.width} ${le.height}">
554
+ <rect width="100%" height="100%" fill="${H}"/>
555
+ ${K}
556
+ </svg>`},[I,H]);i.useImperativeHandle(n,()=>({clear:ue,undo:fe,isEmpty:()=>I.length===0,getData:()=>{const le=d.current;if(!le||I.length===0)return null;const U=le.getBoundingClientRect();return{strokes:I,width:U.width,height:U.height,timestamp:Date.now()}},setData:le=>{w(le.strokes)},toDataURL:V,toBlob:ne,toSVG:oe,getCanvas:()=>d.current}),[I,ue,fe,V,ne,oe]),i.useEffect(()=>{const le=d.current;if(!le)return;const U=K=>{l&&K.preventDefault()};return le.addEventListener("touchmove",U,{passive:!1}),()=>le.removeEventListener("touchmove",U)},[l]);const xe=N||$||L||u;return e.jsxs("div",{className:`nice-signature ${y?"nice-signature--disabled":""} ${m?"nice-signature--readonly":""} ${S??""}`,style:{width:o},"data-testid":x,children:[xe&&e.jsxs("div",{className:"nice-signature__toolbar",children:[L&&e.jsx("div",{className:"nice-signature__color-picker",children:e.jsx("input",{type:"color",value:c,onChange:le=>s(le.target.value),disabled:y||m,title:"Pen color"})}),u&&e.jsx("div",{className:"nice-signature__size-slider",children:e.jsx("input",{type:"range",min:M,max:E,step:.5,value:F,onChange:le=>O(parseFloat(le.target.value)),disabled:y||m,title:"Pen size"})}),e.jsxs("div",{className:"nice-signature__actions",children:[$&&e.jsx("button",{type:"button",onClick:fe,disabled:y||m||I.length===0,className:"nice-signature__btn",title:"Undo",children:"↩️"}),N&&e.jsx("button",{type:"button",onClick:ue,disabled:y||m||me,className:"nice-signature__btn",title:"Clear",children:"🗑️"})]})]}),e.jsxs("div",{className:"nice-signature__canvas-wrapper",style:{height:p},children:[e.jsx("canvas",{ref:d,className:"nice-signature__canvas",style:{width:"100%",height:"100%",cursor:y||m?"not-allowed":"crosshair",touchAction:"none"},onPointerDown:P,onPointerMove:B,onPointerUp:re,onPointerLeave:re}),me&&!l&&D&&e.jsx("div",{className:"nice-signature__placeholder",children:D}),e.jsx("div",{className:"nice-signature__line"})]})]})});const Gt="nice-signature-styles";if(typeof document<"u"&&!document.getElementById(Gt)){const t=document.createElement("style");t.id=Gt,t.textContent=`
557
+ .nice-signature {
558
+ display: flex;
559
+ flex-direction: column;
560
+ border: 1px solid var(--nice-border, #e0e0e0);
561
+ border-radius: var(--nice-radius-sm, 4px);
562
+ overflow: hidden;
563
+ background: var(--nice-bg-surface, #fff);
564
+ }
565
+
566
+ .nice-signature--disabled {
567
+ opacity: 0.6;
568
+ }
569
+
570
+ .nice-signature__toolbar {
571
+ display: flex;
572
+ align-items: center;
573
+ gap: var(--nice-space-2, 8px);
574
+ padding: var(--nice-space-2, 8px);
575
+ background: var(--nice-bg-muted, #f5f5f5);
576
+ border-bottom: 1px solid var(--nice-border, #e0e0e0);
577
+ }
578
+
579
+ .nice-signature__color-picker input {
580
+ width: 32px;
581
+ height: 32px;
582
+ padding: var(--nice-space-0-5, 2px);
583
+ border: 1px solid var(--nice-border, #e0e0e0);
584
+ border-radius: var(--nice-radius-sm, 4px);
585
+ cursor: pointer;
586
+ }
587
+
588
+ .nice-signature__size-slider {
589
+ flex: 1;
590
+ max-width: 120px;
591
+ }
592
+
593
+ .nice-signature__size-slider input {
594
+ width: 100%;
595
+ }
596
+
597
+ .nice-signature__actions {
598
+ display: flex;
599
+ gap: var(--nice-space-1, 4px);
600
+ margin-left: auto;
601
+ }
602
+
603
+ .nice-signature__btn {
604
+ padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
605
+ border: 1px solid var(--nice-border, #e0e0e0);
606
+ border-radius: var(--nice-radius-sm, 4px);
607
+ background: var(--nice-bg-surface, #fff);
608
+ cursor: pointer;
609
+ font-size: 14px;
610
+ }
611
+
612
+ .nice-signature__btn:hover:not(:disabled) {
613
+ background: var(--nice-bg-hover, #f0f0f0);
614
+ }
615
+
616
+ .nice-signature__btn:disabled {
617
+ opacity: 0.4;
618
+ cursor: not-allowed;
619
+ }
620
+
621
+ .nice-signature__canvas-wrapper {
622
+ position: relative;
623
+ background: var(--nice-bg, #FFF);
624
+ }
625
+
626
+ .nice-signature__canvas {
627
+ display: block;
628
+ }
629
+
630
+ .nice-signature__placeholder {
631
+ position: absolute;
632
+ top: 50%;
633
+ left: 50%;
634
+ transform: translate(-50%, -50%);
635
+ color: var(--nice-text-secondary, #999);
636
+ font-size: 14px;
637
+ pointer-events: none;
638
+ user-select: none;
639
+ }
640
+
641
+ .nice-signature__line {
642
+ position: absolute;
643
+ bottom: 30px;
644
+ left: 20px;
645
+ right: 20px;
646
+ height: 1px;
647
+ background: var(--nice-border, #ccc);
648
+ pointer-events: none;
649
+ }
650
+
651
+ /* Display component */
652
+ .nice-signature-display {
653
+ border: 1px solid var(--nice-border, #e0e0e0);
654
+ border-radius: var(--nice-radius-sm, 4px);
655
+ overflow: hidden;
656
+ }
657
+
658
+ .nice-signature-display__canvas-wrapper {
659
+ position: relative;
660
+ background: var(--nice-bg, #FFF);
661
+ }
662
+
663
+ .nice-signature-display__canvas {
664
+ display: block;
665
+ }
666
+
667
+ .nice-signature-display__placeholder {
668
+ position: absolute;
669
+ top: 50%;
670
+ left: 50%;
671
+ transform: translate(-50%, -50%);
672
+ color: var(--nice-text-secondary, #999);
673
+ font-size: 14px;
674
+ }
675
+ `,document.head.appendChild(t)}const Si={strokeColor:"#ff3333",fillColor:"transparent",strokeWidth:2,opacity:1,fontSize:16,fontFamily:"sans-serif"};function Ei(t,n){switch(n.type){case"SET_TOOL":return{...t,activeTool:n.tool,selectedId:null};case"SET_STYLE":return{...t,style:{...t.style,...n.style}};case"ADD_ANNOTATION":return{...t,annotations:[...t.annotations,n.annotation],past:[...t.past,t.annotations],future:[]};case"UPDATE_ANNOTATION":return{...t,annotations:t.annotations.map(a=>a.id===n.id?{...a,...n.updates}:a),past:[...t.past,t.annotations],future:[]};case"DELETE_ANNOTATION":return{...t,annotations:t.annotations.filter(a=>a.id!==n.id),selectedId:t.selectedId===n.id?null:t.selectedId,past:[...t.past,t.annotations],future:[]};case"SELECT":return{...t,selectedId:n.id};case"SET_ANNOTATIONS":return{...t,annotations:n.annotations,past:[],future:[]};case"SET_ZOOM":return{...t,zoom:n.zoom};case"SET_PAN":return{...t,panX:n.panX,panY:n.panY};case"UNDO":{if(t.past.length===0)return t;const a=t.past[t.past.length-1];return{...t,annotations:a,past:t.past.slice(0,-1),future:[t.annotations,...t.future]}}case"REDO":{if(t.future.length===0)return t;const a=t.future[0];return{...t,annotations:a,past:[...t.past,t.annotations],future:t.future.slice(1)}}case"CLEAR":return{...t,annotations:[],selectedId:null,past:[...t.past,t.annotations],future:[]};default:return t}}let Di=0;function Ti(){return`ann-${Date.now()}-${Di++}`}function zi(t){const{style:n}=t,a=`stroke="${n.strokeColor}" stroke-width="${n.strokeWidth}" fill="${n.fillColor}" opacity="${n.opacity}"`;switch(t.tool){case"rectangle":return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" ${a} />`;case"ellipse":{const r=t.x+t.width/2,o=t.y+t.height/2;return`<ellipse cx="${r}" cy="${o}" rx="${t.width/2}" ry="${t.height/2}" ${a} />`}case"arrow":{const r=t,o=Math.atan2(r.endY-r.y,r.endX-r.x),p=12,v=r.endX-p*Math.cos(o-Math.PI/6),C=r.endY-p*Math.sin(o-Math.PI/6),M=r.endX-p*Math.cos(o+Math.PI/6),E=r.endY-p*Math.sin(o+Math.PI/6);return`<line x1="${r.x}" y1="${r.y}" x2="${r.endX}" y2="${r.endY}" ${a} />
676
+ <polygon points="${r.endX},${r.endY} ${v},${C} ${M},${E}" fill="${n.strokeColor}" opacity="${n.opacity}" />`}case"line":{const r=t;return`<line x1="${r.x}" y1="${r.y}" x2="${r.endX}" y2="${r.endY}" ${a} />`}case"text":{const r=t;return`<text x="${r.x}" y="${r.y+(r.style.fontSize??16)}" fill="${n.strokeColor}" font-size="${n.fontSize}" font-family="${n.fontFamily}" opacity="${n.opacity}">${Ri(r.text)}</text>`}case"freehand":{const r=t;return r.points.length<2?"":`<path d="${r.points.map((o,p)=>`${p===0?"M":"L"}${o.x},${o.y}`).join(" ")}" ${a} fill="none" />`}case"blur":{const r=t,o=`blur-${r.id}`;return`<defs><filter id="${o}"><feGaussianBlur stdDeviation="${r.intensity??5}" /></filter></defs>
677
+ <rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" fill="transparent" stroke="none" filter="url(#${o})" />`}default:return""}}function Ri(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}const Cn=i.forwardRef(({src:t,alt:n="Annotatable image",annotations:a,activeTool:r,defaultStyle:o,onAnnotationsChange:p,className:v,readOnly:C=!1,minZoom:M=.1,maxZoom:E=5},H)=>{const D=i.useRef(null),f=i.useRef(null),j=i.useRef(null),[R,Q]=i.useState(!1),[q,Z]=i.useState({width:0,height:0}),[y,T]=i.useReducer(Ei,{annotations:a??[],selectedId:null,activeTool:r??"select",style:{...Si,...o},zoom:1,panX:0,panY:0,past:[],future:[]});i.useEffect(()=>{r&&T({type:"SET_TOOL",tool:r})},[r]),i.useEffect(()=>{p==null||p(y.annotations)},[y.annotations,p]),i.useEffect(()=>{const u=new Image;u.crossOrigin="anonymous",u.onload=()=>{j.current=u,Z({width:u.naturalWidth,height:u.naturalHeight}),Q(!0)},u.src=t},[t]);const A=i.useRef({isDrawing:!1,startX:0,startY:0,currentAnnotation:null,freehandPoints:[]}),k=i.useCallback((u,d)=>{const I=D.current;if(!I)return{x:0,y:0};const w=I.getBoundingClientRect();return{x:(u-w.left-y.panX)/y.zoom,y:(d-w.top-y.panY)/y.zoom}},[y.zoom,y.panX,y.panY]),z=i.useCallback(()=>{var _,g;const u=D.current,d=u==null?void 0:u.getContext("2d"),I=j.current;if(!u||!d||!I||!R)return;u.width=((_=f.current)==null?void 0:_.clientWidth)??I.naturalWidth,u.height=((g=f.current)==null?void 0:g.clientHeight)??I.naturalHeight,d.clearRect(0,0,u.width,u.height),d.save(),d.translate(y.panX,y.panY),d.scale(y.zoom,y.zoom),d.drawImage(I,0,0);for(const l of y.annotations){switch(d.save(),d.globalAlpha=l.style.opacity,d.strokeStyle=l.style.strokeColor,d.fillStyle=l.style.fillColor,d.lineWidth=l.style.strokeWidth,l.tool){case"rectangle":d.strokeRect(l.x,l.y,l.width,l.height),l.style.fillColor!=="transparent"&&d.fillRect(l.x,l.y,l.width,l.height);break;case"ellipse":{d.beginPath(),d.ellipse(l.x+l.width/2,l.y+l.height/2,Math.abs(l.width/2),Math.abs(l.height/2),0,0,Math.PI*2),d.stroke(),l.style.fillColor!=="transparent"&&d.fill();break}case"arrow":{const h=l;d.beginPath(),d.moveTo(h.x,h.y),d.lineTo(h.endX,h.endY),d.stroke();const c=Math.atan2(h.endY-h.y,h.endX-h.x),s=12;d.beginPath(),d.moveTo(h.endX,h.endY),d.lineTo(h.endX-s*Math.cos(c-Math.PI/6),h.endY-s*Math.sin(c-Math.PI/6)),d.lineTo(h.endX-s*Math.cos(c+Math.PI/6),h.endY-s*Math.sin(c+Math.PI/6)),d.closePath(),d.fillStyle=l.style.strokeColor,d.fill();break}case"line":{const h=l;d.beginPath(),d.moveTo(h.x,h.y),d.lineTo(h.endX,h.endY),d.stroke();break}case"text":{const h=l;d.font=`${h.style.fontSize??16}px ${h.style.fontFamily??"sans-serif"}`,d.fillStyle=h.style.strokeColor,d.fillText(h.text,h.x,h.y+(h.style.fontSize??16));break}case"freehand":{const h=l;if(h.points.length<2)break;d.beginPath(),d.moveTo(h.points[0].x,h.points[0].y);for(let c=1;c<h.points.length;c++)d.lineTo(h.points[c].x,h.points[c].y);d.stroke();break}case"blur":{const h=l;d.filter=`blur(${h.intensity??5}px)`,d.drawImage(I,h.x,h.y,h.width,h.height,h.x,h.y,h.width,h.height),d.filter="none";break}}l.id===y.selectedId&&(d.strokeStyle="#4488ff",d.lineWidth=1,d.setLineDash([4,4]),d.strokeRect(l.x-2,l.y-2,l.width+4,l.height+4),d.setLineDash([])),d.restore()}const w=A.current;if(w.isDrawing&&w.currentAnnotation){d.save();const l=w.currentAnnotation;if(d.globalAlpha=l.style.opacity,d.strokeStyle=l.style.strokeColor,d.lineWidth=l.style.strokeWidth,d.setLineDash([6,3]),l.tool==="freehand"){const h=l;if(h.points.length>=2){d.beginPath(),d.moveTo(h.points[0].x,h.points[0].y);for(let c=1;c<h.points.length;c++)d.lineTo(h.points[c].x,h.points[c].y);d.stroke()}}else if(l.tool==="rectangle")d.strokeRect(l.x,l.y,l.width,l.height);else if(l.tool==="ellipse")d.beginPath(),d.ellipse(l.x+l.width/2,l.y+l.height/2,Math.abs(l.width/2),Math.abs(l.height/2),0,0,Math.PI*2),d.stroke();else if(l.tool==="arrow"||l.tool==="line"){const h=l;d.beginPath(),d.moveTo(h.x,h.y),d.lineTo(h.endX,h.endY),d.stroke()}d.restore()}d.restore()},[y,R]);i.useEffect(()=>{z()},[z]);const S=i.useCallback(u=>{if(C)return;const d=k(u.clientX,u.clientY),I=y.activeTool;if(I==="select"){const g=[...y.annotations].reverse().find(l=>l.tool==="freehand"?!1:d.x>=l.x&&d.x<=l.x+l.width&&d.y>=l.y&&d.y<=l.y+l.height);T({type:"SELECT",id:(g==null?void 0:g.id)??null});return}const w=A.current;w.isDrawing=!0,w.startX=d.x,w.startY=d.y;const _={id:Ti(),style:{...y.style},x:d.x,y:d.y,width:0,height:0};switch(I){case"rectangle":w.currentAnnotation={..._,tool:"rectangle"};break;case"ellipse":w.currentAnnotation={..._,tool:"ellipse"};break;case"arrow":w.currentAnnotation={..._,tool:"arrow",endX:d.x,endY:d.y};break;case"line":w.currentAnnotation={..._,tool:"line",endX:d.x,endY:d.y};break;case"text":w.currentAnnotation={..._,tool:"text",text:"Text",width:100,height:y.style.fontSize??16};break;case"freehand":w.freehandPoints=[d],w.currentAnnotation={..._,tool:"freehand",points:[d]};break;case"blur":w.currentAnnotation={..._,tool:"blur",intensity:5};break}},[C,k,y.activeTool,y.style,y.annotations]),x=i.useCallback(u=>{const d=A.current;if(!d.isDrawing||!d.currentAnnotation)return;const I=k(u.clientX,u.clientY),w=d.currentAnnotation;if(w.tool==="freehand"){d.freehandPoints.push(I),w.points=[...d.freehandPoints];const _=d.freehandPoints.map(l=>l.x),g=d.freehandPoints.map(l=>l.y);w.x=Math.min(..._),w.y=Math.min(...g),w.width=Math.max(..._)-w.x,w.height=Math.max(...g)-w.y}else if(w.tool==="arrow"||w.tool==="line")w.endX=I.x,w.endY=I.y,w.width=Math.abs(I.x-d.startX),w.height=Math.abs(I.y-d.startY);else{const _=Math.min(d.startX,I.x),g=Math.min(d.startY,I.y);w.x=_,w.y=g,w.width=Math.abs(I.x-d.startX),w.height=Math.abs(I.y-d.startY)}z()},[k,z]),m=i.useCallback(()=>{const u=A.current;if(!u.isDrawing||!u.currentAnnotation)return;const d=u.currentAnnotation;(d.tool==="text"||d.tool==="freehand"||Math.abs(d.width)>2||Math.abs(d.height)>2)&&T({type:"ADD_ANNOTATION",annotation:d}),u.isDrawing=!1,u.currentAnnotation=null,u.freehandPoints=[]},[]),N=i.useCallback(u=>{u.preventDefault();const d=u.deltaY>0?.9:1.1,I=Math.max(M,Math.min(E,y.zoom*d));T({type:"SET_ZOOM",zoom:I})},[y.zoom,M,E]);i.useEffect(()=>{if(C)return;const u=d=>{(d.metaKey||d.ctrlKey)&&d.key==="z"&&!d.shiftKey?(d.preventDefault(),T({type:"UNDO"})):(d.metaKey||d.ctrlKey)&&(d.key==="y"||d.key==="z"&&d.shiftKey)?(d.preventDefault(),T({type:"REDO"})):(d.key==="Delete"||d.key==="Backspace")&&y.selectedId&&T({type:"DELETE_ANNOTATION",id:y.selectedId})};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[C,y.selectedId]),i.useImperativeHandle(H,()=>({exportAsDataURL:async(u="png",d=.92)=>{const I=document.createElement("canvas"),w=j.current;if(!w)return"";I.width=w.naturalWidth,I.height=w.naturalHeight;const _=I.getContext("2d");_.drawImage(w,0,0);for(const g of y.annotations){if(_.save(),_.globalAlpha=g.style.opacity,_.strokeStyle=g.style.strokeColor,_.fillStyle=g.style.fillColor,_.lineWidth=g.style.strokeWidth,g.tool==="rectangle")_.strokeRect(g.x,g.y,g.width,g.height);else if(g.tool==="ellipse")_.beginPath(),_.ellipse(g.x+g.width/2,g.y+g.height/2,Math.abs(g.width/2),Math.abs(g.height/2),0,0,Math.PI*2),_.stroke();else if(g.tool==="freehand"){const l=g;if(l.points.length>=2){_.beginPath(),_.moveTo(l.points[0].x,l.points[0].y);for(let h=1;h<l.points.length;h++)_.lineTo(l.points[h].x,l.points[h].y);_.stroke()}}else if(g.tool==="text"){const l=g;_.font=`${l.style.fontSize??16}px ${l.style.fontFamily??"sans-serif"}`,_.fillStyle=l.style.strokeColor,_.fillText(l.text,l.x,l.y+(l.style.fontSize??16))}_.restore()}return I.toDataURL(`image/${u}`,d)},exportAnnotations:()=>[...y.annotations],importAnnotations:u=>{T({type:"SET_ANNOTATIONS",annotations:u})},exportAsSVG:()=>{const{width:u,height:d}=q,I=y.annotations.map(zi);return`<svg xmlns="http://www.w3.org/2000/svg" width="${u}" height="${d}" viewBox="0 0 ${u} ${d}">
678
+ ${I.join(`
679
+ `)}
680
+ </svg>`},undo:()=>T({type:"UNDO"}),redo:()=>T({type:"REDO"}),setZoom:u=>{T({type:"SET_ZOOM",zoom:Math.max(M,Math.min(E,u))})},fitToScreen:()=>{const u=f.current,d=j.current;if(!u||!d)return;const I=u.clientWidth/d.naturalWidth,w=u.clientHeight/d.naturalHeight,_=Math.min(I,w,1);T({type:"SET_ZOOM",zoom:_}),T({type:"SET_PAN",panX:0,panY:0})},clear:()=>T({type:"CLEAR"})}),[y.annotations,q,M,E]);const $=i.useCallback(u=>{if(u.touches.length!==1)return;const d=u.touches[0];S({clientX:d.clientX,clientY:d.clientY,preventDefault:()=>{}})},[S]),L=i.useCallback(u=>{if(u.touches.length!==1)return;const d=u.touches[0];x({clientX:d.clientX,clientY:d.clientY})},[x]);return e.jsx("div",{ref:f,className:`nice-image-annotator ${v??""}`,style:{position:"relative",overflow:"hidden",width:"100%",height:"100%"},children:e.jsx("canvas",{ref:D,className:"nice-image-annotator__canvas",style:{cursor:y.activeTool==="select"?"default":"crosshair"},onMouseDown:S,onMouseMove:x,onMouseUp:m,onMouseLeave:m,onWheel:N,onTouchStart:$,onTouchMove:L,onTouchEnd:m,role:"img","aria-label":n})})});Cn.displayName="NiceImageAnnotator";const Li=[{target:".nice-md-editor",titleKey:"tutorial.markdownEditor.intro.title",title:"Markdown editor",contentKey:"tutorial.markdownEditor.intro.content",content:"Write Markdown with the formatting toolbar; toggle the live preview to see the rendered result, and export to HTML.",placement:"auto"}];function Ai(t){let n=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return n=n.replace(/```(\w*)\n([\s\S]*?)```/g,(a,r,o)=>`<pre><code class="language-${r}">${o.trim()}</code></pre>`),n=n.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(a,r,o,p)=>{const v=r.split("|").filter(M=>M.trim()).map(M=>`<th>${M.trim()}</th>`).join(""),C=p.trim().split(`
681
+ `).map(M=>`<tr>${M.split("|").filter(E=>E.trim()).map(E=>`<td>${E.trim()}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${v}</tr></thead><tbody>${C}</tbody></table>`}),n=n.replace(/^#### (.+)$/gm,"<h4>$1</h4>"),n=n.replace(/^### (.+)$/gm,"<h3>$1</h3>"),n=n.replace(/^## (.+)$/gm,"<h2>$1</h2>"),n=n.replace(/^# (.+)$/gm,"<h1>$1</h1>"),n=n.replace(/^&gt; (.+)$/gm,"<blockquote>$1</blockquote>"),n=n.replace(/^---$/gm,"<hr/>"),n=n.replace(/^- \[x\] (.+)$/gm,'<li class="task done">☑ $1</li>'),n=n.replace(/^- \[ \] (.+)$/gm,'<li class="task">☐ $1</li>'),n=n.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),n=n.replace(/\*(.+?)\*/g,"<em>$1</em>"),n=n.replace(/~~(.+?)~~/g,"<del>$1</del>"),n=n.replace(/`(.+?)`/g,"<code>$1</code>"),n=n.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" style="max-width:100%"/>'),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2">$1</a>'),n=n.replace(/^\- (.+)$/gm,"<li>$1</li>"),n=n.replace(/^\d+\. (.+)$/gm,"<li>$1</li>"),n=n.replace(/\n/g,"<br/>"),n}const Ii=[{key:"bold",label:"B",md:"**",tip:"Bold",shortcut:"Ctrl+B",group:"format"},{key:"italic",label:"I",md:"*",tip:"Italic",shortcut:"Ctrl+I",group:"format"},{key:"strike",label:"S̶",md:"~~",tip:"Strikethrough",group:"format"},{key:"code",label:"< >",md:"`",tip:"Inline code",group:"format"},{key:"h1",label:"H1",md:"# ",tip:"Heading 1",group:"heading"},{key:"h2",label:"H2",md:"## ",tip:"Heading 2",group:"heading"},{key:"h3",label:"H3",md:"### ",tip:"Heading 3",group:"heading"},{key:"ul",label:"•",md:"- ",tip:"Unordered list",group:"list"},{key:"ol",label:"1.",md:"1. ",tip:"Ordered list",group:"list"},{key:"task",label:"☑",md:"- [ ] ",tip:"Task list",group:"list"},{key:"quote",label:"❝",md:"> ",tip:"Blockquote",group:"block"},{key:"hr",label:"—",md:`---
682
+ `,tip:"Horizontal rule",group:"block"},{key:"link",label:"🔗",md:"[](url)",tip:"Link",shortcut:"Ctrl+K",group:"insert"},{key:"image",label:"🖼",md:"![](url)",tip:"Image",group:"insert"},{key:"table",label:"⊞",md:`| H1 | H2 | H3 |
683
+ | --- | --- | --- |
684
+ | c1 | c2 | c3 |
685
+ `,tip:"Table",group:"insert"},{key:"codeblock",label:"```",md:"```\n",tip:"Code block",group:"insert"}],Pi=["format","heading","list","block","insert"],Nn=i.forwardRef(({value:t="",onChange:n,preview:a="side",placeholder:r,disabled:o,readOnly:p,size:v="md",editorSize:C="standard",toolbar:M=!0,minHeight:E=200,showWordCount:H=!1,showLineNumbers:D=!1,onExportHtml:f,onImageUpload:j,tutorial:R,className:Q,style:q,id:Z},y)=>{const T=G.hl(Z),[A,k]=i.useState("edit"),[z,S]=i.useState(!1),x=i.useRef(null),m=i.useMemo(()=>Ai(t),[t]),N=i.useMemo(()=>{const _=t.trim()?t.trim().split(/\s+/).length:0,g=t.length,l=t.split(`
686
+ `).length;return{words:_,chars:g,lines:l}},[t]),$=i.useCallback(_=>{const g=x.current;if(!g)return;const l=g.selectionStart,h=g.selectionEnd,c=t.slice(l,h);let s,F;_==="[](url)"?(s=t.slice(0,l)+`[${c||"text"}](url)`+t.slice(h),F=l+1+(c||"text").length+2):_==="![](url)"?(s=t.slice(0,l)+`![${c||"alt"}](url)`+t.slice(h),F=l+2+(c||"alt").length+2):_.endsWith(`
687
+ `)||_.endsWith(" ")?(s=t.slice(0,l)+_+c+t.slice(h),F=l+_.length+c.length):(s=t.slice(0,l)+_+c+_+t.slice(h),F=l+_.length+c.length+_.length),n==null||n(s),requestAnimationFrame(()=>{g.focus(),g.setSelectionRange(F,F)})},[t,n]),L=i.useCallback(_=>{if((_.ctrlKey||_.metaKey)&&(_.key==="b"?(_.preventDefault(),$("**")):_.key==="i"?(_.preventDefault(),$("*")):_.key==="k"&&(_.preventDefault(),$("[](url)"))),_.key==="Tab"){_.preventDefault();const g=_.currentTarget,l=g.selectionStart,h=g.selectionEnd,c=" ";if(_.shiftKey){const s=t.slice(0,l).lastIndexOf(`
688
+ `)+1;if(t.slice(s,s+c.length)===c){const F=t.slice(0,s)+t.slice(s+c.length);n==null||n(F),requestAnimationFrame(()=>{g.selectionStart=g.selectionEnd=l-c.length})}}else{const s=t.slice(0,l)+c+t.slice(h);n==null||n(s),requestAnimationFrame(()=>{g.selectionStart=g.selectionEnd=l+c.length})}}},[t,n,$]),u=i.useCallback(async _=>{if(!j)return;const g=Array.from(_.dataTransfer.files).filter(l=>l.type.startsWith("image/"));if(g.length!==0){_.preventDefault();for(const l of g){const h=await j(l),c=x.current;if(!c)continue;const s=c.selectionStart,F=`![${l.name}](${h})
689
+ `,O=t.slice(0,s)+F+t.slice(s);n==null||n(O)}}},[t,n,j]),d=a!=="tab"||A==="edit",I=a==="side"||a==="tab"&&A==="preview"||a===!0,w=`nice-md-editor nice-md-editor--${v} nice-editor--${C} nice-md-editor--preview-${a}${z?" nice-md-editor--fullscreen":""} ${Q||""}`;return e.jsxs("div",{ref:y,id:T,className:w,style:{position:"relative",...q},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(R,Li)})}),M&&e.jsxs("div",{className:"nice-md-editor__toolbar",children:[Pi.map((_,g)=>e.jsxs(i.Fragment,{children:[g>0&&e.jsx("span",{className:"nice-md-editor__sep"}),Ii.filter(l=>l.group===_).map(l=>e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:l.shortcut?`${l.tip} (${l.shortcut})`:l.tip,disabled:o||p,onClick:()=>$(l.md),children:l.label},l.key))]},_)),e.jsx("span",{className:"nice-md-editor__sep"}),e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:"Fullscreen",onClick:()=>S(!z),children:z?"⊙":"⛶"}),f&&e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:"Export HTML",onClick:()=>f(m),children:"↗"}),a==="tab"&&e.jsxs("span",{className:"nice-md-editor__tabs",children:[e.jsx("button",{type:"button",className:`nice-md-editor__tab${A==="edit"?" nice-md-editor__tab--active":""}`,onClick:()=>k("edit"),children:"Edit"}),e.jsx("button",{type:"button",className:`nice-md-editor__tab${A==="preview"?" nice-md-editor__tab--active":""}`,onClick:()=>k("preview"),children:"Preview"})]})]}),e.jsxs("div",{className:"nice-md-editor__body",style:{minHeight:E},children:[d&&e.jsxs("div",{className:"nice-md-editor__editor-wrap",children:[D&&e.jsx("div",{className:"nice-md-editor__line-numbers",children:Array.from({length:N.lines},(_,g)=>e.jsx("div",{className:"nice-md-editor__line-no",children:g+1},g))}),e.jsx("textarea",{ref:x,className:"nice-md-editor__textarea",value:t,onChange:_=>n==null?void 0:n(_.target.value),onKeyDown:L,onDrop:u,placeholder:r,disabled:o,readOnly:p,style:{minHeight:E}})]}),I&&e.jsx("div",{className:"nice-md-editor__preview",dangerouslySetInnerHTML:{__html:G.dl(m)},style:{minHeight:E}})]}),H&&e.jsxs("div",{className:"nice-md-editor__statusbar",children:[e.jsxs("span",{children:[N.words," words"]}),e.jsxs("span",{children:[N.chars," chars"]}),e.jsxs("span",{children:[N.lines," lines"]})]})]})});Nn.displayName="NiceMarkdownEditor";const Wi=[{target:".nice-image-editor",titleKey:"tutorial.imageEditor.intro.title",title:"Image editor",contentKey:"tutorial.imageEditor.intro.content",content:"Use the toolbar to crop, rotate, flip, adjust brightness/contrast and annotate; undo/redo your edits, then save the result.",placement:"auto"}],Qt={rotation:0,flipH:!1,flipV:!1,brightness:100,contrast:100,saturate:100,blur:0,crop:null,annotations:[]},Hi=["crop","rotate","flip","brightness","contrast","saturate","blur","annotate"],wn=i.forwardRef(({src:t,size:n="md",editorSize:a="standard",tools:r=Hi,showToolbar:o=!0,showZoom:p=!0,maxUndo:v=30,onSave:C,onCancel:M,onChange:E,width:H="100%",height:D=500,tutorial:f,className:j,style:R,id:Q,...q},Z)=>{const y=G.hl(Q),{t:T}=G.ce(),A=i.useRef(null),k=i.useRef(null),[z,S]=i.useState({...Qt}),[x,m]=i.useState(null),[N,$]=i.useState(!1),[L,u]=i.useState(1),[d,I]=i.useState("rect"),[w,_]=i.useState("var(--nice-danger, #ff0000)"),[g,l]=i.useState({w:0,h:0}),[h,c]=i.useState([]),[s,F]=i.useState([]),[O,Y]=i.useState(null),[J,me]=i.useState(null),[de,P]=i.useState(null),B=i.useCallback(K=>{c(W=>[...W.slice(-(v-1)),K]),F([])},[v]),re=i.useCallback(K=>{S(W=>{B(W);const se={...W,...K};return E==null||E(se),se})},[E,B]),ue=i.useCallback(()=>{if(h.length===0)return;const K=h[h.length-1];c(W=>W.slice(0,-1)),F(W=>[...W,z]),S(K),E==null||E(K)},[h,z,E]),fe=i.useCallback(()=>{if(s.length===0)return;const K=s[s.length-1];F(W=>W.slice(0,-1)),c(W=>[...W,z]),S(K),E==null||E(K)},[s,z,E]);i.useEffect(()=>{const K=new Image;K.crossOrigin="anonymous",K.onload=()=>{k.current=K,l({w:K.width,h:K.height}),$(!0)},K.src=t},[t]),i.useEffect(()=>{if(!N||!A.current||!k.current)return;const K=A.current,W=K.getContext("2d");if(!W)return;const se=k.current,be=z.rotation%180!==0,ie=be?se.height:se.width,ce=be?se.width:se.height;K.width=ie,K.height=ce,W.clearRect(0,0,ie,ce),W.save(),W.filter=`brightness(${z.brightness}%) contrast(${z.contrast}%) saturate(${z.saturate}%) blur(${z.blur}px)`,W.translate(ie/2,ce/2),W.rotate(z.rotation*Math.PI/180),W.scale(z.flipH?-1:1,z.flipV?-1:1),W.drawImage(se,-se.width/2,-se.height/2),W.restore(),z.annotations.forEach(he=>{switch(W.save(),W.strokeStyle=he.color??"red",W.fillStyle=he.color??"red",W.lineWidth=he.strokeWidth??2,W.font=`${he.fontSize??16}px sans-serif`,he.type){case"text":W.fillText(he.text??"",he.x,he.y);break;case"rect":W.strokeRect(he.x,he.y,he.width??100,he.height??50);break;case"circle":{const ke=(he.width??50)/2,$e=(he.height??50)/2;W.beginPath(),W.ellipse(he.x+ke,he.y+$e,ke,$e,0,0,Math.PI*2),W.stroke();break}case"line":W.beginPath(),W.moveTo(he.x,he.y),W.lineTo(he.x+(he.width??100),he.y+(he.height??0)),W.stroke();break;case"arrow":{const ke=he.x+(he.width??100),$e=he.y+(he.height??0);W.beginPath(),W.moveTo(he.x,he.y),W.lineTo(ke,$e),W.stroke();const Ee=Math.atan2($e-he.y,ke-he.x),Me=10;W.beginPath(),W.moveTo(ke,$e),W.lineTo(ke-Me*Math.cos(Ee-.4),$e-Me*Math.sin(Ee-.4)),W.lineTo(ke-Me*Math.cos(Ee+.4),$e-Me*Math.sin(Ee+.4)),W.closePath(),W.fill();break}}W.restore()}),J&&(W.save(),W.fillStyle="var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",W.fillRect(0,0,ie,ce),W.clearRect(J.x,J.y,J.w,J.h),W.strokeStyle="var(--bg-primary, #fff)",W.lineWidth=2,W.setLineDash([5,5]),W.strokeRect(J.x,J.y,J.w,J.h),W.restore())},[N,z,J]);const V=i.useCallback(K=>{if(!A.current)return;const W=A.current.getBoundingClientRect(),se=A.current.width/W.width,be=A.current.height/W.height,ie=(K.clientX-W.left)*se,ce=(K.clientY-W.top)*be;x==="crop"?Y({startX:ie,startY:ce}):x==="annotate"&&P({startX:ie,startY:ce})},[x]),ne=i.useCallback(K=>{if(!A.current)return;const W=A.current.getBoundingClientRect(),se=A.current.width/W.width,be=A.current.height/W.height,ie=(K.clientX-W.left)*se,ce=(K.clientY-W.top)*be;O&&me({x:Math.min(O.startX,ie),y:Math.min(O.startY,ce),w:Math.abs(ie-O.startX),h:Math.abs(ce-O.startY)})},[O]),oe=i.useCallback(K=>{if(O&&J&&J.w>5&&J.h>5&&re({crop:{x:J.x,y:J.y,width:J.w,height:J.h}}),Y(null),de&&A.current){const W=A.current.getBoundingClientRect(),se=A.current.width/W.width,be=A.current.height/W.height,ie=(K.clientX-W.left)*se,ce=(K.clientY-W.top)*be,he=ie-de.startX,ke=ce-de.startY;if(Math.abs(he)>3||Math.abs(ke)>3||d==="text"){const $e={type:d,x:de.startX,y:de.startY,width:Math.abs(he)||100,height:Math.abs(ke)||50,color:w,strokeWidth:2,text:d==="text"?prompt(T("imageEditor.annotationText","Text:"))??"":void 0};re({annotations:[...z.annotations,$e]})}P(null)}},[O,J,de,d,w,z.annotations,re,T]),xe=i.useCallback(()=>{if(!z.crop||!A.current)return;const K=A.current,W=K.getContext("2d");if(!W)return;const{x:se,y:be,width:ie,height:ce}=z.crop,he=W.getImageData(se,be,ie,ce);K.width=ie,K.height=ce,W.putImageData(he,0,0),me(null),m(null)},[z.crop]),le=i.useCallback(()=>{if(!A.current)return;const K=A.current.toDataURL("image/png");C==null||C(K,z)},[C,z]),U=i.useCallback(()=>{S({...Qt}),me(null),m(null)},[]);return i.useMemo(()=>`brightness(${z.brightness}%) contrast(${z.contrast}%) saturate(${z.saturate}%) blur(${z.blur}px)`,[z.brightness,z.contrast,z.saturate,z.blur]),e.jsxs("div",{ref:Z,id:y,className:`nice-image-editor nice-image-editor--${n} nice-editor--${a} ${j??""}`,style:{position:"relative",...R,width:H,height:D},role:"application","aria-label":T("imageEditor.label","Image Editor"),...q,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(f,Wi)})}),o&&e.jsxs("div",{className:"nice-image-editor__toolbar",role:"toolbar",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:ue,disabled:h.length===0,title:T("imageEditor.undo","Undo"),children:"↶"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:fe,disabled:s.length===0,title:T("imageEditor.redo","Redo"),children:"↷"}),e.jsx("span",{className:"nice-image-editor__sep"}),r.includes("rotate")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({rotation:(z.rotation-90+360)%360}),title:T("imageEditor.rotateLeft","Rotate left"),children:"↺"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({rotation:(z.rotation+90)%360}),title:T("imageEditor.rotateRight","Rotate right"),children:"↻"})]}),r.includes("flip")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({flipH:!z.flipH}),title:T("imageEditor.flipH","Flip horizontal"),children:"⇔"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({flipV:!z.flipV}),title:T("imageEditor.flipV","Flip vertical"),children:"⇕"})]}),r.includes("crop")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:`nice-image-editor__btn ${x==="crop"?"nice-image-editor__btn--active":""}`,onClick:()=>m(x==="crop"?null:"crop"),title:T("imageEditor.crop","Crop"),children:"⊡"}),x==="crop"&&z.crop&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:xe,title:T("imageEditor.applyCrop","Apply crop"),children:"✓"})]}),r.includes("brightness")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[T("imageEditor.brightness","☀"),e.jsx("input",{type:"range",min:0,max:200,value:z.brightness,onChange:K=>re({brightness:Number(K.target.value)}),className:"nice-image-editor__slider",title:T("imageEditor.brightness","Brightness")})]}),r.includes("contrast")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[T("imageEditor.contrast","◑"),e.jsx("input",{type:"range",min:0,max:200,value:z.contrast,onChange:K=>re({contrast:Number(K.target.value)}),className:"nice-image-editor__slider",title:T("imageEditor.contrast","Contrast")})]}),r.includes("saturate")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[T("imageEditor.saturate","🎨"),e.jsx("input",{type:"range",min:0,max:200,value:z.saturate,onChange:K=>re({saturate:Number(K.target.value)}),className:"nice-image-editor__slider",title:T("imageEditor.saturate","Saturation")})]}),r.includes("blur")&&e.jsxs("label",{className:"nice-image-editor__slider-label",children:[T("imageEditor.blur","⊘"),e.jsx("input",{type:"range",min:0,max:20,step:.5,value:z.blur,onChange:K=>re({blur:Number(K.target.value)}),className:"nice-image-editor__slider",title:T("imageEditor.blur","Blur")})]}),r.includes("annotate")&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:`nice-image-editor__btn ${x==="annotate"?"nice-image-editor__btn--active":""}`,onClick:()=>m(x==="annotate"?null:"annotate"),title:T("imageEditor.annotate","Annotate"),children:"✎"}),x==="annotate"&&e.jsxs(e.Fragment,{children:[e.jsxs("select",{className:"nice-image-editor__select",value:d,onChange:K=>I(K.target.value),children:[e.jsx("option",{value:"rect",children:"□ Rect"}),e.jsx("option",{value:"circle",children:"○ Circle"}),e.jsx("option",{value:"line",children:"╱ Line"}),e.jsx("option",{value:"arrow",children:"→ Arrow"}),e.jsx("option",{value:"text",children:"T Text"})]}),e.jsx("input",{type:"color",value:w,onChange:K=>_(K.target.value),className:"nice-image-editor__color",title:T("imageEditor.color","Color")}),z.annotations.length>0&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>re({annotations:z.annotations.slice(0,-1)}),title:T("imageEditor.removeLastAnnotation","Remove last"),children:"⌫"})]})]}),e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:U,title:T("imageEditor.reset","Reset"),children:"⟲"}),C&&e.jsx("button",{type:"button",className:"nice-image-editor__btn nice-image-editor__btn--save",onClick:le,children:T("imageEditor.save","Save")}),M&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:M,children:T("imageEditor.cancel","Cancel")})]}),e.jsx("div",{className:"nice-image-editor__canvas-wrap",children:e.jsx("canvas",{ref:A,className:"nice-image-editor__canvas",onMouseDown:V,onMouseMove:ne,onMouseUp:oe,style:{cursor:x==="crop"||x==="annotate"?"crosshair":"default",transform:`scale(${L})`,transformOrigin:"center center"}})}),p&&e.jsxs("div",{className:"nice-image-editor__footer",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>u(K=>Math.max(.1,K-.1)),title:"Zoom out",children:"−"}),e.jsxs("span",{style:{fontSize:"0.85em",minWidth:40,textAlign:"center"},children:[Math.round(L*100),"%"]}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>u(K=>Math.min(5,K+.1)),title:"Zoom in",children:"+"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>u(1),title:"Reset zoom",children:"1:1"}),e.jsx("span",{style:{flex:1}}),e.jsxs("span",{style:{fontSize:"0.8em",color:"var(--nice-text-secondary, #666)"},children:[g.w,"×",g.h,"px · ",z.rotation,"°"]})]})]})});wn.displayName="NiceImageEditor";const $n=i.forwardRef(({value:t,onChange:n,penColor:a="var(--text-primary, #000)",penWidth:r=2,backgroundColor:o="var(--bg-primary, #fff)",width:p=400,height:v=200,size:C="md",disabled:M=!1,readOnly:E=!1,showClear:H=!0,showUndo:D=!0,label:f,exportFormat:j="image/png",className:R,style:Q,id:q,...Z},y)=>{const T=G.hl(q),{t:A}=G.ce(),k=i.useRef(null),[z,S]=i.useState(!1),x=i.useRef([]),m=i.useRef([]),[N,$]=i.useState(!0),L=i.useCallback(()=>{const l=k.current;if(!l)return;const h=l.getContext("2d");if(h){h.fillStyle=o,h.fillRect(0,0,l.width,l.height),h.strokeStyle=a,h.lineWidth=r,h.lineCap="round",h.lineJoin="round";for(const c of x.current)if(!(c.length<2)){h.beginPath(),h.moveTo(c[0].x,c[0].y);for(let s=1;s<c.length;s++)h.lineTo(c[s].x,c[s].y);h.stroke()}}},[o,a,r]);i.useEffect(()=>{if(t&&k.current){const l=new Image;l.onload=()=>{var c;const h=(c=k.current)==null?void 0:c.getContext("2d");!h||!k.current||(h.fillStyle=o,h.fillRect(0,0,k.current.width,k.current.height),h.drawImage(l,0,0),$(!1))},l.src=t}else t||(x.current=[],$(!0),L())},[t,o,L]),i.useEffect(()=>{const l=k.current;l&&(l.width=p,l.height=v,L())},[p,v,L]);const u=i.useCallback(l=>{const h=k.current,c=h.getBoundingClientRect(),s=h.width/c.width,F=h.height/c.height;if("touches"in l){const O=l.touches[0];return{x:(O.clientX-c.left)*s,y:(O.clientY-c.top)*F}}return{x:(l.clientX-c.left)*s,y:(l.clientY-c.top)*F}},[]),d=i.useCallback(l=>{if(M||E)return;l.preventDefault();const h=u(l);m.current=[h],S(!0)},[M,E,u]),I=i.useCallback(l=>{if(!z)return;l.preventDefault();const h=u(l);m.current.push(h);const c=k.current,s=c==null?void 0:c.getContext("2d");if(!s||!c)return;const F=m.current;F.length>=2&&(s.strokeStyle=a,s.lineWidth=r,s.lineCap="round",s.beginPath(),s.moveTo(F[F.length-2].x,F[F.length-2].y),s.lineTo(h.x,h.y),s.stroke())},[z,u,a,r]),w=i.useCallback(()=>{if(z&&(S(!1),m.current.length>0&&(x.current.push([...m.current]),m.current=[],$(!1),k.current))){const l=k.current.toDataURL(j);n==null||n(l)}},[z,j,n]),_=i.useCallback(()=>{x.current=[],m.current=[],$(!0),L(),n==null||n(null)},[L,n]),g=i.useCallback(()=>{if(x.current.length!==0&&(x.current.pop(),$(x.current.length===0),L(),k.current)){const l=x.current.length>0?k.current.toDataURL(j):null;n==null||n(l)}},[L,j,n]);return e.jsxs("div",{ref:y,id:T,className:`nice-signature nice-signature--${C} ${M?"nice-signature--disabled":""} ${E?"nice-signature--readonly":""} ${R??""}`,style:Q,...Z,children:[f&&e.jsx("label",{className:"nice-signature__label",children:f}),e.jsx("div",{className:"nice-signature__canvas-wrap",style:{width:p,height:v},children:e.jsx("canvas",{ref:k,className:"nice-signature__canvas",onMouseDown:d,onMouseMove:I,onMouseUp:w,onMouseLeave:w,onTouchStart:d,onTouchMove:I,onTouchEnd:w,style:{touchAction:"none",cursor:M||E?"default":"crosshair"},"aria-label":f??A("signature.label","Signature pad"),role:"img"})}),(H||D)&&!E&&!M&&e.jsxs("div",{className:"nice-signature__actions",children:[D&&e.jsx("button",{type:"button",className:"nice-signature__btn",onClick:g,disabled:N,children:A("signature.undo","Undo")}),H&&e.jsx("button",{type:"button",className:"nice-signature__btn",onClick:_,disabled:N,children:A("signature.clear","Clear")})]})]})});$n.displayName="NiceSignaturePad";const Oi=[{target:".nice-doc-editor",titleKey:"tutorial.documentEditor.intro.title",title:"Document editor",contentKey:"tutorial.documentEditor.intro.content",content:"Compose a document from blocks: use the toolbar or slash commands to add headings, lists, media and more, then export to HTML.",placement:"auto"}];let Fi=0;function $t(){return`blk-${++Fi}-${Date.now().toString(36)}`}function Bt(t=""){return{id:$t(),type:"paragraph",content:t}}function Ui(t,n=""){const a={id:$t(),type:t,content:n};return t==="heading"&&(a.level=2),t==="list"&&(a.listType="unordered"),t==="callout"&&(a.icon="??"),t==="toggle"&&(a.open=!0),a}const qi=[{type:"paragraph",label:"Text",icon:"�",keywords:"paragraph text"},{type:"heading",label:"Heading",icon:"H",keywords:"heading title"},{type:"list",label:"Bulleted list",icon:"�",keywords:"bullet unordered list"},{type:"list",label:"Numbered list",icon:"1.",keywords:"numbered ordered list"},{type:"list",label:"Checklist",icon:"?",keywords:"check todo list"},{type:"quote",label:"Quote",icon:"?",keywords:"quote blockquote"},{type:"callout",label:"Callout",icon:"??",keywords:"callout info alert"},{type:"toggle",label:"Toggle",icon:"?",keywords:"toggle collapse expand"},{type:"code",label:"Code",icon:"</>",keywords:"code snippet"},{type:"image",label:"Image",icon:"??",keywords:"image photo picture"},{type:"video",label:"Video",icon:"??",keywords:"video embed"},{type:"table",label:"Table",icon:"?",keywords:"table grid"},{type:"divider",label:"Divider",icon:"-",keywords:"divider line separator"},{type:"pageBreak",label:"Page Break",icon:"?",keywords:"page break"}];function Xi(t){const n=[t.align?`text-align:${t.align}`:"",t.color?`color:${t.color}`:"",t.bgColor?`background-color:${t.bgColor}`:"",t.indent?`margin-left:${t.indent*24}px`:""].filter(Boolean).join(";"),a=n?` style="${n}"`:"",r=(o,p)=>{let v=p;return t.bold&&(v=`<strong>${v}</strong>`),t.italic&&(v=`<em>${v}</em>`),t.underline&&(v=`<u>${v}</u>`),t.strikethrough&&(v=`<s>${v}</s>`),`<${o}${a}>${v}</${o}>`};switch(t.type){case"heading":return r(`h${t.level??2}`,t.content);case"paragraph":return r("p",t.content||"&nbsp;");case"list":{const o=t.listType==="ordered"?"ol":"ul",p=t.content.split(`
690
+ `).map((v,C)=>{var M;return t.listType==="checklist"?`<li><input type="checkbox" ${((M=t.checked)==null?void 0:M[C])??!1?"checked":""} disabled />${v}</li>`:`<li>${v}</li>`}).join("");return`<${o}${a}>${p}</${o}>`}case"image":return`<figure${a}><img src="${t.src??""}" alt="${t.alt??""}" /></figure>`;case"video":return`<figure${a}><video src="${t.src??""}" controls></video></figure>`;case"divider":return"<hr />";case"pageBreak":return'<div style="page-break-after:always"></div>';case"code":return`<pre><code class="language-${t.language??""}">${t.content}</code></pre>`;case"quote":return r("blockquote",t.content);case"callout":return`<div class="nice-doc-callout"${a}><span>${t.icon??"??"}</span><div>${t.content}</div></div>`;case"toggle":return`<details${a}><summary>${t.content.split(`
691
+ `)[0]}</summary>${t.content.split(`
692
+ `).slice(1).join("<br>")}</details>`;case"table":return`<table${a}>${t.content}</table>`;case"embed":return`<iframe src="${t.src??""}" style="width:100%;border:none;min-height:300px"></iframe>`;default:return r("p",t.content)}}function Ki(t){let n=0,a=0;for(const r of t){const o=r.content??"";n+=o.length;const p=o.trim().split(/\s+/).filter(Boolean);a+=p.length}return{words:a,chars:n,readingTime:Math.max(1,Math.ceil(a/200))}}const Mn=i.forwardRef(({blocks:t,onChange:n,readOnly:a=!1,showToolbar:r=!0,size:o="md",editorSize:p="standard",placeholder:v,onExport:C,onImageUpload:M,maxUndo:E=50,slashCommands:H=!0,showWordCount:D=!1,showToc:f=!1,showFindReplace:j=!0,tutorial:R,className:Q,style:q,id:Z,...y},T)=>{var X,pe,ve,Ne,ye,Te,je,Re,Ie,Ae,Pe,ot,Ve,ct,Mt,St;const A=G.hl(Z),{t:k}=G.ce(),[z,S]=i.useState(()=>t??[Bt()]),x=t??z,[m,N]=i.useState(0),$=i.useRef(new Map),L=i.useRef(null),[u,d]=i.useState(!1),[I,w]=i.useState(""),[_,g]=i.useState(""),[l,h]=i.useState([]),[c,s]=i.useState(0),[F,O]=i.useState(!1),Y=i.useRef([]),J=i.useRef([]),me=i.useCallback(b=>{Y.current.push(b.map(ee=>({...ee,checked:ee.checked?[...ee.checked]:void 0}))),Y.current.length>E&&Y.current.shift(),J.current=[]},[E]),de=i.useCallback(()=>{if(Y.current.length===0)return;const b=Y.current.pop();J.current.push(x.map(ee=>({...ee}))),t||S(b),n==null||n(b)},[x,t,n]),P=i.useCallback(()=>{if(J.current.length===0)return;const b=J.current.pop();Y.current.push(x.map(ee=>({...ee}))),t||S(b),n==null||n(b)},[x,t,n]),[B,re]=i.useState(!1),[ue,fe]=i.useState(""),[V,ne]=i.useState(0),oe=i.useMemo(()=>{if(!B||!H)return[];const b=ue.toLowerCase();return qi.filter(ee=>ee.label.toLowerCase().includes(b)||ee.keywords.includes(b))},[B,ue,H]),[xe,le]=i.useState(null),[U,K]=i.useState(null),W=i.useCallback(b=>{me(x);const ee=b(x);t||S(ee),n==null||n(ee)},[x,t,n,me]),se=i.useCallback((b,ee)=>{W(te=>te.map((we,De)=>De===b?{...we,...ee}:we))},[W]),be=i.useCallback((b,ee)=>{const te=ee??Bt();W(we=>{const De=[...we];return De.splice(b+1,0,te),De}),N(b+1)},[W]),ie=i.useCallback(b=>{const ee={...x[b],id:$t()};be(b,ee)},[x,be]),ce=i.useCallback(b=>{x.length<=1||(W(ee=>ee.filter((te,we)=>we!==b)),N(Math.max(0,b-1)))},[x.length,W]),he=i.useCallback((b,ee)=>{const te=b+ee;te<0||te>=x.length||(W(we=>{const De=[...we];return[De[b],De[te]]=[De[te],De[b]],De}),N(te))},[x.length,W]),ke=i.useCallback((b,ee)=>{const te={type:ee};ee==="heading"&&(te.level=2),ee==="list"&&(te.listType="unordered"),ee==="callout"&&(te.icon="??"),ee==="toggle"&&(te.open=!0),se(b,te)},[se]),$e=i.useCallback(b=>{var te,we;const ee=Ui(b.type);b.type==="list"&&b.label.includes("Numbered")&&(ee.listType="ordered"),b.type==="list"&&b.label.includes("Checklist")&&(ee.listType="checklist",ee.checked=[]),((te=x[m])==null?void 0:te.content)===""||((we=x[m])==null?void 0:we.content)==="/"?W(De=>De.map((Ue,Ye)=>Ye===m?{...ee,id:Ue.id}:Ue)):be(m,ee),re(!1),fe("")},[x,m,W,be]),Ee=i.useCallback((b,ee)=>{if(a)return;const te=x[ee];if(!(te!=null&&te.locked)){if((b.ctrlKey||b.metaKey)&&b.key==="z"&&!b.shiftKey){b.preventDefault(),de();return}if((b.ctrlKey||b.metaKey)&&(b.key==="y"||b.key==="z"&&b.shiftKey)){b.preventDefault(),P();return}if((b.ctrlKey||b.metaKey)&&b.key==="d"){b.preventDefault(),ie(ee);return}if((b.ctrlKey||b.metaKey)&&b.key==="b"){b.preventDefault(),se(ee,{bold:!(te!=null&&te.bold)});return}if((b.ctrlKey||b.metaKey)&&b.key==="i"){b.preventDefault(),se(ee,{italic:!(te!=null&&te.italic)});return}if((b.ctrlKey||b.metaKey)&&b.key==="u"){b.preventDefault(),se(ee,{underline:!(te!=null&&te.underline)});return}if((b.ctrlKey||b.metaKey)&&b.key==="e"){b.preventDefault(),se(ee,{strikethrough:!(te!=null&&te.strikethrough)});return}if(b.key==="Tab"&&!b.shiftKey){b.preventDefault(),se(ee,{indent:Math.min(((te==null?void 0:te.indent)??0)+1,4)});return}if(b.key==="Tab"&&b.shiftKey){b.preventDefault(),se(ee,{indent:Math.max(((te==null?void 0:te.indent)??0)-1,0)});return}if((b.ctrlKey||b.metaKey)&&b.key==="f"&&j){b.preventDefault(),d(we=>!we);return}if(B&&oe.length>0){if(b.key==="ArrowDown"){b.preventDefault(),ne(we=>Math.min(we+1,oe.length-1));return}if(b.key==="ArrowUp"){b.preventDefault(),ne(we=>Math.max(we-1,0));return}if(b.key==="Enter"){b.preventDefault(),$e(oe[V]);return}if(b.key==="Escape"){re(!1);return}}b.key==="Enter"&&!b.shiftKey?(b.preventDefault(),be(ee)):b.key==="Backspace"&&x[ee].content===""&&x.length>1?(b.preventDefault(),ce(ee)):b.key==="ArrowUp"&&b.altKey?(b.preventDefault(),he(ee,-1)):b.key==="ArrowDown"&&b.altKey&&(b.preventDefault(),he(ee,1))}},[a,x,be,ce,he,de,P,ie,se,B,oe,V,$e,j]),Me=i.useCallback((b,ee)=>{const te=b.target.textContent??"";H&&te.startsWith("/")?(re(!0),fe(te.slice(1)),ne(0)):B&&re(!1),me(x);const we=x.map((De,Ue)=>Ue===ee?{...De,content:te}:De);t||S(we),n==null||n(we)},[x,t,n,me,H,B]),qe=i.useCallback((b,ee)=>{le(ee),b.dataTransfer.effectAllowed="move"},[]),Qe=i.useCallback((b,ee)=>{b.preventDefault(),b.dataTransfer.dropEffect="move",K(ee)},[]),We=i.useCallback((b,ee)=>{if(b.preventDefault(),xe===null||xe===ee){le(null),K(null);return}W(te=>{const we=[...te],[De]=we.splice(xe,1);return we.splice(ee>xe?ee-1:ee,0,De),we}),N(ee>xe?ee-1:ee),le(null),K(null)},[xe,W]);i.useEffect(()=>{if(!u||!I){h([]);return}const b=I.toLowerCase(),ee=[];x.forEach((te,we)=>{const De=(te.content??"").toLowerCase();let Ue=0;for(;Ue<De.length;){const Ye=De.indexOf(b,Ue);if(Ye===-1)break;ee.push({blockIdx:we,start:Ye,end:Ye+b.length}),Ue=Ye+1}}),h(ee),s(0)},[I,u,x]);const Oe=i.useCallback(()=>{if(l.length===0)return;const b=(c+1)%l.length;s(b),N(l[b].blockIdx)},[l,c]),Be=i.useCallback(()=>{if(l.length===0)return;const b=(c-1+l.length)%l.length;s(b),N(l[b].blockIdx)},[l,c]),Je=i.useCallback(()=>{if(l.length===0||!I)return;const b=l[c],ee=x[b.blockIdx],te=ee.content.slice(0,b.start),we=ee.content.slice(b.end);se(b.blockIdx,{content:te+_+we})},[l,c,I,_,x,se]),et=i.useCallback(()=>{if(!I)return;const b=I;W(ee=>ee.map(te=>({...te,content:te.content.split(b).join(_)})))},[I,_,W]),Xe=i.useMemo(()=>f?x.map((b,ee)=>b.type==="heading"?{idx:ee,level:b.level??2,text:b.content}:null).filter(Boolean):[],[x,f]),Fe=i.useCallback(async b=>{var te;const ee=(te=b.target.files)==null?void 0:te[0];if(ee){if(M){const we=await M(ee);se(m,{src:we})}b.target.value=""}},[M,m,se]);i.useEffect(()=>{const b=x[m];if(b){const ee=$.current.get(b.id);ee&&ee.focus()}},[m,x]);const Ke=i.useCallback(()=>{const b=x.map(Xi).join(`
693
+ `);C==null||C(b)},[x,C]),ae=i.useMemo(()=>D?Ki(x):null,[x,D]),[ge,Ce]=i.useState(null),ze=i.useCallback((b,ee)=>{a||(b.preventDefault(),Ce({x:b.clientX,y:b.clientY,idx:ee}))},[a]);return i.useEffect(()=>{if(!ge)return;const b=()=>Ce(null);return window.addEventListener("click",b),()=>window.removeEventListener("click",b)},[ge]),e.jsxs("div",{ref:T,id:A,className:`nice-doc-editor nice-doc-editor--${o} nice-editor--${p} ${a?"nice-doc-editor--readonly":""} ${Q??""}`,style:{position:"relative",...q},role:"application","aria-label":k("docEditor.label","Document Editor"),...y,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(R,Oi)})}),r&&!a&&e.jsxs("div",{className:"nice-doc-editor__toolbar",role:"toolbar",style:{display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",padding:"4px 8px"},children:[e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:de,title:k("docEditor.undo","Undo (Ctrl+Z)"),children:"?"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:P,title:k("docEditor.redo","Redo (Ctrl+Y)"),children:"?"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(_e.Ze,{size:"sm",value:((X=x[m])==null?void 0:X.type)??"paragraph",onChange:b=>ke(m,b),label:"",options:[{value:"paragraph",label:k("docEditor.paragraph","Paragraph")},{value:"heading",label:k("docEditor.heading","Heading")},{value:"list",label:k("docEditor.list","List")},{value:"code",label:k("docEditor.code","Code")},{value:"quote",label:k("docEditor.quote","Quote")},{value:"callout",label:k("docEditor.callout","Callout")},{value:"toggle",label:k("docEditor.toggle","Toggle")},{value:"divider",label:k("docEditor.divider","Divider")},{value:"image",label:k("docEditor.image","Image")},{value:"video",label:k("docEditor.video","Video")},{value:"pageBreak",label:k("docEditor.pageBreak","Page Break")}],style:{minWidth:100}}),((pe=x[m])==null?void 0:pe.type)==="heading"&&e.jsx(_e.Ze,{size:"sm",value:String(((ve=x[m])==null?void 0:ve.level)??2),onChange:b=>se(m,{level:Number(b)}),label:"",options:[{value:"1",label:"H1"},{value:"2",label:"H2"},{value:"3",label:"H3"},{value:"4",label:"H4"},{value:"5",label:"H5"},{value:"6",label:"H6"}],style:{minWidth:55}}),((Ne=x[m])==null?void 0:Ne.type)==="list"&&e.jsx(_e.Ze,{size:"sm",value:((ye=x[m])==null?void 0:ye.listType)??"unordered",onChange:b=>se(m,{listType:b}),label:"",options:[{value:"unordered",label:"� Bullets"},{value:"ordered",label:"1. Numbers"},{value:"checklist",label:"? Checklist"}],style:{minWidth:90}}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(_e.hn,{size:"sm",variant:(Te=x[m])!=null&&Te.bold?"primary":"ghost",onClick:()=>{var b;return se(m,{bold:!((b=x[m])!=null&&b.bold)})},title:k("docEditor.bold","Bold (Ctrl+B)"),children:e.jsx("strong",{children:"B"})}),e.jsx(_e.hn,{size:"sm",variant:(je=x[m])!=null&&je.italic?"primary":"ghost",onClick:()=>{var b;return se(m,{italic:!((b=x[m])!=null&&b.italic)})},title:k("docEditor.italic","Italic (Ctrl+I)"),children:e.jsx("em",{children:"I"})}),e.jsx(_e.hn,{size:"sm",variant:(Re=x[m])!=null&&Re.underline?"primary":"ghost",onClick:()=>{var b;return se(m,{underline:!((b=x[m])!=null&&b.underline)})},title:k("docEditor.underline","Underline (Ctrl+U)"),children:e.jsx("u",{children:"U"})}),e.jsx(_e.hn,{size:"sm",variant:(Ie=x[m])!=null&&Ie.strikethrough?"primary":"ghost",onClick:()=>{var b;return se(m,{strikethrough:!((b=x[m])!=null&&b.strikethrough)})},title:k("docEditor.strikethrough","Strikethrough (Ctrl+E)"),children:e.jsx("s",{children:"S"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(_e.hn,{size:"sm",variant:((Ae=x[m])==null?void 0:Ae.align)==="left"?"primary":"ghost",onClick:()=>se(m,{align:"left"}),title:k("docEditor.alignLeft","Left"),children:"?"}),e.jsx(_e.hn,{size:"sm",variant:((Pe=x[m])==null?void 0:Pe.align)==="center"?"primary":"ghost",onClick:()=>se(m,{align:"center"}),title:k("docEditor.alignCenter","Center"),children:"?"}),e.jsx(_e.hn,{size:"sm",variant:((ot=x[m])==null?void 0:ot.align)==="right"?"primary":"ghost",onClick:()=>se(m,{align:"right"}),title:k("docEditor.alignRight","Right"),children:"?"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>{var b;return se(m,{indent:Math.min((((b=x[m])==null?void 0:b.indent)??0)+1,4)})},title:k("docEditor.indent","Indent (Tab)"),children:"??"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>{var b;return se(m,{indent:Math.max((((b=x[m])==null?void 0:b.indent)??0)-1,0)})},title:k("docEditor.outdent","Outdent (Shift+Tab)"),children:"??"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(_e.Xe,{size:"sm",label:"",value:((Ve=x[m])==null?void 0:Ve.color)??"var(--text-primary, #000000)",onChange:b=>se(m,{color:b}),title:"Text color"}),e.jsx(_e.Xe,{size:"sm",label:"",value:((ct=x[m])==null?void 0:ct.bgColor)??"var(--bg-primary, #ffffff)",onChange:b=>se(m,{bgColor:b}),title:"Block background"}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(_e.hn,{size:"sm",variant:(Mt=x[m])!=null&&Mt.locked?"primary":"ghost",onClick:()=>{var b;return se(m,{locked:!((b=x[m])!=null&&b.locked)})},title:k("docEditor.lock","Lock/Unlock block"),children:"??"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>ie(m),title:k("docEditor.duplicate","Duplicate (Ctrl+D)"),children:"?"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>ce(m),title:k("docEditor.delete","Delete block"),children:"??"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>be(m),title:k("docEditor.addBlock","Add block"),children:"+"}),j&&e.jsx(_e.hn,{size:"sm",variant:u?"primary":"ghost",onClick:()=>d(b=>!b),title:k("docEditor.find","Find & Replace (Ctrl+F)"),children:"??"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>O(b=>!b),title:k("docEditor.shortcuts","Keyboard shortcuts"),children:"?"}),C&&e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:Ke,children:k("docEditor.export","Export HTML")})]}),e.jsx("input",{ref:L,type:"file",accept:"image/*,video/*",style:{display:"none"},onChange:Fe}),u&&e.jsxs("div",{className:"nice-doc-editor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--nice-doc-find-bg, #f8f9fa)",borderBottom:"1px solid var(--border-color, #ddd)"},children:[e.jsx(_e.Pe,{size:"sm",placeholder:k("docEditor.findPlaceholder","Find..."),value:I,onChange:w,style:{flex:1,maxWidth:200}}),e.jsx(_e.Pe,{size:"sm",placeholder:k("docEditor.replacePlaceholder","Replace..."),value:_,onChange:g,style:{flex:1,maxWidth:200}}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:Be,title:k("docEditor.findPrev","Previous"),children:"?"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:Oe,title:k("docEditor.findNext","Next"),children:"?"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:Je,title:k("docEditor.replaceOne","Replace"),disabled:a,children:k("docEditor.replace","Replace")}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:et,title:k("docEditor.replaceAll","Replace all"),disabled:a,children:k("docEditor.replaceAllBtn","All")}),e.jsx("span",{style:{fontSize:"0.75em",color:"var(--text-muted, #666)"},children:l.length>0?`${c+1}/${l.length}`:"0/0"}),e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>d(!1),children:"?"})]}),F&&e.jsx("div",{className:"nice-doc-editor__shortcuts-overlay",style:{position:"fixed",inset:0,background:"var(--nice-overlay-40, rgba(0, 0, 0, 0.4))",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>O(!1),children:e.jsxs("div",{style:{background:"var(--bg-primary, #fff)",borderRadius:8,padding:24,maxWidth:420,width:"90%",boxShadow:"0 8px 32px var(--nice-overlay-20, rgba(0, 0, 0, 0.2))"},onClick:b=>b.stopPropagation(),children:[e.jsx("h3",{style:{margin:"0 0 12px"},children:k("docEditor.shortcutsTitle","Keyboard Shortcuts")}),e.jsx("table",{style:{width:"100%",fontSize:"0.875em",borderCollapse:"collapse"},children:e.jsx("tbody",{children:[["Ctrl+B",k("docEditor.bold","Bold")],["Ctrl+I",k("docEditor.italic","Italic")],["Ctrl+U",k("docEditor.underline","Underline")],["Ctrl+E",k("docEditor.strikethrough","Strikethrough")],["Ctrl+D",k("docEditor.duplicate","Duplicate block")],["Ctrl+Z",k("docEditor.undo","Undo")],["Ctrl+Y",k("docEditor.redo","Redo")],["Ctrl+F",k("docEditor.find","Find & Replace")],["Enter",k("docEditor.newBlock","New block")],["Backspace",k("docEditor.deleteEmpty","Delete empty block")],["Alt+?",k("docEditor.moveUp","Move block up")],["Alt+?",k("docEditor.moveDown","Move block down")],["Tab",k("docEditor.indent","Indent")],["Shift+Tab",k("docEditor.outdent","Outdent")],["/",k("docEditor.slashCmd","Slash commands")]].map(([b,ee])=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--border-color, #eee)"},children:[e.jsx("td",{style:{padding:"4px 8px",fontFamily:"monospace",fontWeight:600},children:b}),e.jsx("td",{style:{padding:"4px 8px"},children:ee})]},b))})}),e.jsx("div",{style:{textAlign:"right",marginTop:12},children:e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>O(!1),children:k("docEditor.close","Close")})})]})}),e.jsxs("div",{style:{display:"flex",gap:0},children:[f&&Xe.length>0&&e.jsxs("nav",{className:"nice-doc-editor__toc",style:{width:200,minWidth:160,borderRight:"1px solid var(--border-color, #eee)",padding:"8px 4px",fontSize:"0.8em",overflowY:"auto",maxHeight:500},children:[e.jsx("div",{style:{fontWeight:600,padding:"4px 8px",fontSize:"0.75em",textTransform:"uppercase",color:"var(--text-muted, #999)"},children:k("docEditor.toc","Contents")}),Xe.map(b=>e.jsx("div",{style:{padding:"3px 8px",paddingLeft:8+(b.level-1)*12,cursor:"pointer",borderRadius:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",background:b.idx===m?"var(--nice-primary-bg, #e8f0fe)":void 0},onClick:()=>N(b.idx),title:b.text,children:b.text||k("docEditor.untitled","Untitled")},b.idx))]}),e.jsx("div",{className:"nice-doc-editor__body",style:{flex:1},children:x.map((b,ee)=>e.jsxs("div",{className:`nice-doc-editor__block nice-doc-editor__block--${b.type} ${ee===m?"nice-doc-editor__block--focused":""} ${U===ee?"nice-doc-editor__block--drop-target":""} ${b.locked?"nice-doc-editor__block--locked":""}`,onClick:()=>N(ee),onContextMenu:te=>ze(te,ee),draggable:!a&&!b.locked,onDragStart:te=>qe(te,ee),onDragOver:te=>Qe(te,ee),onDrop:te=>We(te,ee),onDragEnd:()=>{le(null),K(null)},style:{opacity:xe===ee?.4:1,marginLeft:(b.indent??0)*24},children:[!a&&!b.locked&&e.jsx("div",{className:"nice-doc-editor__block-handle",title:k("docEditor.drag","Drag to reorder"),children:"?"}),b.locked&&e.jsx("span",{className:"nice-doc-editor__lock-icon",style:{position:"absolute",top:2,right:4,fontSize:"0.7em",opacity:.5},children:"??"}),b.type==="divider"?e.jsx("hr",{className:"nice-doc-editor__divider"}):b.type==="pageBreak"?e.jsxs("div",{className:"nice-doc-editor__page-break",style:{borderTop:"2px dashed var(--nice-border, #ccc)",textAlign:"center",padding:4,fontSize:"0.75em",color:"var(--text-muted, #999)"},children:["� ",k("docEditor.pageBreak","Page Break")," �"]}):b.type==="image"||b.type==="video"?e.jsx("div",{className:"nice-doc-editor__media-block",children:b.src?b.type==="image"?e.jsx("img",{src:b.src,alt:b.alt??"",className:"nice-doc-editor__image",style:{maxWidth:"100%"}}):e.jsx("video",{src:b.src,controls:!0,className:"nice-doc-editor__video",style:{maxWidth:"100%"}}):!a&&e.jsxs("div",{style:{display:"flex",gap:4,alignItems:"center"},children:[e.jsx(_e.Pe,{size:"sm",placeholder:k("docEditor.mediaUrl",b.type==="image"?"Image URL":"Video URL"),value:b.src??"",onChange:te=>se(ee,{src:te})}),M&&e.jsx(_e.hn,{size:"sm",variant:"ghost",onClick:()=>{var te;N(ee),(te=L.current)==null||te.click()},children:"??"})]})}):b.type==="callout"?e.jsxs("div",{className:"nice-doc-editor__callout",style:{display:"flex",gap:8,padding:"8px 12px",background:b.bgColor??"#f0f7ff",borderRadius:4,color:b.color},children:[e.jsx("span",{style:{fontSize:"1.2em"},children:b.icon??"??"}),e.jsx("div",{ref:te=>{te&&$.current.set(b.id,te)},className:"nice-doc-editor__content",contentEditable:!a&&!b.locked,suppressContentEditableWarning:!0,onInput:te=>Me(te,ee),onFocus:()=>N(ee),onKeyDown:te=>Ee(te,ee),"data-placeholder":k("docEditor.calloutPlaceholder","Callout text..."),role:"textbox","aria-multiline":"true",style:{flex:1,outline:"none"},children:b.content})]}):b.type==="toggle"?e.jsxs("details",{open:b.open,className:"nice-doc-editor__toggle",onToggle:te=>se(ee,{open:te.target.open}),children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:500},children:b.content.split(`
694
+ `)[0]||k("docEditor.toggleTitle","Toggle")}),e.jsx("div",{ref:te=>{te&&$.current.set(b.id,te)},className:"nice-doc-editor__content",contentEditable:!a&&!b.locked,suppressContentEditableWarning:!0,onInput:te=>Me(te,ee),onFocus:()=>N(ee),onKeyDown:te=>Ee(te,ee),role:"textbox","aria-multiline":"true",style:{padding:"4px 0"},children:b.content.split(`
695
+ `).slice(1).join(`
696
+ `)})]}):b.type==="code"?e.jsxs("div",{className:"nice-doc-editor__code-block",style:{position:"relative"},children:[!a&&e.jsx(_e.Pe,{size:"sm",value:b.language??"",onChange:te=>se(ee,{language:te}),placeholder:"Language",style:{position:"absolute",top:4,right:4,width:80,opacity:.7}}),e.jsx("pre",{ref:te=>{te&&$.current.set(b.id,te)},className:"nice-doc-editor__content",contentEditable:!a&&!b.locked,suppressContentEditableWarning:!0,onInput:te=>Me(te,ee),onFocus:()=>N(ee),onKeyDown:te=>Ee(te,ee),role:"textbox","aria-multiline":"true",style:{fontFamily:"monospace",background:"var(--bg-elevated, #1e1e1e)",color:"var(--text-secondary, #d4d4d4)",padding:12,borderRadius:4,overflow:"auto"},children:b.content})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:te=>{te&&$.current.set(b.id,te)},className:"nice-doc-editor__content",contentEditable:!a&&!b.locked,suppressContentEditableWarning:!0,style:{textAlign:b.align,fontWeight:b.bold?"bold":void 0,fontStyle:b.italic?"italic":void 0,textDecoration:[b.underline?"underline":"",b.strikethrough?"line-through":""].filter(Boolean).join(" ")||void 0,color:b.color,backgroundColor:b.bgColor},onInput:te=>Me(te,ee),onFocus:()=>N(ee),onKeyDown:te=>Ee(te,ee),"data-placeholder":!b.content&&v?v:void 0,role:"textbox","aria-multiline":"true",children:b.content}),B&&ee===m&&oe.length>0&&e.jsx("ul",{className:"nice-doc-editor__slash-menu",style:{position:"absolute",left:0,top:"100%",zIndex:100,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",listStyle:"none",margin:0,padding:4,minWidth:180,maxHeight:240,overflow:"auto"},children:oe.map((te,we)=>e.jsxs("li",{className:we===V?"nice-doc-editor__slash-item--active":"",style:{padding:"6px 10px",cursor:"pointer",borderRadius:4,display:"flex",gap:8,alignItems:"center",background:we===V?"var(--nice-primary-bg, #e8f0fe)":void 0},onMouseDown:De=>{De.preventDefault(),$e(te)},onMouseEnter:()=>ne(we),children:[e.jsx("span",{style:{width:24,textAlign:"center"},children:te.icon}),e.jsx("span",{children:te.label})]},`${te.type}-${te.label}`))})]})]},b.id))})]}),ge&&e.jsxs("div",{className:"nice-doc-editor__ctx-menu",style:{position:"fixed",left:ge.x,top:ge.y,zIndex:1e3,background:"var(--bg-primary, #fff)",border:"1px solid var(--border-color, #ddd)",borderRadius:6,boxShadow:"0 4px 16px var(--nice-overlay-12, rgba(0, 0, 0, 0.12))",padding:4,minWidth:160},children:[e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{ie(ge.idx),Ce(null)},children:"? Duplicate"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{be(ge.idx),Ce(null)},children:"+ Insert below"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{he(ge.idx,-1),Ce(null)},children:"? Move up"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{he(ge.idx,1),Ce(null)},children:"? Move down"}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{var b;se(ge.idx,{locked:!((b=x[ge.idx])!=null&&b.locked)}),Ce(null)},children:(St=x[ge.idx])!=null&&St.locked?"?? Unlock":"?? Lock"}),e.jsx("hr",{style:{margin:"2px 0",border:"none",borderTop:"1px solid var(--border-color, #eee)"}}),e.jsx("div",{style:{padding:"6px 12px",cursor:"pointer",color:"var(--nice-danger-dark, #d32f2f)"},onClick:()=>{ce(ge.idx),Ce(null)},children:"?? Delete"})]}),D&&ae&&e.jsxs("div",{className:"nice-doc-editor__footer",style:{padding:"4px 12px",fontSize:"0.75em",color:"var(--text-muted, #666)",borderTop:"1px solid var(--border-color, #eee)",display:"flex",gap:16},children:[e.jsxs("span",{children:[ae.words," ",k("docEditor.words","words")]}),e.jsxs("span",{children:[ae.chars," ",k("docEditor.chars","characters")]}),e.jsxs("span",{children:[x.length," ",k("docEditor.blocks","blocks")]}),e.jsxs("span",{children:["~",ae.readingTime," ",k("docEditor.readingTime","min read")]})]})]})});Mn.displayName="NiceDocumentEditor";const Zi=["street","streetNumber","apartment","city","postalCode","state","country"],ut={street:"Street",streetNumber:"Number",apartment:"Apt/Suite",city:"City",postalCode:"Postal Code",state:"State/Province",country:"Country"},Sn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f={},onChange:j,fields:R=Zi,placeholders:Q={},countries:q,layout:Z="vertical",countryFirst:y=!1,validatePostalCode:T},A)=>{const k=G.Nl(D,M),z=k==="hidden";k==="disabled"&&(o=!0),k==="readOnly"&&(p=!0);const{t:S}=G.ce(),x=G.hl(M),m=i.useCallback((u,d)=>{j==null||j({...f,[u]:d})},[f,j]),N=i.useMemo(()=>{if(T&&f.postalCode)return T(f.postalCode,f.country)},[T,f.postalCode,f.country]),$=i.useMemo(()=>y&&R.includes("country")?["country",...R.filter(u=>u!=="country")]:R,[R,y]),L=`nice-address nice-address--${Z} nice-size-${v}`;return z?null:e.jsxs("div",{ref:A,id:x,className:`${L}${E?` ${E}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:H,role:"group","aria-label":t??S("address","Address"),children:[t&&e.jsxs("label",{className:"nice-address__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-address__fields",children:$.map(u=>u==="country"&&q?e.jsxs("div",{className:`nice-address__field nice-address__field--${u}`,children:[e.jsx("label",{className:"nice-address__field-label",children:S(u,ut[u])}),e.jsxs("select",{className:"nice-input nice-select",value:f.country??"",onChange:d=>m("country",d.target.value),disabled:o,"aria-label":S(u,ut[u]),children:[e.jsx("option",{value:"",children:Q.country??S("selectCountry","— Select country —")}),q.map(d=>e.jsx("option",{value:d.code,children:d.name},d.code))]})]},u):e.jsxs("div",{className:`nice-address__field nice-address__field--${u}`,children:[e.jsx("label",{className:"nice-address__field-label",children:S(u,ut[u])}),e.jsx("input",{className:`nice-input${u==="postalCode"&&N?" nice-input--error":""}`,type:"text",name:C?`${C}.${u}`:u,value:f[u]??"",onChange:d=>m(u,d.target.value),placeholder:Q[u]??"",disabled:o,readOnly:p,"aria-label":S(u,ut[u])}),u==="postalCode"&&N&&e.jsx("span",{className:"nice-error-text",children:N})]},u))}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Sn.displayName="NiceAddressInput";const Vi=[{code:"PLN",symbol:"zł",name:"Polish Zloty"},{code:"EUR",symbol:"€",name:"Euro"},{code:"USD",symbol:"$",name:"US Dollar"},{code:"GBP",symbol:"£",name:"British Pound"},{code:"CZK",symbol:"Kč",name:"Czech Koruna"},{code:"CHF",symbol:"Fr",name:"Swiss Franc"}],En=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f,onChange:j,onBlur:R,currency:Q="PLN",onCurrencyChange:q,currencies:Z=Vi,useMinorUnit:y=!1,min:T,max:A,locale:k,placeholder:z,showCurrencySelector:S},x)=>{const m=G.Nl(D,M),N=m==="hidden";m==="disabled"&&(o=!0),m==="readOnly"&&(p=!0);const{t:$}=G.ce(),L=G.hl(M),u=i.useMemo(()=>Z.find(l=>l.code===Q)??Z[0],[Q,Z]),d=(u==null?void 0:u.decimals)??2,I=i.useMemo(()=>f==null?"":(y?f/Math.pow(10,d):f).toFixed(d),[f,y,d]),w=i.useCallback(l=>{const h=l.replace(/[^\d.,\-]/g,"").replace(",",".");if(h===""||h==="-"){j==null||j(null);return}const c=parseFloat(h);if(isNaN(c))return;const s=y?Math.round(c*Math.pow(10,d)):c;T!=null&&s<T||A!=null&&s>A||(j==null||j(s))},[j,y,d,T,A]),_=S??Z.length>1,g=i.useMemo(()=>{if(f==null)return"";const l=y?f/Math.pow(10,d):f;try{return new Intl.NumberFormat(k,{style:"currency",currency:(u==null?void 0:u.code)??"USD",minimumFractionDigits:d}).format(l)}catch{return`${l.toFixed(d)} ${u==null?void 0:u.code}`}},[f,y,d,k,u]);return N?null:e.jsxs("div",{ref:x,id:L,className:`nice-currency nice-size-${v}${E?` ${E}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:H,children:[t&&e.jsxs("label",{className:"nice-currency__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-currency__row",children:[_&&e.jsx("select",{className:"nice-currency__select nice-select",value:Q,onChange:l=>q==null?void 0:q(l.target.value),disabled:o,"aria-label":$("currency","Currency"),children:Z.map(l=>e.jsxs("option",{value:l.code,children:[l.symbol," ",l.code]},l.code))}),!_&&e.jsx("span",{className:"nice-currency__symbol",children:u==null?void 0:u.symbol}),e.jsx("input",{className:"nice-input nice-currency__amount",type:"text",inputMode:"decimal",name:C,value:I,onChange:l=>w(l.target.value),onBlur:R,placeholder:z??`0.${"0".repeat(d)}`,disabled:o,readOnly:p,"aria-label":$("amount","Amount")})]}),g&&f!=null&&e.jsx("span",{className:"nice-currency__formatted",children:g}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});En.displayName="NiceCurrencyInput";const Yi=[{target:".nice-invoice-lines",titleKey:"tutorial.invoiceLineEditor.intro.title",title:"Invoice lines",contentKey:"tutorial.invoiceLineEditor.intro.content",content:"Add line items with quantity, unit price, VAT and discount — net, gross and the VAT breakdown are calculated automatically.",placement:"auto"}];let Gi=1;function Qi(t){return{id:`new-${Gi++}`,description:"",quantity:1,unitPrice:0,vatRate:t,discount:0,unit:"szt."}}function Dn(t){const n=t.quantity*t.unitPrice*(1-(t.discount??0)/100),a=Math.round(n*100)/100,r=Math.round(a*(t.vatRate??0)/100*100)/100;return{...t,netAmount:a,grossAmount:a+r}}function Bi(t){const n=t.map(Dn),a=n.reduce((C,M)=>C+(M.netAmount??0),0),r=n.reduce((C,M)=>C+(M.grossAmount??0),0),o=r-a,p=new Map;for(const C of n){const M=C.vatRate??0,E=p.get(M)??{base:0,amount:0};E.base+=C.netAmount??0,E.amount+=(C.grossAmount??0)-(C.netAmount??0),p.set(M,E)}const v=Array.from(p.entries()).map(([C,M])=>({rate:C,base:Math.round(M.base*100)/100,amount:Math.round(M.amount*100)/100}));return{totalNet:Math.round(a*100)/100,totalVat:Math.round(o*100)/100,totalGross:Math.round(r*100)/100,vatBreakdown:v}}const Tn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f=[],onChange:j,onTotalsChange:R,currencySymbol:Q="zł",defaultVatRate:q=23,vatRates:Z=[0,5,8,23],units:y=["szt.","h","kg","m","usł."],showDiscount:T=!0,showUnit:A=!0,showTotals:k=!0,editable:z=!0,maxLines:S,tutorial:x},m)=>{const N=G.Nl(D,M),$=N==="hidden";N==="disabled"&&(o=!0),N==="readOnly"&&(p=!0);const{t:L}=G.ce(),u=G.hl(M),d=i.useMemo(()=>f.map(Dn),[f]),I=i.useMemo(()=>Bi(f),[f]);i.useEffect(()=>{R==null||R(I)},[I,R]);const w=i.useCallback((h,c,s)=>{const F=[...f];F[h]={...F[h],[c]:s},j==null||j(F)},[f,j]),_=i.useCallback(()=>{S&&f.length>=S||(j==null||j([...f,Qi(q)]))},[f,j,q,S]),g=i.useCallback(h=>{j==null||j(f.filter((c,s)=>s!==h))},[f,j]),l=h=>`${h.toFixed(2)} ${Q}`;return $?null:e.jsxs("div",{ref:m,id:u,className:`nice-invoice-lines nice-size-${v}${E?` ${E}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:{position:"relative",...H},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(x,Yi)})}),t&&e.jsxs("label",{className:"nice-invoice-lines__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("table",{className:"nice-invoice-lines__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"nice-il__th-num",children:"#"}),e.jsx("th",{className:"nice-il__th-desc",children:L("description","Description")}),e.jsx("th",{className:"nice-il__th-qty",children:L("qty","Qty")}),A&&e.jsx("th",{className:"nice-il__th-unit",children:L("unit","Unit")}),e.jsx("th",{className:"nice-il__th-price",children:L("unitPrice","Unit Price")}),T&&e.jsx("th",{className:"nice-il__th-disc",children:L("discount","Disc %")}),e.jsx("th",{className:"nice-il__th-vat",children:L("vat","VAT %")}),e.jsx("th",{className:"nice-il__th-net",children:L("net","Net")}),e.jsx("th",{className:"nice-il__th-gross",children:L("gross","Gross")}),z&&!p&&e.jsx("th",{className:"nice-il__th-actions"})]})}),e.jsx("tbody",{children:d.map((h,c)=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-il__cell-num",children:c+1}),e.jsx("td",{className:"nice-il__cell-desc",children:e.jsx("input",{className:"nice-input",type:"text",value:h.description,onChange:s=>w(c,"description",s.target.value),disabled:o,readOnly:p,placeholder:L("itemDescription","Item description")})}),e.jsx("td",{className:"nice-il__cell-qty",children:e.jsx("input",{className:"nice-input",type:"number",value:h.quantity,onChange:s=>w(c,"quantity",parseFloat(s.target.value)||0),disabled:o,readOnly:p,min:0,step:"any"})}),A&&e.jsx("td",{className:"nice-il__cell-unit",children:e.jsx("select",{className:"nice-select",value:h.unit??"",onChange:s=>w(c,"unit",s.target.value),disabled:o,children:y.map(s=>e.jsx("option",{value:s,children:s},s))})}),e.jsx("td",{className:"nice-il__cell-price",children:e.jsx("input",{className:"nice-input",type:"number",value:h.unitPrice,onChange:s=>w(c,"unitPrice",parseFloat(s.target.value)||0),disabled:o,readOnly:p,min:0,step:"0.01"})}),T&&e.jsx("td",{className:"nice-il__cell-disc",children:e.jsx("input",{className:"nice-input",type:"number",value:h.discount??0,onChange:s=>w(c,"discount",parseFloat(s.target.value)||0),disabled:o,readOnly:p,min:0,max:100})}),e.jsx("td",{className:"nice-il__cell-vat",children:e.jsx("select",{className:"nice-select",value:h.vatRate??0,onChange:s=>w(c,"vatRate",parseInt(s.target.value,10)),disabled:o,children:Z.map(s=>e.jsxs("option",{value:s,children:[s,"%"]},s))})}),e.jsx("td",{className:"nice-il__cell-net",children:l(h.netAmount??0)}),e.jsx("td",{className:"nice-il__cell-gross",children:l(h.grossAmount??0)}),z&&!p&&e.jsx("td",{className:"nice-il__cell-actions",children:e.jsx("button",{type:"button",className:"nice-btn nice-btn--icon nice-btn--sm",onClick:()=>g(c),disabled:o,title:L("remove","Remove"),children:"✕"})})]},h.id))})]}),z&&!p&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outlined nice-btn--sm nice-invoice-lines__add",onClick:_,disabled:o||S!=null&&f.length>=S,children:["+ ",L("addLine","Add line")]}),k&&e.jsxs("div",{className:"nice-invoice-lines__totals",children:[e.jsxs("div",{className:"nice-il__total-row",children:[e.jsxs("span",{children:[L("totalNet","Net total"),":"]}),e.jsx("span",{className:"nice-il__total-value",children:l(I.totalNet)})]}),I.vatBreakdown.map(h=>e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--vat",children:[e.jsxs("span",{children:["VAT ",h.rate,"%:"]}),e.jsx("span",{className:"nice-il__total-value",children:l(h.amount)})]},h.rate)),e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--gross",children:[e.jsxs("span",{children:[L("totalGross","Gross total"),":"]}),e.jsx("span",{className:"nice-il__total-value nice-il__total-value--gross",children:l(I.totalGross)})]})]}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Tn.displayName="NiceInvoiceLineEditor";const zn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f=[],onChange:j,contacts:R=[],onSearch:Q,searchDelay:q=300,multiple:Z=!1,placeholder:y,onContactClick:T,maxSelections:A},k)=>{const z=G.Nl(D,M),S=z==="hidden";z==="disabled"&&(o=!0),z==="readOnly"&&(p=!0);const{t:x}=G.ce(),m=G.hl(M),[N,$]=i.useState(""),[L,u]=i.useState([]),[d,I]=i.useState(!1),[w,_]=i.useState(!1),g=i.useMemo(()=>{const s=[...R,...L],F=new Map(s.map(O=>[O.id,O]));return f.map(O=>F.get(O)).filter(Boolean)},[f,R,L]),l=i.useCallback(s=>{if($(s),s.length<1){u([]),I(!1);return}if(Q){_(!0);const Y=setTimeout(async()=>{const J=await Q(s);u(J),I(!0),_(!1)},q);return()=>clearTimeout(Y)}const F=s.toLowerCase(),O=R.filter(Y=>{var J,me;return Y.name.toLowerCase().includes(F)||((J=Y.email)==null?void 0:J.toLowerCase().includes(F))||((me=Y.phone)==null?void 0:me.includes(s))});u(O),I(!0)},[Q,R,q]),h=i.useCallback(s=>{if(Z)if(f.includes(s.id))j==null||j(f.filter(F=>F!==s.id));else{if(A&&f.length>=A)return;j==null||j([...f,s.id])}else j==null||j([s.id]),I(!1),$("")},[f,j,Z,A]),c=i.useCallback(s=>{j==null||j(f.filter(F=>F!==s))},[f,j]);return S?null:e.jsxs("div",{ref:k,id:m,className:`nice-contact-picker nice-size-${v}${E?` ${E}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:H,children:[t&&e.jsxs("label",{className:"nice-contact-picker__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),g.length>0&&e.jsx("div",{className:"nice-contact-picker__chips",children:g.map(s=>e.jsxs("span",{className:"nice-contact-picker__chip",onClick:()=>T==null?void 0:T(s),children:[s.avatarUrl&&e.jsx("img",{src:s.avatarUrl,alt:"",className:"nice-contact-picker__chip-avatar"}),e.jsx("span",{children:s.name}),!p&&e.jsx("button",{type:"button",className:"nice-contact-picker__chip-remove",onClick:F=>{F.stopPropagation(),c(s.id)},disabled:o,children:"×"})]},s.id))}),!p&&e.jsxs("div",{className:"nice-contact-picker__search",children:[e.jsx("input",{className:"nice-input",type:"text",value:N,onChange:s=>l(s.target.value),onFocus:()=>N.length>0&&I(!0),onBlur:()=>setTimeout(()=>I(!1),200),placeholder:y??x("searchContacts","Search contacts…"),disabled:o,"aria-label":x("searchContacts","Search contacts")}),w&&e.jsx("span",{className:"nice-contact-picker__spinner",children:"⏳"})]}),d&&L.length>0&&e.jsx("div",{className:"nice-contact-picker__dropdown",role:"listbox",children:L.map(s=>e.jsxs("div",{className:`nice-contact-picker__option${f.includes(s.id)?" nice-contact-picker__option--selected":""}`,role:"option","aria-selected":f.includes(s.id),onClick:()=>h(s),children:[s.avatarUrl&&e.jsx("img",{src:s.avatarUrl,alt:"",className:"nice-contact-picker__option-avatar"}),e.jsxs("div",{className:"nice-contact-picker__option-info",children:[e.jsx("span",{className:"nice-contact-picker__option-name",children:s.name}),s.subtitle&&e.jsx("span",{className:"nice-contact-picker__option-subtitle",children:s.subtitle}),s.email&&e.jsx("span",{className:"nice-contact-picker__option-email",children:s.email})]}),s.type&&e.jsx("span",{className:"nice-contact-picker__option-type",children:s.type==="person"?"👤":"🏢"})]},s.id))}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});zn.displayName="NiceContactPicker";const Ji=[{target:".nice-pdf-annotation",titleKey:"tutorial.pdfAnnotationEditor.intro.title",title:"PDF annotations",contentKey:"tutorial.pdfAnnotationEditor.intro.content",content:"Pick a tool from the toolbar (highlight, underline, freehand, text…), mark up the page, navigate pages and zoom as needed.",placement:"auto"}],ea=["highlight","underline","strikethrough","freehand","text","rect","arrow"],ta={highlight:"🖍️",underline:"⎁",strikethrough:"S̶",freehand:"✏️",text:"T",rect:"▭",arrow:"→",stamp:"🔏"},Rn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",id:C,className:M,style:E,accessMode:H,src:D,annotations:f=[],onAnnotationsChange:j,activeTool:R,onToolChange:Q,currentPage:q=1,onPageChange:Z,totalPages:y=1,defaultColor:T="var(--nice-warning, #ffff00)",tools:A=ea,author:k,zoom:z=1,onZoomChange:S,onAnnotationClick:x,onAnnotationDelete:m,tutorial:N},$)=>{const L=G.Nl(H,C),u=L==="hidden";L==="disabled"&&(o=!0),L==="readOnly"&&(p=!0);const{t:d}=G.ce(),I=G.hl(C),w=f.filter(l=>l.page===q),_=i.useCallback(l=>{Q==null||Q(R===l?null:l)},[R,Q]),g=i.useCallback(l=>{if(p||!R||R==="freehand")return;const h=l.currentTarget.getBoundingClientRect(),c=(l.clientX-h.left)/h.width,s=(l.clientY-h.top)/h.height,F={id:`ann-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,tool:R,page:q,x:c,y:s,color:T,author:k,createdAt:new Date().toISOString(),text:R==="text"?"":void 0};j==null||j([...f,F])},[p,R,q,T,k,f,j]);return u?null:e.jsxs("div",{ref:$,id:I,className:`nice-pdf-annotation nice-size-${v}${M?` ${M}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:{position:"relative",...E},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(G.Ud,{steps:G.Kd(N,Ji)})}),t&&e.jsxs("div",{className:"nice-pdf-annotation__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),!p&&e.jsxs("div",{className:"nice-pdf-annotation__toolbar",children:[A.map(l=>e.jsx("button",{type:"button",className:`nice-pdf-annotation__tool-btn${R===l?" nice-pdf-annotation__tool-btn--active":""}`,onClick:()=>_(l),disabled:o,title:d(`pdfTool_${l}`,l),children:ta[l]},l)),e.jsx("span",{className:"nice-pdf-annotation__toolbar-sep"}),e.jsx("button",{type:"button",disabled:o,onClick:()=>S==null?void 0:S(Math.max(.25,z-.25)),title:d("zoomOut","Zoom out"),children:"−"}),e.jsxs("span",{className:"nice-pdf-annotation__zoom",children:[Math.round(z*100),"%"]}),e.jsx("button",{type:"button",disabled:o,onClick:()=>S==null?void 0:S(Math.min(4,z+.25)),title:d("zoomIn","Zoom in"),children:"+"})]}),e.jsxs("div",{className:"nice-pdf-annotation__viewport",style:{transform:`scale(${z})`,transformOrigin:"top left"},children:[e.jsx("iframe",{src:D,className:"nice-pdf-annotation__frame",title:d("pdfViewer","PDF Viewer")}),e.jsx("div",{className:"nice-pdf-annotation__layer",onClick:g,children:w.map(l=>e.jsxs("div",{className:`nice-pdf-annotation__mark nice-pdf-annotation__mark--${l.tool}`,style:{left:`${l.x*100}%`,top:`${l.y*100}%`,backgroundColor:l.color},onClick:h=>{h.stopPropagation(),x==null||x(l)},title:l.text??l.tool,children:[l.text&&e.jsx("span",{children:l.text}),!p&&e.jsx("button",{type:"button",className:"nice-pdf-annotation__mark-delete",onClick:h=>{h.stopPropagation(),m==null||m(l.id)},children:"×"})]},l.id))})]}),e.jsxs("div",{className:"nice-pdf-annotation__pager",children:[e.jsx("button",{type:"button",disabled:o||q<=1,onClick:()=>Z==null?void 0:Z(q-1),children:"◀"}),e.jsx("span",{children:d("pageOf","{page} / {total}").replace("{page}",String(q)).replace("{total}",String(y))}),e.jsx("button",{type:"button",disabled:o||q>=y,onClick:()=>Z==null?void 0:Z(q+1),children:"▶"})]}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Rn.displayName="NicePDFAnnotationEditor";const Ln=i.forwardRef(({label:t,helperText:n,error:a,disabled:r,readOnly:o,size:p="md",id:v,className:C,style:M,accessMode:E,pages:H,selectedPageId:D,content:f="",contentFormat:j="html",editing:R=!1,onPageSelect:Q,onContentChange:q,onSave:Z,onCreatePage:y,onDeletePage:T,onEditToggle:A,onVersionHistory:k,sidebarWidth:z=260,sidebarCollapsed:S=!1,onSidebarToggle:x,searchable:m=!0,onSearch:N},$)=>{const L=G.Nl(E,v),u=L==="hidden";L==="disabled"&&(r=!0),L==="readOnly"&&(o=!0);const{t:d}=G.ce(),I=G.hl(v),[w,_]=i.useState(""),[g,l]=i.useState(""),[h,c]=i.useState(!1),s=i.useMemo(()=>{const J=me=>{for(const de of me){if(de.id===D)return de;if(de.children){const P=J(de.children);if(P)return P}}};return J(H)},[H,D]),F=i.useCallback(J=>{_(J),N==null||N(J)},[N]),O=i.useCallback(()=>{g.trim()&&(y==null||y(D??null,g.trim()),l(""),c(!1))},[g,D,y]),Y=(J,me=0)=>e.jsx("ul",{className:"nice-wiki__tree",style:{paddingLeft:me>0?16:0},children:J.map(de=>{var P;return e.jsxs("li",{className:"nice-wiki__tree-item",children:[e.jsxs("div",{className:`nice-wiki__tree-node${de.id===D?" nice-wiki__tree-node--active":""}${de.isDraft?" nice-wiki__tree-node--draft":""}`,onClick:()=>Q==null?void 0:Q(de),role:"treeitem","aria-selected":de.id===D,children:[e.jsx("span",{className:"nice-wiki__tree-icon",children:(P=de.children)!=null&&P.length?"📁":"📄"}),e.jsx("span",{className:"nice-wiki__tree-title",children:de.title}),de.isDraft&&e.jsx("span",{className:"nice-wiki__tree-draft",children:d("draft","Draft")})]}),de.children&&de.children.length>0&&Y(de.children,me+1)]},de.id)})});return u?null:e.jsxs("div",{ref:$,id:I,className:`nice-wiki nice-size-${p}${C?` ${C}`:""}${r?" nice-disabled":""}`,style:M,children:[!S&&e.jsxs("aside",{className:"nice-wiki__sidebar",style:{width:z},children:[e.jsxs("div",{className:"nice-wiki__sidebar-header",children:[e.jsx("span",{className:"nice-wiki__sidebar-title",children:t??d("wiki","Wiki")}),x&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-toggle",onClick:()=>x(!0),children:"«"})]}),m&&e.jsx("input",{type:"text",className:"nice-input nice-wiki__search",value:w,onChange:J=>F(J.target.value),placeholder:d("searchPages","Search pages…"),disabled:r}),e.jsx("div",{className:"nice-wiki__page-tree",role:"tree",children:Y(H)}),y&&!o&&e.jsx("div",{className:"nice-wiki__sidebar-footer",children:h?e.jsxs("div",{className:"nice-wiki__create-form",children:[e.jsx("input",{type:"text",className:"nice-input",value:g,onChange:J=>l(J.target.value),placeholder:d("pageTitle","Page title"),onKeyDown:J=>J.key==="Enter"&&O(),disabled:r}),e.jsx("button",{type:"button",disabled:r||!g.trim(),onClick:O,children:"✓"}),e.jsx("button",{type:"button",onClick:()=>c(!1),children:"✕"})]}):e.jsxs("button",{type:"button",className:"nice-wiki__add-page",onClick:()=>c(!0),disabled:r,children:["+ ",d("newPage","New page")]})})]}),S&&x&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-expand",onClick:()=>x(!1),children:"»"}),e.jsx("main",{className:"nice-wiki__content",children:s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-wiki__content-header",children:[e.jsx("h1",{className:"nice-wiki__page-title",children:s.title}),e.jsxs("div",{className:"nice-wiki__content-actions",children:[A&&!o&&e.jsx("button",{type:"button",disabled:r,onClick:()=>A(!R),children:R?d("preview","Preview"):d("edit","Edit")}),k&&e.jsx("button",{type:"button",disabled:r,onClick:()=>k(s.id),children:d("history","History")}),T&&!o&&e.jsx("button",{type:"button",className:"nice-btn--danger",disabled:r,onClick:()=>T(s.id),children:d("delete","Delete")})]})]}),s.updatedAt&&e.jsxs("div",{className:"nice-wiki__page-meta",children:[s.updatedBy&&e.jsxs("span",{children:[d("lastEditedBy","Last edited by")," ",s.updatedBy]}),e.jsx("span",{children:new Date(s.updatedAt).toLocaleDateString()})]}),R?e.jsxs("div",{className:"nice-wiki__editor",children:[e.jsx("textarea",{className:"nice-wiki__editor-textarea",value:f,onChange:J=>q==null?void 0:q(J.target.value),disabled:r}),Z&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",disabled:r,onClick:()=>Z(s.id,f),children:d("save","Save")})]}):e.jsx("div",{className:"nice-wiki__viewer",children:j==="html"?e.jsx("div",{className:"nice-wiki__html",dangerouslySetInnerHTML:{__html:G.dl(f)}}):e.jsx("pre",{className:"nice-wiki__markdown",children:f})})]}):e.jsx("div",{className:"nice-wiki__empty",children:e.jsx("p",{children:d("selectPage","Select a page from the sidebar or create a new one.")})})}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Ln.displayName="NiceWiki";const na=[{code:"PL",label:"Polska",prefix:"PL",pattern:/^\d{10}$/,placeholder:"1234567890"},{code:"DE",label:"Deutschland",prefix:"DE",pattern:/^\d{9}$/,placeholder:"123456789"},{code:"GB",label:"United Kingdom",prefix:"GB",pattern:/^\d{9}(\d{3})?$/,placeholder:"123456789"},{code:"FR",label:"France",prefix:"FR",pattern:/^[A-Z0-9]{2}\d{9}$/,placeholder:"XX123456789"},{code:"CZ",label:"Česko",prefix:"CZ",pattern:/^\d{8,10}$/,placeholder:"12345678"},{code:"SK",label:"Slovensko",prefix:"SK",pattern:/^\d{10}$/,placeholder:"1234567890"},{code:"IT",label:"Italia",prefix:"IT",pattern:/^\d{11}$/,placeholder:"12345678901"},{code:"ES",label:"España",prefix:"ES",pattern:/^[A-Z0-9]\d{7}[A-Z0-9]$/,placeholder:"X1234567X"}],An=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f="",onChange:j,countryCode:R="PL",onCountryChange:Q,countries:q=na,showCountrySelector:Z=!0,autoPrefixVat:y=!0,validationResult:T,onValidateRequest:A,placeholder:k},z)=>{const S=G.Nl(D,M),x=S==="hidden";S==="disabled"&&(o=!0),S==="readOnly"&&(p=!0);const{t:m}=G.ce(),N=G.hl(M),$=i.useMemo(()=>q.find(w=>w.code===R)??q[0],[q,R]),L=i.useCallback(w=>{let _=w.toUpperCase();return $&&_.startsWith($.prefix)&&(_=_.slice($.prefix.length)),$?$.pattern.test(_):_.length>0},[$]),u=i.useCallback(w=>{const _=w.target.value.replace(/\s/g,"");j==null||j(_,L(_))},[j,L]),d=y&&f&&$&&!f.toUpperCase().startsWith($.prefix)?`${$.prefix}${f}`:f,I=L(f);return x?null:e.jsxs("div",{ref:z,id:N,className:`nice-vat-input nice-size-${v}${E?` ${E}`:""}${a||!I&&f.length>0?" nice-error":""}${o?" nice-disabled":""}`,style:H,children:[t&&e.jsxs("label",{className:"nice-vat-input__label",htmlFor:`${N}-input`,children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-vat-input__row",children:[Z&&e.jsx("select",{className:"nice-vat-input__country",value:R,onChange:w=>Q==null?void 0:Q(w.target.value),disabled:o||p,children:q.map(w=>e.jsx("option",{value:w.code,children:w.prefix},w.code))}),e.jsx("input",{id:`${N}-input`,className:"nice-input nice-vat-input__field",type:"text",name:C,value:f,onChange:u,readOnly:p,disabled:o,placeholder:k??($==null?void 0:$.placeholder),required:r,"aria-invalid":!I&&f.length>0}),A&&f.length>0&&e.jsx("button",{type:"button",className:"nice-vat-input__verify",disabled:o||!I,onClick:()=>A(y?d:f,R),title:m("verifyVat","Verify VAT number"),children:"🔍"})]}),T&&e.jsxs("div",{className:`nice-vat-input__result nice-vat-input__result--${T.valid?"valid":"invalid"}`,children:[T.valid?"✅":"❌"," ",T.companyName??T.error??(T.valid?m("vatValid","VAT number valid"):m("vatInvalid","VAT number invalid"))]}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});An.displayName="NiceVatInput";const ia=[{id:"pl-23",label:"23%",rate:.23,countryCode:"PL",category:"standard",isDefault:!0},{id:"pl-8",label:"8%",rate:.08,countryCode:"PL",category:"reduced"},{id:"pl-5",label:"5%",rate:.05,countryCode:"PL",category:"reduced"},{id:"pl-0",label:"0%",rate:0,countryCode:"PL",category:"zero"},{id:"pl-zw",label:"zw.",rate:0,countryCode:"PL",category:"exempt"},{id:"pl-np",label:"n.p.",rate:0,countryCode:"PL",category:"exempt"}],In=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f,onChange:j,rates:R,countryCode:Q,placeholder:q,showPercentage:Z=!0},y)=>{const T=G.Nl(D,M),A=T==="hidden";T==="disabled"&&(o=!0),T==="readOnly"&&(p=!0);const{t:k}=G.ce(),z=G.hl(M),S=i.useMemo(()=>{const m=R??ia;return Q?m.filter(N=>!N.countryCode||N.countryCode===Q):m},[R,Q]),x=i.useCallback(m=>{const N=m.target.value,$=S.find(L=>L.id===N);$&&(j==null||j(N,$))},[j,S]);return A?null:e.jsxs("div",{ref:y,id:z,className:`nice-tax-rate nice-size-${v}${E?` ${E}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:H,children:[t&&e.jsxs("label",{className:"nice-tax-rate__label",htmlFor:`${z}-select`,children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("select",{id:`${z}-select`,className:"nice-select nice-tax-rate__select",name:C,value:f??"",onChange:x,disabled:o||p,required:r,children:[e.jsx("option",{value:"",disabled:!0,children:q??k("selectRate","Select rate…")}),S.map(m=>e.jsxs("option",{value:m.id,children:[m.label,Z&&m.category!=="exempt"?` (${(m.rate*100).toFixed(0)}%)`:""]},m.id))]}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});In.displayName="NiceTaxRatePicker";const aa={asset:"var(--nice-color-info, #5bc0de)",liability:"var(--nice-color-warning, #f0ad4e)",equity:"var(--nice-color-success, #5cb85c)",revenue:"var(--nice-color-primary, #337ab7)",expense:"var(--nice-color-error, #d9534f)"},Pn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",name:C,id:M,className:E,style:H,accessMode:D,value:f,onChange:j,accounts:R,treeView:Q=!1,placeholder:q,searchable:Z=!0,showType:y=!0,onSearch:T},A)=>{const k=G.Nl(D,M),z=k==="hidden";k==="disabled"&&(o=!0),k==="readOnly"&&(p=!0);const{t:S}=G.ce(),x=G.hl(M),[m,N]=i.useState(""),[$,L]=i.useState(!1),u=i.useMemo(()=>{const g=l=>{for(const h of l){if(h.code===f)return h;if(h.children){const c=g(h.children);if(c)return c}}};return g(R)},[R,f]),d=i.useMemo(()=>{const g=[],l=h=>{for(const c of h)g.push(c),c.children&&l(c.children)};return l(R),g},[R]),I=i.useMemo(()=>{if(!m)return d;const g=m.toLowerCase();return d.filter(l=>l.code.toLowerCase().includes(g)||l.name.toLowerCase().includes(g))},[d,m]),w=i.useCallback(g=>{N(g),T==null||T(g),L(!0)},[T]),_=i.useCallback(g=>{j==null||j(g.code,g),L(!1),N("")},[j]);return z?null:e.jsxs("div",{ref:A,id:x,className:`nice-account-picker nice-size-${v}${E?` ${E}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:H,children:[t&&e.jsxs("label",{className:"nice-account-picker__label",htmlFor:`${x}-input`,children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-account-picker__control",children:Z&&!p?e.jsx("input",{id:`${x}-input`,className:"nice-input",type:"text",value:$?m:u?`${u.code} — ${u.name}`:"",onChange:g=>w(g.target.value),onFocus:()=>{N(""),L(!0)},onBlur:()=>setTimeout(()=>L(!1),200),placeholder:q??S("searchAccount","Search account…"),disabled:o,required:r}):e.jsx("div",{className:"nice-account-picker__display",children:u?`${u.code} — ${u.name}`:q??S("selectAccount","Select account…")})}),$&&I.length>0&&e.jsx("div",{className:"nice-account-picker__dropdown",role:"listbox",children:I.map(g=>e.jsxs("div",{className:`nice-account-picker__option${g.code===f?" nice-account-picker__option--selected":""}${g.isActive===!1?" nice-account-picker__option--inactive":""}`,role:"option","aria-selected":g.code===f,onClick:()=>_(g),children:[y&&g.type&&e.jsx("span",{className:"nice-account-picker__type",style:{color:aa[g.type]},title:g.type,children:"●"}),e.jsx("span",{className:"nice-account-picker__code",children:g.code}),e.jsx("span",{className:"nice-account-picker__name",children:g.name})]},g.code))}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Pn.displayName="NiceAccountPicker";const Wn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",id:C,className:M,style:E,accessMode:H,mode:D="manual",onScan:f,onModeChange:j,beepOnScan:R=!0,beepFrequency:Q=1800,beepDuration:q=150,placeholder:Z,scanHistory:y=[],showHistory:T=!0,maxHistory:A=10,autoFocus:k=!0,onCameraFrame:z},S)=>{const x=G.Nl(H,C),m=x==="hidden";x==="disabled"&&(o=!0),x==="readOnly"&&(p=!0);const{t:N}=G.ce(),$=G.hl(C),[L,u]=i.useState(""),d=i.useRef(null),I=i.useRef(null),w=i.useCallback(()=>{if(R)try{I.current||(I.current=new AudioContext);const l=I.current,h=l.createOscillator(),c=l.createGain();h.connect(c),c.connect(l.destination),h.frequency.value=Q,h.type="square",c.gain.value=.3,h.start(),h.stop(l.currentTime+q/1e3)}catch{}},[R,Q,q]),_=i.useCallback(()=>{var l;L.trim()&&(w(),f==null||f({value:L.trim(),format:"manual",scannedAt:new Date}),u(""),(l=d.current)==null||l.focus())},[L,f,w]),g=y.slice(0,A);return m?null:e.jsxs("div",{ref:S,id:$,className:`nice-scanner nice-size-${v}${M?` ${M}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:E,children:[t&&e.jsxs("div",{className:"nice-scanner__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsxs("div",{className:"nice-scanner__modes",children:[e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${D==="camera"?" nice-scanner__mode-btn--active":""}`,onClick:()=>j==null?void 0:j("camera"),disabled:o,children:["📷 ",N("camera","Camera")]}),e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${D==="manual"?" nice-scanner__mode-btn--active":""}`,onClick:()=>j==null?void 0:j("manual"),disabled:o,children:["⌨️ ",N("manual","Manual")]})]}),D==="camera"&&e.jsx("div",{className:"nice-scanner__camera",children:e.jsx("div",{className:"nice-scanner__viewfinder",children:e.jsxs("div",{className:"nice-scanner__viewfinder-overlay",children:[e.jsx("span",{children:"📷"}),e.jsx("p",{children:N("cameraPlaceholder","Camera preview — connect scanner adapter")})]})})}),D==="manual"&&!p&&e.jsxs("div",{className:"nice-scanner__manual",children:[e.jsx("input",{ref:d,className:"nice-input nice-scanner__input",type:"text",value:L,onChange:l=>u(l.target.value),onKeyDown:l=>l.key==="Enter"&&_(),placeholder:Z??N("enterCode","Enter or scan code…"),disabled:o,autoFocus:k}),e.jsx("button",{type:"button",className:"nice-scanner__submit",onClick:_,disabled:o||!L.trim(),children:"✓"})]}),T&&g.length>0&&e.jsxs("div",{className:"nice-scanner__history",children:[e.jsx("div",{className:"nice-scanner__history-label",children:N("recentScans","Recent scans")}),g.map((l,h)=>e.jsxs("div",{className:"nice-scanner__history-item",children:[e.jsx("span",{className:"nice-scanner__history-value",children:l.value}),l.format&&e.jsx("span",{className:"nice-scanner__history-format",children:l.format}),e.jsx("span",{className:"nice-scanner__history-time",children:l.scannedAt.toLocaleTimeString()})]},h))]}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Wn.displayName="NiceScannerControl";const Hn=i.forwardRef(({label:t,helperText:n,error:a,required:r,disabled:o,readOnly:p,size:v="md",id:C,className:M,style:E,accessMode:H,value:D="",onChange:f,onComplete:j,length:R=4,masked:Q=!0,showKeypad:q=!1,autoSubmit:Z=!0,shake:y=!1,placeholderChar:T="·"},A)=>{const k=G.Nl(H,C),z=k==="hidden";k==="disabled"&&(o=!0),k==="readOnly"&&(p=!0);const{t:S}=G.ce(),x=G.hl(C),m=i.useRef([]),[N,$]=i.useState(!1);i.useEffect(()=>{if(y){$(!0);const w=setTimeout(()=>$(!1),500);return()=>clearTimeout(w)}},[y]);const L=D.split("").slice(0,R);for(;L.length<R;)L.push("");const u=i.useCallback((w,_)=>{var h;const g=[...L];g[w]=_;const l=g.join("");f==null||f(l),_&&w<R-1&&((h=m.current[w+1])==null||h.focus()),Z&&l.length===R&&l.indexOf("")===-1&&(j==null||j(l))},[L,R,f,j,Z]),d=i.useCallback((w,_)=>{var g,l,h;w.key==="Backspace"&&!L[_]&&_>0&&((g=m.current[_-1])==null||g.focus(),u(_-1,"")),w.key==="ArrowLeft"&&_>0&&((l=m.current[_-1])==null||l.focus()),w.key==="ArrowRight"&&_<R-1&&((h=m.current[_+1])==null||h.focus())},[L,R,u]),I=i.useCallback(w=>{var _,g,l;if(w==="clear"){f==null||f(""),(_=m.current[0])==null||_.focus();return}if(w==="backspace"){const h=D.slice(0,-1);f==null||f(h);const c=Math.max(0,h.length-1);(g=m.current[c])==null||g.focus();return}if(D.length<R){const h=D+w;f==null||f(h),h.length<R&&((l=m.current[h.length])==null||l.focus()),Z&&h.length===R&&(j==null||j(h))}},[D,R,f,j,Z]);return z?null:e.jsxs("div",{ref:A,id:x,className:`nice-pin nice-size-${v}${N?" nice-pin--shake":""}${M?` ${M}`:""}${a?" nice-error":""}${o?" nice-disabled":""}`,style:E,children:[t&&e.jsxs("label",{className:"nice-pin__label",children:[t,r&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-pin__boxes",children:L.map((w,_)=>e.jsx("input",{ref:g=>{m.current[_]=g},className:"nice-pin__box",type:Q?"password":"text",inputMode:"numeric",maxLength:1,value:w,onChange:g=>{const l=g.target.value.replace(/\D/g,"");l.length<=1&&u(_,l)},onKeyDown:g=>d(g,_),disabled:o,readOnly:p,placeholder:T,"aria-label":`${S("digit","Digit")} ${_+1}`},_))}),q&&!p&&e.jsx("div",{className:"nice-pin__keypad",children:["1","2","3","4","5","6","7","8","9","clear","0","backspace"].map(w=>e.jsx("button",{type:"button",className:`nice-pin__key${w==="clear"||w==="backspace"?" nice-pin__key--action":""}`,onClick:()=>I(w),disabled:o,children:w==="clear"?"C":w==="backspace"?"⌫":w},w))}),n&&e.jsx("span",{className:"nice-helper-text",children:n}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})});Hn.displayName="NicePinCodeInput";exports.$=Jt;exports.A=Rn;exports.B=yn;exports.C=Hn;exports.D=ri;exports.E=Wn;exports.H=$n;exports.I=In;exports.J=bn;exports.K=An;exports.L=Ln;exports.M=_n;exports.Q=cn;exports.R=kn;exports.S=mt;exports.T=pt;exports.U=on;exports.V=rt;exports.W=nn;exports.X=_t;exports.Y=He;exports.Z=lt;exports._=Le;exports.a=Pn;exports.a0=rn;exports.a1=tn;exports.a2=en;exports.a3=Ct;exports.a4=ht;exports.a5=mi;exports.a6=ji;exports.b=Sn;exports.c=un;exports.d=st;exports.f=sn;exports.g=zn;exports.i=En;exports.j=ai;exports.k=Mn;exports.l=li;exports.n=dn;exports.o=wt;exports.q=Cn;exports.r=wn;exports.s=pn;exports.t=Tn;exports.v=mn;exports.w=jn;exports.x=Jn;exports.y=Nn;exports.z=gn;