@nice2dev/ui 1.4.2 → 1.4.4

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.
@@ -1,432 +0,0 @@
1
- "use strict";const e=require("react/jsx-runtime"),r=require("@nice2dev/ui-core"),n=require("react"),it=require("react-dom"),Ze=require("./NiceSelect-BNPXs6FQ.cjs"),mt=require("./pickerCommons-CwcCc8Qi.cjs"),Qe=require("./devops-cgRBnZVX.cjs"),ht=require("./NiceForm-CT9hEXpc.cjs"),nt=require("./no-code-B3BHeyG-.cjs"),an=require("@nice2dev/i18n"),Mn=require("./NiceHtmlEditor-C1OVtLQ6.cjs"),Me=require("./NiceButton-DzCqkG5a.cjs"),Bt=require("./NiceColorPicker-BLwYNSXJ.cjs"),It=require("./NiceCodeEditor-DhdjnDLV.cjs"),kt=require("./injectStyleOnce-DeWaxcdf.cjs"),Tn=({min:t=0,max:i=100,step:a=1,startValue:o=t,endValue:l=i,onChange:g,showLabels:y=!0,formatLabel:M,valuePlacement:P="none",label:I,error:J,helperText:X,required:O,disabled:$,readOnly:Y,loading:ae,size:ne="md",id:le,className:G,style:B,accessMode:k,showKeyboardHints:s,labelPlacement:T,errorPlacement:F,labelWidth:R,controlWidth:_})=>{const b=r.useNiceAccessMode(k,le),N=b==="hidden";(b==="disabled"||b==="readOnly")&&($=!0);const{t:f}=r.useNiceTranslation(),E=r.useControlId(le),L=n.useRef(null),w=n.useMemo(()=>[r.COMMON_SHORTCUTS.increment,r.COMMON_SHORTCUTS.decrement,r.COMMON_SHORTCUTS.first,r.COMMON_SHORTCUTS.last,{key:"Tab",description:f("shortcuts.switchThumb","Switch thumb")}],[f]),d=p=>(p-t)/(i-t)*100,z=p=>M?M(p):String(p),j=n.useCallback(p=>{const C=Math.round(p/a)*a;return Math.max(t,Math.min(i,C))},[t,i,a]),h=n.useCallback((p,C)=>{p.preventDefault();const S=L.current;if(!S||$)return;const m=D=>{const W=S.getBoundingClientRect(),v=Math.max(0,Math.min(1,(D.clientX-W.left)/W.width)),q=j(t+v*(i-t));C==="start"?g?.(Math.min(q,l),l):g?.(o,Math.max(q,o))},A=()=>{document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",A)};document.addEventListener("pointermove",m),document.addEventListener("pointerup",A)},[t,i,j,o,l,g,$]),c=(p,C)=>{if($||Y)return;const S=C==="start"?o:l,m=C==="start"?t:o,A=C==="start"?l:i,D=Math.max(a,(i-t)/10),W=p.key==="ArrowRight"||p.key==="ArrowUp"?S+a:p.key==="ArrowLeft"||p.key==="ArrowDown"?S-a:p.key==="PageUp"?S+D:p.key==="PageDown"?S-D:p.key==="Home"?m:p.key==="End"?A:null;if(W===null)return;p.preventDefault();const v=Math.max(m,Math.min(A,j(W)));C==="start"?g?.(v,l):g?.(o,v)};return N?null:e.jsxs("div",{className:`nice-field nice-field--${ne} nice-field--rangeslider ${T==="left"?"nice-field--label-left":""} ${F==="right"?"nice-field--error-right":""} ${J?"nice-field--error":""} ${ae?"nice-field--loading":""} ${G||""}`,style:{...B,...R!=null&&{"--nice-field-label-width":typeof R=="number"?`${R}px`:R},..._!=null&&{"--nice-field-control-width":typeof _=="number"?`${_}px`:_}},"aria-busy":ae||void 0,children:[(I||P==="right"&&T!=="left")&&(T!=="left"?e.jsxs("div",{className:"nice-range-slider__header",children:[I?e.jsx("label",{className:"nice-field__label",htmlFor:E,children:e.jsxs("span",{className:"nice-field__label-text",children:[I,O&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:w,size:"sm"})]})}):e.jsx("span",{}),P==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--header",children:[z(o)," – ",z(l)]})]}):I&&e.jsx("label",{className:"nice-field__label",htmlFor:E,children:e.jsxs("span",{className:"nice-field__label-text",children:[I,O&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:w,size:"sm"})]})})),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-range-slider__stack",children:[e.jsxs("div",{className:`nice-range-slider ${y?"nice-range-slider--with-labels":""} ${I?"nice-range-slider--has-field-label":""}`,ref:L,children:[e.jsx("div",{className:"nice-range-slider__track",children:e.jsx("div",{className:"nice-range-slider__fill",style:{left:`${d(o)}%`,width:`${d(l)-d(o)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(o)}%`},onPointerDown:p=>Y?void 0:h(p,"start"),onKeyDown:p=>c(p,"start"),role:"slider","aria-label":f("rangeSlider.min","Minimum"),"aria-valuemin":t,"aria-valuemax":l,"aria-valuenow":o,"aria-valuetext":z(o),"aria-disabled":$||void 0,"aria-readonly":Y||void 0,tabIndex:$?-1:0,id:E}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(l)}%`},onPointerDown:p=>Y?void 0:h(p,"end"),onKeyDown:p=>c(p,"end"),role:"slider","aria-label":f("rangeSlider.max","Maximum"),"aria-valuemin":o,"aria-valuemax":i,"aria-valuenow":l,"aria-valuetext":z(l),"aria-disabled":$||void 0,"aria-readonly":Y||void 0,tabIndex:$?-1:0})]}),y&&e.jsxs("div",{className:"nice-range-slider__values",children:[e.jsx("span",{className:"nice-range-slider__values-start",style:{left:`${d(o)}%`},children:z(o)}),e.jsx("span",{className:"nice-range-slider__values-end",style:{left:`${d(l)}%`},children:z(l)})]}),P==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[z(o)," – ",z(l)]})]}),P==="right"&&T==="left"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[z(o)," – ",z(l)]}),ae&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),F==="right"&&J&&e.jsx("div",{className:"nice-field__error",role:"alert",children:J}),F==="right"&&!J&&X&&e.jsx("div",{className:"nice-field__helper",children:X})]}),F!=="right"&&J&&e.jsx("div",{className:"nice-field__error",role:"alert",children:J}),F!=="right"&&!J&&X&&e.jsx("div",{className:"nice-field__helper",children:X})]})},Rn={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160,small:64,medium:80,large:100},gt=6,ct=135,sn=405,st=sn-ct;function Mt(t,i,a,o){const l=(o-90)*(Math.PI/180);return{x:t+a*Math.cos(l),y:i+a*Math.sin(l)}}function Ht(t,i,a,o,l){const g=Mt(t,i,a,o),y=Mt(t,i,a,l),M=l-o>180?1:0;return`M ${g.x} ${g.y} A ${a} ${a} 0 ${M} 1 ${y.x} ${y.y}`}const An=Object.assign(n.forwardRef(({value:t=0,onChange:i,min:a=0,max:o=100,step:l=1,showValue:g=!0,valueTemplate:y="{value}",label:M,helperText:P,error:I,required:J,disabled:X,readOnly:O,size:$="md",name:Y,id:ae,className:ne,style:le,labelPlacement:G="top",errorPlacement:B,labelWidth:k,controlWidth:s,loading:T,isLabelCentered:F=!0,...R},_)=>{const b=r.useControlId(ae),N=n.useRef(!1),f=n.useRef(null),E=typeof $=="number"?$:Rn[$],L=E/2,w=E/2,d=(E-gt*2)/2,z=o>a?(t-a)/(o-a):0,j=ct+z*st,h=n.useCallback(m=>{let A=m-ct;A<0&&(A+=360),A>st&&(A=A-st<360-A?st:0);const D=Math.max(0,Math.min(1,A/st)),W=a+D*(o-a),v=Math.round(W/l)*l;return Math.max(a,Math.min(o,v))},[a,o,l]),c=n.useCallback(m=>{if(X||O)return;const A=f.current;if(!A)return;const D=A.getBoundingClientRect(),W=m.clientX-D.left-D.width/2,v=m.clientY-D.top-D.height/2;let q=Math.atan2(W,-v)*(180/Math.PI);q<0&&(q+=360);const H=h(q);i?.(H)},[h,X,O,i]);n.useEffect(()=>{const m=D=>{N.current&&c(D)},A=()=>{N.current=!1};return window.addEventListener("pointermove",m),window.addEventListener("pointerup",A),()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",A)}},[c]);const p=n.useCallback(m=>{if(X||O)return;let A=t;const D=Math.max(l,(o-a)/10);m.key==="ArrowUp"||m.key==="ArrowRight"?(m.preventDefault(),A=Math.min(o,t+l)):m.key==="ArrowDown"||m.key==="ArrowLeft"?(m.preventDefault(),A=Math.max(a,t-l)):m.key==="PageUp"||m.key==="PageDown"?(m.preventDefault(),A=Math.max(a,Math.min(o,t+(m.key==="PageUp"?D:-D)))):(m.key==="Home"||m.key==="End")&&(m.preventDefault(),A=m.key==="Home"?a:o),A!==t&&i?.(A)},[t,i,a,o,l,X,O]),C=(y||"{value}").replace("{value}",String(t)),S=Mt(L,w,d,j);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${B||"bottom"} nice-field--${typeof $=="string"?$:"md"} ${T?"nice-field--loading":""} ${ne||""}`,style:{...le,...k!=null&&{"--nice-field-label-width":typeof k=="number"?`${k}px`:k},...s!=null&&{"--nice-field-control-width":typeof s=="number"?`${s}px`:s}},"aria-busy":T||void 0,...R,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${G} ${F?"nice-knob-field--label-centered":""}`,children:[M&&e.jsx("label",{htmlFor:b,className:`nice-field__label ${J?"nice-field__label--required":""}`,children:M}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:m=>{f.current=m,typeof _=="function"?_(m):_&&(_.current=m)},className:`nice-knob nice-knob--${$} ${X?"nice-knob--disabled":""} ${I?"nice-knob--error":""}`,role:"slider",id:b,tabIndex:X?-1:0,"aria-valuenow":t,"aria-valuemin":a,"aria-valuemax":o,"aria-disabled":X,"aria-invalid":!!I,onPointerDown:m=>{X||O||(N.current=!0,c(m))},onKeyDown:p,children:[e.jsxs("svg",{width:E,height:E,viewBox:`0 0 ${E} ${E}`,children:[e.jsx("path",{d:Ht(L,w,d,ct,sn),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:gt,strokeLinecap:"round"}),z>0&&e.jsx("path",{d:Ht(L,w,d,ct,j),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:gt,strokeLinecap:"round"}),e.jsx("circle",{cx:S.x,cy:S.y,r:gt,fill:"var(--nice-primary, #3b82f6)"})]}),g&&e.jsx("span",{className:"nice-knob__value",children:C}),Y&&e.jsx("input",{type:"hidden",name:Y,value:t}),T&&e.jsx("span",{className:"nice-knob__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]})})]}),I&&e.jsx("div",{className:"nice-field__error",role:"alert",children:I}),!I&&P&&e.jsx("div",{className:"nice-field__helper",children:P})]})}),{displayName:"NiceKnob"}),Dn=({options:t,value:i,defaultValue:a,onChange:o,searchable:l=!0,clearable:g,loading:y,placeholder:M,label:P,error:I,helperText:J,required:X,disabled:O,readOnly:$,size:Y="md",id:ae,className:ne,style:le,data:G,columns:B,valueField:k="id",displayField:s,dropdownWidth:T,menuGap:F,labelPlacement:R,errorPlacement:_,labelWidth:b,controlWidth:N})=>{const f=O||$||y,E=r.useControlId(ae),{t:L}=r.useNiceTranslation(),[w,d]=r.useControllableState({value:i,defaultValue:a,fallbackValue:"",onChange:o,componentName:"NiceLookup"}),[z,j]=n.useState(!1),[h,c]=n.useState(""),p=n.useRef(null),C=n.useRef(null),{popupRef:S,coords:m,ready:A,themeClass:D,portalTarget:W}=Ze.useAnchoredPopup(z,C,()=>j(!1)),v=!!(G&&B&&B.length>0),q=s??(B&&B[0]?.key),H=n.useMemo(()=>!v||!G?[]:G.map(se=>({value:String(se[k]??""),label:q?String(se[q]??""):""})),[v,G,k,q]),me=n.useMemo(()=>v?H:t??[],[v,H,t]),pe=me.find(se=>String(se.value)===w),je=n.useMemo(()=>{if(!v||!G)return[];if(!h)return G;const se=h.toLowerCase();return G.filter(xe=>B.some(K=>String(xe[K.key]??"").toLowerCase().includes(se)))},[v,G,B,h]),ge=n.useMemo(()=>{if(v||!h)return me;const se=h.toLowerCase();return me.filter(xe=>xe.label.toLowerCase().includes(se))},[me,h,v]),ue=v?je:ge,{activeIndex:de,setActiveIndex:he,handleKeyDown:oe}=mt.useListKeyboardNav(ue,{open:z,onSelect:se=>{const xe=String(v?se[k]??"":se.value);d(xe),j(!1),c("")},onClose:()=>j(!1),onOpen:()=>!f&&j(!0),intentRef:S}),_e=`${n.useId()}-listbox`,te=se=>`${_e}-opt-${se}`,ke=z&&ue.length>0?te(de):void 0;return n.useLayoutEffect(()=>{ke&&document.getElementById(ke)?.scrollIntoView?.({block:"nearest"})},[ke]),e.jsxs("div",{className:`nice-field nice-field--lookup nice-field--${Y} ${I?"nice-field--error":""} ${R==="left"?"nice-field--label-left":""} ${_==="right"&&(I||J)?"nice-field--error-right":""} ${y?"nice-field--loading":""} ${O?"nice-field--disabled":""} ${ne||""}`,style:{...N!=null&&{"--nice-field-control-width":typeof N=="number"?`${N}px`:N},...b!=null&&{"--nice-field-label-width":typeof b=="number"?`${b}px`:b},...F!=null&&{"--nice-dropdown-gap":`${F}px`},...le},"aria-busy":y||void 0,ref:p,children:[P&&e.jsxs("label",{className:"nice-field__label",htmlFor:E,children:[P,X&&e.jsx("span",{className:"nice-field__required",children:"*"})]}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-field__input-wrap",ref:C,children:[e.jsxs("button",{type:"button",id:E,className:`nice-select__trigger ${O?"nice-select__trigger--disabled":""}`,onClick:()=>!f&&j(!z),onKeyDown:oe,disabled:O,"aria-readonly":$||void 0,role:"combobox","aria-haspopup":"listbox","aria-expanded":z,"aria-controls":z?_e:void 0,"aria-activedescendant":l?void 0:ke,children:[e.jsx("span",{children:pe?.label||M||L("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[g&&w&&!O&&!$&&e.jsx("span",{onKeyDown:r.clickOnActivationKey,className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":L("controls.clear","Clear"),onClick:se=>{se.stopPropagation(),d("")},children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:`nice-select__arrow${$?" nice-select__arrow--hidden":""}`,children:e.jsx(r.NiceIcon,{name:"chevron-down",size:16})})]})]}),z&&m&&W&&it.createPortal(e.jsxs("div",{ref:S,className:`nice-dropdown nice-lookup__dropdown${D?` ${D}`:""}`,"data-theme":D==="nice-dark"?"dark":D==="nice-light"?"light":void 0,style:{position:"fixed",top:m.top,left:m.left,zIndex:1e3,marginTop:"var(--nice-dropdown-gap, 0px)",background:"var(--nice-bg-primary)",border:"1px solid var(--nice-border-color)",borderRadius:"var(--nice-radius-md)",boxShadow:"0 4px 16px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",minWidth:m.width,width:T!=null?typeof T=="number"?`${T}px`:T:v?"max-content":m.width,opacity:A?1:0,pointerEvents:A?void 0:"none"},children:[l&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:h,onChange:se=>{c(se.target.value),he(0)},onKeyDown:oe,placeholder:L("controls.search","Search..."),"aria-label":L("controls.search","Search..."),"aria-controls":_e,"aria-activedescendant":ke,"aria-autocomplete":"list",autoFocus:!0,style:{width:"100%",padding:"4px 8px",border:"1px solid var(--nice-border-color)",borderRadius:4,background:"var(--nice-bg-primary)",color:"var(--nice-text-primary)"}})}),v?e.jsxs("table",{className:"nice-lookup__grid",role:"listbox",id:_e,style:{width:"100%",borderCollapse:"collapse",color:"var(--nice-text-primary)"},children:[e.jsx("thead",{children:e.jsx("tr",{children:B.map(se=>e.jsx("th",{style:{padding:"6px 10px",textAlign:"left",fontSize:12,fontWeight:600,color:"var(--nice-text-secondary)",background:"var(--nice-bg-secondary)",borderBottom:"1px solid var(--nice-border-color)",width:se.width!=null?typeof se.width=="number"?`${se.width}px`:se.width:void 0},children:se.header},se.key))})}),e.jsx("tbody",{children:je.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:B.length,style:{padding:12,textAlign:"center",color:"var(--nice-text-muted)"},children:L("controls.noResults","No results")})}):je.map((se,xe)=>{const K=String(se[k]??""),U=K===w,Z=xe===de;return e.jsx("tr",{id:te(xe),role:"option","aria-selected":U,onClick:()=>{d(K),j(!1),c("")},style:{cursor:"pointer",background:U||Z?"var(--nice-hover-bg)":"transparent"},onMouseEnter:()=>he(xe),children:B.map(x=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--nice-border-color)"},children:String(se[x.key]??"")},x.key))},K)})})]}):e.jsx("ul",{className:"nice-dropdown__list",role:"listbox",id:_e,style:{listStyle:"none",margin:0,padding:4,maxHeight:240,overflowY:"auto",position:"static",background:"transparent",border:"none",borderRadius:0,boxShadow:"none"},children:ge.length===0?e.jsx("li",{className:"nice-dropdown__empty",style:{padding:8,color:"var(--nice-text-muted)"},children:L("controls.noResults","No results")}):ge.map((se,xe)=>e.jsx("li",{id:te(xe),role:"option",className:`nice-dropdown__option ${String(se.value)===w?"nice-dropdown__option--selected":""} ${xe===de?"nice-dropdown__option--active":""}`,onClick:()=>{d(String(se.value)),j(!1),c("")},onMouseEnter:()=>he(xe),"aria-selected":String(se.value)===w,children:se.label},String(se.value)))})]}),W)]}),y&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),_==="right"&&I&&e.jsx("div",{className:"nice-field__error",role:"alert",children:I}),_==="right"&&!I&&J&&e.jsx("div",{className:"nice-field__hint",children:J})]}),_!=="right"&&I&&e.jsx("div",{className:"nice-field__error",children:I}),_!=="right"&&!I&&J&&e.jsx("div",{className:"nice-field__hint",children:J})]})},zn=[];function Ft(t){const i=[],a=o=>{for(const l of o)i.push(l),l.children&&a(l.children)};return a(t),i}function rn(t,i){const a=i.toLowerCase();return t.reduce((o,l)=>{const g=l.children?rn(l.children,i):[];return(l.label.toLowerCase().includes(a)||g.length>0)&&o.push({...l,children:g.length>0?g:l.children}),o},[])}const cn=({node:t,level:i,selectedKeys:a,expandedKeys:o,onToggleExpand:l,onSelect:g,selectableLeafsOnly:y,maxDepth:M})=>{const{t:P}=r.useNiceTranslation(),I=typeof M=="number"?Math.min(10,Math.max(1,M)):1/0,X=!(i+1>=I)&&t.children&&t.children.length>0,O=o.has(t.key),$=a.has(t.key),Y=!X,ae=!t.disabled&&(!y||Y),ne=Math.min(i+1,10),le={paddingLeft:i*16+14,"--nice-row-bg":`var(--nice-tree-level-${ne}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${ne}-text, inherit)`,"--nice-row-hover-bg":`var(--nice-tree-level-${ne}-hover-bg, var(--nice-bg-secondary, #f3f4f6))`,"--nice-row-active-bg":`var(--nice-tree-level-${ne}-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 ${$?"nice-tree-select__node--selected":""} ${t.disabled?"nice-tree-select__node--disabled":""}`,style:le,"data-nice-depth":ne,onClick:()=>{t.disabled||(X?l(t.key):ae&&g(t.key))},role:"treeitem","aria-level":i+1,"aria-selected":$,"aria-expanded":X?O:void 0,"aria-disabled":t.disabled,"data-key":String(t.key),children:[X?e.jsx("button",{type:"button",className:"nice-tree-select__toggle-btn",tabIndex:-1,onClick:G=>{G.stopPropagation(),l(t.key)},"aria-label":P("controls.toggle","Toggle"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:12,style:{transform:O?"rotate(90deg)":"none",transition:"transform 0.15s"}})}):e.jsx("span",{style:{width:12,display:"inline-block"}}),e.jsx("span",{className:"nice-tree-select__node-label",children:t.label})]}),X&&O&&t.children.map(G=>e.jsx(cn,{node:G,level:i+1,selectedKeys:a,expandedKeys:o,onToggleExpand:l,onSelect:g,selectableLeafsOnly:y,maxDepth:M},G.key))]})},Ln=Object.assign(n.forwardRef(({nodes:t=zn,value:i,onChange:a,multiple:o=!1,searchable:l=!1,placeholder:g,selectableLeafsOnly:y=!1,clearable:M=!1,maxDepth:P,label:I,helperText:J,error:X,required:O,disabled:$,readOnly:Y,size:ae="md",name:ne,id:le,className:G,style:B,controlWidth:k,menuGap:s,labelPlacement:T,errorPlacement:F,labelWidth:R,..._},b)=>{const{t:N}=r.useNiceTranslation(),f=r.useControlId(le),[E,L]=n.useState(!1),[w,d]=n.useState(""),[z,j]=n.useState(new Set),h=n.useRef(null),{popupRef:c,coords:p,ready:C,themeClass:S,portalTarget:m}=Ze.useAnchoredPopup(E,h,()=>L(!1)),A=n.useMemo(()=>i==null?new Set:new Set(Array.isArray(i)?i:[i]),[i]),D=n.useMemo(()=>w?rn(t,w):t,[t,w]),W=n.useMemo(()=>{const ue=Ft(t);return Array.from(A).map(de=>ue.find(he=>he.key===de)?.label).filter(Boolean)},[A,t]),v=n.useCallback(ue=>{j(de=>{const he=new Set(de);return he.has(ue)?he.delete(ue):he.add(ue),he})},[]),q=n.useCallback(ue=>{if(o){const de=new Set(A);de.has(ue)?de.delete(ue):de.add(ue),a?.(Array.from(de))}else a?.(ue),L(!1)},[o,A,a]),H=n.useCallback(ue=>{ue.stopPropagation(),a?.(o?[]:"")},[a,o]),me=n.useRef(null),pe=`${f}-tree`;r.useTreeFocus(me,{onToggle:(ue,de)=>{const he=Ft(D).find(oe=>String(oe.key)===ue.dataset.key);he&&z.has(he.key)!==de&&v(he.key)}});const je=n.useCallback(()=>(me.current?.querySelector('[role="treeitem"][tabindex="0"]')??me.current?.querySelector('[role="treeitem"]'))?.focus(),[]),ge=!!p;return n.useEffect(()=>{E&&ge&&!l&&je()},[E,ge,l,je]),e.jsxs("div",{className:`nice-field nice-field--${ae}${T?` nice-field--label-${T}`:""}${F==="right"?" nice-field--error-right":""} ${G||""}`,style:{width:"fit-content",maxWidth:"100%",...s!=null&&{"--nice-dropdown-gap":`${s}px`},...R!=null&&{"--nice-field-label-width":typeof R=="number"?`${R}px`:R},...B},..._,children:[I&&e.jsx("label",{htmlFor:f,className:`nice-field__label ${O?"nice-field__label--required":""}`,children:I}),e.jsxs("div",{ref:h,className:"nice-tree-select",style:{position:"relative",width:k!=null&&k!==""?typeof k=="number"?`${k}px`:k:"var(--nice-field-control-width, 220px)"},children:[e.jsxs("div",{ref:b,id:f,className:`nice-input nice-input--${ae} ${X?"nice-input--error":""} ${$?"nice-input--disabled":""} ${Y?"nice-input--readonly":""}`,role:"combobox","aria-expanded":E,"aria-haspopup":"tree","aria-controls":E?pe:void 0,"aria-invalid":!!X,tabIndex:$?-1:0,onClick:()=>!$&&!Y&&L(!E),onKeyDown:ue=>{(ue.key==="Enter"||ue.key===" "||ue.key==="ArrowDown"||ue.key==="ArrowUp")&&!$&&!Y&&(ue.preventDefault(),E?je():L(!0))},children:[e.jsx("span",{className:"nice-tree-select__display",children:W.length>0?W.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:g??N("controls.select","Select...")})}),M&&A.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:H,"aria-label":N("controls.clear","Clear"),children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:"nice-tree-select__arrow",style:{transform:E?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx(r.NiceIcon,{name:"chevron-down",size:14})})]}),E&&p&&m&&it.createPortal(e.jsxs("div",{ref:c,className:`nice-tree-select__dropdown${S?` ${S}`:""}`,"data-theme":S==="nice-dark"?"dark":S==="nice-light"?"light":void 0,style:{position:"fixed",left:p.left,top:p.top,width:p.width,minWidth:p.width,zIndex:1e3,opacity:C?1:0,pointerEvents:C?void 0:"none"},children:[l&&e.jsx("div",{className:"nice-select__search",onClick:ue=>ue.stopPropagation(),role:"presentation",children:e.jsx("input",{type:"text",placeholder:N("controls.search","Search..."),"aria-label":N("controls.search","Search..."),"aria-controls":pe,value:w,onChange:ue=>d(ue.target.value),onKeyDown:ue=>{ue.key==="ArrowDown"&&(ue.preventDefault(),je())},autoFocus:!0})}),e.jsx("div",{ref:me,id:pe,className:"nice-tree-select__list",role:"tree","aria-label":I||g||N("controls.select","Select..."),"aria-multiselectable":o||void 0,children:D.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:N("controls.noResults","No results")}):D.map(ue=>e.jsx(cn,{node:ue,level:0,selectedKeys:A,expandedKeys:z,onToggleExpand:v,onSelect:q,selectableLeafsOnly:y,maxDepth:P},ue.key))})]}),m)]}),ne&&e.jsx("input",{type:"hidden",name:ne,value:Array.isArray(i)?i.join(","):i??""}),X&&e.jsx("div",{id:`${f}-error`,className:"nice-field__error",role:"alert",children:X}),!X&&J&&e.jsx("div",{id:`${f}-helper`,className:"nice-field__helper",children:J})]})}),{displayName:"NiceTreeSelect"}),Pn=({displayValue:t,placeholder:i,clearable:a,children:o,onClear:l,open:g,onOpenChange:y,dropdownWidth:M,searchable:P=!0,onSearch:I,searchPlaceholder:J,label:X,error:O,helperText:$,required:Y,disabled:ae,size:ne="md",id:le,className:G,style:B,accessMode:k,showKeyboardHints:s,displayStyle:T})=>{r.useComponentDisplayStyle("input",T),r.useComponentDisplayClass("input",T);const F=r.useNiceAccessMode(k,le),R=F==="hidden";(F==="disabled"||F==="readOnly")&&(ae=!0);const _=r.useControlId(le),{t:b}=r.useNiceTranslation(),[N,f]=n.useState(!1),[E,L]=n.useState(""),w=n.useRef(null),d=n.useRef(null),z=g??N,j=n.useMemo(()=>[{key:"Enter",description:b("shortcuts.openDropdown","Open dropdown")},r.COMMON_SHORTCUTS.cancel],[b]),h=A=>{y?y(A):f(A)},{popupRef:c,coords:p,ready:C,themeClass:S,portalTarget:m}=Ze.useAnchoredPopup(z,d,()=>h(!1));return R?null:e.jsxs("div",{className:`nice-field nice-field--${ne} ${O?"nice-field--error":""} ${G||""}`,style:B,ref:w,children:[X&&e.jsxs("label",{className:"nice-field__label",htmlFor:_,children:[X,Y&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:j,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",ref:d,children:[e.jsxs("button",{type:"button",id:_,className:"nice-select__trigger",onClick:()=>!ae&&h(!z),disabled:ae,children:[e.jsx("span",{children:t||i||b("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[a&&t&&!ae&&e.jsx("span",{className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":b("controls.clear","Clear"),onClick:A=>{A.stopPropagation(),l?.()},onKeyDown:A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),A.stopPropagation(),l?.())},children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:"nice-select__arrow",children:e.jsx(r.NiceIcon,{name:"chevron-down",size:16})})]})]}),z&&p&&m&&it.createPortal(e.jsxs("div",{ref:c,className:`nice-dropdown${S?` ${S}`:""}`,"data-theme":S==="nice-dark"?"dark":S==="nice-light"?"light":void 0,style:{position:"fixed",left:p.left,top:p.top,width:M??p.width,minWidth:M??p.width,zIndex:1e3,maxHeight:320,overflowY:"auto",opacity:C?1:0,pointerEvents:C?void 0:"none"},children:[P&&I&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:E,onChange:A=>{L(A.target.value),I(A.target.value)},placeholder:J??b("controls.search","Search..."),autoFocus:!0})}),o]}),m)]}),O&&e.jsx("div",{className:"nice-field__error",children:O}),$&&!O&&e.jsx("div",{className:"nice-field__hint",children:$})]})},On=[],Bn=[];function Je(t,i){return String(t[i])}const Hn={xxs:10,xs:12,sm:12,md:14,lg:18,xl:22,xxl:26},Fn=Object.assign(n.forwardRef(({source:t=On,target:i=Bn,onChange:a,keyField:o="id",labelField:l="label",renderItem:g,filterable:y=!1,searchable:M,groupBy:P,sortable:I=!1,bulkActions:J=!0,maxRight:X,sourceHeader:O,targetHeader:$,disabled:Y=!1,size:ae="md",className:ne,style:le,id:G,...B},k)=>{const{t:s}=r.useNiceTranslation(),T=Hn[ae]??14,[F,R]=n.useState(new Set),[_,b]=n.useState(new Set),[N,f]=n.useState(""),[E,L]=n.useState(""),[w,d]=n.useState(null),z=n.useRef(null),j=n.useRef(null),h={orientation:"vertical",typeahead:!0,pageSize:10};r.useRovingFocus(z,h),r.useRovingFocus(j,h);const c=n.useCallback((v,q,H)=>{q(me=>{const pe=new Set(me);return pe.has(H)?pe.delete(H):pe.add(H),pe})},[]),p=n.useCallback(()=>{const v=t.filter(pe=>F.has(Je(pe,o))),q=t.filter(pe=>!F.has(Je(pe,o))),H=typeof X=="number"?v.slice(0,Math.max(0,X-i.length)):v,me=v.slice(H.length);a([...q,...me],[...i,...H]),R(new Set)},[t,i,F,o,a,X]),C=n.useCallback(()=>{const v=i.filter(H=>_.has(Je(H,o))),q=i.filter(H=>!_.has(Je(H,o)));a([...t,...v],q),b(new Set)},[t,i,_,o,a]),S=n.useCallback(()=>{if(typeof X=="number"){const v=Math.max(0,X-i.length),q=t.slice(0,v),H=t.slice(v);a(H,[...i,...q])}else a([],[...i,...t]);R(new Set)},[t,i,a,X]),m=n.useCallback(()=>{a([...t,...i],[]),b(new Set)},[t,i,a]),A=(v,q)=>{if(!q)return v;const H=q.toLowerCase();return v.filter(me=>String(me[l]).toLowerCase().includes(H))},D=J===!1?{moveAll:!1,removeAll:!1}:J===!0||J===void 0?{moveAll:!0,removeAll:!0}:{moveAll:J.moveAll??!0,removeAll:J.removeAll??!0},W=(v,q,H,me,pe,je,ge,ue)=>{let de=A(v,me);I||(de=[...de].sort((se,xe)=>String(se[l]).localeCompare(String(xe[l]),void 0,{numeric:!0,sensitivity:"base"})));const he=M===!0||y&&M===void 0?"both":M??!1,oe=he==="both"||he==="left"&&ge==="left"||he==="right"&&ge==="right",ve=(()=>{if(!P)return[{label:"",items:de}];const se=new Map;for(const xe of de){const K=String(P(xe));let U=se.get(K);U||(U=[],se.set(K,U)),U.push(xe)}return[...se.entries()].map(([xe,K])=>({label:xe,items:K}))})(),_e=(se,xe)=>{se.dataTransfer.setData("text/plain",xe),se.dataTransfer.effectAllowed="move"},te=(se,xe)=>{if(se.preventDefault(),!I)return;const K=se.currentTarget.getBoundingClientRect(),U=se.clientY<K.top+K.height/2;d(Z=>Z&&Z.side===ge&&Z.key===xe&&Z.before===U?Z:{side:ge,key:xe,before:U})},ke=(se,xe)=>{se.preventDefault();const K=w?.before??!1;d(null);const U=se.dataTransfer.getData("text/plain");if(!U||!I)return;const x=[...ge==="right"?i:t],ee=x.findIndex(fe=>Je(fe,o)===U),ie=x.findIndex(fe=>Je(fe,o)===xe);if(ee===-1||ie===-1||U===xe)return;let ce=K?ie:ie+1;const[be]=x.splice(ee,1);ee<ce&&(ce-=1),x.splice(ce,0,be),a(ge==="right"?t:x,ge==="right"?x:i)};return e.jsxs("div",{className:"nice-picklist__panel",children:[je&&e.jsx("div",{className:"nice-picklist__header",children:je}),oe&&e.jsx("div",{className:"nice-picklist__filter",children:e.jsx("input",{className:"nice-input__native",type:"text",size:1,placeholder:s("controls.search","Search..."),value:me,onChange:se=>pe(se.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true","aria-label":typeof je=="string"?je:void 0,ref:ue,children:[ve.map(se=>e.jsxs(n.Fragment,{children:[se.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:se.label}),se.items.map(xe=>{const K=Je(xe,o),U=q.has(K),x=w&&w.side===ge&&w.key===K?w.before?"nice-picklist__item--drop-before":"nice-picklist__item--drop-after":"";return e.jsxs("div",{className:`nice-picklist__item ${U?"nice-picklist__item--selected":""} ${x}`,role:"option","aria-selected":U,draggable:I,onDragStart:I?ee=>_e(ee,K):void 0,onDragOver:I?ee=>te(ee,K):void 0,onDrop:I?ee=>ke(ee,K):void 0,onDragEnd:I?()=>d(null):void 0,onClick:()=>!Y&&c(q,H,K),onKeyDown:ee=>{(ee.key===" "||ee.key==="Enter")&&(ee.preventDefault(),Y||c(q,H,K))},children:[I&&e.jsx("span",{className:"nice-picklist__drag-handle","aria-hidden":"true",children:e.jsx(r.NiceIcon,{name:"grip",size:T})}),g?g(xe,ge):String(xe[l])]},K)})]},se.label||"__none__")),de.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:s("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:k,id:G,className:`nice-picklist nice-picklist--${ae} ${Y?"nice-picklist--disabled":""} ${ne||""}`,style:le,...B,children:[W(t,F,R,N,f,O??s("picklist.source","Available"),"left",z),e.jsxs("div",{className:"nice-picklist__controls",children:[e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ae}`,disabled:Y||F.size===0,onClick:p,"aria-label":s("picklist.moveRight","Move right"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:T})}),D.moveAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ae}`,disabled:Y||t.length===0,onClick:S,"aria-label":s("picklist.moveAllRight","Move all right"),children:e.jsx(r.NiceIcon,{name:"chevrons-right",size:T})}),e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ae}`,disabled:Y||_.size===0,onClick:C,"aria-label":s("picklist.moveLeft","Move left"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:T})}),D.removeAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ae}`,disabled:Y||i.length===0,onClick:m,"aria-label":s("picklist.moveAllLeft","Move all left"),children:e.jsx(r.NiceIcon,{name:"chevrons-left",size:T})})]}),W(i,_,b,E,L,$??s("picklist.target","Selected"),"right",j)]})}),{displayName:"NicePickList"});function At(t){return t?.startsWith("datetime")?"datetime":t==="week"?"week":t?.startsWith("month")?"month":"date"}function Kn(t){const i=new Date,a=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`,o=At(t);return o==="datetime"?`${a}T00:00`:o==="month"?a.slice(0,7):a}function Kt(t,i){if(!t)return t;const a=new Date(t.length<=10?`${t}T00:00`:t);if(Number.isNaN(a.getTime()))return t;a.setDate(a.getDate()+i);const o=`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,"0")}-${String(a.getDate()).padStart(2,"0")}`;return t.length<=10?o.slice(0,t.length):o+t.slice(10)}function ft(...t){return t.filter(Boolean).sort().pop()}function St(t,i,a){if(!t)return"";const o=new Date(t.length<=10?`${t}T00:00`:t);if(Number.isNaN(o.getTime()))return t;const l=At(a);return l==="month"?o.toLocaleDateString(i,{year:"numeric",month:"2-digit"}):l==="datetime"?o.toLocaleString(i,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):o.toLocaleDateString(i,{year:"numeric",month:"2-digit",day:"2-digit"})}function Ut(t){let i=0;for(const a of t)i+=/[\p{L}\p{N}]/u.test(a)?1:.5;return i}const Un=({startDate:t,endDate:i,defaultStartDate:a,defaultEndDate:o,onStartChange:l,onEndChange:g,min:y,max:M,clearable:P,startPlaceholder:I,endPlaceholder:J,startLabel:X,endLabel:O,layout:$="horizontal",separator:Y="–",gap:ae=12,fullWidth:ne=!1,dateFormatPreset:le,locale:G,timeSelectorType:B,endCondition:k="greater-or-equal",startCondition:s="today-or-greater",singleField:T=!1,label:F,error:R,helperText:_,required:b,disabled:N,size:f="md",id:E,className:L,style:w,accessMode:d,showKeyboardHints:z,labelPlacement:j,errorPlacement:h,labelWidth:c,controlWidth:p,loading:C,readOnly:S})=>{const m=r.useNiceAccessMode(d,E),A=r.useControlId(E),{t:D}=r.useNiceTranslation(),W=m==="disabled"||m==="readOnly"||!!N,[v,q]=r.useControllableState({value:t,defaultValue:a,fallbackValue:"",onChange:l,componentName:"NiceDateRangeBox"}),[H,me]=r.useControllableState({value:i,defaultValue:o,fallbackValue:"",onChange:g,componentName:"NiceDateRangeBox"}),pe=n.useMemo(()=>[{key:"Tab",description:D("shortcuts.switchField","Switch between start/end")},r.COMMON_SHORTCUTS.cancel],[D]),je=n.useRef(null),ge=n.useRef(null),[ue,de]=n.useState(!1),[he,oe]=n.useState(null),[ve,_e]=n.useState(""),te=n.useContext(r.NiceThemeContext),ke=te?.portalTarget??(typeof document<"u"?document.body:null);n.useLayoutEffect(()=>{if(!ue)return;const Ce=je.current?.getBoundingClientRect();Ce&&(oe({left:Ce.left,top:Ce.bottom+6}),_e(te?.portalTarget?"":Qe.scopeThemeClass(je.current)))},[ue,te?.portalTarget]),n.useEffect(()=>{if(!ue)return;const Ce=He=>{const $e=He.target;je.current?.contains($e)||ge.current?.contains($e)||de(!1)},Ne=()=>{const He=je.current?.getBoundingClientRect();He&&oe({left:He.left,top:He.bottom+6})};return document.addEventListener("mousedown",Ce),window.addEventListener("scroll",Ne,!0),window.addEventListener("resize",Ne),()=>{document.removeEventListener("mousedown",Ce),window.removeEventListener("scroll",Ne,!0),window.removeEventListener("resize",Ne)}},[ue]),r.useOverlayFocus(ge,{open:ue,modal:!1,initialFocus:'.nice-calendar__grid [tabindex="0"]',onClose:()=>de(!1)});const se=Kn(le),xe=s==="today-or-greater"?ft(y,se):s==="greater-than-today"?ft(y,Kt(se,1)):y,K=k==="greater-or-equal"?ft(y,v):k==="greater"?ft(y,v?Kt(v,1):void 0):y,U=n.useMemo(()=>{if(R)return R;if(v&&H){if(k==="greater-or-equal"&&H<v)return D("daterange.endBeforeStart","End date must be on or after the start date");if(k==="greater"&&H<=v)return D("daterange.endAfterStart","End date must be after the start date")}if(v){if(s==="today-or-greater"&&v<se)return D("daterange.startInPast","Start date cannot be in the past");if(s==="greater-than-today"&&v<=se)return D("daterange.startAfterToday","Start date must be after today")}},[R,v,H,s,k,se,D]);if(m==="hidden")return null;const Z=Ce=>{q(Ce),Ce&&H&&Ce>H&&me(Ce)},x=$==="horizontal",ee=At(le),ie=G||ht.getDefaultLocale(),ce=typeof Y=="string"&&Y!==""?Y:"–",be=St(v,ie,le),fe=St(H,ie,le),Se=be||fe?`${be||"…"} ${ce} ${fe||"…"}`:"",Re=(()=>{const Ce=St("2026-12-30T22:58",ie,le),Ne=`${Ce} ${ce} ${Ce}`;return`${(Math.max(Ut(Ne),Ut(Se))+1.5).toFixed(1)}ch`})(),De=(Ce,Ne)=>ee==="datetime"?Ne&&Ne.length>10?`${Ce}${Ne.slice(10)}`:`${Ce}T00:00`:ee==="month"?Ce.slice(0,7):Ce,Ge=({start:Ce,end:Ne})=>{q(Ce?De(Ce,v):""),me(Ne?De(Ne,H):""),Ce&&Ne&&de(!1)},Ve=()=>{q(""),me("")},Ue=()=>{!W&&!S&&de(Ce=>!Ce)},Fe=Ce=>Ce&&Ce.length>=10?Ce.slice(0,10):Ce||void 0;return e.jsxs("div",{className:`nice-field nice-field--${f} nice-daterange nice-daterange--${$} ${j==="left"?"nice-field--label-left":""} ${U?"nice-field--error":""} ${C?"nice-field--loading":""} ${L||""}`,style:{...w,...c!=null&&{"--nice-field-label-width":typeof c=="number"?`${c}px`:c},...p!=null&&{"--nice-field-control-width":typeof p=="number"?`${p}px`:p}},"aria-busy":C||void 0,children:[F&&e.jsxs("label",{className:"nice-field__label",htmlFor:A,children:[F,b&&e.jsx("span",{className:"nice-field__required",children:"*"}),z&&e.jsx(r.NiceKeyboardHint,{shortcuts:pe,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[T?e.jsxs("div",{ref:je,className:`nice-input nice-input--date nice-input--${f} nice-daterange__single ${U?"nice-input--error":""} ${W?"nice-input--disabled":""} ${S?"nice-input--readonly":""}`,style:{position:"relative",width:ne?"100%":"fit-content"},children:[e.jsx("input",{id:A,className:"nice-input__native",type:"text",readOnly:!0,value:Se,placeholder:I||D("controls.startDate","Start date"),disabled:W||C,autoComplete:"off","aria-invalid":!!U,"aria-label":F?void 0:D("controls.startDate","Start date"),"aria-haspopup":"dialog","aria-expanded":ue,onClick:Ue,onKeyDown:Ce=>{const Ne=!!Ce.nativeEvent.niceSource;(Ce.key==="Enter"||Ce.key===" "||Ce.key==="ArrowDown"&&!Ne)&&(Ce.preventDefault(),ue||Ue())},style:{width:ne?"100%":Re,cursor:W||S?void 0:"pointer"}}),P&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:Ve,disabled:!v&&!H||W||S,"aria-label":D("controls.clear","Clear"),tabIndex:(v||H)&&!W&&!S?0:-1,children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("button",{type:"button",className:"nice-input__picker-trigger",onClick:Ue,"aria-label":D("controls.openPicker","Open picker"),"aria-expanded":ue,tabIndex:-1,disabled:W||S,children:e.jsx(r.NiceIcon,{name:"calendar",size:16})})]}):e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:x?"row":"column",alignItems:x?j==="left"?"center":"flex-end":"stretch",gap:ae,flexWrap:x?"nowrap":"wrap"},children:[e.jsx("div",{style:{flex:ne?"1 1 0":void 0,minWidth:0},children:e.jsx(ht.NiceDateTimePicker,{id:A,dateFormatPreset:le,displayLocale:G,timeSelectorType:B,label:X,value:v,onChange:Z,min:xe,max:H||M,placeholder:I||D("controls.startDate","Start date"),disabled:W,readOnly:S,size:f,clearable:P,labelPlacement:j,labelWidth:c})}),x&&Y!==""&&Y!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--nice-text-secondary, #666)"},"aria-hidden":"true",children:Y}),e.jsx("div",{style:{flex:ne?"1 1 0":void 0,minWidth:0},children:e.jsx(ht.NiceDateTimePicker,{dateFormatPreset:le,displayLocale:G,timeSelectorType:B,label:O,value:H,onChange:Ce=>me(Ce),min:K||v||y,max:M,placeholder:J||D("controls.endDate","End date"),disabled:W,readOnly:S,size:f,clearable:P,labelPlacement:j,labelWidth:c})})]}),T&&ue&&he&&ke&&it.createPortal(e.jsxs("div",{ref:ge,className:`nice-datetime-popup${ve?` ${ve}`:""}`,style:{position:"fixed",left:he.left,top:he.top,zIndex:1e3},role:"dialog","aria-label":D("controls.openPicker","Open picker"),children:[e.jsx("div",{className:"nice-datetime-popup__body",children:e.jsx("div",{className:"nice-datetime-popup__col nice-datetime-popup__col--date",children:e.jsx(ht.NiceCalendar,{selectionMode:"range",rangeStart:Fe(v),rangeEnd:Fe(H),onRangeChange:Ge,min:Fe(xe),max:Fe(M),size:f})})}),P&&e.jsx("div",{className:"nice-datetime-popup__footer",children:e.jsx("button",{type:"button",className:"nice-datetime-popup__btn",onClick:Ve,disabled:!v&&!H,children:D("controls.clear","Clear")})})]}),ke),C&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),h==="right"&&U&&e.jsx("div",{className:"nice-field__error",role:"alert",children:U}),h==="right"&&!U&&_&&e.jsx("div",{className:"nice-field__helper",children:_})]}),h!=="right"&&U&&e.jsx("div",{className:"nice-field__error",children:U}),h!=="right"&&!U&&_&&e.jsx("div",{className:"nice-field__hint",children:_})]})};function Yn(t,i=30){switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-i,180+i];case"analogous":return[0,-i,i];case"analogous-complementary":return[0,-i,i,180];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 Yt(t,i={}){const a=i.size??16,o="currentColor",l="currentColor";if(i.rectangle||t==="shade-chain"||t==="monochromatic"){const X=Math.max(3,Math.min(7,i.count??5)),O=a*.1,$=a-O*2,Y=Math.max(1.2,a/14),ae=a/2,ne=Array.from({length:X},(le,G)=>{const B=O+$*G/(X-1),k=.25+.75*G/(X-1);return e.jsx("circle",{cx:B,cy:ae,r:Y,fill:l,opacity:k},G)});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:o,strokeOpacity:.25}),ne]})}const y=i.angles??Yn(t),M=a/2,P=a/2,I=a/2-2,J=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:M,cy:P,r:I,fill:"none",stroke:o,strokeOpacity:.25}),y.map((X,O)=>{const $=(X-90)*Math.PI/180,Y=M+I*Math.cos($),ae=P+I*Math.sin($);return e.jsx("circle",{cx:Y,cy:ae,r:J,fill:l},O)})]})}function Xt(t,i,a){return Math.max(i,Math.min(a,t))}function ln({h:t,s:i,v:a}){t=(t%360+360)%360;const o=a*i,l=o*(1-Math.abs(t/60%2-1)),g=a-o;let y=0,M=0,P=0;return t<60?(y=o,M=l):t<120?(y=l,M=o):t<180?(M=o,P=l):t<240?(M=l,P=o):t<300?(y=l,P=o):(y=o,P=l),{r:Math.round((y+g)*255),g:Math.round((M+g)*255),b:Math.round((P+g)*255)}}function Dt({r:t,g:i,b:a}){t/=255,i/=255,a/=255;const o=Math.max(t,i,a),l=Math.min(t,i,a),g=o-l;let y=0;return g!==0&&(o===t?y=(i-a)/g%6:o===i?y=(a-t)/g+2:y=(t-i)/g+4,y=(y*60+360)%360),{h:y,s:o===0?0:g/o,v:o}}function dn({r:t,g:i,b:a}){t/=255,i/=255,a/=255;const o=Math.max(t,i,a),l=Math.min(t,i,a),g=(o+l)/2;if(o===l)return{h:0,s:0,l:g};const y=o-l,M=g>.5?y/(2-o-l):y/(o+l);let P=0;return o===t?P=((i-a)/y+(i<a?6:0))/6:o===i?P=((a-t)/y+2)/6:P=((t-i)/y+4)/6,{h:P*360,s:M,l:g}}function dt(t){const i=t.replace("#",""),a=i.length===3?i[0]+i[0]+i[1]+i[1]+i[2]+i[2]:i,o=parseInt(a,16);return{r:o>>16&255,g:o>>8&255,b:o&255}}function mn({r:t,g:i,b:a}){return"#"+[t,i,a].map(o=>o.toString(16).padStart(2,"0")).join("")}function Pe(t){return mn(ln(t))}function Ke(t){return Dt(dt(t))}function un(t,i){const a=[];for(let o=0;o<i;o++){const l=i<=1?.5:o/(i-1),g=Xt(t.s*(.3+l*.7),0,1),y=Xt(t.v*(1.2-l*.7),0,1);a.push(Pe({h:t.h,s:g,v:y}))}return a}function _t(t,i){if(t==="custom"||t==="shade-chain")return[0];const a=i??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"analogous-complementary":return[0,-a,a,180];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270]}return[0]}function lt(t,i,a){return _t(i,a).map(o=>((t+o)%360+360)%360)}function qt(t,i,a=.12){const o=Math.max(2,i),l=(o-1)/2,g=[];for(let y=0;y<o;y++){const M=(y-l)*a,P=Math.max(.05,Math.min(.98,t.v+M)),I=Math.max(.05,Math.min(1,t.s-Math.abs(M)*.25));g.push(Pe({h:t.h,s:I,v:P}))}return g}function Gt({r:t,g:i,b:a}){const[o,l,g]=[t,i,a].map(y=>{const M=y/255;return M<=.03928?M/12.92:Math.pow((M+.055)/1.055,2.4)});return .2126*o+.7152*l+.0722*g}function xt(t,i){const a=Gt(dt(t)),o=Gt(dt(i)),l=Math.max(a,o),g=Math.min(a,o);return(l+.05)/(g+.05)}function bt(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"AA-lg":"Fail"}const pn={"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 jt(t,i){const a=pn[i];return t.map(o=>{const l=(a.sRange[0]+a.sRange[1])/2,g=(a.vRange[0]+a.vRange[1])/2;return Pe({h:o,s:l,v:g})})}function Xn(){return Math.floor(Math.random()*360)}function hn(t,i,a){const o=Xn(),l=lt(o,t,a),g=[];for(let y=0;y<i;y++){const M=l[y%l.length],P=.55+Math.random()*.4,I=.5+Math.random()*.45;g.push(Pe({h:M+(Math.random()-.5)*8,s:P,v:I}))}return g}const qn=({hues:t,colors:i,baseHue:a,onBaseHueChange:o,mode:l,distance:g,disabled:y})=>{const{t:M}=r.useNiceTranslation(),P=240,I=P/2,J=P/2,X=110,O=55,$=s=>{if(y)return;const T=s.shiftKey?15:1,F=s.key==="ArrowLeft"||s.key==="ArrowDown"?-T:s.key==="ArrowRight"||s.key==="ArrowUp"?T:s.key==="PageDown"?-15:s.key==="PageUp"?15:null;F!==null?(s.preventDefault(),o(((a+F)%360+360)%360)):(s.key==="Home"||s.key==="End")&&(s.preventDefault(),o(s.key==="Home"?0:359))},Y=n.useRef(null),ae=n.useCallback((s,T)=>{const F=Y.current;if(!F)return;const R=F.getBoundingClientRect(),_=(s-R.left)/R.width*P-I,b=(T-R.top)/R.height*P-J,N=(Math.atan2(b,_)*180/Math.PI+360)%360;o(Math.round(N))},[I,J,P,o]),ne=n.useCallback(s=>{if(y)return;s.preventDefault(),ae(s.clientX,s.clientY);const T=R=>ae(R.clientX,R.clientY),F=()=>{document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",F)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",F)},[y,ae]),le=[];for(let s=0;s<360;s+=2){const T=(s-1)*Math.PI/180,F=(s+1)*Math.PI/180,R=Pe({h:s,s:1,v:1});le.push(e.jsx("path",{d:`M${I+O*Math.cos(T)},${J+O*Math.sin(T)} L${I+X*Math.cos(T)},${J+X*Math.sin(T)} A${X},${X} 0 0,1 ${I+X*Math.cos(F)},${J+X*Math.sin(F)} L${I+O*Math.cos(F)},${J+O*Math.sin(F)} A${O},${O} 0 0,0 ${I+O*Math.cos(T)},${J+O*Math.sin(T)} Z`,fill:R},s))}const G=`wheel-center-${l}`,B=t.map((s,T)=>{const F=(X+O)/2,R=s*Math.PI/180;return e.jsx("circle",{cx:I+F*Math.cos(R),cy:J+F*Math.sin(R),r:T===0?8:6,fill:i?.[T]??Pe({h:s,s:.85,v:.9}),stroke:T===0?"var(--nice-bg-primary, #fff)":"var(--nice-border-color, #ccc)",strokeWidth:T===0?3:2},T)});let k=null;if(l==="analogous"||l==="split-complementary"||l==="analogous-complementary"){const s=(X+O)/2,F=_t(l,g).slice(1).map((R,_)=>{const b=(a+R)*Math.PI/180;return e.jsx("line",{x1:I,y1:J,x2:I+s*Math.cos(b),y2:J+s*Math.sin(b),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${_}`)});k=e.jsx(e.Fragment,{children:F})}return e.jsxs("svg",{ref:Y,className:"nice-palette__wheel",viewBox:`0 0 ${P} ${P}`,width:P,height:P,onPointerDown:ne,onKeyDown:$,role:"slider",tabIndex:y?-1:0,"aria-label":M("colorPalette.baseHue","Base hue"),"aria-valuemin":0,"aria-valuemax":359,"aria-valuenow":Math.round(a),"aria-valuetext":`${Math.round(a)}°`,style:{cursor:y?"default":"crosshair",touchAction:"none"},children:[e.jsx("defs",{children:e.jsxs("radialGradient",{id:G,children:[e.jsx("stop",{offset:"0%",stopColor:"var(--nice-bg, #fff)"}),e.jsx("stop",{offset:"100%",stopColor:"transparent"})]})}),le,e.jsx("circle",{cx:I,cy:J,r:O-2,fill:Pe({h:a,s:.6,v:.85})}),e.jsx("circle",{cx:I,cy:J,r:O-2,fill:`url(#${G})`,opacity:.4}),k,B]})},Gn=({colors:t})=>{const{t:i}=r.useNiceTranslation();if(t.length<2)return null;const a=[];for(let o=0;o<t.length;o++){const l=xt(t[o],"var(--nice-bg-primary, #ffffff)"),g=xt(t[o],"var(--nice-text-primary, #000000)");a.push({a:t[o],b:"var(--nice-bg-primary, #ffffff)",ratio:l,level:bt(l)}),a.push({a:t[o],b:"var(--nice-text-primary, #000000)",ratio:g,level:bt(g)});for(let y=o+1;y<t.length;y++){const M=xt(t[o],t[y]);a.push({a:t[o],b:t[y],ratio:M,level:bt(M)})}}return e.jsxs("div",{className:"nice-palette__contrast",children:[e.jsx("div",{className:"nice-palette__section-title",children:i("colorPalette.contrastAnalysisWcag21","Contrast Analysis (WCAG 2.1)")}),e.jsx("div",{className:"nice-palette__contrast-grid",children:a.map((o,l)=>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:o.a}}),e.jsx("span",{className:"nice-palette__contrast-vs",children:i("colorPalette.vs","vs")}),e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:o.b}})]}),e.jsxs("span",{className:"nice-palette__contrast-ratio",children:[o.ratio.toFixed(1),":1"]}),e.jsx("span",{className:`nice-palette__contrast-level nice-palette__contrast-level--${o.level.toLowerCase().replace("-","")}`,children:o.level})]},l))})]})},Vn=({hex:t})=>{const i=dt(t),a=dn(i),o=Dt(i);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"})," ",i.r,", ",i.g,", ",i.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(o.h),"°, ",Math.round(o.s*100),"%,"," ",Math.round(o.v*100),"%"]})]})},Wn={monochromatic:"Monochromatic",complementary:"Complementary","split-complementary":"Split-Complementary",analogous:"Analogous","analogous-complementary":"Analogous + Complementary",triadic:"Triadic",tetradic:"Tetradic (Rectangle)",square:"Square","shade-chain":"Shade chain",custom:"Custom"},Jn={"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"},Zn=["monochromatic","shade-chain","complementary","split-complementary","analogous","analogous-complementary","triadic","tetradic","square","custom"],gn=["lightest-pastel","bright-pastel","shiny","pastel","full","dark","deep","muted","earth"],fn="nice-palette-custom-schemes";function Qn(){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(fn);if(!t)return[];const i=JSON.parse(t);if(Array.isArray(i))return i}catch{}return[]}function ei(t){if(!(typeof window>"u"))try{window.localStorage.setItem(fn,JSON.stringify(t))}catch{}}const ti=Object.assign(n.forwardRef(({id:t,className:i,style:a,accessMode:o,value:l,onChange:g,minColors:y=1,maxColors:M=8,harmonyMode:P,onHarmonyModeChange:I,distance:J,onDistanceChange:X,preset:O,onPresetChange:$,showWheel:Y=!0,showContrast:ae=!0,showInfo:ne=!0,showPresets:le=!0,presets:G=[],showVariations:B=!0,showRandom:k=!0,variationCount:s=5,label:T,labelPlacement:F="top",disabled:R,readOnly:_,loading:b,error:N,colorCount:f,shadeStep:E,onShadeStepChange:L,customSchemes:w,onCustomSchemesChange:d,persistCustomSchemes:z=!0,"data-testid":j},h)=>{const c=r.useNiceAccessMode(o,t),p=c==="hidden";c==="disabled"&&(R=!0);const C=_||c==="readOnly",S=r.useControlId(t),{t:m}=r.useNiceTranslation(),A=Qe.useNiceDialogs(),[D,W]=n.useState("analogous-complementary"),[v,q]=n.useState(30),[H,me]=n.useState(""),[pe,je]=n.useState(0),[ge,ue]=n.useState(.12),[de,he]=n.useState(null),[oe,ve]=n.useState(()=>w??(z?Qn():[])),[_e,te]=n.useState(null),[ke,se]=n.useState(!1),[xe,K]=n.useState(null),[U,Z]=n.useState(""),ee=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),ie=n.useRef(null),ce=n.useRef(null),be=P??D,fe=J??v,Se=O??H,Re=E??ge,De=w??oe;n.useEffect(()=>{!w&&z&&ei(oe)},[oe,w,z]);const Ge=n.useCallback(Q=>{ve(Q),d?.(Q)},[d]),Ve=n.useCallback(Q=>{W(Q),I?.(Q)},[I]),Ue=n.useCallback(Q=>{q(Q),X?.(Q)},[X]),Fe=n.useCallback(Q=>{me(Q),Q&&$?.(Q)},[$]),Ce=n.useMemo(()=>["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)"],[]),Ne=l&&l.length>0?l:Ce,He=Ne[0],$e=n.useMemo(()=>Ke(He),[He]),ut=n.useMemo(()=>lt($e.h,be,fe),[$e.h,be,fe]),Le=n.useCallback((Q,ye,we,Te,qe)=>{const pt=f??qe??de??Ne.length,et=pt!==void 0?Math.max(y,Math.min(M,pt)):void 0;if(ye==="shade-chain"){const Be=et??Math.max(y,5),We=qt({h:Q,s:$e.s||.7,v:$e.v||.6},Be,Re);g?.(We);return}let tt;const at=ye==="custom"&&_e?De.find(Be=>Be.id===_e):null;at&&at.angles.length>0?tt=at.angles.map(Be=>((Q+Be)%360+360)%360):tt=lt(Q,ye,we);let Ae;if(Te&&pn[Te]?Ae=jt(tt,Te):Ae=tt.map(Be=>Pe({h:Be,s:$e.s||.7,v:$e.v||.85})),at?.lightnessOffsets?.length&&(Ae=Ae.map((Be,We)=>{const Ot=at.lightnessOffsets?.[We];if(Ot==null)return Be;const Ct=Ke(Be);return Pe({h:Ct.h,s:Ct.s,v:Math.max(.05,Math.min(.98,Ct.v+Ot))})})),et!==void 0){for(;Ae.length<et;){const Be=Ae[Ae.length-1]||"#888888",We=Ke(Be);Ae.push(Pe({h:(We.h+18)%360,s:We.s,v:We.v}))}Ae=Ae.slice(0,et)}else{for(;Ae.length<y;)Ae.push(Ae[Ae.length-1]||"var(--nice-text-secondary, #888888)");Ae.length>M&&(Ae=Ae.slice(0,M))}g?.(Ae)},[$e.s,$e.v,y,M,g,f,de,Ne.length,Re,_e,De]),ze=n.useCallback(Q=>{if(!R){if(be==="custom"){const ye=Pe({h:Q,s:$e.s||.7,v:$e.v||.85}),we=[...Ne];we[pe]=ye,g?.(we);return}Le(Q,be,fe,Se)}},[R,be,fe,Se,Le,$e.s,$e.v,Ne,pe,g]),Oe=n.useCallback(Q=>{if(R||(Ve(Q),Q==="custom"))return;const ye=_t(Q).length,we=ye<=1;if(f==null&&!we){const Te=Math.max(y,Math.min(M,ye));he(Te),Le($e.h,Q,fe,Se,Te)}else Le($e.h,Q,fe,Se)},[R,$e.h,fe,Se,Ve,Le,f,y,M]),wt=n.useCallback(Q=>{R||(Ue(Q),Le($e.h,be,Q,Se))},[R,$e.h,be,Se,Ue,Le]),u=n.useCallback(Q=>{if(R)return;Fe(Q);const ye=lt($e.h,be,fe),we=jt(ye,Q);g?.(we.slice(0,M))},[R,$e.h,be,fe,M,Fe,g]),V=n.useCallback((Q,ye)=>{if(R)return;const we=[...Ne];we[Q]=ye,g?.(we)},[R,Ne,g]),re=n.useCallback(()=>{if(R||Ne.length>=M)return;const Q=Ke(Ne[Ne.length-1]),ye=Pe({h:(Q.h+30)%360,s:Q.s,v:Q.v});g?.([...Ne,ye])},[R,Ne,M,g]),Ee=n.useCallback(Q=>{if(R||Ne.length<=y)return;const ye=Ne.filter((we,Te)=>Te!==Q);g?.(ye),pe>=ye.length&&je(Math.max(0,ye.length-1))},[R,Ne,y,g,pe]),Ie=n.useCallback(()=>{if(R)return;const Q=Math.max(y,Math.min(M,_t(be).length)),ye=hn(be,Q,fe);g?.(ye)},[R,y,M,be,fe,g]),Ye=n.useMemo(()=>{if(!B)return[];const Q=Ne[pe]||Ne[0];return un(Ke(Q),s)},[B,Ne,pe,s]),Xe=Ne[pe]||Ne[0],Nt=n.useMemo(()=>{const Q=Ke(Xe);return Pe({h:(Q.h+180)%360,s:Q.s,v:Q.v})},[Xe]);n.useLayoutEffect(()=>{if(!ke||!ie.current)return;Z(Qe.scopeThemeClass(ie.current));const Q=()=>{const ye=ie.current?.getBoundingClientRect();if(!ye)return;const we=600;let Te=ye.left;Te+we>window.innerWidth-8&&(Te=Math.max(8,window.innerWidth-we-8));let qe=ye.bottom+6;qe>window.innerHeight*.5&&(qe=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,540)-8)),K({left:Te,top:qe})};return Q(),window.addEventListener("scroll",Q,!0),window.addEventListener("resize",Q),()=>{window.removeEventListener("scroll",Q,!0),window.removeEventListener("resize",Q)}},[ke]),n.useEffect(()=>{if(!ke)return;const Q=ye=>{const we=ye.target;ie.current?.contains(we)||ce.current?.contains(we)||(we instanceof Element?we:we?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"], [aria-modal="true"]')||se(!1)};return document.addEventListener("mousedown",Q),()=>{document.removeEventListener("mousedown",Q)}},[ke]),r.useOverlayFocus(ce,{open:ke,modal:!1,onClose:()=>se(!1)});const Lt=n.useRef(null);if(r.useRovingFocus(Lt,{orientation:"horizontal",itemSelector:".nice-palette__variation-chip"}),p)return null;const Pt=G.length>0?G:gn,wn=e.jsxs("div",{className:"nice-palette__tab",children:[e.jsxs("div",{className:"nice-palette__modes",style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[e.jsx(Ze.NiceSelect,{label:m("colorPalette.harmony","Harmony"),labelPlacement:"left",size:"sm",disabled:R,value:be==="custom"&&_e?`custom:${_e}`:be,onChange:Q=>{const ye=Array.isArray(Q)?Q[0]:Q;if(typeof ye=="string")if(ye.startsWith("custom:")){const we=ye.slice(7);te(we),Oe("custom")}else te(null),Oe(ye)},options:[...Zn.map(Q=>({value:Q,label:Wn[Q]})),...De.map(Q=>({value:`custom:${Q.id}`,label:Q.name}))],renderOption:(Q,ye)=>{const we=String(Q.value),Te=we.startsWith("custom:"),qe=Te?De.find(tt=>tt.id===we.slice(7)):null,pt=qe?qe.angles:void 0,et=Te?"custom":we;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:Yt(et,{angles:pt,size:16,count:f})}),e.jsx("span",{style:{fontWeight:ye?600:400},children:Q.label})]})}}),be==="shade-chain"&&e.jsx(nt.NiceNumberInput,{label:m("colorPalette.step","Step"),labelPlacement:"left",size:"sm",min:.02,max:.5,step:.02,precision:2,value:Re,onChange:Q=>{const ye=typeof Q=="number"?Q:Number(Q);Number.isNaN(ye)||(ue(ye),L?.(ye),Le($e.h,be,fe,Se))},showStepper:!0,disabled:R}),e.jsx(nt.NiceNumberInput,{label:m("colorPalette.colors","Colors"),labelPlacement:"left",size:"sm",min:Math.max(2,y),max:Math.min(12,M),step:1,precision:0,value:f??de??Ne.length,onChange:Q=>{const ye=typeof Q=="number"?Q:Number(Q);if(!Number.isFinite(ye))return;const we=Math.max(Math.max(2,y),Math.min(Math.min(12,M),Math.round(ye)));he(we),be==="shade-chain"?g?.(qt({h:$e.h,s:$e.s||.7,v:$e.v||.6},we,Re)):setTimeout(()=>Le($e.h,be,fe,Se),0)},showStepper:!0,disabled:R})]}),e.jsx("div",{className:"nice-palette__main",children:e.jsxs("div",{className:"nice-palette__strips",children:[e.jsxs("div",{className:"nice-palette__swatches",children:[Ne.map((Q,ye)=>e.jsxs("div",{role:"presentation",className:`nice-palette__swatch-wrapper ${pe===ye?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>je(ye),onFocus:()=>je(ye),children:[e.jsx("span",{className:"nice-palette__swatch",style:{background:Q}}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:Q.toUpperCase(),maxLength:7,disabled:R,onClick:we=>we.stopPropagation(),onChange:we=>V(ye,we.target.value),"aria-label":m("colorPalette.colorN","Color {n}").replace("{n}",String(ye+1))}),Ne.length>y&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:we=>{we.stopPropagation(),Ee(ye)},disabled:R,"aria-label":m("colorPalette.removeColor","Remove color"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},ye)),Ne.length<M&&e.jsxs("button",{type:"button",className:"nice-palette__add-btn",onClick:re,disabled:R,title:m("colorPalette.addColor","Add color"),children:[e.jsx(r.NiceIcon,{name:"plus",size:14}),e.jsx("span",{children:m("colorPalette.add","Add")})]})]}),e.jsxs("div",{className:"nice-palette__complementary",children:[e.jsx("span",{className:"nice-palette__section-tag",children:m("colorPalette.complementary","Complementary")}),e.jsx("div",{className:"nice-palette__swatch nice-palette__swatch--sm",style:{background:Nt},title:Nt.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:Nt.toUpperCase()})]}),k&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:Ie,disabled:R,title:m("colorPalette.randomPalette","Random palette"),"aria-label":m("colorPalette.randomPalette","Random palette"),children:[e.jsx(r.NiceIcon,{name:"shuffle",size:14})," ",m("colorPalette.randomPalette2","Random Palette")]})]})})]}),Nn=e.jsx("div",{className:"nice-palette__tab",children:Ye.length>0?e.jsxs("div",{className:"nice-palette__variations",children:[e.jsx("span",{className:"nice-palette__section-tag",children:m("colorPalette.tintsShades","Tints & Shades")}),e.jsx("div",{ref:Lt,className:"nice-palette__variation-strip",role:"group","aria-label":m("colorPalette.tintsShades","Tints & Shades"),children:Ye.map((Q,ye)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:Q},title:Q.toUpperCase(),onClick:()=>{R||V(pe,Q)},onKeyDown:we=>{!R&&(we.key==="Enter"||we.key===" ")&&(we.preventDefault(),V(pe,Q))},role:"button","aria-label":Q.toUpperCase()},ye))})]}):e.jsx("div",{className:"nice-palette__empty",children:m("colorPalette.noVariationsAvailable","No variations available.")})}),Cn=e.jsx("div",{className:"nice-palette__tab",children:e.jsx("div",{className:"nice-palette__preset-grid",children:Pt.map(Q=>{const ye=jt(ut,Q);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${Se===Q?"nice-palette__preset-card--active":""}`,onClick:()=>u(Q),disabled:R,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:ye.map((we,Te)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:we}},Te))}),e.jsx("span",{className:"nice-palette__preset-label",children:Jn[Q]})]},Q)})})}),Sn=e.jsxs("div",{className:"nice-palette__tab",children:[ne&&e.jsxs("div",{className:"nice-palette__info-panel",children:[e.jsx("div",{className:"nice-palette__section-title",children:m("colorPalette.selectedColorInfo","Selected Color Info")}),e.jsx(Vn,{hex:Xe})]}),ae&&e.jsxs("div",{className:"nice-palette__info-panel",children:[e.jsx("div",{className:"nice-palette__section-title",children:m("colorPalette.contrastAnalysisWcag21","Contrast Analysis (WCAG 2.1)")}),e.jsx(Gn,{colors:Ne})]})]}),En=e.jsx("div",{className:"nice-palette__tab nice-palette__custom-schemes",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[De.length===0&&e.jsx("div",{style:{fontSize:12,color:"var(--nice-text-muted)"},children:m("colorPalette.schemes.empty","Save the current palette as a reusable scheme.")}),De.map(Q=>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:Yt("custom",{angles:Q.angles,size:16})}),e.jsx("span",{style:{flex:1},children:Q.name}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>{te(Q.id),Oe("custom")},disabled:R,children:m("colorPalette.use","Use")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>Ge(De.filter(ye=>ye.id!==Q.id)),disabled:R,"aria-label":m("colorPalette.delete","Delete {name}").replace("{name}",String(Q.name)),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},Q.id)),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R,onClick:()=>{const Q=Ke(Ne[0]).h,ye=Ne.map(we=>(Ke(we).h-Q+540)%360-180);A.prompt({title:m("colorPalette.schemeNamePrompt","Scheme name"),defaultValue:`Scheme ${De.length+1}`}).then(we=>{if(!we)return;const Te={id:`cs-${Date.now()}`,name:we,angles:ye};Ge([...De,Te])})},children:m("colorPalette.saveCurrentAsScheme","+ Save current as scheme")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R||De.length===0,onClick:()=>{typeof navigator>"u"||navigator.clipboard?.writeText(JSON.stringify(De,null,2))},children:m("colorPalette.exportJson","Export JSON")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:R,onClick:()=>{A.prompt({title:m("colorPalette.pasteSchemesPrompt","Paste the schemes JSON")}).then(Q=>{if(Q)try{const ye=JSON.parse(Q);Array.isArray(ye)&&Ge(ye)}catch{}})},children:m("colorPalette.importJson","Import JSON")})]})]})}),ot=[{id:"colors",label:m("colorPalette.colors","Colors"),content:wn}];le&&Pt.length>0&&ot.push({id:"presets",label:m("colorPalette.presets","Presets"),content:Cn}),B&&ot.push({id:"variations",label:m("colorPalette.variations","Variations"),content:Nn}),(ne||ae)&&ot.push({id:"info",label:m("colorPalette.info","Info"),content:Sn}),ot.push({id:"schemes",label:m("colorPalette.schemes","Schemes"),content:En});const $n=e.jsxs("div",{className:"nice-palette__popup-header",children:[Y&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(qn,{hues:ut,colors:Ne,baseHue:$e.h,onBaseHueChange:ze,mode:be,distance:fe,disabled:R}),(be==="analogous"||be==="split-complementary"||be==="analogous-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsx("label",{children:m("colorPalette.distance","Distance: {dist}°").replace("{dist}",String(fe))}),e.jsx("input",{type:"range",min:10,max:90,value:fe,onChange:Q=>wt(Number(Q.target.value)),disabled:R,className:"nice-palette__distance-slider","aria-label":m("colorPalette.distanceLabel","Distance")})]})]}),e.jsx("button",{type:"button",className:"nice-palette__confirm",onClick:()=>se(!1),"aria-label":m("controls.confirm","Confirm"),title:m("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),In=e.jsxs("div",{className:"nice-palette nice-palette--studio",children:[$n,e.jsx(mt.NiceTabs,{tabs:ot,variant:"enclosed",size:"sm"})]});return e.jsxs("div",{ref:h,id:S,className:`nice-field nice-palette-field ${R?"nice-palette--disabled":""} ${F==="left"?"nice-field--label-left":""} ${b?"nice-field--loading":""} ${N?"nice-field--error":""} ${i||""}`,style:a,"data-testid":j,children:[A.element,T&&e.jsx("label",{htmlFor:S,className:"nice-field__label",children:T}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("div",{ref:ie,className:"nice-palette__field-swatches",role:"button",tabIndex:R||C?-1:0,"aria-haspopup":"dialog","aria-expanded":ke,"aria-readonly":C||void 0,"aria-label":m("colorPalette.openStudio","Open palette studio"),onClick:()=>{!R&&!C&&se(Q=>!Q)},onKeyDown:Q=>{!R&&!C&&(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),se(ye=>!ye))},children:Ne.map((Q,ye)=>e.jsx("span",{role:"presentation",className:"nice-palette__field-swatch",style:{background:Q},title:Q.toUpperCase(),onClick:we=>{we.stopPropagation(),!R&&!C&&(je(ye),se(!0))}},ye))}),b&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),ke&&xe&&ee&&it.createPortal(e.jsx("div",{ref:ce,className:`nice-palette__popup${U?` ${U}`:""}`,"data-theme":U==="nice-dark"?"dark":U==="nice-light"?"light":void 0,role:"dialog","aria-label":m("colorPalette.studio","Palette studio"),style:{position:"fixed",left:xe.left,top:xe.top,zIndex:1e3},children:In}),ee)]}),typeof N=="string"&&N&&e.jsx("div",{className:"nice-field__error",role:"alert",children:N})]})}),{displayName:"NiceColorPalette"});function Tt(){return{type:"linear",angle:90,stops:[{color:"var(--nice-primary, #3b82f6)",position:0},{color:"var(--nice-accent, #8b5cf6)",position:100}]}}function Rt(t){const i=t.stops.slice().sort((o,l)=>o.position-l.position).map(o=>`${o.color} ${o.position}%`).join(", "),a=t.repeating?"repeating-":"";switch(t.type){case"linear":return`${a}linear-gradient(${t.angle}deg, ${i})`;case"radial":{const o=t.shape||"ellipse",l=t.size||"farthest-corner",g=t.positionX??50,y=t.positionY??50;return`${a}radial-gradient(${o} ${l} at ${g}% ${y}%, ${i})`}case"conic":{const o=t.angle??0,l=t.positionX??50,g=t.positionY??50;return`${a}conic-gradient(from ${o}deg at ${l}% ${g}%, ${i})`}}}function yn(t){const i=t.trim(),a=i.startsWith("repeating-");if(i.includes("linear-gradient")){const o=i.match(/linear-gradient\((.+)\)/)?.[1];if(!o)return null;const l=o.split(",").map(I=>I.trim());let g=90,y=0;const M=l[0].match(/^(\d+)deg$/);M&&(g=parseInt(M[1]),y=1);const P=Et(l.slice(y));return{type:"linear",angle:g,repeating:a,stops:P}}if(i.includes("radial-gradient")){const o=i.match(/radial-gradient\((.+)\)/)?.[1];if(!o)return null;const l=o.split(",").map(y=>y.trim()),g=Et(l.filter(y=>y.includes("#")||y.includes("rgb")));return{type:"radial",angle:0,repeating:a,stops:g.length>=2?g:Tt().stops}}if(i.includes("conic-gradient")){const o=i.match(/conic-gradient\((.+)\)/)?.[1];if(!o)return null;const l=o.split(",").map(y=>y.trim()),g=Et(l.filter(y=>y.includes("#")||y.includes("rgb")));return{type:"conic",angle:0,repeating:a,stops:g.length>=2?g:Tt().stops}}return null}function Et(t){return t.map((i,a,o)=>{const l=i.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(l){const g=l[2]?parseFloat(l[2]):a/Math.max(1,o.length-1)*100;return{color:l[1],position:g}}return{color:i,position:a/Math.max(1,o.length-1)*100}})}function ni(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ii(t=2){const i=["linear","radial","conic"],a=i[Math.floor(Math.random()*i.length)],o=[];for(let l=0;l<t;l++)o.push({color:ni(),position:Math.round(l/(t-1)*100)});return{type:a,angle:Math.floor(Math.random()*360),stops:o,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 xn=[{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}}],oi=Object.assign(n.forwardRef(({id:t,className:i,style:a,accessMode:o,value:l,onChange:g,showCssOutput:y=!0,showPresets:M=!0,showEditor:P=!0,showRandom:I=!0,maxStops:J=10,label:X,labelPlacement:O="top",disabled:$,readOnly:Y,loading:ae,error:ne,errorPlacement:le="bottom",width:G,"data-testid":B},k)=>{const s=r.useNiceAccessMode(o,t),T=s==="hidden";s==="disabled"&&($=!0);const F=Y||s==="readOnly",R=r.useControlId(t),{t:_}=r.useNiceTranslation(),b=l??Tt(),N=n.useMemo(()=>Rt(b),[b]),[f,E]=n.useState(0),[L,w]=n.useState(""),d=n.useRef(null),[z,j]=n.useState(!1),[h,c]=n.useState(null),[p,C]=n.useState(""),m=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),A=n.useRef(null),D=n.useRef(null),W=typeof G=="number"?G:340;n.useLayoutEffect(()=>{if(!z||!A.current)return;C(Qe.scopeThemeClass(A.current));const x=()=>{const ee=A.current?.getBoundingClientRect();if(!ee)return;let ie=ee.left;ie+W>window.innerWidth-8&&(ie=Math.max(8,window.innerWidth-W-8));let ce=ee.bottom+6;ce>window.innerHeight*.5&&(ce=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,520)-8)),c({left:ie,top:ce})};return x(),window.addEventListener("scroll",x,!0),window.addEventListener("resize",x),()=>{window.removeEventListener("scroll",x,!0),window.removeEventListener("resize",x)}},[z,W]),n.useEffect(()=>{if(!z)return;const x=ee=>{const ie=ee.target;A.current?.contains(ie)||D.current?.contains(ie)||(ie instanceof Element?ie:ie?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||j(!1)};return document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x)}},[z]),r.useOverlayFocus(D,{open:z,modal:!1,onClose:()=>j(!1)});const v=n.useCallback(x=>{g?.(x)},[g]),q=n.useCallback(x=>{$||v({...b,type:x})},[$,b,v]),H=n.useCallback(x=>{$||v({...b,angle:x})},[$,b,v]),me=n.useCallback(x=>{$||v({...b,repeating:x})},[$,b,v]),pe=n.useCallback(x=>{$||v({...b,shape:x})},[$,b,v]),je=n.useCallback((x,ee)=>{if($)return;const ie=b.stops.map((ce,be)=>be===x?{...ce,...ee}:ce);v({...b,stops:ie})},[$,b,v]),ge=n.useRef(!1),ue=n.useCallback((x,ee)=>{if($||!d.current)return;x.stopPropagation(),x.preventDefault(),E(ee),ge.current=!1;const ie=be=>{if(!d.current)return;ge.current=!0;const fe=d.current.getBoundingClientRect(),Se=Math.round(Math.max(0,Math.min(100,(be.clientX-fe.left)/fe.width*100)));je(ee,{position:Se})},ce=()=>{document.removeEventListener("pointermove",ie),document.removeEventListener("pointerup",ce),document.removeEventListener("pointercancel",ce)};document.addEventListener("pointermove",ie),document.addEventListener("pointerup",ce),document.addEventListener("pointercancel",ce)},[$,je]),de=n.useCallback(()=>{if($||b.stops.length>=J)return;const x=b.stops.slice().sort((fe,Se)=>fe.position-Se.position);let ee=0,ie=x[0];for(let fe=0;fe<x.length-1;fe++){const Se=x[fe+1].position-x[fe].position;Se>ee&&(ee=Se,ie=x[fe])}const ce=Math.round(ie.position+ee/2),be="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");v({...b,stops:[...b.stops,{color:be,position:ce}]})},[$,b,J,v]),he=n.useCallback(x=>{if($||b.stops.length<=2)return;const ee=b.stops.filter((ie,ce)=>ce!==x);v({...b,stops:ee}),f>=ee.length&&E(ee.length-1)},[$,b,f,v]),oe=(x,ee)=>{const ie=b.stops[ee];if($||!ie)return;const ce=x.shiftKey?10:1,be=x.key==="ArrowLeft"||x.key==="ArrowDown"?ie.position-ce:x.key==="ArrowRight"||x.key==="ArrowUp"?ie.position+ce:x.key==="PageDown"?ie.position-10:x.key==="PageUp"?ie.position+10:x.key==="Home"?0:x.key==="End"?100:null;be!==null?(x.preventDefault(),je(ee,{position:Math.max(0,Math.min(100,be))})):(x.key==="Delete"||x.key==="Backspace")&&b.stops.length>2&&(x.preventDefault(),he(ee))},ve=n.useCallback(()=>{if($)return;const x=2+Math.floor(Math.random()*3);v(ii(x))},[$,v]),_e=n.useCallback(()=>{if($||!L.trim())return;const x=yn(L);x&&v(x)},[$,L,v]),te=n.useCallback(x=>{if($||!d.current||b.stops.length>=J)return;const ee=x.target;if(ge.current||ee.closest(".nice-gradient__stop-marker")){ge.current=!1;return}const ie=d.current.getBoundingClientRect(),ce=Math.round((x.clientX-ie.left)/ie.width*100),be="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),fe=[...b.stops,{color:be,position:ce}];v({...b,stops:fe}),E(fe.length-1)},[$,b,J,v]),ke=n.useMemo(()=>b.stops.slice().sort((x,ee)=>x.position-ee.position),[b.stops]),se=n.useMemo(()=>`linear-gradient(90deg, ${ke.map(x=>`${x.color} ${x.position}%`).join(", ")})`,[ke]);if(T)return null;const xe=e.jsxs("div",{className:"nice-gradient__tab",children:[P&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-gradient__type-row",children:[["linear","radial","conic"].map(x=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${b.type===x?"nice-gradient__type-btn--active":""}`,onClick:()=>q(x),disabled:$,"aria-pressed":b.type===x,children:x.charAt(0).toUpperCase()+x.slice(1)},x)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:b.repeating??!1,onChange:x=>me(x.target.checked),disabled:$}),_("controls.repeating","Repeating")]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[b.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.angle","Angle: {angle}°").replace("{angle}",String(b.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:b.angle,onChange:x=>H(Number(x.target.value)),disabled:$,className:"nice-gradient__slider","aria-label":_("gradient.angle","Angle")}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(x=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${b.angle===x?"nice-gradient__angle-btn--active":""}`,onClick:()=>H(x),disabled:$,title:`${x}°`,"aria-label":`${x}°`,"aria-pressed":b.angle===x,children:e.jsx("span",{style:{transform:`rotate(${x}deg)`,display:"inline-flex"},children:e.jsx(r.NiceIcon,{name:"arrow-right",size:14})})},x))})]}),b.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.shape","Shape:")}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(x=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(b.shape||"ellipse")===x?"nice-gradient__shape-btn--active":""}`,onClick:()=>pe(x),disabled:$,"aria-pressed":(b.shape||"ellipse")===x,children:x},x))})]}),(b.type==="radial"||b.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.center","Center: {positionX}%, {positionY}%").replace("{positionX}",String(b.positionX??50)).replace("{positionY}",String(b.positionY??50))}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:b.positionX??50,onChange:x=>v({...b,positionX:Number(x.target.value)}),disabled:$,className:"nice-gradient__slider","aria-label":_("gradient.centerX","Horizontal center")}),e.jsx("input",{type:"range",min:0,max:100,value:b.positionY??50,onChange:x=>v({...b,positionY:Number(x.target.value)}),disabled:$,className:"nice-gradient__slider","aria-label":_("gradient.centerY","Vertical center")})]})]}),b.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.startAngle","Start angle: {angle}°").replace("{angle}",String(b.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:b.angle,onChange:x=>H(Number(x.target.value)),disabled:$,className:"nice-gradient__slider","aria-label":_("gradient.startAngle","Start angle")})]})]}),e.jsxs("div",{className:"nice-gradient__bar-container",children:[e.jsx("div",{role:"presentation",ref:d,className:"nice-gradient__bar",style:{background:se},onClick:te,children:b.stops.map((x,ee)=>e.jsx("div",{className:`nice-gradient__stop-marker ${f===ee?"nice-gradient__stop-marker--active":""}`,style:{left:`${x.position}%`},onPointerDown:ie=>ue(ie,ee),onClick:ie=>{ie.stopPropagation(),E(ee),ge.current=!1},onFocus:()=>E(ee),onKeyDown:ie=>oe(ie,ee),role:"slider",tabIndex:$?-1:0,"aria-label":_("gradient.stop","Stop {n}").replace("{n}",String(ee+1)),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":x.position,"aria-valuetext":`${x.color} ${x.position}%`,title:`${x.color} @ ${x.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:x.color}})},ee))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:de,disabled:$||b.stops.length>=J,title:_("controls.addStop","Add stop"),"aria-label":_("controls.addStop","Add stop"),children:e.jsx(r.NiceIcon,{name:"plus",size:14})})]}),e.jsx("div",{className:"nice-gradient__stop-editor",children:e.jsx("div",{className:"nice-gradient__stop-list",children:ke.map((x,ee)=>{const ie=b.stops.indexOf(x);return e.jsxs("div",{role:"presentation",className:`nice-gradient__stop-row ${f===ie?"nice-gradient__stop-row--active":""}`,onClick:()=>E(ie),onFocus:()=>E(ie),children:[e.jsx("input",{type:"color",value:x.color,onChange:ce=>je(ie,{color:ce.target.value}),disabled:$,className:"nice-gradient__stop-color","aria-label":_("gradient.stopColor","Stop color")}),e.jsx("input",{type:"text",value:x.color.toUpperCase(),maxLength:7,onChange:ce=>je(ie,{color:ce.target.value}),disabled:$,className:"nice-gradient__stop-hex","aria-label":_("gradient.stopHex","Stop color (hex)")}),e.jsx("input",{type:"number",min:0,max:100,value:x.position,onChange:ce=>je(ie,{position:Number(ce.target.value)}),disabled:$,className:"nice-gradient__stop-pos","aria-label":_("gradient.stopPosition","Stop position")}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),b.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>he(ie),disabled:$,"aria-label":_("controls.removeStop","Remove stop"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},ie)})})})]}),I&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:ve,disabled:$,title:_("controls.randomGradient","Random gradient"),"aria-label":_("controls.randomGradient","Random gradient"),children:[e.jsx(r.NiceIcon,{name:"shuffle",size:14})," ",_("controls.randomGradient2","Random Gradient")]})]}),K=e.jsx("div",{className:"nice-gradient__tab",children:e.jsx("div",{className:"nice-gradient__preset-grid",children:xn.map((x,ee)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{$||v(x.value)},disabled:$,title:x.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:Rt(x.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:x.name})]},ee))})}),U=e.jsxs("div",{className:"nice-gradient__tab",children:[e.jsxs("div",{className:"nice-gradient__css-output",children:[e.jsx("code",{children:`background: ${N};`}),e.jsx("button",{type:"button",className:"nice-gradient__copy-btn",onClick:()=>navigator.clipboard?.writeText(`background: ${N};`),title:_("controls.copyCss","Copy CSS"),"aria-label":_("controls.copyCss","Copy CSS"),children:e.jsx(r.NiceIcon,{name:"clipboard",size:16})})]}),e.jsxs("div",{className:"nice-gradient__css-import",children:[e.jsx("input",{type:"text",className:"nice-gradient__css-input",placeholder:_("controls.pasteCssGradientToImport","Paste CSS gradient to import..."),value:L,onChange:x=>w(x.target.value),disabled:$,"aria-label":_("gradient.importCss","CSS gradient to import")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:_e,disabled:$,children:_("controls.import","Import")})]})]}),Z=[{id:"editor",label:_("controls.editor","Editor"),content:xe}];return M&&Z.push({id:"presets",label:_("controls.presets","Presets"),content:K}),y&&Z.push({id:"css",label:"CSS",content:U}),e.jsxs("div",{ref:k,id:R,className:`nice-field nice-gradient-field ${$?"nice-gradient--disabled":""} ${O==="left"?"nice-field--label-left":""} ${ae?"nice-field--loading":""} ${ne?"nice-field--error":""} ${le==="right"?"nice-field--error-right":""} ${i||""}`,style:a,"data-testid":B,children:[X&&e.jsx("label",{htmlFor:R,className:"nice-field__label",children:X}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("button",{ref:A,type:"button",className:"nice-gradient__swatch",style:{background:N},"aria-haspopup":"dialog","aria-expanded":z,"aria-readonly":F||void 0,"aria-label":_("controls.openGradientEditor","Open gradient editor"),disabled:$,onClick:()=>{!$&&!F&&j(x=>!x)}}),ae&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),le==="right"&&typeof ne=="string"&&ne&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ne}),z&&h&&m&&it.createPortal(e.jsx("div",{ref:D,className:`nice-gradient__popup${p?` ${p}`:""}`,"data-theme":p==="nice-dark"?"dark":p==="nice-light"?"light":void 0,role:"dialog","aria-label":_("controls.gradientEditor","Gradient editor"),style:{position:"fixed",left:h.left,top:h.top,width:G!=null?typeof G=="number"?`${G}px`:G:340,zIndex:1e3},children:e.jsxs("div",{className:"nice-gradient nice-gradient--studio",children:[e.jsxs("div",{className:"nice-gradient__popup-header",children:[e.jsx("div",{className:"nice-gradient__preview",style:{background:N}}),e.jsx("button",{type:"button",className:"nice-gradient__confirm",onClick:()=>j(!1),"aria-label":_("controls.confirm","Confirm"),title:_("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),e.jsx(mt.NiceTabs,{tabs:Z,variant:"enclosed",size:"sm"})]})}),m)]}),le!=="right"&&typeof ne=="string"&&ne&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ne})]})}),{displayName:"NiceGradientPicker"}),ai=[{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"}],si=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}],ri=n.forwardRef(function(i,a){const{enableAI:o=!0,aiModel:l,enableImprove:g=!0,enableTranslate:y=!0,enableGenerate:M=!0,toolbar:P,languages:I=ai,textStyles:J=si,onImprove:X,onTranslate:O,onGenerate:$,showAIToolbar:Y=!0,value:ae,onChange:ne,...le}=i,G=n.useRef(null),[B,k]=n.useState(!1),[s,T]=n.useState(!1),[F,R]=n.useState(!1),[_,b]=n.useState(""),[N,f]=n.useState(""),[E,L]=n.useState("professional"),[w,d]=n.useState(""),[z,j]=n.useState(I[0]?.code||"en"),[h,c]=n.useState(""),[p,C]=n.useState(""),{t:S}=an.useNiceTranslation(),m=r.useNiceAI(),{improveText:A,translate:D,generateHtml:W,isLoading:v}=r.useTextImprovement(),q=o&&m.isConfigured,H=n.useCallback(()=>{const oe=window.getSelection();return oe&&oe.toString().trim()?oe.toString():""},[]),me=n.useCallback(oe=>{const ve=window.getSelection();if(ve&&ve.rangeCount>0){const _e=ve.getRangeAt(0);_e.deleteContents();const te=document.createElement("div");te.innerHTML=oe;const ke=document.createDocumentFragment();for(;te.firstChild;)ke.appendChild(te.firstChild);if(_e.insertNode(ke),G.current){const se=G.current.innerHTML;ne?.(se)}}},[ne]),pe=n.useCallback(async(oe="professional")=>{if(!q||!g)return"";const ve=H();if(!ve)return"";b(ve),L(oe),k(!0),f("");try{const _e=await A(ve,oe);return f(_e),X?.(ve,_e,oe),_e}catch{return f(S("htmlEditorAI.improveFailed","Failed to improve text")),""}},[q,g,H,A,X,S]),je=n.useCallback(async oe=>{if(!q||!y)return"";const ve=H();if(!ve)return"";b(ve),j(oe),T(!0),d("");try{const _e=I.find(ke=>ke.code===oe)?.label||oe,te=await D(ve,_e);return d(te),O?.(ve,te,oe),te}catch{return d(S("htmlEditorAI.translateFailed","Failed to translate text")),""}},[q,y,H,D,I,O,S]),ge=n.useCallback(async oe=>{if(!q||!M||!oe.trim())return"";c(oe),C("");try{const ve=await W(oe);return C(ve),$?.(oe,ve),ve}catch{return C(S("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[q,M,W,$,S]),ue=n.useCallback(()=>{N&&me(N),k(!1),f("")},[N,me]),de=n.useCallback(()=>{w&&me(w),T(!1),d("")},[w,me]),he=n.useCallback(()=>{if(p&&G.current){document.execCommand("insertHTML",!1,p);const oe=G.current.innerHTML;ne?.(oe)}R(!1),C(""),c("")},[p,ne]);return n.useImperativeHandle(a,()=>({getEditor:()=>G.current,focus:()=>G.current?.focus(),getValue:()=>G.current?.innerHTML||"",setValue:oe=>{G.current&&(G.current.innerHTML=oe,ne?.(oe))},getSelection:H,insertHtml:oe=>{document.execCommand("insertHTML",!1,oe),G.current&&ne?.(G.current.innerHTML)},improveSelection:pe,translateSelection:je,generateHtml:ge})),n.useCallback(oe=>{G.current=oe},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":i["data-testid"],children:[Y&&q&&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:S("htmlEditorAI.ai","AI")}),v&&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:[g&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>pe(),disabled:v,title:S("htmlEditorAI.improveText","Improve selected text"),children:[e.jsx(r.NiceIcon,{name:"star",size:14})," ",S("htmlEditorAI.improve","Improve")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu",children:J.map(({style:oe,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>pe(oe),children:ve},oe))})]}),y&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",disabled:v,title:S("htmlEditorAI.translateText","Translate selected text"),children:[e.jsx(r.NiceIcon,{name:"globe",size:14})," ",S("htmlEditorAI.translate","Translate")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu nice-html-editor-ai__dropdown-menu--languages",children:I.map(({code:oe,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>je(oe),children:ve},oe))})]}),M&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>R(!0),disabled:v,title:S("htmlEditorAI.generateHtml","Generate HTML from description"),children:[e.jsx(r.NiceIcon,{name:"zap",size:14})," ",S("htmlEditorAI.generate","Generate")]})]})]}),e.jsx("div",{className:"nice-html-editor-ai__editor-wrapper",children:e.jsx(Mn.NiceHtmlEditor,{value:ae,onChange:ne,toolbar:P,...le})}),B&&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:[e.jsx(r.NiceIcon,{name:"star",size:16})," ",S("htmlEditorAI.improveText","Improve Text")]}),e.jsx("div",{className:"nice-html-editor-ai__style-selector",children:J.map(({style:oe,label:ve})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${E===oe?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{L(oe),pe(oe)},children:ve},oe))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>k(!1),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:v?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:_})]}),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:ue,disabled:!N||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",S("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{k(!1),f("")},children:S("htmlEditorAI.cancel","Cancel")})]})]}),s&&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:[e.jsx(r.NiceIcon,{name:"globe",size:16})," ",S("htmlEditorAI.translateText","Translate Text")]}),e.jsx("div",{className:"nice-html-editor-ai__language-selector",children:e.jsx("select",{value:z,onChange:oe=>{j(oe.target.value),je(oe.target.value)},className:"nice-html-editor-ai__language-select",children:I.map(({code:oe,label:ve})=>e.jsx("option",{value:oe,children:ve},oe))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>T(!1),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:v?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:_})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:I.find(oe=>oe.code===z)?.label||z}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:w})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:de,disabled:!w||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",S("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{T(!1),d("")},children:S("htmlEditorAI.cancel","Cancel")})]})]}),F&&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:[e.jsx(r.NiceIcon,{name:"zap",size:16})," ",S("htmlEditorAI.generateHtml","Generate HTML")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>{R(!1),C(""),c("")},children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),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:h,onChange:oe=>c(oe.target.value),className:"nice-html-editor-ai__generate-textarea",rows:3}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__generate-btn",onClick:()=>ge(h),disabled:v||!h.trim(),children:v?S("htmlEditorAI.generating","Generating..."):S("htmlEditorAI.generate","Generate")})]}),p&&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:p}}),e.jsx("h5",{children:S("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:p})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:he,disabled:!p||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",S("htmlEditorAI.insert","Insert")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{R(!1),C(""),c("")},children:S("htmlEditorAI.cancel","Cancel")})]})]})]})}),ci=[{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 li(t){let i=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return i=i.replace(/```(\w*)\n([\s\S]*?)```/g,(a,o,l)=>`<pre><code class="language-${o}">${l.trim()}</code></pre>`),i=i.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(a,o,l,g)=>{const y=o.split("|").filter(P=>P.trim()).map(P=>`<th>${P.trim()}</th>`).join(""),M=g.trim().split(`
2
- `).map(P=>`<tr>${P.split("|").filter(J=>J.trim()).map(J=>`<td>${J.trim()}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${y}</tr></thead><tbody>${M}</tbody></table>`}),i=i.replace(/^#### (.+)$/gm,"<h4>$1</h4>"),i=i.replace(/^### (.+)$/gm,"<h3>$1</h3>"),i=i.replace(/^## (.+)$/gm,"<h2>$1</h2>"),i=i.replace(/^# (.+)$/gm,"<h1>$1</h1>"),i=i.replace(/^&gt; (.+)$/gm,"<blockquote>$1</blockquote>"),i=i.replace(/^---$/gm,"<hr/>"),i=i.replace(/^- \[x\] (.+)$/gm,'<li class="task done"><input type="checkbox" checked disabled> $1</li>'),i=i.replace(/^- \[ \] (.+)$/gm,'<li class="task"><input type="checkbox" disabled> $1</li>'),i=i.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),i=i.replace(/\*(.+?)\*/g,"<em>$1</em>"),i=i.replace(/~~(.+?)~~/g,"<del>$1</del>"),i=i.replace(/`(.+?)`/g,"<code>$1</code>"),i=i.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" style="max-width:100%"/>'),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2">$1</a>'),i=i.replace(/^- (.+)$/gm,"<li>$1</li>"),i=i.replace(/^\d+\. (.+)$/gm,"<li>$1</li>"),i=i.replace(/\n/g,"<br/>"),i}const di=[{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",icon:"type",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",icon:"list",md:"- ",tip:"Unordered list",group:"list"},{key:"ol",label:"1.",md:"1. ",tip:"Ordered list",group:"list"},{key:"task",icon:"check-square",md:"- [ ] ",tip:"Task list",group:"list"},{key:"quote",icon:"message",md:"> ",tip:"Blockquote",group:"block"},{key:"hr",icon:"minus",md:`---
3
- `,tip:"Horizontal rule",group:"block"},{key:"link",icon:"link",md:"[](url)",tip:"Link",shortcut:"Ctrl+K",group:"insert"},{key:"image",icon:"image",md:"![](url)",tip:"Image",group:"insert"},{key:"table",icon:"table",md:`| H1 | H2 | H3 |
4
- | --- | --- | --- |
5
- | c1 | c2 | c3 |
6
- `,tip:"Table",group:"insert"},{key:"codeblock",label:"```",md:"```\n",tip:"Code block",group:"insert"}],mi=["format","heading","list","block","insert"],ui=Object.assign(n.forwardRef(({value:t="",onChange:i,preview:a="side",placeholder:o,disabled:l,readOnly:g,size:y="md",editorSize:M="standard",toolbar:P=!0,minHeight:I=200,showWordCount:J=!1,showLineNumbers:X=!1,onExportHtml:O,onImageUpload:$,tutorial:Y,className:ae,style:ne,id:le,"data-testid":G},B)=>{const{t:k}=r.useNiceTranslation(),s=r.useControlId(le),[T,F]=n.useState("edit"),[R,_]=n.useState(!1),b=n.useRef(null),[N]=n.useState(r.createTabEscape),f=n.useMemo(()=>li(t),[t]),E=n.useMemo(()=>{const c=t.trim()?t.trim().split(/\s+/).length:0,p=t.length,C=t.split(`
7
- `).length;return{words:c,chars:p,lines:C}},[t]),L=n.useCallback(c=>{const p=b.current;if(!p)return;const C=p.selectionStart,S=p.selectionEnd,m=t.slice(C,S);let A,D;c==="[](url)"?(A=t.slice(0,C)+`[${m||"text"}](url)`+t.slice(S),D=C+1+(m||"text").length+2):c==="![](url)"?(A=t.slice(0,C)+`![${m||"alt"}](url)`+t.slice(S),D=C+2+(m||"alt").length+2):c.endsWith(`
8
- `)||c.endsWith(" ")?(A=t.slice(0,C)+c+m+t.slice(S),D=C+c.length+m.length):(A=t.slice(0,C)+c+m+c+t.slice(S),D=C+c.length+m.length+c.length),i?.(A),requestAnimationFrame(()=>{p.focus(),p.setSelectionRange(D,D)})},[t,i]),w=n.useCallback(c=>{if(!N(c)&&((c.ctrlKey||c.metaKey)&&(c.key==="b"?(c.preventDefault(),L("**")):c.key==="i"?(c.preventDefault(),L("*")):c.key==="k"&&(c.preventDefault(),L("[](url)"))),c.key==="Tab"&&!g)){c.preventDefault();const p=c.currentTarget,C=p.selectionStart,S=p.selectionEnd,m=" ";if(c.shiftKey){const W=t.slice(0,C).lastIndexOf(`
9
- `)+1;if(t.slice(W,W+m.length)===m){const v=t.slice(0,W)+t.slice(W+m.length);i?.(v),requestAnimationFrame(()=>{p.selectionStart=p.selectionEnd=C-m.length})}}else{const A=t.slice(0,C)+m+t.slice(S);i?.(A),requestAnimationFrame(()=>{p.selectionStart=p.selectionEnd=C+m.length})}}},[t,i,L,N,g]),d=n.useCallback(async c=>{if(!$)return;const p=Array.from(c.dataTransfer.files).filter(C=>C.type.startsWith("image/"));if(p.length!==0){c.preventDefault();for(const C of p){const S=await $(C),m=b.current;if(!m)continue;const A=m.selectionStart,D=`![${C.name}](${S})
10
- `,W=t.slice(0,A)+D+t.slice(A);i?.(W)}}},[t,i,$]),z=a!=="tab"||T==="edit",j=a==="side"||a==="tab"&&T==="preview"||a===!0,h=`nice-md-editor nice-md-editor--${y} nice-editor--${M} nice-md-editor--preview-${a}${R?" nice-md-editor--fullscreen":""} ${ae||""}`;return e.jsxs("div",{ref:B,id:s,className:h,style:{position:"relative",...ne},"data-testid":G,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(Y,ci)})}),P&&e.jsxs("div",{className:"nice-md-editor__toolbar",children:[mi.map((c,p)=>e.jsxs(n.Fragment,{children:[p>0&&e.jsx("span",{className:"nice-md-editor__sep"}),di.filter(C=>C.group===c).map(C=>e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:C.shortcut?`${C.tip} (${C.shortcut})`:C.tip,disabled:l||g,onClick:()=>L(C.md),"aria-label":C.tip,children:C.icon?e.jsx(r.NiceIcon,{name:C.icon,size:16}):C.label},C.key))]},c)),e.jsx("span",{className:"nice-md-editor__sep"}),e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:k("markdownEditor.fullscreen","Fullscreen"),"aria-label":k("markdownEditor.fullscreen","Fullscreen"),onClick:()=>_(!R),children:e.jsx(r.NiceIcon,{name:R?"collapse":"expand",size:16})}),O&&e.jsx("button",{type:"button",className:"nice-md-editor__btn",title:k("markdownEditor.exportHtml","Export HTML"),"aria-label":k("markdownEditor.exportHtml","Export HTML"),onClick:()=>O(f),children:e.jsx(r.NiceIcon,{name:"external-link",size:16})}),a==="tab"&&e.jsxs("span",{className:"nice-md-editor__tabs",children:[e.jsx("button",{type:"button",className:`nice-md-editor__tab${T==="edit"?" nice-md-editor__tab--active":""}`,onClick:()=>F("edit"),children:k("markdownEditor.edit","Edit")}),e.jsx("button",{type:"button",className:`nice-md-editor__tab${T==="preview"?" nice-md-editor__tab--active":""}`,onClick:()=>F("preview"),children:k("markdownEditor.preview","Preview")})]})]}),e.jsxs("div",{className:"nice-md-editor__body",style:{minHeight:I},children:[z&&e.jsxs("div",{className:"nice-md-editor__editor-wrap",children:[X&&e.jsx("div",{className:"nice-md-editor__line-numbers",children:Array.from({length:E.lines},(c,p)=>e.jsx("div",{className:"nice-md-editor__line-no",children:p+1},p))}),e.jsx("textarea",{ref:b,className:"nice-md-editor__textarea",value:t,onChange:c=>i?.(c.target.value),onKeyDown:w,onDrop:d,placeholder:o,disabled:l,readOnly:g,style:{minHeight:I},"aria-describedby":g?void 0:`${s}-tab-hint`}),!g&&e.jsx("span",{id:`${s}-tab-hint`,className:"nice-sr-only",children:k("input.tabEscapeHint","Tab indents. To leave the editor, press Escape, then Tab.")})]}),j&&e.jsx("div",{className:"nice-md-editor__preview",dangerouslySetInnerHTML:{__html:r.sanitizeHtml(f)},style:{minHeight:I}})]}),J&&e.jsxs("div",{className:"nice-md-editor__statusbar",children:[e.jsx("span",{children:k("markdownEditor.words","{words} words").replace("{words}",String(E.words))}),e.jsx("span",{children:k("markdownEditor.chars","{chars} chars").replace("{chars}",String(E.chars))}),e.jsx("span",{children:k("markdownEditor.lines","{lines} lines").replace("{lines}",String(E.lines))})]})]})}),{displayName:"NiceMarkdownEditor"}),pi=[{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 hi=0;function zt(){return`blk-${++hi}-${Date.now().toString(36)}`}function Vt(t=""){return{id:zt(),type:"paragraph",content:t}}function gi(t,i=""){const a={id:zt(),type:t,content:i};return t==="heading"&&(a.level=2),t==="list"&&(a.listType="unordered"),t==="toggle"&&(a.open=!0),a}const fi=[{type:"paragraph",label:"Text",icon:"align-left",keywords:"paragraph text"},{type:"heading",label:"Heading",icon:"type",keywords:"heading title"},{type:"list",label:"Bulleted list",icon:"list",keywords:"bullet unordered list"},{type:"list",label:"Numbered list",icon:"list-ordered",keywords:"numbered ordered list"},{type:"list",label:"Checklist",icon:"check-square",keywords:"check todo list"},{type:"quote",label:"Quote",icon:"quote",keywords:"quote blockquote"},{type:"callout",label:"Callout",icon:"info",keywords:"callout info alert"},{type:"toggle",label:"Toggle",icon:"chevron-right",keywords:"toggle collapse expand"},{type:"code",label:"Code",icon:"code",keywords:"code snippet"},{type:"image",label:"Image",icon:"image",keywords:"image photo picture"},{type:"video",label:"Video",icon:"video",keywords:"video embed"},{type:"table",label:"Table",icon:"table",keywords:"table grid"},{type:"divider",label:"Divider",icon:"minus",keywords:"divider line separator"},{type:"pageBreak",label:"Page Break",icon:"page-break",keywords:"page break"}];function rt(t){return t.type==="toggle"?t.content.split(`
11
- `).slice(1).join(`
12
- `):t.content}function yi(t){const i=[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=i?` style="${i}"`:"",o=(l,g)=>{let y=g;return t.bold&&(y=`<strong>${y}</strong>`),t.italic&&(y=`<em>${y}</em>`),t.underline&&(y=`<u>${y}</u>`),t.strikethrough&&(y=`<s>${y}</s>`),`<${l}${a}>${y}</${l}>`};switch(t.type){case"heading":return o(`h${t.level??2}`,t.content);case"paragraph":return o("p",t.content||"&nbsp;");case"list":{const l=t.listType==="ordered"?"ol":"ul",g=t.content.split(`
13
- `).map((y,M)=>t.listType==="checklist"?`<li><input type="checkbox" ${t.checked?.[M]??!1?"checked":""} disabled />${y}</li>`:`<li>${y}</li>`).join("");return`<${l}${a}>${g}</${l}>`}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 o("blockquote",t.content);case"callout":return`<div class="nice-doc-callout"${a}>${t.icon?`<span>${t.icon}</span>`:""}<div>${t.content}</div></div>`;case"toggle":return`<details${a}><summary>${t.content.split(`
14
- `)[0]}</summary>${t.content.split(`
15
- `).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 o("p",t.content)}}function xi(t){let i=0,a=0;for(const o of t){const l=o.content??"";i+=l.length;const g=l.trim().split(/\s+/).filter(Boolean);a+=g.length}return{words:a,chars:i,readingTime:Math.max(1,Math.ceil(a/200))}}const bi=Object.assign(n.forwardRef(({blocks:t,onChange:i,readOnly:a=!1,showToolbar:o=!0,size:l="md",editorSize:g="standard",placeholder:y,onExport:M,onImageUpload:P,maxUndo:I=50,slashCommands:J=!0,showWordCount:X=!1,showToc:O=!1,showFindReplace:$=!0,tutorial:Y,className:ae,style:ne,id:le,...G},B)=>{const k=r.useControlId(le),{t:s}=r.useNiceTranslation(),[T]=n.useState(r.createTabEscape),F=`${k}-tab-hint`,R=n.useRef(null);r.useRovingFocus(R,{orientation:"horizontal",itemSelector:"button"});const[_,b]=n.useState(()=>t??[Vt()]),N=t??_,[f,E]=n.useState(0),L=n.useRef(new Map),w=n.useRef(null),d=n.useRef(new Map),z=(u,V)=>{const re=d.current.get(u);return re!==void 0?re:(d.current.set(u,V),V)};n.useLayoutEffect(()=>{for(const u of N){const V=L.current.get(u.id);if(!V||!V.isConnected||V.getAttribute("contenteditable")===null)continue;const re=rt(u);V.textContent!==re&&(V.textContent=re)}});const[j,h]=n.useState(!1),[c,p]=n.useState(""),[C,S]=n.useState(""),[m,A]=n.useState([]),[D,W]=n.useState(0),[v,q]=n.useState(!1),H=n.useRef([]),me=n.useRef([]),pe=n.useCallback(u=>{H.current.push(u.map(V=>({...V,checked:V.checked?[...V.checked]:void 0}))),H.current.length>I&&H.current.shift(),me.current=[]},[I]),je=n.useCallback(()=>{if(H.current.length===0)return;const u=H.current.pop();me.current.push(N.map(V=>({...V}))),t||b(u),i?.(u)},[N,t,i]),ge=n.useCallback(()=>{if(me.current.length===0)return;const u=me.current.pop();H.current.push(N.map(V=>({...V}))),t||b(u),i?.(u)},[N,t,i]),[ue,de]=n.useState(!1),[he,oe]=n.useState(""),[ve,_e]=n.useState(0),te=n.useMemo(()=>{if(!ue||!J)return[];const u=he.toLowerCase();return fi.filter(V=>V.label.toLowerCase().includes(u)||V.keywords.includes(u))},[ue,he,J]),[ke,se]=n.useState(null),[xe,K]=n.useState(null),U=n.useCallback(u=>{pe(N);const V=u(N);t||b(V),i?.(V)},[N,t,i,pe]),Z=n.useCallback((u,V)=>{U(re=>re.map((Ee,Ie)=>Ie===u?{...Ee,...V}:Ee))},[U]),x=n.useCallback((u,V)=>{const re=V??Vt();U(Ee=>{const Ie=[...Ee];return Ie.splice(u+1,0,re),Ie}),E(u+1)},[U]),ee=n.useCallback(u=>{const V={...N[u],id:zt()};x(u,V)},[N,x]),ie=n.useCallback(u=>{N.length<=1||(U(V=>V.filter((re,Ee)=>Ee!==u)),E(Math.max(0,u-1)))},[N.length,U]),ce=n.useCallback((u,V)=>{const re=u+V;re<0||re>=N.length||(U(Ee=>{const Ie=[...Ee];return[Ie[u],Ie[re]]=[Ie[re],Ie[u]],Ie}),E(re))},[N.length,U]),be=n.useCallback((u,V)=>{const re={type:V};V==="heading"&&(re.level=2),V==="list"&&(re.listType="unordered"),V==="toggle"&&(re.open=!0),Z(u,re)},[Z]),fe=n.useCallback(u=>{const V=gi(u.type);u.type==="list"&&u.label.includes("Numbered")&&(V.listType="ordered"),u.type==="list"&&u.label.includes("Checklist")&&(V.listType="checklist",V.checked=[]),N[f]?.content===""||N[f]?.content==="/"?U(re=>re.map((Ee,Ie)=>Ie===f?{...V,id:Ee.id}:Ee)):x(f,V),de(!1),oe("")},[N,f,U,x]),Se=n.useCallback((u,V)=>{if(T(u)||a)return;const re=N[V];if(!re?.locked){if((u.ctrlKey||u.metaKey)&&u.key==="z"&&!u.shiftKey){u.preventDefault(),je();return}if((u.ctrlKey||u.metaKey)&&(u.key==="y"||u.key==="z"&&u.shiftKey)){u.preventDefault(),ge();return}if((u.ctrlKey||u.metaKey)&&u.key==="d"){u.preventDefault(),ee(V);return}if((u.ctrlKey||u.metaKey)&&u.key==="b"){u.preventDefault(),Z(V,{bold:!re?.bold});return}if((u.ctrlKey||u.metaKey)&&u.key==="i"){u.preventDefault(),Z(V,{italic:!re?.italic});return}if((u.ctrlKey||u.metaKey)&&u.key==="u"){u.preventDefault(),Z(V,{underline:!re?.underline});return}if((u.ctrlKey||u.metaKey)&&u.key==="e"){u.preventDefault(),Z(V,{strikethrough:!re?.strikethrough});return}if(u.key==="Tab"&&!u.shiftKey){u.preventDefault(),Z(V,{indent:Math.min((re?.indent??0)+1,4)});return}if(u.key==="Tab"&&u.shiftKey){u.preventDefault(),Z(V,{indent:Math.max((re?.indent??0)-1,0)});return}if((u.ctrlKey||u.metaKey)&&u.key==="f"&&$){u.preventDefault(),h(Ee=>!Ee);return}if(ue&&te.length>0){if(u.key==="ArrowDown"){u.preventDefault(),_e(Ee=>Math.min(Ee+1,te.length-1));return}if(u.key==="ArrowUp"){u.preventDefault(),_e(Ee=>Math.max(Ee-1,0));return}if(u.key==="Enter"){u.preventDefault(),fe(te[ve]);return}if(u.key==="Escape"){de(!1);return}}u.key==="Enter"&&!u.shiftKey?(u.preventDefault(),x(V)):u.key==="Backspace"&&N[V].content===""&&N.length>1?(u.preventDefault(),ie(V)):u.key==="ArrowUp"&&u.altKey?(u.preventDefault(),ce(V,-1)):u.key==="ArrowDown"&&u.altKey&&(u.preventDefault(),ce(V,1))}},[T,a,N,x,ie,ce,je,ge,ee,Z,ue,te,ve,fe,$]),Re=n.useCallback((u,V)=>{const re=u.target.textContent??"";J&&re.startsWith("/")?(de(!0),oe(re.slice(1)),_e(0)):ue&&de(!1),pe(N);const Ee=N.map((Ie,Ye)=>Ye===V?{...Ie,content:Ie.type==="toggle"?`${Ie.content.split(`
16
- `)[0]}
17
- ${re}`:re}:Ie);t||b(Ee),i?.(Ee)},[N,t,i,pe,J,ue]),De=n.useCallback((u,V)=>{se(V),u.dataTransfer.effectAllowed="move"},[]),Ge=n.useCallback((u,V)=>{u.preventDefault(),u.dataTransfer.dropEffect="move",K(V)},[]),Ve=n.useCallback((u,V)=>{if(u.preventDefault(),ke===null||ke===V){se(null),K(null);return}U(re=>{const Ee=[...re],[Ie]=Ee.splice(ke,1);return Ee.splice(V>ke?V-1:V,0,Ie),Ee}),E(V>ke?V-1:V),se(null),K(null)},[ke,U]);n.useEffect(()=>{if(!j||!c){A([]);return}const u=c.toLowerCase(),V=[];N.forEach((re,Ee)=>{const Ie=(re.content??"").toLowerCase();let Ye=0;for(;Ye<Ie.length;){const Xe=Ie.indexOf(u,Ye);if(Xe===-1)break;V.push({blockIdx:Ee,start:Xe,end:Xe+u.length}),Ye=Xe+1}}),A(V),W(0)},[c,j,N]);const Ue=n.useCallback(()=>{if(m.length===0)return;const u=(D+1)%m.length;W(u),E(m[u].blockIdx)},[m,D]),Fe=n.useCallback(()=>{if(m.length===0)return;const u=(D-1+m.length)%m.length;W(u),E(m[u].blockIdx)},[m,D]),Ce=n.useCallback(()=>{if(m.length===0||!c)return;const u=m[D],V=N[u.blockIdx],re=V.content.slice(0,u.start),Ee=V.content.slice(u.end);Z(u.blockIdx,{content:re+C+Ee})},[m,D,c,C,N,Z]),Ne=n.useCallback(()=>{if(!c)return;const u=c;U(V=>V.map(re=>({...re,content:re.content.split(u).join(C)})))},[c,C,U]),He=n.useMemo(()=>O?N.map((u,V)=>u.type==="heading"?{idx:V,level:u.level??2,text:u.content}:null).filter(Boolean):[],[N,O]),$e=n.useCallback(async u=>{const V=u.target.files?.[0];if(V){if(P){const re=await P(V);Z(f,{src:re})}u.target.value=""}},[P,f,Z]);n.useEffect(()=>{const u=N[f];if(u){const V=L.current.get(u.id);V&&V.focus()}},[f,N]);const ut=n.useCallback(()=>{const u=N.map(yi).join(`
18
- `);M?.(u)},[N,M]),Le=n.useMemo(()=>X?xi(N):null,[N,X]),[ze,Oe]=n.useState(null),wt=n.useCallback((u,V)=>{a||(u.preventDefault(),Oe({x:u.clientX,y:u.clientY,idx:V}))},[a]);return n.useEffect(()=>{if(!ze)return;const u=()=>Oe(null);return window.addEventListener("click",u),()=>window.removeEventListener("click",u)},[ze]),e.jsxs("div",{ref:B,id:k,className:`nice-doc-editor nice-doc-editor--${l} nice-editor--${g} ${a?"nice-doc-editor--readonly":""} ${ae??""}`,style:{position:"relative",...ne},role:"application","aria-label":s("docEditor.label","Document Editor"),...G,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(Y,pi)})}),o&&!a&&e.jsxs("div",{ref:R,className:"nice-doc-editor__toolbar",role:"toolbar","aria-label":s("docEditor.toolbar","Formatting"),style:{display:"flex",flexWrap:"wrap",gap:4,alignItems:"center",padding:"4px 8px"},children:[e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:je,title:s("docEditor.undo","Undo (Ctrl+Z)"),ariaLabel:s("docEditor.undo","Undo (Ctrl+Z)"),children:e.jsx(r.NiceIcon,{name:"undo",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:ge,title:s("docEditor.redo","Redo (Ctrl+Y)"),ariaLabel:s("docEditor.redo","Redo (Ctrl+Y)"),children:e.jsx(r.NiceIcon,{name:"redo",size:"sm"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(Ze.NiceSelect,{size:"sm",value:N[f]?.type??"paragraph",onChange:u=>be(f,u),label:"",options:[{value:"paragraph",label:s("docEditor.paragraph","Paragraph")},{value:"heading",label:s("docEditor.heading","Heading")},{value:"list",label:s("docEditor.list","List")},{value:"code",label:s("docEditor.code","Code")},{value:"quote",label:s("docEditor.quote","Quote")},{value:"callout",label:s("docEditor.callout","Callout")},{value:"toggle",label:s("docEditor.toggle","Toggle")},{value:"divider",label:s("docEditor.divider","Divider")},{value:"image",label:s("docEditor.image","Image")},{value:"video",label:s("docEditor.video","Video")},{value:"pageBreak",label:s("docEditor.pageBreak","Page Break")}],style:{minWidth:100}}),N[f]?.type==="heading"&&e.jsx(Ze.NiceSelect,{size:"sm",value:String(N[f]?.level??2),onChange:u=>Z(f,{level:Number(u)}),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}}),N[f]?.type==="list"&&e.jsx(Ze.NiceSelect,{size:"sm",value:N[f]?.listType??"unordered",onChange:u=>Z(f,{listType:u}),label:"",options:[{value:"unordered",label:s("docEditor.bullets","Bullets")},{value:"ordered",label:s("docEditor.numbers","Numbers")},{value:"checklist",label:s("docEditor.checklist","Checklist")}],style:{minWidth:90}}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.bold?"primary":"ghost",onClick:()=>Z(f,{bold:!N[f]?.bold}),title:s("docEditor.bold","Bold (Ctrl+B)"),children:e.jsx("strong",{children:"B"})}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.italic?"primary":"ghost",onClick:()=>Z(f,{italic:!N[f]?.italic}),title:s("docEditor.italic","Italic (Ctrl+I)"),children:e.jsx("em",{children:"I"})}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.underline?"primary":"ghost",onClick:()=>Z(f,{underline:!N[f]?.underline}),title:s("docEditor.underline","Underline (Ctrl+U)"),children:e.jsx("u",{children:"U"})}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.strikethrough?"primary":"ghost",onClick:()=>Z(f,{strikethrough:!N[f]?.strikethrough}),title:s("docEditor.strikethrough","Strikethrough (Ctrl+E)"),children:e.jsx("s",{children:"S"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.align==="left"?"primary":"ghost",onClick:()=>Z(f,{align:"left"}),title:s("docEditor.alignLeft","Left"),ariaLabel:s("docEditor.alignLeft","Left"),children:e.jsx(r.NiceIcon,{name:"align-left",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.align==="center"?"primary":"ghost",onClick:()=>Z(f,{align:"center"}),title:s("docEditor.alignCenter","Center"),ariaLabel:s("docEditor.alignCenter","Center"),children:e.jsx(r.NiceIcon,{name:"align-center",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.align==="right"?"primary":"ghost",onClick:()=>Z(f,{align:"right"}),title:s("docEditor.alignRight","Right"),ariaLabel:s("docEditor.alignRight","Right"),children:e.jsx(r.NiceIcon,{name:"align-right",size:"sm"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>Z(f,{indent:Math.min((N[f]?.indent??0)+1,4)}),title:s("docEditor.indent","Indent (Tab)"),ariaLabel:s("docEditor.indent","Indent (Tab)"),children:e.jsx(r.NiceIcon,{name:"indent",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>Z(f,{indent:Math.max((N[f]?.indent??0)-1,0)}),title:s("docEditor.outdent","Outdent (Shift+Tab)"),ariaLabel:s("docEditor.outdent","Outdent (Shift+Tab)"),children:e.jsx(r.NiceIcon,{name:"outdent",size:"sm"})}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(Bt.NiceColorPicker,{size:"sm",label:"",value:N[f]?.color??"var(--nice-text-primary, #000000)",onChange:u=>Z(f,{color:u}),title:s("docEditor.textColor","Text color")}),e.jsx(Bt.NiceColorPicker,{size:"sm",label:"",value:N[f]?.bgColor??"var(--nice-bg-primary, #ffffff)",onChange:u=>Z(f,{bgColor:u}),title:s("docEditor.blockBackground","Block background")}),e.jsx("span",{className:"nice-doc-editor__sep"}),e.jsx(Me.NiceButton,{size:"sm",variant:N[f]?.locked?"primary":"ghost",onClick:()=>Z(f,{locked:!N[f]?.locked}),title:s("docEditor.lock","Lock/Unlock block"),ariaLabel:s("docEditor.lock","Lock/Unlock block"),children:e.jsx(r.NiceIcon,{name:N[f]?.locked?"lock":"unlock",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>ee(f),title:s("docEditor.duplicate","Duplicate (Ctrl+D)"),ariaLabel:s("docEditor.duplicate","Duplicate (Ctrl+D)"),children:e.jsx(r.NiceIcon,{name:"copy",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>ie(f),title:s("docEditor.delete","Delete block"),ariaLabel:s("docEditor.delete","Delete block"),children:e.jsx(r.NiceIcon,{name:"trash",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>x(f),title:s("docEditor.addBlock","Add block"),ariaLabel:s("docEditor.addBlock","Add block"),children:e.jsx(r.NiceIcon,{name:"plus",size:"sm"})}),$&&e.jsx(Me.NiceButton,{size:"sm",variant:j?"primary":"ghost",onClick:()=>h(u=>!u),title:s("docEditor.find","Find & Replace (Ctrl+F)"),ariaLabel:s("docEditor.find","Find & Replace (Ctrl+F)"),children:e.jsx(r.NiceIcon,{name:"search",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>q(u=>!u),title:s("docEditor.shortcuts","Keyboard shortcuts"),ariaLabel:s("docEditor.shortcuts","Keyboard shortcuts"),children:e.jsx(r.NiceIcon,{name:"keyboard",size:"sm"})}),M&&e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:ut,children:s("docEditor.export","Export HTML")})]}),e.jsx("input",{ref:w,type:"file",accept:"image/*,video/*",style:{display:"none"},onChange:$e}),j&&e.jsxs("div",{className:"nice-doc-editor__find-bar",style:{display:"flex",gap:4,alignItems:"center",padding:"4px 8px",background:"var(--nice-bg-secondary, #f8f9fa)",borderBottom:"1px solid var(--nice-border-color, #ddd)"},children:[e.jsx(nt.NiceTextInput,{size:"sm",placeholder:s("docEditor.findPlaceholder","Find..."),value:c,onChange:p,style:{flex:1,maxWidth:200}}),e.jsx(nt.NiceTextInput,{size:"sm",placeholder:s("docEditor.replacePlaceholder","Replace..."),value:C,onChange:S,style:{flex:1,maxWidth:200}}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:Fe,title:s("docEditor.findPrev","Previous"),ariaLabel:s("docEditor.findPrev","Previous"),children:e.jsx(r.NiceIcon,{name:"chevron-up",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:Ue,title:s("docEditor.findNext","Next"),ariaLabel:s("docEditor.findNext","Next"),children:e.jsx(r.NiceIcon,{name:"chevron-down",size:"sm"})}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:Ce,title:s("docEditor.replaceOne","Replace"),disabled:a,children:s("docEditor.replace","Replace")}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:Ne,title:s("docEditor.replaceAll","Replace all"),disabled:a,children:s("docEditor.replaceAllBtn","All")}),e.jsx("span",{style:{fontSize:"0.75em",color:"var(--nice-text-muted, #666)"},children:m.length>0?`${D+1}/${m.length}`:"0/0"}),e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>h(!1),title:s("docEditor.closeFind","Close"),ariaLabel:s("docEditor.closeFind","Close"),children:e.jsx(r.NiceIcon,{name:"close",size:"sm"})})]}),v&&e.jsx("div",{role:"presentation",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:()=>q(!1),children:e.jsxs("div",{role:"presentation",style:{background:"var(--nice-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:u=>u.stopPropagation(),children:[e.jsx("h3",{style:{margin:"0 0 12px"},children:s("docEditor.shortcutsTitle","Keyboard Shortcuts")}),e.jsx("table",{style:{width:"100%",fontSize:"0.875em",borderCollapse:"collapse"},children:e.jsx("tbody",{children:[["Ctrl+B",s("docEditor.bold","Bold")],["Ctrl+I",s("docEditor.italic","Italic")],["Ctrl+U",s("docEditor.underline","Underline")],["Ctrl+E",s("docEditor.strikethrough","Strikethrough")],["Ctrl+D",s("docEditor.duplicate","Duplicate block")],["Ctrl+Z",s("docEditor.undo","Undo")],["Ctrl+Y",s("docEditor.redo","Redo")],["Ctrl+F",s("docEditor.find","Find & Replace")],["Enter",s("docEditor.newBlock","New block")],["Backspace",s("docEditor.deleteEmpty","Delete empty block")],["Alt+↑",s("docEditor.moveUp","Move block up")],["Alt+↓",s("docEditor.moveDown","Move block down")],["Tab",s("docEditor.indent","Indent")],["Shift+Tab",s("docEditor.outdent","Outdent")],["Esc, Tab",s("docEditor.leaveEditor","Leave the editor")],["/",s("docEditor.slashCmd","Slash commands")]].map(([u,V])=>e.jsxs("tr",{style:{borderBottom:"1px solid var(--nice-border-color, #eee)"},children:[e.jsx("td",{style:{padding:"4px 8px",fontFamily:"monospace",fontWeight:600},children:u}),e.jsx("td",{style:{padding:"4px 8px"},children:V})]},u))})}),e.jsx("div",{style:{textAlign:"right",marginTop:12},children:e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>q(!1),children:s("docEditor.close","Close")})})]})}),e.jsxs("div",{style:{display:"flex",gap:0},children:[O&&He.length>0&&e.jsxs("nav",{className:"nice-doc-editor__toc",style:{width:200,minWidth:160,borderRight:"1px solid var(--nice-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(--nice-text-muted, #999)"},children:s("docEditor.toc","Contents")}),He.map(u=>e.jsx("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"3px 8px",paddingLeft:8+(u.level-1)*12,cursor:"pointer",borderRadius:4,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",background:u.idx===f?"var(--nice-primary-bg, #e8f0fe)":void 0},onClick:()=>E(u.idx),title:u.text,children:u.text||s("docEditor.untitled","Untitled")},u.idx))]}),e.jsxs("div",{className:"nice-doc-editor__body",style:{flex:1},children:[!a&&e.jsx("span",{id:F,className:"nice-sr-only",children:s("input.tabEscapeHint","Tab indents. To leave the editor, press Escape, then Tab.")}),N.map((u,V)=>e.jsxs("div",{role:"presentation",className:`nice-doc-editor__block nice-doc-editor__block--${u.type} ${V===f?"nice-doc-editor__block--focused":""} ${xe===V?"nice-doc-editor__block--drop-target":""} ${u.locked?"nice-doc-editor__block--locked":""}`,onClick:()=>E(V),onContextMenu:re=>wt(re,V),draggable:!a&&!u.locked,onDragStart:re=>De(re,V),onDragOver:re=>Ge(re,V),onDrop:re=>Ve(re,V),onDragEnd:()=>{se(null),K(null)},style:{opacity:ke===V?.4:1,marginLeft:(u.indent??0)*24},children:[!a&&!u.locked&&e.jsx("div",{className:"nice-doc-editor__block-handle",title:s("docEditor.drag","Drag to reorder"),children:e.jsx(r.NiceIcon,{name:"grip",size:"sm"})}),u.locked&&e.jsx("span",{className:"nice-doc-editor__lock-icon",style:{position:"absolute",top:2,right:4,fontSize:"0.7em",opacity:.5},children:e.jsx(r.NiceIcon,{name:"lock",size:"sm"})}),u.type==="divider"?e.jsx("hr",{className:"nice-doc-editor__divider"}):u.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(--nice-text-muted, #999)"},children:["— ",s("docEditor.pageBreak","Page Break")," —"]}):u.type==="image"||u.type==="video"?e.jsx("div",{className:"nice-doc-editor__media-block",children:u.src?u.type==="image"?e.jsx("img",{src:u.src,alt:u.alt??"",className:"nice-doc-editor__image",style:{maxWidth:"100%"}}):e.jsx("video",{src:u.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(nt.NiceTextInput,{size:"sm",placeholder:u.type==="image"?s("docEditor.imageUrl","Image URL"):s("docEditor.videoUrl","Video URL"),value:u.src??"",onChange:re=>Z(V,{src:re})}),P&&e.jsx(Me.NiceButton,{size:"sm",variant:"ghost",onClick:()=>{E(V),w.current?.click()},title:s("docEditor.upload","Upload file"),ariaLabel:s("docEditor.upload","Upload file"),children:e.jsx(r.NiceIcon,{name:"upload",size:"sm"})})]})}):u.type==="callout"?e.jsxs("div",{className:"nice-doc-editor__callout",style:{display:"flex",gap:8,padding:"8px 12px",background:u.bgColor??"var(--nice-info-bg, #f0f7ff)",borderRadius:4,color:u.color},children:[e.jsx("span",{style:{fontSize:"1.2em",display:"inline-flex"},children:u.icon??e.jsx(r.NiceIcon,{name:"info",size:"sm"})}),e.jsx("div",{ref:re=>{re&&L.current.set(u.id,re)},className:"nice-doc-editor__content",contentEditable:!a&&!u.locked,suppressContentEditableWarning:!0,onInput:re=>Re(re,V),onFocus:()=>E(V),onKeyDown:re=>Se(re,V),"data-placeholder":s("docEditor.calloutPlaceholder","Callout text..."),role:"textbox","aria-multiline":"true","aria-describedby":a?void 0:F,style:{flex:1,outline:"none"},children:z(u.id,rt(u))})]}):u.type==="toggle"?e.jsxs("details",{open:u.open,className:"nice-doc-editor__toggle",onToggle:re=>Z(V,{open:re.target.open}),children:[e.jsx("summary",{style:{cursor:"pointer",fontWeight:500},children:u.content.split(`
19
- `)[0]||s("docEditor.toggleTitle","Toggle")}),e.jsx("div",{ref:re=>{re&&L.current.set(u.id,re)},className:"nice-doc-editor__content",contentEditable:!a&&!u.locked,suppressContentEditableWarning:!0,onInput:re=>Re(re,V),onFocus:()=>E(V),onKeyDown:re=>Se(re,V),role:"textbox","aria-multiline":"true","aria-describedby":a?void 0:F,style:{padding:"4px 0"},children:z(u.id,rt(u))})]}):u.type==="code"?e.jsxs("div",{className:"nice-doc-editor__code-block",style:{position:"relative"},children:[!a&&e.jsx(nt.NiceTextInput,{size:"sm",value:u.language??"",onChange:re=>Z(V,{language:re}),placeholder:s("docEditor.language","Language"),style:{position:"absolute",top:4,right:4,width:80,opacity:.7}}),e.jsx("pre",{ref:re=>{re&&L.current.set(u.id,re)},className:"nice-doc-editor__content",contentEditable:!a&&!u.locked,suppressContentEditableWarning:!0,onInput:re=>Re(re,V),onFocus:()=>E(V),onKeyDown:re=>Se(re,V),role:"textbox","aria-multiline":"true","aria-describedby":a?void 0:F,style:{fontFamily:"monospace",background:"var(--nice-bg-elevated, #1e1e1e)",color:"var(--nice-text-secondary, #d4d4d4)",padding:12,borderRadius:4,overflow:"auto"},children:z(u.id,rt(u))})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx("div",{ref:re=>{re&&L.current.set(u.id,re)},className:"nice-doc-editor__content",contentEditable:!a&&!u.locked,suppressContentEditableWarning:!0,style:{textAlign:u.align,fontWeight:u.bold?"bold":void 0,fontStyle:u.italic?"italic":void 0,textDecoration:[u.underline?"underline":"",u.strikethrough?"line-through":""].filter(Boolean).join(" ")||void 0,color:u.color,backgroundColor:u.bgColor},onInput:re=>Re(re,V),onFocus:()=>E(V),onKeyDown:re=>Se(re,V),"data-placeholder":!u.content&&y?y:void 0,role:"textbox","aria-multiline":"true","aria-describedby":a?void 0:F,children:z(u.id,rt(u))}),ue&&V===f&&te.length>0&&e.jsx("ul",{className:"nice-doc-editor__slash-menu",style:{position:"absolute",left:0,top:"100%",zIndex:100,background:"var(--nice-bg-primary, #fff)",border:"1px solid var(--nice-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:te.map((re,Ee)=>e.jsxs("li",{role:"presentation",className:Ee===ve?"nice-doc-editor__slash-item--active":"",style:{padding:"6px 10px",cursor:"pointer",borderRadius:4,display:"flex",gap:8,alignItems:"center",background:Ee===ve?"var(--nice-primary-bg, #e8f0fe)":void 0},onMouseDown:Ie=>{Ie.preventDefault(),fe(re)},onMouseEnter:()=>_e(Ee),children:[e.jsx("span",{style:{width:24,display:"inline-flex",justifyContent:"center"},children:e.jsx(r.NiceIcon,{name:re.icon,size:"sm"})}),e.jsx("span",{children:re.label})]},`${re.type}-${re.label}`))})]})]},u.id))]})]}),ze&&e.jsxs("div",{className:"nice-doc-editor__ctx-menu",style:{position:"fixed",left:ze.x,top:ze.y,zIndex:1e3,background:"var(--nice-bg-primary, #fff)",border:"1px solid var(--nice-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.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{ee(ze.idx),Oe(null)},children:[e.jsx(r.NiceIcon,{name:"copy",size:"sm"})," ",s("docEditor.duplicate2","Duplicate")]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{x(ze.idx),Oe(null)},children:[e.jsx(r.NiceIcon,{name:"plus",size:"sm"})," ",s("docEditor.insertBelow","Insert below")]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{ce(ze.idx,-1),Oe(null)},children:[e.jsx(r.NiceIcon,{name:"arrow-up",size:"sm"})," ",s("docEditor.moveUp2","Move up")]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{ce(ze.idx,1),Oe(null)},children:[e.jsx(r.NiceIcon,{name:"arrow-down",size:"sm"})," ",s("docEditor.moveDown2","Move down")]}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"6px 12px",cursor:"pointer"},onClick:()=>{Z(ze.idx,{locked:!N[ze.idx]?.locked}),Oe(null)},children:[e.jsx(r.NiceIcon,{name:N[ze.idx]?.locked?"unlock":"lock",size:"sm"})," ",N[ze.idx]?.locked?s("docEditor.unlock","Unlock"):s("docEditor.lock2","Lock")]}),e.jsx("hr",{style:{margin:"2px 0",border:"none",borderTop:"1px solid var(--nice-border-color, #eee)"}}),e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,style:{padding:"6px 12px",cursor:"pointer",color:"var(--nice-danger-dark, #d32f2f)"},onClick:()=>{ie(ze.idx),Oe(null)},children:[e.jsx(r.NiceIcon,{name:"trash",size:"sm"})," ",s("docEditor.delete2","Delete")]})]}),X&&Le&&e.jsxs("div",{className:"nice-doc-editor__footer",style:{padding:"4px 12px",fontSize:"0.75em",color:"var(--nice-text-muted, #666)",borderTop:"1px solid var(--nice-border-color, #eee)",display:"flex",gap:16},children:[e.jsxs("span",{children:[Le.words," ",s("docEditor.words","words")]}),e.jsxs("span",{children:[Le.chars," ",s("docEditor.chars","characters")]}),e.jsxs("span",{children:[N.length," ",s("docEditor.blocks","blocks")]}),e.jsxs("span",{children:["~",Le.readingTime," ",s("docEditor.readingTime","min read")]})]})]})}),{displayName:"NiceDocumentEditor"}),ji=[],vi=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,disabled:o,readOnly:l,size:g="md",id:y,className:M,style:P,accessMode:I,pages:J=ji,selectedPageId:X,content:O="",contentFormat:$="html",editing:Y=!1,onPageSelect:ae,onContentChange:ne,onSave:le,onCreatePage:G,onDeletePage:B,onEditToggle:k,onVersionHistory:s,sidebarWidth:T=260,sidebarCollapsed:F=!1,onSidebarToggle:R,searchable:_=!0,onSearch:b},N)=>{const f=r.useNiceAccessMode(I,y),E=f==="hidden";f==="disabled"&&(o=!0),f==="readOnly"&&(l=!0);const{t:L}=r.useNiceTranslation(),w=r.useControlId(y),[d,z]=n.useState(""),[j,h]=n.useState(""),[c,p]=n.useState(!1),C=n.useMemo(()=>{const W=v=>{for(const q of v){if(q.id===X)return q;if(q.children){const H=W(q.children);if(H)return H}}};return W(J)},[J,X]),S=n.useCallback(W=>{z(W),b?.(W)},[b]),m=n.useCallback(()=>{j.trim()&&(G?.(X??null,j.trim()),h(""),p(!1))},[j,X,G]),A=n.useRef(null);r.useTreeFocus(A,{rowSelector:".nice-wiki__tree-node",onToggle:()=>{}});const D=(W,v=0)=>e.jsx("ul",{className:"nice-wiki__tree",role:v>0?"group":"none",style:{paddingLeft:v>0?16:0},children:W.map(q=>e.jsxs("li",{className:"nice-wiki__tree-item",role:"treeitem","aria-label":q.title,"aria-selected":q.id===X,children:[e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,className:`nice-wiki__tree-node${q.id===X?" nice-wiki__tree-node--active":""}${q.isDraft?" nice-wiki__tree-node--draft":""}`,onClick:()=>ae?.(q),children:[e.jsx("span",{className:"nice-wiki__tree-icon",children:e.jsx(r.NiceIcon,{name:q.children?.length?"folder":"file",size:14})}),e.jsx("span",{className:"nice-wiki__tree-title",children:q.title}),q.isDraft&&e.jsx("span",{className:"nice-wiki__tree-draft",children:L("draft","Draft")})]}),q.children&&q.children.length>0&&D(q.children,v+1)]},q.id))});return E?null:e.jsxs("div",{ref:N,id:w,className:`nice-wiki nice-size-${g}${M?` ${M}`:""}${o?" nice-disabled":""}`,style:P,children:[!F&&e.jsxs("aside",{className:"nice-wiki__sidebar",style:{width:T},children:[e.jsxs("div",{className:"nice-wiki__sidebar-header",children:[e.jsx("span",{className:"nice-wiki__sidebar-title",children:t??L("wiki","Wiki")}),R&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-toggle",onClick:()=>R(!0),"aria-label":L("collapseSidebar","Collapse sidebar"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:16})})]}),_&&e.jsx("input",{type:"text",className:"nice-input nice-wiki__search",value:d,onChange:W=>S(W.target.value),placeholder:L("searchPages","Search pages…"),disabled:o}),e.jsx("div",{ref:A,className:"nice-wiki__page-tree",role:"tree","aria-label":t??L("wiki","Wiki"),children:D(J)}),G&&!l&&e.jsx("div",{className:"nice-wiki__sidebar-footer",children:c?e.jsxs("div",{className:"nice-wiki__create-form",children:[e.jsx("input",{type:"text",className:"nice-input",value:j,onChange:W=>h(W.target.value),placeholder:L("pageTitle","Page title"),onKeyDown:W=>W.key==="Enter"&&m(),disabled:o}),e.jsx("button",{type:"button",disabled:o||!j.trim(),onClick:m,"aria-label":L("create","Create"),children:e.jsx(r.NiceIcon,{name:"check",size:14})}),e.jsx("button",{type:"button",onClick:()=>p(!1),"aria-label":L("cancel","Cancel"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}):e.jsxs("button",{type:"button",className:"nice-wiki__add-page",onClick:()=>p(!0),disabled:o,children:[e.jsx(r.NiceIcon,{name:"plus",size:14})," ",L("newPage","New page")]})})]}),F&&R&&e.jsx("button",{type:"button",className:"nice-wiki__sidebar-expand",onClick:()=>R(!1),"aria-label":L("expandSidebar","Expand sidebar"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:16})}),e.jsx("main",{className:"nice-wiki__content",children:C?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-wiki__content-header",children:[e.jsx("h1",{className:"nice-wiki__page-title",children:C.title}),e.jsxs("div",{className:"nice-wiki__content-actions",children:[k&&!l&&e.jsx("button",{type:"button",disabled:o,onClick:()=>k(!Y),children:Y?L("preview","Preview"):L("edit","Edit")}),s&&e.jsx("button",{type:"button",disabled:o,onClick:()=>s(C.id),children:L("history","History")}),B&&!l&&e.jsx("button",{type:"button",className:"nice-btn--danger",disabled:o,onClick:()=>B(C.id),children:L("delete","Delete")})]})]}),C.updatedAt&&e.jsxs("div",{className:"nice-wiki__page-meta",children:[C.updatedBy&&e.jsxs("span",{children:[L("lastEditedBy","Last edited by")," ",C.updatedBy]}),e.jsx("span",{children:new Date(C.updatedAt).toLocaleDateString()})]}),Y?e.jsxs("div",{className:"nice-wiki__editor",children:[e.jsx("textarea",{className:"nice-wiki__editor-textarea",value:O,onChange:W=>ne?.(W.target.value),disabled:o}),le&&e.jsx("button",{type:"button",className:"nice-btn nice-btn--primary",disabled:o,onClick:()=>le(C.id,O),children:L("save","Save")})]}):e.jsx("div",{className:"nice-wiki__viewer",children:$==="html"?e.jsx("div",{className:"nice-wiki__html",dangerouslySetInnerHTML:{__html:r.sanitizeHtml(O)}}):e.jsx("pre",{className:"nice-wiki__markdown",children:O})})]}):e.jsx("div",{className:"nice-wiki__empty",children:e.jsx("p",{children:L("selectPage","Select a page from the sidebar or create a new one.")})})}),i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})}),{displayName:"NiceWiki"}),_i=n.forwardRef(function(i,a){const{enableAI:o=!0,aiModel:l,enableInlineCompletion:g=!0,completionDelay:y=500,enableExplain:M=!0,enableRefactor:P=!0,enableGenerate:I=!0,systemPrompt:J,onExplain:X,onRefactor:O,showAIToolbar:$=!0,aiShortcutKey:Y="Ctrl",language:ae="plaintext",value:ne,onChange:le,onCursorPositionChange:G,...B}=i,k=n.useRef(null),[s,T]=n.useState(null),[F,R]=n.useState(!1),[_,b]=n.useState(""),[N,f]=n.useState(!1),[E,L]=n.useState(""),[w,d]=n.useState(""),[z,j]=n.useState(""),h=n.useRef(void 0),{t:c}=an.useNiceTranslation(),p=r.useNiceAI(),{complete:C,explain:S,refactor:m,generateFromComment:A,isLoading:D}=r.useCodeCompletion({language:ae,model:l}),W=o&&p.isConfigured,v=n.useCallback(async()=>{if(!W||!g||!k.current||!k.current.getEditor())return;const he=k.current.getCursorPosition(),ve=k.current.getValue().split(`
20
- `),_e=ve.slice(0,he.lineNumber-1),te=ve[he.lineNumber-1]||"",ke=[..._e,te.slice(0,he.column-1)].join(`
21
- `),se=[te.slice(he.column-1),...ve.slice(he.lineNumber)].join(`
22
- `);try{const xe=await C(ke,se);xe&&T({lineNumber:he.lineNumber,column:he.column,text:xe})}catch{}},[W,g,C]),q=n.useCallback(async()=>{if(!W||!M||!k.current)return"";const de=k.current.getSelection();if(!de)return"";j(de),R(!0),b("");try{const he=await S(de);return b(he),X?.(de,he),he}catch{return b(c("codeEditorAI.explanationFailed","Failed to explain code")),""}},[W,M,S,X,c]),H=n.useCallback(async de=>{if(!W||!P||!k.current)return"";const he=k.current.getSelection();if(!he)return"";try{const oe=await m(he,de);return d(oe),O?.(he,oe),oe}catch{return""}},[W,P,m,O]),me=n.useCallback(async()=>{if(!W||!I||!k.current)return;const de=k.current.getCursorPosition(),oe=k.current.getValue().split(`
23
- `);let ve="";for(let _e=de.lineNumber-1;_e>=0&&_e>=de.lineNumber-3;_e--){const te=oe[_e]?.trim()||"";if(te.startsWith("//")||te.startsWith("#")||te.startsWith("/*")||te.startsWith("*")){ve=te.replace(/^\/\/\s*|^#\s*|^\/\*\s*|\*\/\s*$|^\*\s*/g,"").trim();break}}if(ve)try{const _e=await A(ve);_e&&k.current&&k.current.insertText(`
24
- `+_e)}catch{}},[W,I,A]),pe=n.useCallback(()=>{!s||!k.current||(k.current.insertText(s.text),T(null))},[s]),je=n.useCallback(()=>{T(null)},[]),ge=n.useCallback(de=>{G?.(de),!(!W||!g)&&(h.current&&clearTimeout(h.current),T(null),h.current=setTimeout(()=>{v()},y))},[G,W,g,y,v]);n.useEffect(()=>{if(!k.current?.getEditor()||!W)return;const he=oe=>{if(Y==="Ctrl"&&oe.ctrlKey||Y==="Alt"&&oe.altKey||Y==="Meta"&&oe.metaKey){if(oe.key===" "&&g&&(oe.preventDefault(),v()),oe.key==="e"&&M&&(oe.preventDefault(),q()),oe.key==="r"&&P){oe.preventDefault();const _e=k.current?.getSelection();_e&&(j(_e),f(!0))}oe.key==="g"&&I&&(oe.preventDefault(),me())}oe.key==="Tab"&&s&&(oe.preventDefault(),pe()),oe.key==="Escape"&&s&&je()};return window.addEventListener("keydown",he),()=>window.removeEventListener("keydown",he)},[W,Y,g,M,P,I,v,q,me,s,pe,je]),n.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const ue=n.useCallback(()=>{if(!w||!k.current)return;const de=k.current.getEditor();if(de?.executeEdits&&de?.getSelection){const he=de.getSelection();de.executeEdits("ai-refactor",[{range:he,text:w}])}f(!1),d(""),L("")},[w]);return n.useImperativeHandle(a,()=>({...k.current,getEditor:()=>k.current?.getEditor(),getMonaco:()=>k.current?.getMonaco(),focus:()=>k.current?.focus(),getValue:()=>k.current?.getValue()||"",setValue:de=>k.current?.setValue(de),getSelection:()=>k.current?.getSelection()||"",insertText:de=>k.current?.insertText(de),formatDocument:()=>k.current?.formatDocument(),goToLine:(de,he)=>k.current?.goToLine(de,he),findReplace:()=>k.current?.findReplace(),undo:()=>k.current?.undo(),redo:()=>k.current?.redo(),getCursorPosition:()=>k.current?.getCursorPosition()||{lineNumber:1,column:1},setMarkers:de=>k.current?.setMarkers(de),triggerCompletion:v,explainSelection:q,refactorSelection:H,generateFromComment:me,acceptCompletion:pe,dismissCompletion:je})),e.jsxs("div",{className:"nice-code-editor-ai","data-testid":i["data-testid"],children:[$&&W&&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:c("codeEditorAI.ai","AI")}),D&&e.jsx("span",{className:"nice-code-editor-ai__loading",children:c("codeEditorAI.loading","Thinking...")})]}),e.jsxs("div",{className:"nice-code-editor-ai__toolbar-right",children:[g&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>v(),disabled:D,title:`${c("codeEditorAI.complete","Complete")} (${Y}+Space)`,children:[e.jsx(r.NiceIcon,{name:"lightbulb",size:14})," ",c("codeEditorAI.complete","Complete")]}),M&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>q(),disabled:D,title:`${c("codeEditorAI.explain","Explain")} (${Y}+E)`,children:[e.jsx(r.NiceIcon,{name:"book",size:14})," ",c("codeEditorAI.explain","Explain")]}),P&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>{const de=k.current?.getSelection();de&&(j(de),f(!0))},disabled:D,title:`${c("codeEditorAI.refactor","Refactor")} (${Y}+R)`,children:[e.jsx(r.NiceIcon,{name:"settings",size:14})," ",c("codeEditorAI.refactor","Refactor")]}),I&&e.jsxs("button",{type:"button",className:"nice-code-editor-ai__toolbar-btn",onClick:()=>me(),disabled:D,title:`${c("codeEditorAI.generate","Generate")} (${Y}+G)`,children:[e.jsx(r.NiceIcon,{name:"zap",size:14})," ",c("codeEditorAI.generate","Generate")]})]})]}),e.jsxs("div",{className:"nice-code-editor-ai__editor-wrapper",children:[e.jsx(It.NiceCodeEditor,{ref:k,value:ne,onChange:le,language:ae,onCursorPositionChange:ge,...B}),s&&e.jsxs("div",{className:"nice-code-editor-ai__ghost-text",style:{top:`calc(${(s.lineNumber-1)*19}px + 4px)`,left:`calc(${(s.column-1)*7.8}px + 60px)`},children:[e.jsx("span",{className:"nice-code-editor-ai__ghost-text-content",children:s.text}),e.jsx("span",{className:"nice-code-editor-ai__ghost-text-hint",children:c("codeEditorAI.tab","Tab {accept}").replace("{accept}",String(c("codeEditorAI.toAccept","to accept")))})]})]}),F&&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:[e.jsx(r.NiceIcon,{name:"book",size:16})," ",c("codeEditorAI.explanation","Explanation")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>R(!1),"aria-label":c("codeEditorAI.close","Close"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-code-editor-ai__panel-body",children:D?e.jsx("div",{className:"nice-code-editor-ai__panel-loading",children:c("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:z}),e.jsx("div",{className:"nice-code-editor-ai__explanation-text",children:_||c("codeEditorAI.noExplanation","Select code and click Explain")})]})})]}),N&&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:[e.jsx(r.NiceIcon,{name:"settings",size:16})," ",c("codeEditorAI.refactorCode","Refactor Code")]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__panel-close",onClick:()=>{f(!1),d(""),L("")},"aria-label":c("codeEditorAI.close","Close"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsxs("div",{className:"nice-code-editor-ai__panel-body",children:[e.jsx("pre",{className:"nice-code-editor-ai__code-preview",children:z}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-input",children:[e.jsx("input",{type:"text",placeholder:c("codeEditorAI.refactorInstruction",'Describe how to refactor (e.g., "extract function", "add error handling")'),value:E,onChange:de=>L(de.target.value),onKeyDown:de=>{de.key==="Enter"&&E&&H(E)}}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__refactor-btn",onClick:()=>H(E),disabled:D||!E,children:D?c("codeEditorAI.refactoring","Refactoring..."):c("codeEditorAI.refactor","Refactor")})]}),w&&e.jsxs("div",{className:"nice-code-editor-ai__refactor-result",children:[e.jsx("h5",{children:c("codeEditorAI.refactoredCode","Refactored Code")}),e.jsx("pre",{className:"nice-code-editor-ai__code-preview nice-code-editor-ai__code-preview--result",children:w}),e.jsxs("div",{className:"nice-code-editor-ai__refactor-actions",children:[e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-apply",onClick:ue,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",c("codeEditorAI.apply","Apply")]}),e.jsxs("button",{type:"button",className:"nice-code-editor-ai__refactor-discard",onClick:()=>{d(""),L("")},children:[e.jsx(r.NiceIcon,{name:"close",size:14})," ",c("codeEditorAI.discard","Discard")]})]})]})]})]})]})}),ki=[];function wi(t){const i=t instanceof Date?t:new Date(t),a=(o,l=2)=>String(o).padStart(l,"0");return`${a(i.getHours())}:${a(i.getMinutes())}:${a(i.getSeconds())}.${a(i.getMilliseconds(),3)}`}function Ni(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}const bn=n.forwardRef(function(i,a){const{t:o}=r.useNiceTranslation();kt.injectStyleOnce(Ci,Si);const{entries:l=ki,maxHeight:g=240,autoScroll:y=!0,showTimestamps:M=!0,levelFilter:P,onClear:I,title:J,emptyText:X=o("logConsole.noOutput","No output"),clearLabel:O=o("logConsole.clear","Clear"),fontFamily:$,className:Y,style:ae,id:ne,"data-testid":le}=i,G=n.useRef(null),B=n.useMemo(()=>{if(!P||P.length===0)return l;const T=new Set(P);return l.filter(F=>T.has(F.level??"log"))},[l,P]);n.useEffect(()=>{y&&G.current&&(G.current.scrollTop=G.current.scrollHeight)},[B.length,y]);const k=!!J||!!I,s="nice-log-console"+(Y?` ${Y}`:"");return e.jsxs("div",{ref:a,id:ne,className:s,style:{...$?{fontFamily:$}:null,...ae},"data-testid":le,children:[k&&e.jsxs("div",{className:"nice-log-console__header",children:[e.jsx("span",{className:"nice-log-console__title",children:J}),I&&e.jsx("button",{type:"button",className:"nice-log-console__clear",onClick:I,"aria-label":O,children:O})]}),e.jsx("div",{ref:G,className:"nice-log-console__body",style:{maxHeight:typeof g=="number"?`${g}px`:g},role:"log","aria-live":"polite","aria-relevant":"additions",children:B.length===0?e.jsx("div",{className:"nice-log-console__empty",children:X}):B.map((T,F)=>{const R=T.level??"log";return e.jsxs("div",{className:`nice-log-console__entry nice-log-console__entry--${R}`,children:[M&&T.timestamp!=null&&e.jsx("span",{className:"nice-log-console__time",children:wi(T.timestamp)}),e.jsx("span",{className:"nice-log-console__level",children:R}),T.source&&e.jsx("span",{className:"nice-log-console__source",children:T.source}),e.jsx("span",{className:"nice-log-console__message",children:T.message}),T.data!==void 0&&e.jsx("pre",{className:"nice-log-console__data",children:Ni(T.data)})]},F)})})]})}),Ci="nice-log-console-styles",Si=`
25
- .nice-log-console {
26
- display: flex;
27
- flex-direction: column;
28
- border: 1px solid var(--nice-border, #e0e0e0);
29
- border-radius: var(--nice-radius-sm, 4px);
30
- background: var(--nice-surface, #fff);
31
- color: var(--nice-text-primary, #1f2937);
32
- overflow: hidden;
33
- font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
34
- font-size: 12px;
35
- line-height: 1.55;
36
- }
37
- .nice-log-console__header {
38
- display: flex;
39
- align-items: center;
40
- justify-content: space-between;
41
- gap: var(--nice-space-2, 8px);
42
- padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
43
- border-bottom: 1px solid var(--nice-border, #e0e0e0);
44
- background: var(--nice-bg-secondary, #f5f5f5);
45
- }
46
- .nice-log-console__title {
47
- font-weight: 600;
48
- font-size: 12px;
49
- }
50
- .nice-log-console__clear {
51
- border: 1px solid var(--nice-border, #e0e0e0);
52
- background: var(--nice-surface, #fff);
53
- color: var(--nice-text-secondary, #6b7280);
54
- border-radius: var(--nice-radius-sm, 4px);
55
- padding: 2px 8px;
56
- font: inherit;
57
- font-size: 11px;
58
- cursor: pointer;
59
- }
60
- .nice-log-console__clear:hover {
61
- color: var(--nice-text-primary, #1f2937);
62
- border-color: var(--nice-border-color, #9ca3af);
63
- }
64
- .nice-log-console__body {
65
- flex: 1;
66
- overflow: auto;
67
- padding: var(--nice-space-2, 8px);
68
- }
69
- .nice-log-console__empty {
70
- color: var(--nice-text-muted, #9ca3af);
71
- font-style: italic;
72
- padding: var(--nice-space-2, 8px) 0;
73
- }
74
- .nice-log-console__entry {
75
- display: flex;
76
- flex-wrap: wrap;
77
- align-items: baseline;
78
- gap: var(--nice-space-2, 8px);
79
- padding: 1px 0;
80
- white-space: pre-wrap;
81
- word-break: break-word;
82
- }
83
- .nice-log-console__time {
84
- color: var(--nice-text-muted, #9ca3af);
85
- flex: 0 0 auto;
86
- }
87
- .nice-log-console__level {
88
- flex: 0 0 auto;
89
- text-transform: uppercase;
90
- font-size: 10px;
91
- font-weight: 700;
92
- letter-spacing: 0.04em;
93
- opacity: 0.8;
94
- min-width: 38px;
95
- }
96
- .nice-log-console__source {
97
- flex: 0 0 auto;
98
- color: var(--nice-primary, #2563eb);
99
- }
100
- .nice-log-console__message {
101
- flex: 1 1 auto;
102
- }
103
- .nice-log-console__data {
104
- flex: 1 0 100%;
105
- margin: 2px 0 4px;
106
- padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
107
- background: var(--nice-bg-secondary, #f5f5f5);
108
- border-radius: var(--nice-radius-sm, 4px);
109
- overflow: auto;
110
- font: inherit;
111
- }
112
- .nice-log-console__entry--info .nice-log-console__level { color: var(--nice-primary, #2563eb); }
113
- .nice-log-console__entry--warn { color: var(--nice-warning-text, #92400e); }
114
- .nice-log-console__entry--warn .nice-log-console__level { color: var(--nice-warning, #d97706); }
115
- .nice-log-console__entry--error { color: var(--nice-danger, #dc2626); }
116
- .nice-log-console__entry--error .nice-log-console__level { color: var(--nice-danger, #dc2626); }
117
- .nice-log-console__entry--debug { color: var(--nice-text-muted, #9ca3af); }
118
- .nice-log-console__entry--trace { color: var(--nice-text-disabled, #b8bfc9); }
119
- .nice-log-console__entry--trace .nice-log-console__level { color: var(--nice-text-disabled, #b8bfc9); }
120
- `,Ei=[{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 Wt(t){if(t===void 0)return"";if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return String(t)}}function Jt(t){const i=t.trim();if(i==="")return{value:void 0,error:null};try{return{value:JSON.parse(i),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)}}const Ii=n.forwardRef(function(i,a){const{t:o}=r.useNiceTranslation();kt.injectStyleOnce(Mi,Ti);const{value:l,defaultValue:g,onChange:y,language:M="javascript",onRun:P,input:I,onInputChange:J,showInputPanel:X,extraLibs:O,height:$=260,running:Y,autoRun:ae=!1,autoRunDelay:ne=600,layout:le="vertical",runLabel:G=o("scriptRunner.run","Run"),theme:B="auto",tutorial:k,className:s,style:T,id:F,"data-testid":R}=i,[_,b]=r.useControllableState({value:l,defaultValue:g,fallbackValue:"",onChange:y,componentName:"NiceScriptRunner"}),N=X??I!==void 0,[f,E]=n.useState(()=>Wt(I)),[L,w]=n.useState(null),[d,z]=n.useState(!1),[j,h]=n.useState(null),c=Y??d,p=B==="light"?"vs":B==="dark"?"vs-dark":B;n.useEffect(()=>{E(Wt(I))},[I]);const C=n.useCallback(async()=>{const W=Jt(f),v=typeof performance<"u"?performance.now():Date.now();Y===void 0&&z(!0);try{const q=await P(_,W.value),H=q.durationMs??Math.round((typeof performance<"u"?performance.now():Date.now())-v);h({...q,durationMs:H})}catch(q){h({ok:!1,error:q instanceof Error?q.message:String(q),durationMs:Math.round((typeof performance<"u"?performance.now():Date.now())-v)})}finally{Y===void 0&&z(!1)}},[f,P,_,Y]),S=n.useRef(C);S.current=C,n.useEffect(()=>{if(!ae)return;const W=setTimeout(()=>{S.current()},ne);return()=>clearTimeout(W)},[ae,ne,_,f]);const m=n.useCallback(W=>{E(W);const v=Jt(W);w(v.error),J?.(v.value)},[J]),A=typeof $=="number"?`${$}px`:$,D=`nice-script-runner nice-script-runner--${le}`+(s?` ${s}`:"");return e.jsxs("div",{ref:a,id:F,className:D,style:T,"data-testid":R,children:[e.jsxs("div",{className:"nice-script-runner__toolbar",children:[e.jsxs("button",{type:"button",className:"nice-script-runner__run",onClick:()=>void C(),disabled:c,children:[c?"…":e.jsx(r.NiceIcon,{name:"play",size:14})," ",G]}),j?.durationMs!=null&&e.jsxs("span",{className:"nice-script-runner__status",children:[e.jsx("span",{className:"nice-script-runner__badge nice-script-runner__badge--"+(j.ok?"ok":"error"),children:j.ok?o("scriptRunner.ok","OK"):o("scriptRunner.failed","Failed")}),e.jsxs("span",{className:"nice-script-runner__duration",children:[j.durationMs," ms"]})]}),k&&e.jsx("span",{style:{marginLeft:"auto"},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(k,Ei)})})]}),e.jsxs("div",{className:"nice-script-runner__panes",children:[e.jsxs("div",{className:"nice-script-runner__editors",children:[e.jsx(It.NiceCodeEditor,{value:_,onChange:b,language:M,theme:p,height:A,extraLibs:O,options:{minimap:!1}}),N&&e.jsxs("div",{className:"nice-script-runner__input",children:[e.jsxs("div",{className:"nice-script-runner__pane-label",children:[o("scriptRunner.inputJson","Input (JSON)"),L&&e.jsxs("span",{className:"nice-script-runner__input-error",children:[" — ",L]})]}),e.jsx(It.NiceCodeEditor,{value:f,onChange:m,language:"json",theme:p,height:120,options:{minimap:!1,lineNumbers:"off"}})]})]}),e.jsxs("div",{className:"nice-script-runner__output",children:[j?.error&&e.jsx("div",{className:"nice-script-runner__error",children:j.error}),j&&j.result!==void 0&&e.jsxs("div",{className:"nice-script-runner__result",children:[e.jsx("div",{className:"nice-script-runner__pane-label",children:o("scriptRunner.result","Result")}),e.jsx("pre",{className:"nice-script-runner__result-body",children:$i(j.result)})]}),e.jsx(bn,{title:o("scriptRunner.logs","Logs"),entries:j?.logs??[],maxHeight:160,emptyText:"Run the script to see logs"})]})]})]})}),Mi="nice-script-runner-styles",Ti=`
121
- .nice-script-runner {
122
- display: flex;
123
- flex-direction: column;
124
- gap: var(--nice-space-2, 8px);
125
- border: 1px solid var(--nice-border, #e0e0e0);
126
- border-radius: var(--nice-radius-md, 6px);
127
- padding: var(--nice-space-2, 8px);
128
- background: var(--nice-surface, #fff);
129
- }
130
- .nice-script-runner__toolbar {
131
- display: flex;
132
- align-items: center;
133
- gap: var(--nice-space-2, 8px);
134
- }
135
- .nice-script-runner__run {
136
- border: 0;
137
- background: var(--nice-primary, #2563eb);
138
- color: var(--nice-text-inverse, #fff);
139
- border-radius: var(--nice-radius-sm, 4px);
140
- padding: 6px 14px;
141
- font: inherit;
142
- font-weight: 600;
143
- cursor: pointer;
144
- }
145
- .nice-script-runner__run:disabled {
146
- opacity: 0.6;
147
- cursor: default;
148
- }
149
- .nice-script-runner__status {
150
- display: inline-flex;
151
- align-items: center;
152
- gap: var(--nice-space-2, 8px);
153
- font-size: 12px;
154
- }
155
- .nice-script-runner__badge {
156
- padding: 1px 8px;
157
- border-radius: 999px;
158
- font-size: 11px;
159
- font-weight: 700;
160
- }
161
- .nice-script-runner__badge--ok {
162
- background: var(--nice-success-bg, #dcfce7);
163
- color: var(--nice-success-text, #166534);
164
- }
165
- .nice-script-runner__badge--error {
166
- background: var(--nice-danger-bg, #fee2e2);
167
- color: var(--nice-danger-text, #991b1b);
168
- }
169
- .nice-script-runner__duration {
170
- color: var(--nice-text-muted, #9ca3af);
171
- }
172
- .nice-script-runner__panes {
173
- display: grid;
174
- gap: var(--nice-space-2, 8px);
175
- }
176
- .nice-script-runner--horizontal .nice-script-runner__panes {
177
- grid-template-columns: 1fr 1fr;
178
- }
179
- .nice-script-runner__editors,
180
- .nice-script-runner__output {
181
- display: flex;
182
- flex-direction: column;
183
- gap: var(--nice-space-2, 8px);
184
- min-width: 0;
185
- }
186
- .nice-script-runner__pane-label {
187
- font-size: 11px;
188
- font-weight: 600;
189
- text-transform: uppercase;
190
- letter-spacing: 0.04em;
191
- color: var(--nice-text-secondary, #6b7280);
192
- }
193
- .nice-script-runner__input-error {
194
- color: var(--nice-danger, #dc2626);
195
- text-transform: none;
196
- font-weight: 400;
197
- }
198
- .nice-script-runner__error {
199
- padding: var(--nice-space-2, 8px);
200
- border-radius: var(--nice-radius-sm, 4px);
201
- background: var(--nice-danger-bg, #fee2e2);
202
- color: var(--nice-danger-text, #991b1b);
203
- font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
204
- font-size: 12px;
205
- white-space: pre-wrap;
206
- }
207
- .nice-script-runner__result-body {
208
- margin: 4px 0 0;
209
- padding: var(--nice-space-2, 8px);
210
- border: 1px solid var(--nice-border, #e0e0e0);
211
- border-radius: var(--nice-radius-sm, 4px);
212
- background: var(--nice-bg-secondary, #f9fafb);
213
- max-height: 200px;
214
- overflow: auto;
215
- font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
216
- font-size: 12px;
217
- }
218
- `,Ri=[{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"}],Ai=n.forwardRef(function(i,a){const{t:o}=r.useNiceTranslation();kt.injectStyleOnce(Di,zi);const{value:l,defaultValue:g,onChange:y,allowSecret:M=!1,allowToggle:P=!1,allowDescription:I=!1,keySuggestions:J,keyPlaceholder:X=o("keyValueEditor.key","Key"),valuePlaceholder:O=o("keyValueEditor.value","Value"),addLabel:$=o("keyValueEditor.add","Add"),readOnly:Y=!1,duplicateKeyWarning:ae=!0,tutorial:ne,className:le,style:G,id:B,"data-testid":k}=i,[s,T]=r.useControllableState({value:l,defaultValue:g,fallbackValue:[],onChange:y,componentName:"NiceKeyValueEditor"}),F=n.useMemo(()=>`nice-kv-keys-${Math.random().toString(36).slice(2,9)}`,[]),R=n.useMemo(()=>{const E=new Map,L=new Set;if(ae){for(const w of s){const d=w.key.trim();d!==""&&E.set(d,(E.get(d)??0)+1)}E.forEach((w,d)=>{w>1&&L.add(d)})}return L},[s,ae]),_=(E,L)=>{T(s.map((w,d)=>d===E?{...w,...L}:w))},b=E=>{T(s.filter((L,w)=>w!==E))},N=()=>{T([...s,{key:"",value:"",type:"text",enabled:!0}])},f="nice-key-value-editor"+(le?` ${le}`:"");return e.jsxs("div",{ref:a,id:B,className:f,style:{position:"relative",...G},"data-testid":k,children:[e.jsx("span",{style:{position:"absolute",top:0,right:0,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(ne,Ri)})}),J&&J.length>0&&e.jsx("datalist",{id:F,children:J.map(E=>e.jsx("option",{value:E},E))}),e.jsx("div",{className:"nice-key-value-editor__rows",children:s.map((E,L)=>{const w=E.type==="secret",d=E.key.trim()!==""&&R.has(E.key.trim()),z=P&&E.enabled===!1;return e.jsxs("div",{className:"nice-key-value-editor__row"+(z?" nice-key-value-editor__row--disabled":""),children:[P&&e.jsx("input",{type:"checkbox",className:"nice-key-value-editor__toggle",checked:E.enabled!==!1,onChange:j=>_(L,{enabled:j.target.checked}),disabled:Y,"aria-label":o("keyValueEditor.enabled","Enabled")}),e.jsx("input",{type:"text",className:"nice-key-value-editor__key"+(d?" nice-key-value-editor__key--dup":""),value:E.key,list:J?F:void 0,placeholder:X,onChange:j=>_(L,{key:j.target.value}),readOnly:Y,"aria-label":X,title:d?o("keyValueEditor.duplicateKey","Duplicate key"):void 0}),e.jsx("input",{type:w?"password":"text",className:"nice-key-value-editor__value",value:E.value,placeholder:O,onChange:j=>_(L,{value:j.target.value}),readOnly:Y,autoComplete:w?"new-password":"off","aria-label":O}),M&&e.jsx("button",{type:"button",className:"nice-key-value-editor__secret"+(w?" nice-key-value-editor__secret--on":""),onClick:()=>_(L,{type:w?"text":"secret"}),disabled:Y,title:w?o("keyValueEditor.secretClickToRevealAs","Secret (click to reveal as text)"):o("keyValueEditor.markAsSecret","Mark as secret"),"aria-pressed":w,"aria-label":o("keyValueEditor.toggleSecret","Toggle secret"),children:e.jsx(r.NiceIcon,{name:"lock",size:16})}),I&&e.jsx("input",{type:"text",className:"nice-key-value-editor__desc",value:E.description??"",placeholder:o("keyValueEditor.description","Description"),onChange:j=>_(L,{description:j.target.value}),readOnly:Y,"aria-label":o("keyValueEditor.description","Description")}),!Y&&e.jsx("button",{type:"button",className:"nice-key-value-editor__remove",onClick:()=>b(L),title:o("keyValueEditor.removeRow","Remove row"),"aria-label":o("keyValueEditor.removeRow","Remove row"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},E.id??L)})}),!Y&&e.jsxs("button",{type:"button",className:"nice-key-value-editor__add",onClick:N,children:["+ ",$]})]})}),Di="nice-key-value-editor-styles",zi=`
219
- .nice-key-value-editor {
220
- display: flex;
221
- flex-direction: column;
222
- gap: var(--nice-space-2, 8px);
223
- }
224
- .nice-key-value-editor__rows {
225
- display: flex;
226
- flex-direction: column;
227
- gap: var(--nice-space-1, 4px);
228
- }
229
- .nice-key-value-editor__row {
230
- display: flex;
231
- align-items: center;
232
- gap: var(--nice-space-1, 4px);
233
- }
234
- .nice-key-value-editor__row--disabled {
235
- opacity: 0.55;
236
- }
237
- .nice-key-value-editor__key,
238
- .nice-key-value-editor__value,
239
- .nice-key-value-editor__desc {
240
- flex: 1 1 0;
241
- min-width: 0;
242
- padding: 6px 8px;
243
- border: 1px solid var(--nice-border, #d1d5db);
244
- border-radius: var(--nice-radius-sm, 4px);
245
- background: var(--nice-bg, #fff);
246
- color: var(--nice-text-primary, #1f2937);
247
- font: inherit;
248
- font-size: 13px;
249
- }
250
- .nice-key-value-editor__key {
251
- flex-basis: 30%;
252
- font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
253
- }
254
- .nice-key-value-editor__key--dup {
255
- border-color: var(--nice-danger, #dc2626);
256
- background: var(--nice-danger-bg, #fee2e2);
257
- }
258
- .nice-key-value-editor__key:focus,
259
- .nice-key-value-editor__value:focus,
260
- .nice-key-value-editor__desc:focus {
261
- outline: none;
262
- border-color: var(--nice-primary, #2563eb);
263
- }
264
- .nice-key-value-editor__toggle {
265
- flex: 0 0 auto;
266
- }
267
- .nice-key-value-editor__secret,
268
- .nice-key-value-editor__remove {
269
- flex: 0 0 auto;
270
- border: 1px solid var(--nice-border, #d1d5db);
271
- background: var(--nice-surface, #fff);
272
- border-radius: var(--nice-radius-sm, 4px);
273
- padding: 5px 8px;
274
- font-size: 13px;
275
- line-height: 1;
276
- cursor: pointer;
277
- }
278
- .nice-key-value-editor__secret--on {
279
- border-color: var(--nice-warning, #d97706);
280
- background: var(--nice-warning-bg, #fef3c7);
281
- }
282
- .nice-key-value-editor__remove:hover {
283
- border-color: var(--nice-danger, #dc2626);
284
- color: var(--nice-danger, #dc2626);
285
- }
286
- .nice-key-value-editor__add {
287
- align-self: flex-start;
288
- border: 1px dashed var(--nice-border, #d1d5db);
289
- background: transparent;
290
- color: var(--nice-primary, #2563eb);
291
- border-radius: var(--nice-radius-sm, 4px);
292
- padding: 5px 12px;
293
- font: inherit;
294
- font-size: 13px;
295
- font-weight: 600;
296
- cursor: pointer;
297
- }
298
- .nice-key-value-editor__add:hover {
299
- background: var(--nice-bg-secondary, #f5f5f5);
300
- }
301
- `,Li=["street","streetNumber","apartment","city","postalCode","state","country"],yt={street:"Street",streetNumber:"Number",apartment:"Apt/Suite",city:"City",postalCode:"Postal Code",state:"State/Province",country:"Country"},Pi=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,required:o,disabled:l,readOnly:g,size:y="md",name:M,id:P,className:I,style:J,accessMode:X,value:O={},onChange:$,fields:Y=Li,placeholders:ae={},countries:ne,layout:le="vertical",countryFirst:G=!1,validatePostalCode:B},k)=>{const s=r.useNiceAccessMode(X,P),T=s==="hidden";s==="disabled"&&(l=!0),s==="readOnly"&&(g=!0);const{t:F}=r.useNiceTranslation(),R=r.useControlId(P),_=n.useCallback((E,L)=>{$?.({...O,[E]:L})},[O,$]),b=n.useMemo(()=>{if(B&&O.postalCode)return B(O.postalCode,O.country)},[B,O.postalCode,O.country]),N=n.useMemo(()=>G&&Y.includes("country")?["country",...Y.filter(E=>E!=="country")]:Y,[Y,G]),f=`nice-address nice-address--${le} nice-size-${y}`;return T?null:e.jsxs("div",{ref:k,id:R,className:`${f}${I?` ${I}`:""}${a?" nice-error":""}${l?" nice-disabled":""}`,style:J,role:"group","aria-label":t??F("address","Address"),children:[t&&e.jsxs("label",{className:"nice-address__label",children:[t,o&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-address__fields",children:N.map(E=>E==="country"&&ne?e.jsxs("div",{className:`nice-address__field nice-address__field--${E}`,children:[e.jsx("label",{className:"nice-address__field-label",children:F(E,yt[E])}),e.jsxs("select",{className:"nice-input nice-select",value:O.country??"",onChange:L=>_("country",L.target.value),disabled:l,"aria-label":F(E,yt[E]),children:[e.jsx("option",{value:"",children:ae.country??F("selectCountry","— Select country —")}),ne.map(L=>e.jsx("option",{value:L.code,children:L.name},L.code))]})]},E):e.jsxs("div",{className:`nice-address__field nice-address__field--${E}`,children:[e.jsx("label",{className:"nice-address__field-label",children:F(E,yt[E])}),e.jsx("input",{className:`nice-input${E==="postalCode"&&b?" nice-input--error":""}`,type:"text",name:M?`${M}.${E}`:E,value:O[E]??"",onChange:L=>_(E,L.target.value),placeholder:ae[E]??"",disabled:l,readOnly:g,"aria-label":F(E,yt[E])}),E==="postalCode"&&b&&e.jsx("span",{className:"nice-error-text",children:b})]},E))}),i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})}),{displayName:"NiceAddressInput"}),Oi=[],Bi={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)"},Hi=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,required:o,disabled:l,readOnly:g,size:y="md",name:M,id:P,className:I,style:J,accessMode:X,value:O,onChange:$,accounts:Y=Oi,treeView:ae=!1,placeholder:ne,searchable:le=!0,showType:G=!0,onSearch:B},k)=>{const s=r.useNiceAccessMode(X,P),T=s==="hidden";s==="disabled"&&(l=!0),s==="readOnly"&&(g=!0);const{t:F}=r.useNiceTranslation(),R=r.useControlId(P),[_,b]=n.useState(""),[N,f]=n.useState(!1),E=n.useMemo(()=>{const m=A=>{for(const D of A){if(D.code===O)return D;if(D.children){const W=m(D.children);if(W)return W}}};return m(Y)},[Y,O]),L=n.useMemo(()=>{const m=[],A=D=>{for(const W of D)m.push(W),W.children&&A(W.children)};return A(Y),m},[Y]),w=n.useMemo(()=>{if(!_)return L;const m=_.toLowerCase();return L.filter(A=>A.code.toLowerCase().includes(m)||A.name.toLowerCase().includes(m))},[L,_]),d=n.useCallback(m=>{b(m),B?.(m),f(!0)},[B]),z=n.useCallback(m=>{$?.(m.code,m),f(!1),b("")},[$]),j=n.useRef(null),h=N&&w.length>0,{activeIndex:c,setActiveIndex:p,handleKeyDown:C}=mt.useListKeyboardNav(w,{open:h,onSelect:m=>z(m),onClose:()=>f(!1),onOpen:()=>{p(0),f(!0)},intentRef:j}),S=`${R}-accounts`;return T?null:e.jsxs("div",{ref:k,id:R,className:`nice-account-picker nice-size-${y}${I?` ${I}`:""}${a?" nice-error":""}${l?" nice-disabled":""}`,style:J,children:[t&&e.jsxs("label",{className:"nice-account-picker__label",htmlFor:`${R}-input`,children:[t,o&&e.jsx("span",{className:"nice-required",children:"*"})]}),e.jsx("div",{className:"nice-account-picker__control",children:le&&!g?e.jsx("input",{ref:j,id:`${R}-input`,className:"nice-input",type:"text",value:N?_:E?`${E.code} — ${E.name}`:"",onChange:m=>{d(m.target.value),p(0)},onFocus:()=>{b(""),p(-1),f(!0)},onBlur:()=>setTimeout(()=>f(!1),200),onKeyDown:C,placeholder:ne??F("searchAccount","Search account…"),disabled:l,required:o,autoComplete:"off",role:"combobox","aria-autocomplete":"list","aria-expanded":h,"aria-controls":h?S:void 0,"aria-activedescendant":h&&w[c]?`${S}-${c}`:void 0}):e.jsx("div",{className:"nice-account-picker__display",children:E?`${E.code} — ${E.name}`:ne??F("selectAccount","Select account…")})}),h&&e.jsx("div",{className:"nice-account-picker__dropdown",role:"listbox",id:S,children:w.map((m,A)=>e.jsxs("div",{id:`${S}-${A}`,className:`nice-account-picker__option${m.code===O?" nice-account-picker__option--selected":""}${A===c?" nice-account-picker__option--active":""}${m.isActive===!1?" nice-account-picker__option--inactive":""}`,role:"option","aria-selected":m.code===O,onMouseEnter:()=>p(A),onClick:()=>z(m),children:[G&&m.type&&e.jsx("span",{className:"nice-account-picker__type",style:{color:Bi[m.type]},title:m.type,children:e.jsx(r.NiceIcon,{name:"circle",size:10})}),e.jsx("span",{className:"nice-account-picker__code",children:m.code}),e.jsx("span",{className:"nice-account-picker__name",children:m.name})]},m.code))}),i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})}),{displayName:"NiceAccountPicker"}),Fi=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,required:o,disabled:l,readOnly:g,size:y="md",name:M,id:P,className:I,style:J,accessMode:X,value:O=[],onChange:$,contacts:Y=[],onSearch:ae,searchDelay:ne=300,multiple:le=!1,placeholder:G,onContactClick:B,maxSelections:k},s)=>{const T=r.useNiceAccessMode(X,P),F=T==="hidden";T==="disabled"&&(l=!0),T==="readOnly"&&(g=!0);const{t:R}=r.useNiceTranslation(),_=r.useControlId(P),[b,N]=n.useState(""),[f,E]=n.useState([]),[L,w]=n.useState(!1),[d,z]=n.useState(!1),j=n.useMemo(()=>{const v=[...Y,...f],q=new Map(v.map(H=>[H.id,H]));return O.map(H=>q.get(H)).filter(Boolean)},[O,Y,f]),h=n.useCallback(v=>{if(N(v),v.length<1){E([]),w(!1);return}if(ae){z(!0);const me=setTimeout(async()=>{const pe=await ae(v);E(pe),w(!0),z(!1)},ne);return()=>clearTimeout(me)}const q=v.toLowerCase(),H=Y.filter(me=>me.name.toLowerCase().includes(q)||me.email?.toLowerCase().includes(q)||me.phone?.includes(v));E(H),w(!0)},[ae,Y,ne]),c=n.useCallback(v=>{if(le)if(O.includes(v.id))$?.(O.filter(q=>q!==v.id));else{if(k&&O.length>=k)return;$?.([...O,v.id])}else $?.([v.id]),w(!1),N("")},[O,$,le,k]),p=n.useCallback(v=>{$?.(O.filter(q=>q!==v))},[O,$]),C=n.useRef(null),S=L&&f.length>0,{activeIndex:m,setActiveIndex:A,handleKeyDown:D}=mt.useListKeyboardNav(f,{open:S,onSelect:v=>c(v),onClose:()=>w(!1),onOpen:()=>{f.length>0&&(A(0),w(!0))},intentRef:C}),W=`${_}-results`;return F?null:e.jsxs("div",{ref:s,id:_,className:`nice-contact-picker nice-size-${y}${I?` ${I}`:""}${a?" nice-error":""}${l?" nice-disabled":""}`,style:J,children:[t&&e.jsxs("label",{className:"nice-contact-picker__label",children:[t,o&&e.jsx("span",{className:"nice-required",children:"*"})]}),j.length>0&&e.jsx("div",{className:"nice-contact-picker__chips",children:j.map(v=>e.jsxs("span",{role:B?"button":void 0,tabIndex:B?0:void 0,onKeyDown:B?r.clickOnActivationKey:void 0,className:"nice-contact-picker__chip",onClick:()=>B?.(v),children:[v.avatarUrl&&e.jsx("img",{src:v.avatarUrl,alt:"",className:"nice-contact-picker__chip-avatar"}),e.jsx("span",{children:v.name}),!g&&e.jsx("button",{type:"button",className:"nice-contact-picker__chip-remove",onClick:q=>{q.stopPropagation(),p(v.id)},disabled:l,"aria-label":R("controls.remove","Remove"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},v.id))}),!g&&e.jsxs("div",{className:"nice-contact-picker__search",children:[e.jsx("input",{ref:C,className:"nice-input",type:"text",value:b,onChange:v=>{h(v.target.value),A(0)},onFocus:()=>b.length>0&&w(!0),onBlur:()=>setTimeout(()=>w(!1),200),onKeyDown:D,placeholder:G??R("searchContacts","Search contacts…"),disabled:l,"aria-label":R("contactPicker.search","Search contacts"),autoComplete:"off",role:"combobox","aria-autocomplete":"list","aria-expanded":S,"aria-controls":S?W:void 0,"aria-activedescendant":S&&f[m]?`${W}-${m}`:void 0}),d&&e.jsx("span",{className:"nice-contact-picker__spinner",children:e.jsx(r.NiceIcon,{name:"refresh",size:16})})]}),S&&e.jsx("div",{className:"nice-contact-picker__dropdown",role:"listbox",id:W,"aria-multiselectable":le||void 0,children:f.map((v,q)=>e.jsxs("div",{id:`${W}-${q}`,className:`nice-contact-picker__option${O.includes(v.id)?" nice-contact-picker__option--selected":""}${q===m?" nice-contact-picker__option--active":""}`,role:"option","aria-selected":O.includes(v.id),onMouseEnter:()=>A(q),onClick:()=>c(v),children:[v.avatarUrl&&e.jsx("img",{src:v.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:v.name}),v.subtitle&&e.jsx("span",{className:"nice-contact-picker__option-subtitle",children:v.subtitle}),v.email&&e.jsx("span",{className:"nice-contact-picker__option-email",children:v.email})]}),v.type&&e.jsx("span",{className:"nice-contact-picker__option-type",children:e.jsx(r.NiceIcon,{name:v.type==="person"?"user":"building",size:16})})]},v.id))}),i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})}),{displayName:"NiceContactPicker"}),Ki={recent:"🕒",smileys:"😀",people:"👋",animals:"🐱",food:"🍕",travel:"✈️",activities:"⚽",objects:"💡",symbols:"❤️",flags:"🏳️"},Zt={recent:"Recently Used",smileys:"Smileys & Emotion",people:"People & Body",animals:"Animals & Nature",food:"Food & Drink",travel:"Travel & Places",activities:"Activities",objects:"Objects",symbols:"Symbols",flags:"Flags"},$t=["","🏻","🏼","🏽","🏾","🏿"],vt=[{emoji:"😀",name:"grinning face",category:"smileys",keywords:["happy","smile"]},{emoji:"😃",name:"grinning face with big eyes",category:"smileys"},{emoji:"😄",name:"grinning face with smiling eyes",category:"smileys"},{emoji:"😁",name:"beaming face",category:"smileys"},{emoji:"😅",name:"grinning face with sweat",category:"smileys"},{emoji:"🤣",name:"rolling on the floor laughing",category:"smileys",keywords:["rofl"]},{emoji:"😂",name:"face with tears of joy",category:"smileys",keywords:["lol","laugh"]},{emoji:"🙂",name:"slightly smiling face",category:"smileys"},{emoji:"😉",name:"winking face",category:"smileys",keywords:["wink"]},{emoji:"😊",name:"smiling face with smiling eyes",category:"smileys"},{emoji:"😇",name:"smiling face with halo",category:"smileys",keywords:["angel"]},{emoji:"🥰",name:"smiling face with hearts",category:"smileys",keywords:["love"]},{emoji:"😍",name:"smiling face with heart-eyes",category:"smileys"},{emoji:"🤩",name:"star-struck",category:"smileys",keywords:["wow"]},{emoji:"😘",name:"face blowing a kiss",category:"smileys",keywords:["kiss"]},{emoji:"😗",name:"kissing face",category:"smileys"},{emoji:"😚",name:"kissing face with closed eyes",category:"smileys"},{emoji:"😋",name:"face savoring food",category:"smileys",keywords:["yum"]},{emoji:"😛",name:"face with tongue",category:"smileys"},{emoji:"😜",name:"winking face with tongue",category:"smileys"},{emoji:"🤪",name:"zany face",category:"smileys",keywords:["crazy"]},{emoji:"😝",name:"squinting face with tongue",category:"smileys"},{emoji:"🤑",name:"money-mouth face",category:"smileys"},{emoji:"🤗",name:"hugging face",category:"smileys",keywords:["hug"]},{emoji:"🤭",name:"face with hand over mouth",category:"smileys"},{emoji:"🤫",name:"shushing face",category:"smileys",keywords:["quiet"]},{emoji:"🤔",name:"thinking face",category:"smileys",keywords:["think","hmm"]},{emoji:"🤐",name:"zipper-mouth face",category:"smileys"},{emoji:"🤨",name:"face with raised eyebrow",category:"smileys"},{emoji:"😐",name:"neutral face",category:"smileys"},{emoji:"😑",name:"expressionless face",category:"smileys"},{emoji:"😶",name:"face without mouth",category:"smileys"},{emoji:"😏",name:"smirking face",category:"smileys",keywords:["smirk"]},{emoji:"😒",name:"unamused face",category:"smileys"},{emoji:"🙄",name:"face with rolling eyes",category:"smileys"},{emoji:"😬",name:"grimacing face",category:"smileys"},{emoji:"😮‍💨",name:"face exhaling",category:"smileys"},{emoji:"🤥",name:"lying face",category:"smileys"},{emoji:"😌",name:"relieved face",category:"smileys"},{emoji:"😔",name:"pensive face",category:"smileys",keywords:["sad"]},{emoji:"😪",name:"sleepy face",category:"smileys"},{emoji:"🤤",name:"drooling face",category:"smileys"},{emoji:"😴",name:"sleeping face",category:"smileys",keywords:["sleep","zzz"]},{emoji:"😷",name:"face with medical mask",category:"smileys",keywords:["sick"]},{emoji:"🤒",name:"face with thermometer",category:"smileys"},{emoji:"🤕",name:"face with head-bandage",category:"smileys"},{emoji:"🤢",name:"nauseated face",category:"smileys"},{emoji:"🤮",name:"face vomiting",category:"smileys"},{emoji:"🤧",name:"sneezing face",category:"smileys"},{emoji:"🥵",name:"hot face",category:"smileys"},{emoji:"🥶",name:"cold face",category:"smileys"},{emoji:"🥴",name:"woozy face",category:"smileys",keywords:["drunk"]},{emoji:"😵",name:"face with crossed-out eyes",category:"smileys"},{emoji:"🤯",name:"exploding head",category:"smileys",keywords:["mind blown"]},{emoji:"🤠",name:"cowboy hat face",category:"smileys"},{emoji:"🥳",name:"partying face",category:"smileys",keywords:["party"]},{emoji:"🥸",name:"disguised face",category:"smileys"},{emoji:"😎",name:"smiling face with sunglasses",category:"smileys",keywords:["cool"]},{emoji:"🤓",name:"nerd face",category:"smileys",keywords:["nerd"]},{emoji:"🧐",name:"face with monocle",category:"smileys"},{emoji:"😕",name:"confused face",category:"smileys"},{emoji:"😟",name:"worried face",category:"smileys"},{emoji:"🙁",name:"slightly frowning face",category:"smileys"},{emoji:"☹️",name:"frowning face",category:"smileys"},{emoji:"😮",name:"face with open mouth",category:"smileys",keywords:["surprised"]},{emoji:"😯",name:"hushed face",category:"smileys"},{emoji:"😲",name:"astonished face",category:"smileys"},{emoji:"😳",name:"flushed face",category:"smileys"},{emoji:"🥺",name:"pleading face",category:"smileys"},{emoji:"😦",name:"frowning face with open mouth",category:"smileys"},{emoji:"😧",name:"anguished face",category:"smileys"},{emoji:"😨",name:"fearful face",category:"smileys"},{emoji:"😰",name:"anxious face with sweat",category:"smileys"},{emoji:"😥",name:"sad but relieved face",category:"smileys"},{emoji:"😢",name:"crying face",category:"smileys",keywords:["cry"]},{emoji:"😭",name:"loudly crying face",category:"smileys",keywords:["sob"]},{emoji:"😱",name:"face screaming in fear",category:"smileys",keywords:["scream"]},{emoji:"😖",name:"confounded face",category:"smileys"},{emoji:"😣",name:"persevering face",category:"smileys"},{emoji:"😞",name:"disappointed face",category:"smileys"},{emoji:"😓",name:"downcast face with sweat",category:"smileys"},{emoji:"😩",name:"weary face",category:"smileys"},{emoji:"😫",name:"tired face",category:"smileys"},{emoji:"🥱",name:"yawning face",category:"smileys"},{emoji:"😤",name:"face with steam from nose",category:"smileys",keywords:["angry"]},{emoji:"😡",name:"pouting face",category:"smileys",keywords:["rage"]},{emoji:"😠",name:"angry face",category:"smileys"},{emoji:"🤬",name:"face with symbols on mouth",category:"smileys",keywords:["swear"]},{emoji:"😈",name:"smiling face with horns",category:"smileys",keywords:["devil"]},{emoji:"👿",name:"angry face with horns",category:"smileys"},{emoji:"💀",name:"skull",category:"smileys",keywords:["dead"]},{emoji:"☠️",name:"skull and crossbones",category:"smileys"},{emoji:"💩",name:"pile of poo",category:"smileys",keywords:["poop"]},{emoji:"🤡",name:"clown face",category:"smileys"},{emoji:"👹",name:"ogre",category:"smileys"},{emoji:"👺",name:"goblin",category:"smileys"},{emoji:"👻",name:"ghost",category:"smileys"},{emoji:"👽",name:"alien",category:"smileys"},{emoji:"👾",name:"alien monster",category:"smileys"},{emoji:"🤖",name:"robot",category:"smileys"},{emoji:"👋",name:"waving hand",category:"people",skinTones:!0,keywords:["wave","hi"]},{emoji:"🤚",name:"raised back of hand",category:"people",skinTones:!0},{emoji:"🖐️",name:"hand with fingers splayed",category:"people",skinTones:!0},{emoji:"✋",name:"raised hand",category:"people",skinTones:!0},{emoji:"🖖",name:"vulcan salute",category:"people",skinTones:!0},{emoji:"👌",name:"ok hand",category:"people",skinTones:!0,keywords:["ok","perfect"]},{emoji:"🤌",name:"pinched fingers",category:"people",skinTones:!0},{emoji:"🤏",name:"pinching hand",category:"people",skinTones:!0},{emoji:"✌️",name:"victory hand",category:"people",skinTones:!0,keywords:["peace"]},{emoji:"🤞",name:"crossed fingers",category:"people",skinTones:!0},{emoji:"🤟",name:"love-you gesture",category:"people",skinTones:!0},{emoji:"🤘",name:"sign of the horns",category:"people",skinTones:!0,keywords:["rock"]},{emoji:"🤙",name:"call me hand",category:"people",skinTones:!0},{emoji:"👈",name:"backhand index pointing left",category:"people",skinTones:!0},{emoji:"👉",name:"backhand index pointing right",category:"people",skinTones:!0},{emoji:"👆",name:"backhand index pointing up",category:"people",skinTones:!0},{emoji:"🖕",name:"middle finger",category:"people",skinTones:!0},{emoji:"👇",name:"backhand index pointing down",category:"people",skinTones:!0},{emoji:"☝️",name:"index pointing up",category:"people",skinTones:!0},{emoji:"👍",name:"thumbs up",category:"people",skinTones:!0,keywords:["like","good"]},{emoji:"👎",name:"thumbs down",category:"people",skinTones:!0,keywords:["dislike","bad"]},{emoji:"✊",name:"raised fist",category:"people",skinTones:!0},{emoji:"👊",name:"oncoming fist",category:"people",skinTones:!0},{emoji:"🤛",name:"left-facing fist",category:"people",skinTones:!0},{emoji:"🤜",name:"right-facing fist",category:"people",skinTones:!0},{emoji:"👏",name:"clapping hands",category:"people",skinTones:!0,keywords:["clap","applause"]},{emoji:"🙌",name:"raising hands",category:"people",skinTones:!0},{emoji:"👐",name:"open hands",category:"people",skinTones:!0},{emoji:"🤲",name:"palms up together",category:"people",skinTones:!0},{emoji:"🤝",name:"handshake",category:"people",skinTones:!0},{emoji:"🙏",name:"folded hands",category:"people",skinTones:!0,keywords:["pray","please"]},{emoji:"✍️",name:"writing hand",category:"people",skinTones:!0},{emoji:"💪",name:"flexed biceps",category:"people",skinTones:!0,keywords:["strong","muscle"]},{emoji:"🐶",name:"dog face",category:"animals",keywords:["dog"]},{emoji:"🐱",name:"cat face",category:"animals",keywords:["cat"]},{emoji:"🐭",name:"mouse face",category:"animals"},{emoji:"🐹",name:"hamster",category:"animals"},{emoji:"🐰",name:"rabbit face",category:"animals"},{emoji:"🦊",name:"fox",category:"animals"},{emoji:"🐻",name:"bear",category:"animals"},{emoji:"🐼",name:"panda",category:"animals"},{emoji:"🐨",name:"koala",category:"animals"},{emoji:"🐯",name:"tiger face",category:"animals"},{emoji:"🦁",name:"lion",category:"animals"},{emoji:"🐮",name:"cow face",category:"animals"},{emoji:"🐷",name:"pig face",category:"animals",keywords:["pig"]},{emoji:"🐸",name:"frog",category:"animals"},{emoji:"🐵",name:"monkey face",category:"animals"},{emoji:"🙈",name:"see-no-evil monkey",category:"animals"},{emoji:"🙉",name:"hear-no-evil monkey",category:"animals"},{emoji:"🙊",name:"speak-no-evil monkey",category:"animals"},{emoji:"🐔",name:"chicken",category:"animals"},{emoji:"🐧",name:"penguin",category:"animals"},{emoji:"🐦",name:"bird",category:"animals"},{emoji:"🐤",name:"baby chick",category:"animals"},{emoji:"🦆",name:"duck",category:"animals"},{emoji:"🦅",name:"eagle",category:"animals"},{emoji:"🦉",name:"owl",category:"animals"},{emoji:"🦇",name:"bat",category:"animals"},{emoji:"🐺",name:"wolf",category:"animals"},{emoji:"🐗",name:"boar",category:"animals"},{emoji:"🐴",name:"horse face",category:"animals"},{emoji:"🦄",name:"unicorn",category:"animals"},{emoji:"🐝",name:"honeybee",category:"animals",keywords:["bee"]},{emoji:"🐛",name:"bug",category:"animals"},{emoji:"🦋",name:"butterfly",category:"animals"},{emoji:"🐌",name:"snail",category:"animals"},{emoji:"🐙",name:"octopus",category:"animals"},{emoji:"🐬",name:"dolphin",category:"animals"},{emoji:"🐳",name:"spouting whale",category:"animals",keywords:["whale"]},{emoji:"🦈",name:"shark",category:"animals"},{emoji:"🐊",name:"crocodile",category:"animals"},{emoji:"🐢",name:"turtle",category:"animals"},{emoji:"🐍",name:"snake",category:"animals"},{emoji:"🦎",name:"lizard",category:"animals"},{emoji:"🐲",name:"dragon face",category:"animals",keywords:["dragon"]},{emoji:"🌸",name:"cherry blossom",category:"animals",keywords:["flower"]},{emoji:"🌹",name:"rose",category:"animals"},{emoji:"🌻",name:"sunflower",category:"animals"},{emoji:"🌺",name:"hibiscus",category:"animals"},{emoji:"🌷",name:"tulip",category:"animals"},{emoji:"🌲",name:"evergreen tree",category:"animals",keywords:["tree"]},{emoji:"🌳",name:"deciduous tree",category:"animals"},{emoji:"🌴",name:"palm tree",category:"animals"},{emoji:"🌵",name:"cactus",category:"animals"},{emoji:"🍀",name:"four leaf clover",category:"animals",keywords:["lucky"]},{emoji:"🍎",name:"red apple",category:"food",keywords:["apple"]},{emoji:"🍊",name:"tangerine",category:"food",keywords:["orange"]},{emoji:"🍋",name:"lemon",category:"food"},{emoji:"🍌",name:"banana",category:"food"},{emoji:"🍉",name:"watermelon",category:"food"},{emoji:"🍇",name:"grapes",category:"food"},{emoji:"🍓",name:"strawberry",category:"food"},{emoji:"🍒",name:"cherries",category:"food"},{emoji:"🍑",name:"peach",category:"food"},{emoji:"🥭",name:"mango",category:"food"},{emoji:"🍍",name:"pineapple",category:"food"},{emoji:"🥝",name:"kiwi fruit",category:"food"},{emoji:"🍅",name:"tomato",category:"food"},{emoji:"🥑",name:"avocado",category:"food"},{emoji:"🥦",name:"broccoli",category:"food"},{emoji:"🥬",name:"leafy green",category:"food"},{emoji:"🥒",name:"cucumber",category:"food"},{emoji:"🌽",name:"ear of corn",category:"food",keywords:["corn"]},{emoji:"🥕",name:"carrot",category:"food"},{emoji:"🧄",name:"garlic",category:"food"},{emoji:"🧅",name:"onion",category:"food"},{emoji:"🥔",name:"potato",category:"food"},{emoji:"🍞",name:"bread",category:"food"},{emoji:"🥐",name:"croissant",category:"food"},{emoji:"🥖",name:"baguette bread",category:"food"},{emoji:"🧀",name:"cheese wedge",category:"food",keywords:["cheese"]},{emoji:"🥚",name:"egg",category:"food"},{emoji:"🍳",name:"cooking",category:"food",keywords:["egg","breakfast"]},{emoji:"🥓",name:"bacon",category:"food"},{emoji:"🥩",name:"cut of meat",category:"food",keywords:["steak"]},{emoji:"🍗",name:"poultry leg",category:"food",keywords:["chicken"]},{emoji:"🍖",name:"meat on bone",category:"food"},{emoji:"🌭",name:"hot dog",category:"food"},{emoji:"🍔",name:"hamburger",category:"food",keywords:["burger"]},{emoji:"🍟",name:"french fries",category:"food",keywords:["fries"]},{emoji:"🍕",name:"pizza",category:"food"},{emoji:"🥪",name:"sandwich",category:"food"},{emoji:"🌮",name:"taco",category:"food"},{emoji:"🌯",name:"burrito",category:"food"},{emoji:"🥗",name:"green salad",category:"food",keywords:["salad"]},{emoji:"🍝",name:"spaghetti",category:"food",keywords:["pasta"]},{emoji:"🍜",name:"steaming bowl",category:"food",keywords:["ramen","noodles"]},{emoji:"🍲",name:"pot of food",category:"food",keywords:["stew"]},{emoji:"🍣",name:"sushi",category:"food"},{emoji:"🍱",name:"bento box",category:"food"},{emoji:"🥟",name:"dumpling",category:"food"},{emoji:"🍩",name:"doughnut",category:"food",keywords:["donut"]},{emoji:"🍪",name:"cookie",category:"food"},{emoji:"🎂",name:"birthday cake",category:"food",keywords:["cake","birthday"]},{emoji:"🍰",name:"shortcake",category:"food",keywords:["cake"]},{emoji:"🧁",name:"cupcake",category:"food"},{emoji:"🍫",name:"chocolate bar",category:"food",keywords:["chocolate"]},{emoji:"🍬",name:"candy",category:"food"},{emoji:"🍭",name:"lollipop",category:"food"},{emoji:"🍦",name:"soft ice cream",category:"food",keywords:["ice cream"]},{emoji:"☕",name:"hot beverage",category:"food",keywords:["coffee","tea"]},{emoji:"🍵",name:"teacup without handle",category:"food",keywords:["tea"]},{emoji:"🥤",name:"cup with straw",category:"food"},{emoji:"🍺",name:"beer mug",category:"food",keywords:["beer"]},{emoji:"🍻",name:"clinking beer mugs",category:"food",keywords:["cheers"]},{emoji:"🥂",name:"clinking glasses",category:"food",keywords:["champagne","toast"]},{emoji:"🍷",name:"wine glass",category:"food",keywords:["wine"]},{emoji:"🍸",name:"cocktail glass",category:"food",keywords:["martini"]},{emoji:"🚗",name:"automobile",category:"travel",keywords:["car"]},{emoji:"🚕",name:"taxi",category:"travel"},{emoji:"🚌",name:"bus",category:"travel"},{emoji:"🚎",name:"trolleybus",category:"travel"},{emoji:"🏎️",name:"racing car",category:"travel"},{emoji:"🚓",name:"police car",category:"travel"},{emoji:"🚑",name:"ambulance",category:"travel"},{emoji:"🚒",name:"fire engine",category:"travel"},{emoji:"🚐",name:"minibus",category:"travel"},{emoji:"🛻",name:"pickup truck",category:"travel"},{emoji:"🚚",name:"delivery truck",category:"travel",keywords:["truck"]},{emoji:"🚲",name:"bicycle",category:"travel",keywords:["bike"]},{emoji:"🛵",name:"motor scooter",category:"travel"},{emoji:"🏍️",name:"motorcycle",category:"travel"},{emoji:"✈️",name:"airplane",category:"travel",keywords:["plane"]},{emoji:"🚀",name:"rocket",category:"travel"},{emoji:"🚁",name:"helicopter",category:"travel"},{emoji:"🛶",name:"canoe",category:"travel"},{emoji:"⛵",name:"sailboat",category:"travel",keywords:["boat"]},{emoji:"🚢",name:"ship",category:"travel"},{emoji:"🚆",name:"train",category:"travel"},{emoji:"🚇",name:"metro",category:"travel",keywords:["subway"]},{emoji:"🏠",name:"house",category:"travel",keywords:["home"]},{emoji:"🏡",name:"house with garden",category:"travel"},{emoji:"🏢",name:"office building",category:"travel",keywords:["office"]},{emoji:"🏣",name:"Japanese post office",category:"travel"},{emoji:"🏥",name:"hospital",category:"travel"},{emoji:"🏦",name:"bank",category:"travel"},{emoji:"🏨",name:"hotel",category:"travel"},{emoji:"🏪",name:"convenience store",category:"travel",keywords:["store"]},{emoji:"🏫",name:"school",category:"travel"},{emoji:"🏭",name:"factory",category:"travel"},{emoji:"🏰",name:"castle",category:"travel"},{emoji:"⛪",name:"church",category:"travel"},{emoji:"🕌",name:"mosque",category:"travel"},{emoji:"🗼",name:"Tokyo tower",category:"travel"},{emoji:"🗽",name:"Statue of Liberty",category:"travel"},{emoji:"🌁",name:"foggy",category:"travel"},{emoji:"🌃",name:"night with stars",category:"travel"},{emoji:"🌄",name:"sunrise over mountains",category:"travel"},{emoji:"🌅",name:"sunrise",category:"travel"},{emoji:"🌆",name:"cityscape at dusk",category:"travel"},{emoji:"🌇",name:"sunset",category:"travel"},{emoji:"🌉",name:"bridge at night",category:"travel"},{emoji:"⛰️",name:"mountain",category:"travel"},{emoji:"🏔️",name:"snow-capped mountain",category:"travel"},{emoji:"🗻",name:"mount fuji",category:"travel"},{emoji:"🏝️",name:"desert island",category:"travel",keywords:["island"]},{emoji:"🏖️",name:"beach with umbrella",category:"travel",keywords:["beach"]},{emoji:"🌋",name:"volcano",category:"travel"},{emoji:"🌍",name:"globe Europe-Africa",category:"travel",keywords:["earth","world"]},{emoji:"🌎",name:"globe Americas",category:"travel"},{emoji:"🌏",name:"globe Asia-Australia",category:"travel"},{emoji:"🌕",name:"full moon",category:"travel",keywords:["moon"]},{emoji:"🌙",name:"crescent moon",category:"travel"},{emoji:"⭐",name:"star",category:"travel"},{emoji:"🌟",name:"glowing star",category:"travel"},{emoji:"☀️",name:"sun",category:"travel"},{emoji:"🌤️",name:"sun behind small cloud",category:"travel"},{emoji:"⛅",name:"sun behind cloud",category:"travel"},{emoji:"🌧️",name:"cloud with rain",category:"travel",keywords:["rain"]},{emoji:"⛈️",name:"cloud with lightning and rain",category:"travel",keywords:["storm"]},{emoji:"🌨️",name:"cloud with snow",category:"travel",keywords:["snow"]},{emoji:"🌈",name:"rainbow",category:"travel"},{emoji:"⚽",name:"soccer ball",category:"activities",keywords:["football","soccer"]},{emoji:"🏀",name:"basketball",category:"activities"},{emoji:"🏈",name:"american football",category:"activities"},{emoji:"⚾",name:"baseball",category:"activities"},{emoji:"🥎",name:"softball",category:"activities"},{emoji:"🎾",name:"tennis",category:"activities"},{emoji:"🏐",name:"volleyball",category:"activities"},{emoji:"🏉",name:"rugby football",category:"activities"},{emoji:"🥏",name:"flying disc",category:"activities",keywords:["frisbee"]},{emoji:"🎱",name:"pool 8 ball",category:"activities",keywords:["billiards"]},{emoji:"🪀",name:"yo-yo",category:"activities"},{emoji:"🏓",name:"ping pong",category:"activities"},{emoji:"🏸",name:"badminton",category:"activities"},{emoji:"🏒",name:"ice hockey",category:"activities"},{emoji:"🥅",name:"goal net",category:"activities"},{emoji:"⛳",name:"flag in hole",category:"activities",keywords:["golf"]},{emoji:"🏹",name:"bow and arrow",category:"activities",keywords:["archery"]},{emoji:"🎣",name:"fishing pole",category:"activities",keywords:["fishing"]},{emoji:"🥊",name:"boxing glove",category:"activities",keywords:["boxing"]},{emoji:"🥋",name:"martial arts uniform",category:"activities"},{emoji:"🎽",name:"running shirt",category:"activities"},{emoji:"🛹",name:"skateboard",category:"activities"},{emoji:"🛷",name:"sled",category:"activities"},{emoji:"⛸️",name:"ice skate",category:"activities"},{emoji:"🥌",name:"curling stone",category:"activities"},{emoji:"🎿",name:"skis",category:"activities",keywords:["skiing"]},{emoji:"🏂",name:"snowboarder",category:"activities",keywords:["snowboard"]},{emoji:"🏋️",name:"person lifting weights",category:"activities",keywords:["gym"]},{emoji:"🤸",name:"person cartwheeling",category:"activities"},{emoji:"🤺",name:"person fencing",category:"activities"},{emoji:"🏊",name:"person swimming",category:"activities",keywords:["swim"]},{emoji:"🚴",name:"person biking",category:"activities",keywords:["cycling"]},{emoji:"🧘",name:"person in lotus position",category:"activities",keywords:["yoga","meditation"]},{emoji:"🏆",name:"trophy",category:"activities",keywords:["winner","champion"]},{emoji:"🥇",name:"gold medal",category:"activities",keywords:["first"]},{emoji:"🥈",name:"silver medal",category:"activities",keywords:["second"]},{emoji:"🥉",name:"bronze medal",category:"activities",keywords:["third"]},{emoji:"🎮",name:"video game",category:"activities",keywords:["game","gaming"]},{emoji:"🕹️",name:"joystick",category:"activities"},{emoji:"🎲",name:"game die",category:"activities",keywords:["dice"]},{emoji:"🧩",name:"puzzle piece",category:"activities",keywords:["puzzle"]},{emoji:"♟️",name:"chess pawn",category:"activities",keywords:["chess"]},{emoji:"🎯",name:"direct hit",category:"activities",keywords:["dart","target"]},{emoji:"🎰",name:"slot machine",category:"activities"},{emoji:"🎭",name:"performing arts",category:"activities",keywords:["theater","drama"]},{emoji:"🎨",name:"artist palette",category:"activities",keywords:["art","paint"]},{emoji:"🎬",name:"clapper board",category:"activities",keywords:["movie","film"]},{emoji:"🎤",name:"microphone",category:"activities",keywords:["karaoke","sing"]},{emoji:"🎧",name:"headphone",category:"activities",keywords:["music"]},{emoji:"🎼",name:"musical score",category:"activities"},{emoji:"🎹",name:"musical keyboard",category:"activities",keywords:["piano"]},{emoji:"🎷",name:"saxophone",category:"activities"},{emoji:"🎸",name:"guitar",category:"activities"},{emoji:"🎻",name:"violin",category:"activities"},{emoji:"🪘",name:"long drum",category:"activities"},{emoji:"🥁",name:"drum",category:"activities"},{emoji:"⌚",name:"watch",category:"objects"},{emoji:"📱",name:"mobile phone",category:"objects",keywords:["phone","smartphone"]},{emoji:"📲",name:"mobile phone with arrow",category:"objects"},{emoji:"💻",name:"laptop",category:"objects",keywords:["computer"]},{emoji:"🖥️",name:"desktop computer",category:"objects"},{emoji:"🖨️",name:"printer",category:"objects"},{emoji:"⌨️",name:"keyboard",category:"objects"},{emoji:"🖱️",name:"computer mouse",category:"objects"},{emoji:"💾",name:"floppy disk",category:"objects"},{emoji:"💿",name:"optical disk",category:"objects",keywords:["cd"]},{emoji:"📀",name:"dvd",category:"objects"},{emoji:"📷",name:"camera",category:"objects"},{emoji:"📹",name:"video camera",category:"objects"},{emoji:"🎥",name:"movie camera",category:"objects"},{emoji:"📺",name:"television",category:"objects",keywords:["tv"]},{emoji:"📻",name:"radio",category:"objects"},{emoji:"🎙️",name:"studio microphone",category:"objects"},{emoji:"⏰",name:"alarm clock",category:"objects",keywords:["clock"]},{emoji:"⏳",name:"hourglass not done",category:"objects"},{emoji:"⌛",name:"hourglass done",category:"objects"},{emoji:"📡",name:"satellite antenna",category:"objects"},{emoji:"🔋",name:"battery",category:"objects"},{emoji:"🔌",name:"electric plug",category:"objects"},{emoji:"💡",name:"light bulb",category:"objects",keywords:["idea"]},{emoji:"🔦",name:"flashlight",category:"objects"},{emoji:"🕯️",name:"candle",category:"objects"},{emoji:"🧯",name:"fire extinguisher",category:"objects"},{emoji:"🛢️",name:"oil drum",category:"objects"},{emoji:"💸",name:"money with wings",category:"objects"},{emoji:"💵",name:"dollar banknote",category:"objects",keywords:["money"]},{emoji:"💳",name:"credit card",category:"objects"},{emoji:"💰",name:"money bag",category:"objects"},{emoji:"🧲",name:"magnet",category:"objects"},{emoji:"🔧",name:"wrench",category:"objects"},{emoji:"🔨",name:"hammer",category:"objects"},{emoji:"🛠️",name:"hammer and wrench",category:"objects",keywords:["tools"]},{emoji:"⚙️",name:"gear",category:"objects",keywords:["settings"]},{emoji:"🔩",name:"nut and bolt",category:"objects"},{emoji:"🔑",name:"key",category:"objects"},{emoji:"🗝️",name:"old key",category:"objects"},{emoji:"🔒",name:"locked",category:"objects",keywords:["lock"]},{emoji:"🔓",name:"unlocked",category:"objects"},{emoji:"📦",name:"package",category:"objects",keywords:["box"]},{emoji:"📫",name:"closed mailbox with raised flag",category:"objects",keywords:["mail"]},{emoji:"📝",name:"memo",category:"objects",keywords:["note"]},{emoji:"📄",name:"page facing up",category:"objects",keywords:["document"]},{emoji:"📁",name:"file folder",category:"objects",keywords:["folder"]},{emoji:"📂",name:"open file folder",category:"objects"},{emoji:"📅",name:"calendar",category:"objects"},{emoji:"📆",name:"tear-off calendar",category:"objects"},{emoji:"📌",name:"pushpin",category:"objects",keywords:["pin"]},{emoji:"📎",name:"paperclip",category:"objects"},{emoji:"✂️",name:"scissors",category:"objects"},{emoji:"📏",name:"straight ruler",category:"objects"},{emoji:"✏️",name:"pencil",category:"objects"},{emoji:"🖊️",name:"pen",category:"objects"},{emoji:"🖍️",name:"crayon",category:"objects"},{emoji:"📚",name:"books",category:"objects",keywords:["book","library"]},{emoji:"📖",name:"open book",category:"objects"},{emoji:"🔗",name:"link",category:"objects"},{emoji:"💊",name:"pill",category:"objects",keywords:["medicine"]},{emoji:"💉",name:"syringe",category:"objects"},{emoji:"🩹",name:"adhesive bandage",category:"objects"},{emoji:"🧪",name:"test tube",category:"objects"},{emoji:"🔬",name:"microscope",category:"objects"},{emoji:"🔭",name:"telescope",category:"objects"},{emoji:"🧬",name:"dna",category:"objects"},{emoji:"🗑️",name:"wastebasket",category:"objects",keywords:["trash","delete"]},{emoji:"🚿",name:"shower",category:"objects"},{emoji:"🛁",name:"bathtub",category:"objects"},{emoji:"🧹",name:"broom",category:"objects"},{emoji:"🧺",name:"basket",category:"objects"},{emoji:"🧻",name:"roll of paper",category:"objects"},{emoji:"🧼",name:"soap",category:"objects"},{emoji:"🪥",name:"toothbrush",category:"objects"},{emoji:"🛒",name:"shopping cart",category:"objects"},{emoji:"🎁",name:"wrapped gift",category:"objects",keywords:["gift","present"]},{emoji:"🎀",name:"ribbon",category:"objects"},{emoji:"🎈",name:"balloon",category:"objects"},{emoji:"🎉",name:"party popper",category:"objects",keywords:["party","celebration"]},{emoji:"🎊",name:"confetti ball",category:"objects"},{emoji:"❤️",name:"red heart",category:"symbols",keywords:["love","heart"]},{emoji:"🧡",name:"orange heart",category:"symbols"},{emoji:"💛",name:"yellow heart",category:"symbols"},{emoji:"💚",name:"green heart",category:"symbols"},{emoji:"💙",name:"blue heart",category:"symbols"},{emoji:"💜",name:"purple heart",category:"symbols"},{emoji:"🖤",name:"black heart",category:"symbols"},{emoji:"🤍",name:"white heart",category:"symbols"},{emoji:"🤎",name:"brown heart",category:"symbols"},{emoji:"💔",name:"broken heart",category:"symbols"},{emoji:"💕",name:"two hearts",category:"symbols"},{emoji:"💖",name:"sparkling heart",category:"symbols"},{emoji:"💗",name:"growing heart",category:"symbols"},{emoji:"💘",name:"heart with arrow",category:"symbols"},{emoji:"💝",name:"heart with ribbon",category:"symbols"},{emoji:"💞",name:"revolving hearts",category:"symbols"},{emoji:"💯",name:"hundred points",category:"symbols",keywords:["100","perfect"]},{emoji:"💢",name:"anger symbol",category:"symbols"},{emoji:"💥",name:"collision",category:"symbols",keywords:["boom","explosion"]},{emoji:"💫",name:"dizzy",category:"symbols"},{emoji:"💦",name:"sweat droplets",category:"symbols"},{emoji:"💨",name:"dashing away",category:"symbols"},{emoji:"🕳️",name:"hole",category:"symbols"},{emoji:"💬",name:"speech balloon",category:"symbols",keywords:["comment","chat"]},{emoji:"👁️‍🗨️",name:"eye in speech bubble",category:"symbols"},{emoji:"🗨️",name:"left speech bubble",category:"symbols"},{emoji:"🗯️",name:"right anger bubble",category:"symbols"},{emoji:"💭",name:"thought balloon",category:"symbols"},{emoji:"💤",name:"zzz",category:"symbols",keywords:["sleep"]},{emoji:"🔔",name:"bell",category:"symbols",keywords:["notification"]},{emoji:"🔕",name:"bell with slash",category:"symbols",keywords:["mute"]},{emoji:"🎵",name:"musical note",category:"symbols",keywords:["music"]},{emoji:"🎶",name:"musical notes",category:"symbols"},{emoji:"➕",name:"plus",category:"symbols",keywords:["add"]},{emoji:"➖",name:"minus",category:"symbols"},{emoji:"➗",name:"divide",category:"symbols"},{emoji:"✖️",name:"multiply",category:"symbols"},{emoji:"♾️",name:"infinity",category:"symbols"},{emoji:"💲",name:"heavy dollar sign",category:"symbols",keywords:["money"]},{emoji:"🔴",name:"red circle",category:"symbols"},{emoji:"🟠",name:"orange circle",category:"symbols"},{emoji:"🟡",name:"yellow circle",category:"symbols"},{emoji:"🟢",name:"green circle",category:"symbols"},{emoji:"🔵",name:"blue circle",category:"symbols"},{emoji:"🟣",name:"purple circle",category:"symbols"},{emoji:"⚫",name:"black circle",category:"symbols"},{emoji:"⚪",name:"white circle",category:"symbols"},{emoji:"🟤",name:"brown circle",category:"symbols"},{emoji:"🔺",name:"red triangle pointed up",category:"symbols"},{emoji:"🔻",name:"red triangle pointed down",category:"symbols"},{emoji:"🔷",name:"large blue diamond",category:"symbols"},{emoji:"🔶",name:"large orange diamond",category:"symbols"},{emoji:"✅",name:"check mark button",category:"symbols",keywords:["done","yes"]},{emoji:"❌",name:"cross mark",category:"symbols",keywords:["no","wrong"]},{emoji:"❎",name:"cross mark button",category:"symbols"},{emoji:"✔️",name:"check mark",category:"symbols"},{emoji:"⭕",name:"hollow red circle",category:"symbols"},{emoji:"❗",name:"exclamation mark",category:"symbols",keywords:["warning"]},{emoji:"❓",name:"question mark",category:"symbols"},{emoji:"❕",name:"white exclamation mark",category:"symbols"},{emoji:"❔",name:"white question mark",category:"symbols"},{emoji:"⚠️",name:"warning",category:"symbols"},{emoji:"🚫",name:"prohibited",category:"symbols",keywords:["no","forbidden"]},{emoji:"🔞",name:"no one under eighteen",category:"symbols"},{emoji:"⛔",name:"no entry",category:"symbols",keywords:["stop"]},{emoji:"🔙",name:"back arrow",category:"symbols"},{emoji:"🔚",name:"end arrow",category:"symbols"},{emoji:"🔛",name:"on! arrow",category:"symbols"},{emoji:"🔜",name:"soon arrow",category:"symbols"},{emoji:"🔝",name:"top arrow",category:"symbols"},{emoji:"🔃",name:"clockwise vertical arrows",category:"symbols",keywords:["refresh"]},{emoji:"🔄",name:"counterclockwise arrows button",category:"symbols",keywords:["sync"]},{emoji:"🔁",name:"repeat button",category:"symbols"},{emoji:"🔀",name:"shuffle tracks button",category:"symbols"},{emoji:"▶️",name:"play button",category:"symbols"},{emoji:"⏸️",name:"pause button",category:"symbols"},{emoji:"⏹️",name:"stop button",category:"symbols"},{emoji:"⏺️",name:"record button",category:"symbols"},{emoji:"⏭️",name:"next track button",category:"symbols"},{emoji:"⏮️",name:"last track button",category:"symbols"},{emoji:"⏩",name:"fast-forward button",category:"symbols"},{emoji:"⏪",name:"fast reverse button",category:"symbols"},{emoji:"🔼",name:"upwards button",category:"symbols"},{emoji:"🔽",name:"downwards button",category:"symbols"},{emoji:"⬆️",name:"up arrow",category:"symbols"},{emoji:"⬇️",name:"down arrow",category:"symbols"},{emoji:"⬅️",name:"left arrow",category:"symbols"},{emoji:"➡️",name:"right arrow",category:"symbols"},{emoji:"↗️",name:"up-right arrow",category:"symbols"},{emoji:"↘️",name:"down-right arrow",category:"symbols"},{emoji:"↙️",name:"down-left arrow",category:"symbols"},{emoji:"↖️",name:"up-left arrow",category:"symbols"},{emoji:"↕️",name:"up-down arrow",category:"symbols"},{emoji:"↔️",name:"left-right arrow",category:"symbols"},{emoji:"🔀",name:"shuffle",category:"symbols"},{emoji:"ℹ️",name:"information",category:"symbols",keywords:["info"]},{emoji:"🆕",name:"new button",category:"symbols",keywords:["new"]},{emoji:"🆗",name:"ok button",category:"symbols",keywords:["ok"]},{emoji:"🆙",name:"up! button",category:"symbols"},{emoji:"🆒",name:"cool button",category:"symbols",keywords:["cool"]},{emoji:"🆓",name:"free button",category:"symbols",keywords:["free"]},{emoji:"🔟",name:"keycap: 10",category:"symbols"},{emoji:"#️⃣",name:"keycap: #",category:"symbols"},{emoji:"*️⃣",name:"keycap: *",category:"symbols"},{emoji:"0️⃣",name:"keycap: 0",category:"symbols"},{emoji:"1️⃣",name:"keycap: 1",category:"symbols"},{emoji:"2️⃣",name:"keycap: 2",category:"symbols"},{emoji:"3️⃣",name:"keycap: 3",category:"symbols"},{emoji:"4️⃣",name:"keycap: 4",category:"symbols"},{emoji:"5️⃣",name:"keycap: 5",category:"symbols"},{emoji:"6️⃣",name:"keycap: 6",category:"symbols"},{emoji:"7️⃣",name:"keycap: 7",category:"symbols"},{emoji:"8️⃣",name:"keycap: 8",category:"symbols"},{emoji:"9️⃣",name:"keycap: 9",category:"symbols"},{emoji:"©️",name:"copyright",category:"symbols"},{emoji:"®️",name:"registered",category:"symbols"},{emoji:"™️",name:"trade mark",category:"symbols"},{emoji:"🏳️",name:"white flag",category:"flags"},{emoji:"🏴",name:"black flag",category:"flags"},{emoji:"🏁",name:"chequered flag",category:"flags",keywords:["finish","racing"]},{emoji:"🚩",name:"triangular flag",category:"flags"},{emoji:"🏳️‍🌈",name:"rainbow flag",category:"flags",keywords:["pride"]},{emoji:"🏳️‍⚧️",name:"transgender flag",category:"flags"},{emoji:"🇺🇸",name:"flag: United States",category:"flags",keywords:["usa","america"]},{emoji:"🇬🇧",name:"flag: United Kingdom",category:"flags",keywords:["uk","britain"]},{emoji:"🇩🇪",name:"flag: Germany",category:"flags"},{emoji:"🇫🇷",name:"flag: France",category:"flags"},{emoji:"🇵🇱",name:"flag: Poland",category:"flags"},{emoji:"🇪🇸",name:"flag: Spain",category:"flags"},{emoji:"🇮🇹",name:"flag: Italy",category:"flags"},{emoji:"🇯🇵",name:"flag: Japan",category:"flags"},{emoji:"🇨🇳",name:"flag: China",category:"flags"},{emoji:"🇰🇷",name:"flag: South Korea",category:"flags"},{emoji:"🇮🇳",name:"flag: India",category:"flags"},{emoji:"🇧🇷",name:"flag: Brazil",category:"flags"},{emoji:"🇷🇺",name:"flag: Russia",category:"flags"},{emoji:"🇦🇺",name:"flag: Australia",category:"flags"},{emoji:"🇨🇦",name:"flag: Canada",category:"flags"},{emoji:"🇲🇽",name:"flag: Mexico",category:"flags"},{emoji:"🇳🇱",name:"flag: Netherlands",category:"flags"},{emoji:"🇧🇪",name:"flag: Belgium",category:"flags"},{emoji:"🇨🇭",name:"flag: Switzerland",category:"flags"},{emoji:"🇦🇹",name:"flag: Austria",category:"flags"},{emoji:"🇸🇪",name:"flag: Sweden",category:"flags"},{emoji:"🇳🇴",name:"flag: Norway",category:"flags"},{emoji:"🇩🇰",name:"flag: Denmark",category:"flags"},{emoji:"🇫🇮",name:"flag: Finland",category:"flags"},{emoji:"🇵🇹",name:"flag: Portugal",category:"flags"},{emoji:"🇬🇷",name:"flag: Greece",category:"flags"},{emoji:"🇹🇷",name:"flag: Turkey",category:"flags"},{emoji:"🇮🇱",name:"flag: Israel",category:"flags"},{emoji:"🇦🇪",name:"flag: United Arab Emirates",category:"flags"},{emoji:"🇸🇦",name:"flag: Saudi Arabia",category:"flags"},{emoji:"🇿🇦",name:"flag: South Africa",category:"flags"},{emoji:"🇪🇬",name:"flag: Egypt",category:"flags"},{emoji:"🇳🇬",name:"flag: Nigeria",category:"flags"},{emoji:"🇹🇭",name:"flag: Thailand",category:"flags"},{emoji:"🇻🇳",name:"flag: Vietnam",category:"flags"},{emoji:"🇸🇬",name:"flag: Singapore",category:"flags"},{emoji:"🇲🇾",name:"flag: Malaysia",category:"flags"},{emoji:"🇮🇩",name:"flag: Indonesia",category:"flags"},{emoji:"🇵🇭",name:"flag: Philippines",category:"flags"},{emoji:"🇦🇷",name:"flag: Argentina",category:"flags"},{emoji:"🇨🇱",name:"flag: Chile",category:"flags"},{emoji:"🇨🇴",name:"flag: Colombia",category:"flags"},{emoji:"🇺🇦",name:"flag: Ukraine",category:"flags"},{emoji:"🇨🇿",name:"flag: Czech Republic",category:"flags"},{emoji:"🇭🇺",name:"flag: Hungary",category:"flags"},{emoji:"🇷🇴",name:"flag: Romania",category:"flags"},{emoji:"🇮🇪",name:"flag: Ireland",category:"flags"},{emoji:"🇳🇿",name:"flag: New Zealand",category:"flags"}],Qt="nice-emoji-picker-recent",jn=({onSelect:t,showSearch:i=!0,searchPlaceholder:a,showSkinTones:o=!0,defaultSkinTone:l=0,showRecent:g=!0,maxRecent:y=24,recentEmojis:M,onRecentChange:P,categories:I,customEmojis:J=[],columns:X=8,size:O="md",className:$="",style:Y,"data-testid":ae="nice-emoji-picker"})=>{const ne=n.useRef(null);r.useRovingFocus(ne,{orientation:"horizontal",wrap:!0,activateOnMove:!0});const{t:le}=r.useNiceTranslation(),[G,B]=n.useState(""),[k,s]=n.useState(g?"recent":"smileys"),[T,F]=n.useState(l),[R,_]=n.useState(!1),b=n.useRef(null),[N,f]=n.useState(()=>{if(typeof window>"u")return[];try{return JSON.parse(localStorage.getItem(Qt)||"[]")}catch{return[]}}),E=M??N,L=n.useMemo(()=>I??[...g?["recent"]:[],"smileys","people","animals","food","travel","activities","objects","symbols","flags"],[I,g]),w=n.useMemo(()=>{if(!G)return vt;const p=G.toLowerCase();return vt.filter(C=>C.name.toLowerCase().includes(p)||C.emoji.includes(p)||C.keywords?.some(S=>S.toLowerCase().includes(p)))},[G]),d=n.useMemo(()=>{const p={};for(const C of L)C==="recent"?p[C]=E.map(S=>vt.find(m=>m.emoji===S)).filter(S=>S!==void 0).slice(0,y):p[C]=w.filter(S=>S.category===C);return p},[L,w,E,y]),z=n.useCallback((p,C)=>!C||T===0?p:p.replace(/[\u{1F3FB}-\u{1F3FF}]/gu,"")+$t[T],[T]),j=n.useCallback(p=>{const C=z(p.emoji,p.skinTones),S=[p.emoji,...E.filter(m=>m!==p.emoji)].slice(0,y);if(M===void 0){f(S);try{localStorage.setItem(Qt,JSON.stringify(S))}catch{}}P?.(S),t?.(C,p)},[z,E,y,M,P,t]),h=n.useCallback(p=>{t?.(`:${p.name}:`,p)},[t]);n.useEffect(()=>{if(!R)return;const p=C=>{b.current&&!b.current.contains(C.target)&&_(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[R]);const c=G?w:d[k]||[];return e.jsxs("div",{className:`nice-emoji-picker nice-emoji-picker--${O} ${$}`,style:Y,"data-testid":ae,children:[i&&e.jsxs("div",{className:"nice-emoji-picker__search",children:[e.jsx("input",{type:"text",value:G,onChange:p=>B(p.target.value),placeholder:a??le("search","Search emoji..."),className:"nice-emoji-picker__search-input","data-testid":`${ae}-search`}),o&&e.jsxs("div",{className:"nice-emoji-picker__skin-tone-wrapper",children:[e.jsxs("button",{ref:b,type:"button",className:"nice-emoji-picker__skin-tone-btn",onClick:()=>_(!R),title:le("skinTone","Skin tone"),children:["✋",$t[T]]}),R&&e.jsx("div",{className:"nice-emoji-picker__skin-tone-menu",children:$t.map((p,C)=>e.jsxs("button",{type:"button",className:`nice-emoji-picker__skin-tone-option ${C===T?"nice-emoji-picker__skin-tone-option--selected":""}`,onClick:()=>{F(C),_(!1)},children:["✋",p]},C))})]})]}),!G&&e.jsx("div",{className:"nice-emoji-picker__categories",ref:ne,role:"tablist",children:L.map(p=>e.jsx("button",{type:"button",className:`nice-emoji-picker__category-btn ${k===p?"nice-emoji-picker__category-btn--selected":""}`,onClick:()=>s(p),title:Zt[p],role:"tab","aria-selected":k===p,children:Ki[p]},p))}),e.jsxs("div",{className:"nice-emoji-picker__grid-container",children:[G?e.jsxs("div",{className:"nice-emoji-picker__section",children:[e.jsx("div",{className:"nice-emoji-picker__section-title",children:le("searchResults","Search Results")}),e.jsx("div",{className:"nice-emoji-picker__grid",style:{gridTemplateColumns:`repeat(${X}, 1fr)`},children:w.length===0?e.jsx("div",{className:"nice-emoji-picker__empty",children:le("noEmojis","No emojis found")}):w.map((p,C)=>e.jsx("button",{type:"button",className:"nice-emoji-picker__emoji",onClick:()=>j(p),title:p.name,children:z(p.emoji,p.skinTones)},`${p.emoji}-${C}`))})]}):e.jsxs("div",{className:"nice-emoji-picker__section",children:[e.jsx("div",{className:"nice-emoji-picker__section-title",children:Zt[k]}),e.jsx("div",{className:"nice-emoji-picker__grid",style:{gridTemplateColumns:`repeat(${X}, 1fr)`},children:c.length===0?e.jsx("div",{className:"nice-emoji-picker__empty",children:k==="recent"?le("noRecent","No recent emojis"):le("noEmojis","No emojis found")}):c.map((p,C)=>e.jsx("button",{type:"button",className:"nice-emoji-picker__emoji",onClick:()=>j(p),title:p.name,children:z(p.emoji,p.skinTones)},`${p.emoji}-${C}`))})]}),J.length>0&&e.jsxs("div",{className:"nice-emoji-picker__section",children:[e.jsx("div",{className:"nice-emoji-picker__section-title",children:le("custom","Custom")}),e.jsx("div",{className:"nice-emoji-picker__grid",style:{gridTemplateColumns:`repeat(${X}, 1fr)`},children:J.map(p=>e.jsx("button",{type:"button",className:"nice-emoji-picker__emoji nice-emoji-picker__emoji--custom",onClick:()=>h(p),title:p.name,children:e.jsx("img",{src:p.url,alt:p.name})},p.id))})]})]})]})};process.env.NODE_ENV!=="production"&&(jn.displayName="NiceEmojiPicker");const Ui=Object.assign(n.forwardRef(({length:t=6,value:i="",onChange:a,masked:o=!1,onComplete:l,label:g,helperText:y,error:M,required:P,disabled:I,readOnly:J,size:X="md",name:O,id:$,className:Y,style:ae,autoFocus:ne,labelPlacement:le,errorPlacement:G,labelWidth:B,controlWidth:k,loading:s,cellWidth:T,...F},R)=>{const _=r.useControlId($),b=n.useRef([]),N=i.padEnd(t,"").slice(0,t).split(""),f=n.useCallback(z=>{const j=Math.max(0,Math.min(t-1,z));b.current[j]?.focus()},[t]),E=n.useCallback(z=>{const j=z.join("");a?.(j),j.length===t&&j.indexOf("")===-1&&/^\d+$/.test(j)&&l?.(j)},[a,l,t]),L=n.useCallback((z,j)=>{const c=j.target.value.replace(/\D/g,"").slice(-1);if(!c)return;const p=[...N];p[z]=c,E(p),f(z+1)},[N,E,f]),w=n.useCallback((z,j)=>{if(j.key==="Backspace"){j.preventDefault();const h=[...N];N[z]?(h[z]="",E(h)):z>0&&(h[z-1]="",E(h),f(z-1))}else j.key==="ArrowLeft"?(j.preventDefault(),f(z-1)):j.key==="ArrowRight"&&(j.preventDefault(),f(z+1))},[N,E,f]),d=n.useCallback(z=>{z.preventDefault();const j=z.clipboardData.getData("text").replace(/\D/g,"").slice(0,t);if(!j)return;const h=j.padEnd(t,"").slice(0,t).split("");for(let c=j.length;c<t;c++)h[c]=N[c]||"";E(h),f(Math.min(j.length,t-1))},[t,N,E,f]);return e.jsxs("div",{className:`nice-field nice-field--${X} nice-field--otp${le?` nice-field--label-${le}`:""}${G==="right"?" nice-field--error-right":""} ${s?"nice-field--loading":""} ${Y||""}`,style:{...ae,...B!=null&&{"--nice-field-label-width":typeof B=="number"?`${B}px`:B},...k!=null&&{"--nice-field-control-width":typeof k=="number"?`${k}px`:k},...T!=null&&{"--nice-otp-cell-width":typeof T=="number"?`${T}px`:T}},"aria-busy":s||void 0,...F,children:[g&&e.jsx("label",{htmlFor:`${_}-0`,className:`nice-field__label ${P?"nice-field__label--required":""}`,children:g}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{ref:R,className:`nice-otp nice-otp--${X} ${M?"nice-otp--error":""} ${I?"nice-otp--disabled":""}`,onPaste:d,children:[Array.from({length:t},(z,j)=>e.jsx("input",{ref:h=>{b.current[j]=h},id:j===0?`${_}-0`:void 0,className:"nice-otp__digit",type:o?"password":"text",inputMode:"numeric",maxLength:2,value:N[j]||"",disabled:I,readOnly:J,autoFocus:ne&&j===0,"aria-invalid":!!M,"aria-label":`${j+1}`,onChange:h=>L(j,h),onKeyDown:h=>w(j,h),onFocus:h=>h.target.select()},j)),O&&e.jsx("input",{type:"hidden",name:O,value:i})]}),G==="right"&&M&&e.jsx("div",{id:`${_}-error`,className:"nice-field__error",role:"alert",children:M}),G==="right"&&!M&&y&&e.jsx("div",{id:`${_}-helper`,className:"nice-field__helper",children:y}),s&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]}),G!=="right"&&M&&e.jsx("div",{id:`${_}-error`,className:"nice-field__error",role:"alert",children:M}),G!=="right"&&!M&&y&&e.jsx("div",{id:`${_}-helper`,className:"nice-field__helper",children:y})]})}),{displayName:"NiceInputOtp"}),Yi=[{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"}],en={rotation:0,flipH:!1,flipV:!1,brightness:100,contrast:100,saturate:100,blur:0,crop:null,annotations:[]},Xi=["crop","rotate","flip","brightness","contrast","saturate","blur","annotate"],qi=Object.assign(n.forwardRef(({src:t,size:i="md",editorSize:a="standard",tools:o=Xi,showToolbar:l=!0,showZoom:g=!0,maxUndo:y=30,onSave:M,onCancel:P,onChange:I,width:J="100%",height:X=500,tutorial:O,className:$,style:Y,id:ae,...ne},le)=>{const G=r.useControlId(ae),{t:B}=r.useNiceTranslation(),{prompt:k,element:s}=Qe.useNiceDialogs(),T=n.useRef(null),F=n.useRef(null);r.useRovingFocus(F,{orientation:"horizontal",itemSelector:"button"});const R=n.useRef(null),[_,b]=n.useState({...en}),[N,f]=n.useState(null),[E,L]=n.useState(!1),[w,d]=n.useState(1),[z,j]=n.useState("rect"),[h,c]=n.useState("var(--nice-danger, #ff0000)"),[p,C]=n.useState({w:0,h:0}),[S,m]=n.useState([]),[A,D]=n.useState([]),[W,v]=n.useState(null),[q,H]=n.useState(null),[me,pe]=n.useState(null),je=n.useCallback(K=>{m(U=>[...U.slice(-(y-1)),K]),D([])},[y]),ge=n.useCallback(K=>{b(U=>{je(U);const Z={...U,...K};return I?.(Z),Z})},[I,je]),ue=n.useCallback(()=>{if(S.length===0)return;const K=S[S.length-1];m(U=>U.slice(0,-1)),D(U=>[...U,_]),b(K),I?.(K)},[S,_,I]),de=n.useCallback(()=>{if(A.length===0)return;const K=A[A.length-1];D(U=>U.slice(0,-1)),m(U=>[...U,_]),b(K),I?.(K)},[A,_,I]);n.useEffect(()=>{const K=new Image;K.crossOrigin="anonymous",K.onload=()=>{R.current=K,C({w:K.width,h:K.height}),L(!0)},K.src=t},[t]),n.useEffect(()=>{if(!E||!T.current||!R.current)return;const K=T.current,U=K.getContext("2d");if(!U)return;const Z=R.current,x=_.rotation%180!==0,ee=x?Z.height:Z.width,ie=x?Z.width:Z.height;K.width=ee,K.height=ie,U.clearRect(0,0,ee,ie),U.save(),U.filter=`brightness(${_.brightness}%) contrast(${_.contrast}%) saturate(${_.saturate}%) blur(${_.blur}px)`,U.translate(ee/2,ie/2),U.rotate(_.rotation*Math.PI/180),U.scale(_.flipH?-1:1,_.flipV?-1:1),U.drawImage(Z,-Z.width/2,-Z.height/2),U.restore(),_.annotations.forEach(ce=>{switch(U.save(),U.strokeStyle=ce.color??"red",U.fillStyle=ce.color??"red",U.lineWidth=ce.strokeWidth??2,U.font=`${ce.fontSize??16}px sans-serif`,ce.type){case"text":U.fillText(ce.text??"",ce.x,ce.y);break;case"rect":U.strokeRect(ce.x,ce.y,ce.width??100,ce.height??50);break;case"circle":{const be=(ce.width??50)/2,fe=(ce.height??50)/2;U.beginPath(),U.ellipse(ce.x+be,ce.y+fe,be,fe,0,0,Math.PI*2),U.stroke();break}case"line":U.beginPath(),U.moveTo(ce.x,ce.y),U.lineTo(ce.x+(ce.width??100),ce.y+(ce.height??0)),U.stroke();break;case"arrow":{const be=ce.x+(ce.width??100),fe=ce.y+(ce.height??0);U.beginPath(),U.moveTo(ce.x,ce.y),U.lineTo(be,fe),U.stroke();const Se=Math.atan2(fe-ce.y,be-ce.x),Re=10;U.beginPath(),U.moveTo(be,fe),U.lineTo(be-Re*Math.cos(Se-.4),fe-Re*Math.sin(Se-.4)),U.lineTo(be-Re*Math.cos(Se+.4),fe-Re*Math.sin(Se+.4)),U.closePath(),U.fill();break}}U.restore()}),q&&(U.save(),U.fillStyle=r.resolveCssColor("var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",U.canvas),U.fillRect(0,0,ee,ie),U.clearRect(q.x,q.y,q.w,q.h),U.strokeStyle=r.resolveCssColor("var(--nice-bg-primary, #fff)",U.canvas),U.lineWidth=2,U.setLineDash([5,5]),U.strokeRect(q.x,q.y,q.w,q.h),U.restore())},[E,_,q]);const he=n.useCallback(K=>{if(!T.current)return;const U=T.current.getBoundingClientRect(),Z=T.current.width/U.width,x=T.current.height/U.height,ee=(K.clientX-U.left)*Z,ie=(K.clientY-U.top)*x;N==="crop"?v({startX:ee,startY:ie}):N==="annotate"&&pe({startX:ee,startY:ie})},[N]),oe=n.useCallback(K=>{if(!T.current)return;const U=T.current.getBoundingClientRect(),Z=T.current.width/U.width,x=T.current.height/U.height,ee=(K.clientX-U.left)*Z,ie=(K.clientY-U.top)*x;W&&H({x:Math.min(W.startX,ee),y:Math.min(W.startY,ie),w:Math.abs(ee-W.startX),h:Math.abs(ie-W.startY)})},[W]),ve=n.useCallback(K=>{if(W&&q&&q.w>5&&q.h>5&&ge({crop:{x:q.x,y:q.y,width:q.w,height:q.h}}),v(null),me&&T.current){const U=T.current.getBoundingClientRect(),Z=T.current.width/U.width,x=T.current.height/U.height,ee=(K.clientX-U.left)*Z,ie=(K.clientY-U.top)*x,ce=ee-me.startX,be=ie-me.startY;if(Math.abs(ce)>3||Math.abs(be)>3||z==="text"){const fe={type:z,x:me.startX,y:me.startY,width:Math.abs(ce)||100,height:Math.abs(be)||50,color:h,strokeWidth:2};if(z==="text"){const Se=_.annotations;k({title:B("imageEditor.annotationText","Text:")}).then(Re=>{Re&&ge({annotations:[...Se,{...fe,text:Re}]})})}else ge({annotations:[..._.annotations,fe]})}pe(null)}},[W,q,me,z,h,_.annotations,ge,B,k]),_e=n.useCallback(()=>{if(!_.crop||!T.current)return;const K=T.current,U=K.getContext("2d");if(!U)return;const{x:Z,y:x,width:ee,height:ie}=_.crop,ce=U.getImageData(Z,x,ee,ie);K.width=ee,K.height=ie,U.putImageData(ce,0,0),H(null),f(null)},[_.crop]),te=n.useCallback(()=>{if(!T.current)return;const K=T.current.toDataURL("image/png");M?.(K,_)},[M,_]),ke=n.useCallback(()=>{b({...en}),H(null),f(null)},[]);n.useMemo(()=>`brightness(${_.brightness}%) contrast(${_.contrast}%) saturate(${_.saturate}%) blur(${_.blur}px)`,[_.brightness,_.contrast,_.saturate,_.blur]);const se=l?e.jsxs("div",{ref:F,className:"nice-image-editor__toolbar",role:"toolbar","aria-label":B("imageEditor.toolbar","Image tools"),children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:ue,disabled:S.length===0,title:B("imageEditor.undo","Undo"),"aria-label":B("imageEditor.undo","Undo"),children:e.jsx(r.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:de,disabled:A.length===0,title:B("imageEditor.redo","Redo"),"aria-label":B("imageEditor.redo","Redo"),children:e.jsx(r.NiceIcon,{name:"forward",size:16})}),e.jsx("span",{className:"nice-image-editor__sep"}),o.includes("rotate")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>ge({rotation:(_.rotation-90+360)%360}),title:B("imageEditor.rotateLeft","Rotate left"),"aria-label":B("imageEditor.rotateLeft","Rotate left"),children:e.jsx(r.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>ge({rotation:(_.rotation+90)%360}),title:B("imageEditor.rotateRight","Rotate right"),"aria-label":B("imageEditor.rotateRight","Rotate right"),children:e.jsx(r.NiceIcon,{name:"forward",size:16})})]}),o.includes("flip")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>ge({flipH:!_.flipH}),title:B("imageEditor.flipH","Flip horizontal"),"aria-label":B("imageEditor.flipH","Flip horizontal"),children:e.jsx(r.NiceIcon,{name:"shuffle",size:16})}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>ge({flipV:!_.flipV}),title:B("imageEditor.flipV","Flip vertical"),"aria-label":B("imageEditor.flipV","Flip vertical"),children:e.jsx(r.NiceIcon,{name:"shuffle",size:16})})]}),o.includes("crop")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:`nice-image-editor__btn ${N==="crop"?"nice-image-editor__btn--active":""}`,onClick:()=>f(N==="crop"?null:"crop"),title:B("imageEditor.crop","Crop"),"aria-label":B("imageEditor.crop","Crop"),children:e.jsx(r.NiceIcon,{name:"box",size:16})}),N==="crop"&&_.crop&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:_e,title:B("imageEditor.applyCrop","Apply crop"),"aria-label":B("imageEditor.applyCrop","Apply crop"),children:e.jsx(r.NiceIcon,{name:"check",size:16})})]}),o.includes("brightness")&&e.jsxs("label",{className:"nice-image-editor__slider-label",title:B("imageEditor.brightness","Brightness"),children:[e.jsx(r.NiceIcon,{name:"lightbulb",size:16}),e.jsx("input",{type:"range",min:0,max:200,value:_.brightness,onChange:K=>ge({brightness:Number(K.target.value)}),className:"nice-image-editor__slider",title:B("imageEditor.brightness","Brightness")})]}),o.includes("contrast")&&e.jsxs("label",{className:"nice-image-editor__slider-label",title:B("imageEditor.contrast","Contrast"),children:[e.jsx(r.NiceIcon,{name:"circle",size:16}),e.jsx("input",{type:"range",min:0,max:200,value:_.contrast,onChange:K=>ge({contrast:Number(K.target.value)}),className:"nice-image-editor__slider",title:B("imageEditor.contrast","Contrast")})]}),o.includes("saturate")&&e.jsxs("label",{className:"nice-image-editor__slider-label",title:B("imageEditor.saturate","Saturation"),children:[e.jsx(r.NiceIcon,{name:"palette",size:16}),e.jsx("input",{type:"range",min:0,max:200,value:_.saturate,onChange:K=>ge({saturate:Number(K.target.value)}),className:"nice-image-editor__slider",title:B("imageEditor.saturate","Saturation")})]}),o.includes("blur")&&e.jsxs("label",{className:"nice-image-editor__slider-label",title:B("imageEditor.blur","Blur"),children:[e.jsx(r.NiceIcon,{name:"eye-off",size:16}),e.jsx("input",{type:"range",min:0,max:20,step:.5,value:_.blur,onChange:K=>ge({blur:Number(K.target.value)}),className:"nice-image-editor__slider",title:B("imageEditor.blur","Blur")})]}),o.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 ${N==="annotate"?"nice-image-editor__btn--active":""}`,onClick:()=>f(N==="annotate"?null:"annotate"),title:B("imageEditor.annotate","Annotate"),"aria-label":B("imageEditor.annotate","Annotate"),children:e.jsx(r.NiceIcon,{name:"edit",size:16})}),N==="annotate"&&e.jsxs(e.Fragment,{children:[e.jsxs("select",{className:"nice-image-editor__select",value:z,onChange:K=>j(K.target.value),children:[e.jsx("option",{value:"rect",children:B("imageEditor.rect","Rect")}),e.jsx("option",{value:"circle",children:B("imageEditor.circle","Circle")}),e.jsx("option",{value:"line",children:B("imageEditor.line","Line")}),e.jsx("option",{value:"arrow",children:B("imageEditor.arrow","Arrow")}),e.jsx("option",{value:"text",children:B("imageEditor.text","Text")})]}),e.jsx("input",{type:"color",value:h,onChange:K=>c(K.target.value),className:"nice-image-editor__color",title:B("imageEditor.color","Color")}),_.annotations.length>0&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>ge({annotations:_.annotations.slice(0,-1)}),title:B("imageEditor.removeLastAnnotation","Remove last"),"aria-label":B("imageEditor.removeLastAnnotation","Remove last"),children:e.jsx(r.NiceIcon,{name:"trash",size:16})})]})]}),e.jsx("span",{className:"nice-image-editor__sep"}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:ke,title:B("imageEditor.reset","Reset"),"aria-label":B("imageEditor.reset","Reset"),children:e.jsx(r.NiceIcon,{name:"refresh",size:16})}),M&&e.jsx("button",{type:"button",className:"nice-image-editor__btn nice-image-editor__btn--save",onClick:te,children:B("imageEditor.save","Save")}),P&&e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:P,children:B("imageEditor.cancel","Cancel")})]}):void 0,xe=g?e.jsxs("div",{className:"nice-image-editor__footer",children:[e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>d(K=>Math.max(.1,K-.1)),title:B("imageEditor.zoomOut","Zoom out"),"aria-label":B("imageEditor.zoomOut","Zoom out"),children:e.jsx(r.NiceIcon,{name:"minus",size:16})}),e.jsxs("span",{style:{fontSize:"0.85em",minWidth:40,textAlign:"center"},children:[Math.round(w*100),"%"]}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>d(K=>Math.min(5,K+.1)),title:B("imageEditor.zoomIn","Zoom in"),"aria-label":B("imageEditor.zoomIn","Zoom in"),children:e.jsx(r.NiceIcon,{name:"plus",size:16})}),e.jsx("button",{type:"button",className:"nice-image-editor__btn",onClick:()=>d(1),title:B("imageEditor.resetZoom","Reset zoom"),children:"1:1"}),e.jsx("span",{style:{flex:1}}),e.jsx("span",{style:{fontSize:"0.8em",color:"var(--nice-text-secondary, #666)"},children:B("imageEditor.px","{w}×{h}px · {rotation}°").replace("{w}",String(p.w)).replace("{h}",String(p.h)).replace("{rotation}",String(_.rotation))})]}):void 0;return e.jsxs(Qe.NiceAppShell,{ref:le,flush:!0,id:G,className:`nice-image-editor nice-image-editor--${i} nice-editor--${a} ${$??""}`,style:{...Y,width:J,height:X},toolbar:se,statusBar:xe,children:[s,e.jsxs("div",{className:"nice-image-editor__canvas-wrap",style:{position:"relative"},role:"application","aria-label":B("imageEditor.label","Image Editor"),...ne,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(O,Yi)})}),e.jsx("canvas",{ref:T,className:"nice-image-editor__canvas",onMouseDown:he,onMouseMove:oe,onMouseUp:ve,style:{cursor:N==="crop"||N==="annotate"?"crosshair":"default",transform:`scale(${w})`,transformOrigin:"center center"}})]})]})}),{displayName:"NiceImageEditor"}),Gi={strokeColor:"#ff3333",fillColor:"transparent",strokeWidth:2,opacity:1,fontSize:16,fontFamily:"sans-serif"};function Vi(t,i){switch(i.type){case"SET_TOOL":return{...t,activeTool:i.tool,selectedId:null};case"SET_STYLE":return{...t,style:{...t.style,...i.style}};case"ADD_ANNOTATION":return{...t,annotations:[...t.annotations,i.annotation],past:[...t.past,t.annotations],future:[]};case"UPDATE_ANNOTATION":return{...t,annotations:t.annotations.map(a=>a.id===i.id?{...a,...i.updates}:a),past:[...t.past,t.annotations],future:[]};case"DELETE_ANNOTATION":return{...t,annotations:t.annotations.filter(a=>a.id!==i.id),selectedId:t.selectedId===i.id?null:t.selectedId,past:[...t.past,t.annotations],future:[]};case"SELECT":return{...t,selectedId:i.id};case"SET_ANNOTATIONS":return{...t,annotations:i.annotations,past:[],future:[]};case"SET_ZOOM":return{...t,zoom:i.zoom};case"SET_PAN":return{...t,panX:i.panX,panY:i.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 Wi=0;function Ji(){return`ann-${Date.now()}-${Wi++}`}function Zi(t){const{style:i}=t,a=`stroke="${i.strokeColor}" stroke-width="${i.strokeWidth}" fill="${i.fillColor}" opacity="${i.opacity}"`;switch(t.tool){case"rectangle":return`<rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" ${a} />`;case"ellipse":{const o=t.x+t.width/2,l=t.y+t.height/2;return`<ellipse cx="${o}" cy="${l}" rx="${t.width/2}" ry="${t.height/2}" ${a} />`}case"arrow":{const o=t,l=Math.atan2(o.endY-o.y,o.endX-o.x),g=12,y=o.endX-g*Math.cos(l-Math.PI/6),M=o.endY-g*Math.sin(l-Math.PI/6),P=o.endX-g*Math.cos(l+Math.PI/6),I=o.endY-g*Math.sin(l+Math.PI/6);return`<line x1="${o.x}" y1="${o.y}" x2="${o.endX}" y2="${o.endY}" ${a} />
302
- <polygon points="${o.endX},${o.endY} ${y},${M} ${P},${I}" fill="${i.strokeColor}" opacity="${i.opacity}" />`}case"line":{const o=t;return`<line x1="${o.x}" y1="${o.y}" x2="${o.endX}" y2="${o.endY}" ${a} />`}case"text":{const o=t;return`<text x="${o.x}" y="${o.y+(o.style.fontSize??16)}" fill="${i.strokeColor}" font-size="${i.fontSize}" font-family="${i.fontFamily}" opacity="${i.opacity}">${Qi(o.text)}</text>`}case"freehand":{const o=t;return o.points.length<2?"":`<path d="${o.points.map((g,y)=>`${y===0?"M":"L"}${g.x},${g.y}`).join(" ")}" ${a} fill="none" />`}case"blur":{const o=t,l=`blur-${o.id}`;return`<defs><filter id="${l}"><feGaussianBlur stdDeviation="${o.intensity??5}" /></filter></defs>
303
- <rect x="${o.x}" y="${o.y}" width="${o.width}" height="${o.height}" fill="transparent" stroke="none" filter="url(#${l})" />`}default:return""}}function Qi(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}const eo=Object.assign(n.forwardRef(({src:t,alt:i,annotations:a,activeTool:o,defaultStyle:l,onAnnotationsChange:g,className:y,readOnly:M=!1,minZoom:P=.1,maxZoom:I=5},J)=>{const{t:X}=r.useNiceTranslation(),O=i??X("imageAnnotator.annotatableImage","Annotatable image"),$=n.useRef(null),Y=n.useRef(null),ae=n.useRef(null),[ne,le]=n.useState(!1),[G,B]=n.useState({width:0,height:0}),[k,s]=n.useReducer(Vi,{annotations:a??[],selectedId:null,activeTool:o??"select",style:{...Gi,...l},zoom:1,panX:0,panY:0,past:[],future:[]});n.useEffect(()=>{o&&s({type:"SET_TOOL",tool:o})},[o]),n.useEffect(()=>{g?.(k.annotations)},[k.annotations,g]),n.useEffect(()=>{const w=new Image;w.crossOrigin="anonymous",w.onload=()=>{ae.current=w,B({width:w.naturalWidth,height:w.naturalHeight}),le(!0)},w.src=t},[t]);const T=n.useRef({isDrawing:!1,startX:0,startY:0,currentAnnotation:null,freehandPoints:[]}),F=n.useCallback((w,d)=>{const z=$.current;if(!z)return{x:0,y:0};const j=z.getBoundingClientRect();return{x:(w-j.left-k.panX)/k.zoom,y:(d-j.top-k.panY)/k.zoom}},[k.zoom,k.panX,k.panY]),R=n.useCallback(()=>{const w=$.current,d=w?.getContext("2d"),z=ae.current;if(!w||!d||!z||!ne)return;w.width=Y.current?.clientWidth??z.naturalWidth,w.height=Y.current?.clientHeight??z.naturalHeight,d.clearRect(0,0,w.width,w.height),d.save(),d.translate(k.panX,k.panY),d.scale(k.zoom,k.zoom),d.drawImage(z,0,0);for(const h of k.annotations){switch(d.save(),d.globalAlpha=h.style.opacity,d.strokeStyle=h.style.strokeColor,d.fillStyle=h.style.fillColor,d.lineWidth=h.style.strokeWidth,h.tool){case"rectangle":d.strokeRect(h.x,h.y,h.width,h.height),h.style.fillColor!=="transparent"&&d.fillRect(h.x,h.y,h.width,h.height);break;case"ellipse":{d.beginPath(),d.ellipse(h.x+h.width/2,h.y+h.height/2,Math.abs(h.width/2),Math.abs(h.height/2),0,0,Math.PI*2),d.stroke(),h.style.fillColor!=="transparent"&&d.fill();break}case"arrow":{const c=h;d.beginPath(),d.moveTo(c.x,c.y),d.lineTo(c.endX,c.endY),d.stroke();const p=Math.atan2(c.endY-c.y,c.endX-c.x),C=12;d.beginPath(),d.moveTo(c.endX,c.endY),d.lineTo(c.endX-C*Math.cos(p-Math.PI/6),c.endY-C*Math.sin(p-Math.PI/6)),d.lineTo(c.endX-C*Math.cos(p+Math.PI/6),c.endY-C*Math.sin(p+Math.PI/6)),d.closePath(),d.fillStyle=h.style.strokeColor,d.fill();break}case"line":{const c=h;d.beginPath(),d.moveTo(c.x,c.y),d.lineTo(c.endX,c.endY),d.stroke();break}case"text":{const c=h;d.font=`${c.style.fontSize??16}px ${c.style.fontFamily??"sans-serif"}`,d.fillStyle=c.style.strokeColor,d.fillText(c.text,c.x,c.y+(c.style.fontSize??16));break}case"freehand":{const c=h;if(c.points.length<2)break;d.beginPath(),d.moveTo(c.points[0].x,c.points[0].y);for(let p=1;p<c.points.length;p++)d.lineTo(c.points[p].x,c.points[p].y);d.stroke();break}case"blur":{const c=h;d.filter=`blur(${c.intensity??5}px)`,d.drawImage(z,c.x,c.y,c.width,c.height,c.x,c.y,c.width,c.height),d.filter="none";break}}h.id===k.selectedId&&(d.strokeStyle=r.resolveCssColor("var(--nice-color-primary, #4488ff)",d.canvas),d.lineWidth=1,d.setLineDash([4,4]),d.strokeRect(h.x-2,h.y-2,h.width+4,h.height+4),d.setLineDash([])),d.restore()}const j=T.current;if(j.isDrawing&&j.currentAnnotation){d.save();const h=j.currentAnnotation;if(d.globalAlpha=h.style.opacity,d.strokeStyle=h.style.strokeColor,d.lineWidth=h.style.strokeWidth,d.setLineDash([6,3]),h.tool==="freehand"){const c=h;if(c.points.length>=2){d.beginPath(),d.moveTo(c.points[0].x,c.points[0].y);for(let p=1;p<c.points.length;p++)d.lineTo(c.points[p].x,c.points[p].y);d.stroke()}}else if(h.tool==="rectangle")d.strokeRect(h.x,h.y,h.width,h.height);else if(h.tool==="ellipse")d.beginPath(),d.ellipse(h.x+h.width/2,h.y+h.height/2,Math.abs(h.width/2),Math.abs(h.height/2),0,0,Math.PI*2),d.stroke();else if(h.tool==="arrow"||h.tool==="line"){const c=h;d.beginPath(),d.moveTo(c.x,c.y),d.lineTo(c.endX,c.endY),d.stroke()}d.restore()}d.restore()},[k,ne]);n.useEffect(()=>{R()},[R]);const _=n.useCallback(w=>{if(M)return;const d=F(w.clientX,w.clientY),z=k.activeTool;if(z==="select"){const c=[...k.annotations].reverse().find(p=>p.tool==="freehand"?!1:d.x>=p.x&&d.x<=p.x+p.width&&d.y>=p.y&&d.y<=p.y+p.height);s({type:"SELECT",id:c?.id??null});return}const j=T.current;j.isDrawing=!0,j.startX=d.x,j.startY=d.y;const h={id:Ji(),style:{...k.style},x:d.x,y:d.y,width:0,height:0};switch(z){case"rectangle":j.currentAnnotation={...h,tool:"rectangle"};break;case"ellipse":j.currentAnnotation={...h,tool:"ellipse"};break;case"arrow":j.currentAnnotation={...h,tool:"arrow",endX:d.x,endY:d.y};break;case"line":j.currentAnnotation={...h,tool:"line",endX:d.x,endY:d.y};break;case"text":j.currentAnnotation={...h,tool:"text",text:X("imageAnnotator.text","Text"),width:100,height:k.style.fontSize??16};break;case"freehand":j.freehandPoints=[d],j.currentAnnotation={...h,tool:"freehand",points:[d]};break;case"blur":j.currentAnnotation={...h,tool:"blur",intensity:5};break}},[M,F,k.activeTool,k.style,k.annotations,X]),b=n.useCallback(w=>{const d=T.current;if(!d.isDrawing||!d.currentAnnotation)return;const z=F(w.clientX,w.clientY),j=d.currentAnnotation;if(j.tool==="freehand"){d.freehandPoints.push(z),j.points=[...d.freehandPoints];const h=d.freehandPoints.map(p=>p.x),c=d.freehandPoints.map(p=>p.y);j.x=Math.min(...h),j.y=Math.min(...c),j.width=Math.max(...h)-j.x,j.height=Math.max(...c)-j.y}else if(j.tool==="arrow"||j.tool==="line")j.endX=z.x,j.endY=z.y,j.width=Math.abs(z.x-d.startX),j.height=Math.abs(z.y-d.startY);else{const h=Math.min(d.startX,z.x),c=Math.min(d.startY,z.y);j.x=h,j.y=c,j.width=Math.abs(z.x-d.startX),j.height=Math.abs(z.y-d.startY)}R()},[F,R]),N=n.useCallback(()=>{const w=T.current;if(!w.isDrawing||!w.currentAnnotation)return;const d=w.currentAnnotation;(d.tool==="text"||d.tool==="freehand"||Math.abs(d.width)>2||Math.abs(d.height)>2)&&s({type:"ADD_ANNOTATION",annotation:d}),w.isDrawing=!1,w.currentAnnotation=null,w.freehandPoints=[]},[]),f=n.useCallback(w=>{w.preventDefault();const d=w.deltaY>0?.9:1.1,z=Math.max(P,Math.min(I,k.zoom*d));s({type:"SET_ZOOM",zoom:z})},[k.zoom,P,I]);n.useEffect(()=>{if(M)return;const w=d=>{(d.metaKey||d.ctrlKey)&&d.key==="z"&&!d.shiftKey?(d.preventDefault(),s({type:"UNDO"})):(d.metaKey||d.ctrlKey)&&(d.key==="y"||d.key==="z"&&d.shiftKey)?(d.preventDefault(),s({type:"REDO"})):(d.key==="Delete"||d.key==="Backspace")&&k.selectedId&&s({type:"DELETE_ANNOTATION",id:k.selectedId})};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[M,k.selectedId]),n.useImperativeHandle(J,()=>({exportAsDataURL:async(w="png",d=.92)=>{const z=document.createElement("canvas"),j=ae.current;if(!j)return"";z.width=j.naturalWidth,z.height=j.naturalHeight;const h=z.getContext("2d");h.drawImage(j,0,0);for(const c of k.annotations){if(h.save(),h.globalAlpha=c.style.opacity,h.strokeStyle=c.style.strokeColor,h.fillStyle=c.style.fillColor,h.lineWidth=c.style.strokeWidth,c.tool==="rectangle")h.strokeRect(c.x,c.y,c.width,c.height);else if(c.tool==="ellipse")h.beginPath(),h.ellipse(c.x+c.width/2,c.y+c.height/2,Math.abs(c.width/2),Math.abs(c.height/2),0,0,Math.PI*2),h.stroke();else if(c.tool==="freehand"){const p=c;if(p.points.length>=2){h.beginPath(),h.moveTo(p.points[0].x,p.points[0].y);for(let C=1;C<p.points.length;C++)h.lineTo(p.points[C].x,p.points[C].y);h.stroke()}}else if(c.tool==="text"){const p=c;h.font=`${p.style.fontSize??16}px ${p.style.fontFamily??"sans-serif"}`,h.fillStyle=p.style.strokeColor,h.fillText(p.text,p.x,p.y+(p.style.fontSize??16))}h.restore()}return z.toDataURL(`image/${w}`,d)},exportAnnotations:()=>[...k.annotations],importAnnotations:w=>{s({type:"SET_ANNOTATIONS",annotations:w})},exportAsSVG:()=>{const{width:w,height:d}=G,z=k.annotations.map(Zi);return`<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${d}" viewBox="0 0 ${w} ${d}">
304
- ${z.join(`
305
- `)}
306
- </svg>`},undo:()=>s({type:"UNDO"}),redo:()=>s({type:"REDO"}),setZoom:w=>{s({type:"SET_ZOOM",zoom:Math.max(P,Math.min(I,w))})},fitToScreen:()=>{const w=Y.current,d=ae.current;if(!w||!d)return;const z=w.clientWidth/d.naturalWidth,j=w.clientHeight/d.naturalHeight,h=Math.min(z,j,1);s({type:"SET_ZOOM",zoom:h}),s({type:"SET_PAN",panX:0,panY:0})},clear:()=>s({type:"CLEAR"})}),[k.annotations,G,P,I]);const E=n.useCallback(w=>{if(w.touches.length!==1)return;const d=w.touches[0];_({clientX:d.clientX,clientY:d.clientY,preventDefault:()=>{}})},[_]),L=n.useCallback(w=>{if(w.touches.length!==1)return;const d=w.touches[0];b({clientX:d.clientX,clientY:d.clientY})},[b]);return e.jsx("div",{ref:Y,className:`nice-image-annotator ${y??""}`,children:e.jsx("canvas",{ref:$,className:"nice-image-annotator__canvas",style:{cursor:k.activeTool==="select"?"default":"crosshair"},onMouseDown:_,onMouseMove:b,onMouseUp:N,onMouseLeave:N,onWheel:f,onTouchStart:E,onTouchMove:L,onTouchEnd:N,role:"img","aria-label":O})})}),{displayName:"NiceImageAnnotator"}),to=[{target:".nice-crop-editor",titleKey:"tutorial.cropEditor.intro.title",title:"Crop editor",contentKey:"tutorial.cropEditor.intro.content",content:"Drag the crop box over the image, pick an aspect ratio, rotate, flip or zoom, then use the result.",placement:"auto"}],vn=[{label:"Free",value:"free"},{label:"1:1",value:"1:1",ratio:1},{label:"4:3",value:"4:3",ratio:4/3},{label:"3:4",value:"3:4",ratio:3/4},{label:"16:9",value:"16:9",ratio:16/9},{label:"9:16",value:"9:16",ratio:9/16},{label:"3:2",value:"3:2",ratio:3/2},{label:"2:3",value:"2:3",ratio:2/3}],_n=({src:t,initialCrop:i={x:10,y:10,width:80,height:80},initialRotation:a=0,initialZoom:o=1,aspectRatios:l=vn,defaultAspectRatio:g="free",customAspectRatio:y,showRotation:M=!0,showFlip:P=!0,showZoom:I=!0,minZoom:J=.5,maxZoom:X=3,zoomStep:O=.1,showGrid:$=!0,overlayColor:Y="var(--nice-overlay-50, rgba(0, 0, 0, 0.5))",toolbarPosition:ae="bottom",toolbarCollapsible:ne=!1,defaultToolbarCollapsed:le=!1,onChange:G,tutorial:B,className:k="",style:s,"data-testid":T="nice-crop-editor"})=>{const{t:F}=r.useNiceTranslation(),R=n.useRef(null),_=n.useRef(null),[b,N]=n.useState(i),[f,E]=n.useState(a),[L,w]=n.useState(o),[d,z]=n.useState(!1),[j,h]=n.useState(!1),[c,p]=n.useState(g),[C,S]=n.useState(le),[m,A]=n.useState(!1),[D,W]=n.useState({x:0,y:0,crop:b}),v=c==="custom"?y:l.find(te=>te.value===c)?.ratio;n.useEffect(()=>{G?.({crop:b,rotation:f,flipH:d,flipV:j,zoom:L})},[b,f,d,j,L,G]);const q=n.useCallback((te,ke)=>{if(!v)return te;const se=R.current?.clientWidth??400,xe=R.current?.clientHeight??300,K=te.width/100*se,U=te.height/100*xe,Z=K/U;if(Math.abs(Z-v)<.01)return te;if(ke?.includes("e")||ke?.includes("w")){const ee=K/v/xe*100;return{...te,height:Math.min(100-te.y,Math.max(5,ee))}}else if(ke?.includes("n")||ke?.includes("s")){const ee=U*v/se*100;return{...te,width:Math.min(100-te.x,Math.max(5,ee))}}else{const ee=K/v/xe*100;return{...te,height:Math.min(100-te.y,Math.max(5,ee))}}},[v]),H=n.useCallback((te,ke)=>{ke===!1||(te.preventDefault(),te.stopPropagation(),A(ke),!R.current?.getBoundingClientRect())||W({x:te.clientX,y:te.clientY,crop:{...b}})},[b]),me=n.useCallback(te=>{if(!m||!R.current)return;const ke=R.current.getBoundingClientRect(),se=(te.clientX-D.x)/ke.width*100,xe=(te.clientY-D.y)/ke.height*100;let K={...D.crop};if(m==="crop")K.x=Math.max(0,Math.min(100-K.width,D.crop.x+se)),K.y=Math.max(0,Math.min(100-K.height,D.crop.y+xe));else{switch(m){case"resize-nw":K.x=Math.max(0,Math.min(D.crop.x+D.crop.width-5,D.crop.x+se)),K.y=Math.max(0,Math.min(D.crop.y+D.crop.height-5,D.crop.y+xe)),K.width=D.crop.width-(K.x-D.crop.x),K.height=D.crop.height-(K.y-D.crop.y);break;case"resize-ne":K.y=Math.max(0,Math.min(D.crop.y+D.crop.height-5,D.crop.y+xe)),K.width=Math.max(5,Math.min(100-K.x,D.crop.width+se)),K.height=D.crop.height-(K.y-D.crop.y);break;case"resize-sw":K.x=Math.max(0,Math.min(D.crop.x+D.crop.width-5,D.crop.x+se)),K.width=D.crop.width-(K.x-D.crop.x),K.height=Math.max(5,Math.min(100-K.y,D.crop.height+xe));break;case"resize-se":K.width=Math.max(5,Math.min(100-K.x,D.crop.width+se)),K.height=Math.max(5,Math.min(100-K.y,D.crop.height+xe));break;case"resize-n":K.y=Math.max(0,Math.min(D.crop.y+D.crop.height-5,D.crop.y+xe)),K.height=D.crop.height-(K.y-D.crop.y);break;case"resize-s":K.height=Math.max(5,Math.min(100-K.y,D.crop.height+xe));break;case"resize-e":K.width=Math.max(5,Math.min(100-K.x,D.crop.width+se));break;case"resize-w":K.x=Math.max(0,Math.min(D.crop.x+D.crop.width-5,D.crop.x+se)),K.width=D.crop.width-(K.x-D.crop.x);break}K=q(K,m.replace("resize-",""))}N(K)},[m,D,q]),pe=n.useCallback(()=>{A(!1)},[]);n.useEffect(()=>{if(m)return document.addEventListener("mousemove",me),document.addEventListener("mouseup",pe),()=>{document.removeEventListener("mousemove",me),document.removeEventListener("mouseup",pe)}},[m,me,pe]);const je=n.useCallback(()=>{E(te=>(te-90+360)%360)},[]),ge=n.useCallback(()=>{E(te=>(te+90)%360)},[]),ue=n.useCallback(()=>{z(te=>!te)},[]),de=n.useCallback(()=>{h(te=>!te)},[]),he=n.useCallback(()=>{N(i),E(a),w(o),z(!1),h(!1),p(g)},[i,a,o,g]);n.useEffect(()=>{N(te=>q(te))},[c,q]);const oe=`translate(-50%, -50%) scale(${L}) rotate(${f}deg) scaleX(${d?-1:1}) scaleY(${j?-1:1})`,ve=ae==="top"?"column-reverse":ae==="left"?"row-reverse":ae==="right"?"row":"column",_e=ae==="left"||ae==="right";return e.jsxs("div",{className:`nice-crop-editor nice-crop-editor--toolbar-${ae} ${k}`,style:{position:"relative",display:"flex",flexDirection:ve,gap:12,...s},"data-testid":T,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(B,to)})}),e.jsxs("div",{ref:R,className:"nice-crop-editor__container","data-testid":`${T}-container`,children:[e.jsx("img",{ref:_,src:t||void 0,alt:"",className:"nice-crop-editor__image",style:{transform:oe},draggable:!1}),e.jsxs("div",{className:"nice-crop-editor__overlay",style:{backgroundColor:Y},children:[e.jsx("div",{className:"nice-crop-editor__overlay-piece",style:{top:0,left:0,right:0,height:`${b.y}%`}}),e.jsx("div",{className:"nice-crop-editor__overlay-piece",style:{bottom:0,left:0,right:0,height:`${100-b.y-b.height}%`}}),e.jsx("div",{className:"nice-crop-editor__overlay-piece",style:{top:`${b.y}%`,left:0,width:`${b.x}%`,height:`${b.height}%`}}),e.jsx("div",{className:"nice-crop-editor__overlay-piece",style:{top:`${b.y}%`,right:0,width:`${100-b.x-b.width}%`,height:`${b.height}%`}})]}),e.jsxs("div",{className:"nice-crop-editor__crop-area",style:{left:`${b.x}%`,top:`${b.y}%`,width:`${b.width}%`,height:`${b.height}%`},onMouseDown:te=>H(te,"crop"),"data-testid":`${T}-crop-area`,children:[$&&e.jsxs("div",{className:"nice-crop-editor__grid",children:[e.jsx("div",{className:"nice-crop-editor__grid-line nice-crop-editor__grid-line--h1"}),e.jsx("div",{className:"nice-crop-editor__grid-line nice-crop-editor__grid-line--h2"}),e.jsx("div",{className:"nice-crop-editor__grid-line nice-crop-editor__grid-line--v1"}),e.jsx("div",{className:"nice-crop-editor__grid-line nice-crop-editor__grid-line--v2"})]}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--nw",onMouseDown:te=>H(te,"resize-nw")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--ne",onMouseDown:te=>H(te,"resize-ne")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--sw",onMouseDown:te=>H(te,"resize-sw")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--se",onMouseDown:te=>H(te,"resize-se")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--n",onMouseDown:te=>H(te,"resize-n")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--s",onMouseDown:te=>H(te,"resize-s")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--e",onMouseDown:te=>H(te,"resize-e")}),e.jsx("div",{className:"nice-crop-editor__handle nice-crop-editor__handle--w",onMouseDown:te=>H(te,"resize-w")})]})]}),e.jsxs("div",{className:`nice-crop-editor__controls ${C?"nice-crop-editor__controls--collapsed":""}`,style:{display:"flex",flexDirection:_e?"column":"row",flexWrap:_e?"nowrap":"wrap",gap:8,alignItems:_e?"stretch":"center",flexShrink:0},children:[ne&&e.jsx("button",{type:"button",className:"nice-crop-editor__toolbar-toggle","aria-expanded":!C,"aria-label":C?F("cropEditor.showToolbar","Show toolbar"):F("cropEditor.hideToolbar","Hide toolbar"),onClick:()=>S(te=>!te),style:{alignSelf:"flex-start",background:"var(--nice-bg-secondary)",border:"1px solid var(--nice-border-color)",borderRadius:4,padding:"2px 8px",cursor:"pointer",color:"var(--nice-text-primary)",fontSize:12},children:e.jsx(r.NiceIcon,{name:C?"chevron-right":"chevron-down",size:14})}),!C&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-crop-editor__control-group",children:[e.jsx("label",{className:"nice-crop-editor__label",children:F("aspectRatio","Aspect Ratio")}),e.jsx("div",{className:"nice-crop-editor__aspect-buttons",children:l.map(te=>e.jsx("button",{type:"button",className:`nice-crop-editor__aspect-btn ${c===te.value?"nice-crop-editor__aspect-btn--selected":""}`,onClick:()=>p(te.value),title:te.label,children:te.label},te.value))})]}),I&&e.jsxs("div",{className:"nice-crop-editor__control-group",children:[e.jsxs("label",{className:"nice-crop-editor__label",children:[F("zoom","Zoom"),": ",Math.round(L*100),"%"]}),e.jsx("input",{type:"range",className:"nice-crop-editor__slider",min:J,max:X,step:O,value:L,onChange:te=>w(parseFloat(te.target.value)),"data-testid":`${T}-zoom`})]}),e.jsxs("div",{className:"nice-crop-editor__control-group nice-crop-editor__control-group--row",children:[M&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-crop-editor__btn",onClick:je,title:F("rotateLeft","Rotate Left"),"aria-label":F("rotateLeft","Rotate Left"),children:e.jsx(r.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{type:"button",className:"nice-crop-editor__btn",onClick:ge,title:F("rotateRight","Rotate Right"),"aria-label":F("rotateRight","Rotate Right"),children:e.jsx(r.NiceIcon,{name:"forward",size:16})})]}),P&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:`nice-crop-editor__btn ${d?"nice-crop-editor__btn--active":""}`,onClick:ue,title:F("flipHorizontal","Flip Horizontal"),"aria-label":F("flipHorizontal","Flip Horizontal"),children:e.jsx(r.NiceIcon,{name:"shuffle",size:16})}),e.jsx("button",{type:"button",className:`nice-crop-editor__btn ${j?"nice-crop-editor__btn--active":""}`,onClick:de,title:F("flipVertical","Flip Vertical"),"aria-label":F("flipVertical","Flip Vertical"),children:e.jsx(r.NiceIcon,{name:"shuffle",size:16})})]}),e.jsx("button",{type:"button",className:"nice-crop-editor__btn nice-crop-editor__btn--reset",onClick:he,title:F("reset","Reset"),"aria-label":F("reset","Reset"),children:e.jsx(r.NiceIcon,{name:"refresh",size:16})})]})]})]})]})};process.env.NODE_ENV!=="production"&&(_n.displayName="NiceCropEditor");const no=[{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"}],io=["highlight","underline","strikethrough","freehand","text","rect","arrow"],oo={highlight:"edit",underline:"type",strikethrough:"type",freehand:"edit",text:"type",rect:"box",arrow:"arrow-right",stamp:"tag"},ao=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,required:o,disabled:l,readOnly:g,size:y="md",id:M,className:P,style:I,accessMode:J,src:X,annotations:O=[],onAnnotationsChange:$,activeTool:Y,onToolChange:ae,currentPage:ne=1,onPageChange:le,totalPages:G=1,defaultColor:B="var(--nice-warning, #ffff00)",tools:k=io,author:s,zoom:T=1,onZoomChange:F,onAnnotationClick:R,onAnnotationDelete:_,tutorial:b},N)=>{const f=r.useNiceAccessMode(J,M),E=f==="hidden";f==="disabled"&&(l=!0),f==="readOnly"&&(g=!0);const{t:L}=r.useNiceTranslation(),w=r.useControlId(M),d=O.filter(m=>m.page===ne),z=n.useCallback(m=>{ae?.(Y===m?null:m)},[Y,ae]),j=n.useCallback(m=>{if(g||!Y||Y==="freehand")return;const A=m.currentTarget.getBoundingClientRect(),D=(m.clientX-A.left)/A.width,W=(m.clientY-A.top)/A.height,v={id:`ann-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,tool:Y,page:ne,x:D,y:W,color:B,author:s,createdAt:new Date().toISOString(),text:Y==="text"?"":void 0};$?.([...O,v])},[g,Y,ne,B,s,O,$]);if(E)return null;const h=t?e.jsxs("div",{className:"nice-pdf-annotation__label",children:[t,o&&e.jsx("span",{className:"nice-required",children:"*"})]}):void 0,c=g?void 0:e.jsxs("div",{className:"nice-pdf-annotation__toolbar",children:[k.map(m=>e.jsx("button",{type:"button",className:`nice-pdf-annotation__tool-btn${Y===m?" nice-pdf-annotation__tool-btn--active":""}`,onClick:()=>z(m),disabled:l,title:L(`pdfTool_${m}`,m),children:e.jsx(r.NiceIcon,{name:oo[m],size:16})},m)),e.jsx("span",{className:"nice-pdf-annotation__toolbar-sep"}),e.jsx("button",{type:"button",disabled:l,onClick:()=>F?.(Math.max(.25,T-.25)),title:L("zoomOut","Zoom out"),"aria-label":L("zoomOut","Zoom out"),children:e.jsx(r.NiceIcon,{name:"minus",size:16})}),e.jsxs("span",{className:"nice-pdf-annotation__zoom",children:[Math.round(T*100),"%"]}),e.jsx("button",{type:"button",disabled:l,onClick:()=>F?.(Math.min(4,T+.25)),title:L("zoomIn","Zoom in"),"aria-label":L("zoomIn","Zoom in"),children:e.jsx(r.NiceIcon,{name:"plus",size:16})})]}),p=e.jsxs("div",{className:"nice-pdf-annotation__pager",children:[e.jsx("button",{type:"button",disabled:l||ne<=1,onClick:()=>le?.(ne-1),"aria-label":L("prevPage","Previous page"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:16})}),e.jsx("span",{children:L("pageOf","{page} / {total}").replace("{page}",String(ne)).replace("{total}",String(G))}),e.jsx("button",{type:"button",disabled:l||ne>=G,onClick:()=>le?.(ne+1),"aria-label":L("nextPage","Next page"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:16})})]}),S=!!i||!!a&&typeof a=="string"?e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]}):void 0;return e.jsx(Qe.NiceAppShell,{ref:N,flush:!0,id:w,className:`nice-pdf-annotation nice-size-${y}${P?` ${P}`:""}${a?" nice-error":""}${l?" nice-disabled":""}`,style:I,menubar:h,toolbar:c,bottomPanel:p,statusBar:S,children:e.jsxs("div",{style:{position:"relative",height:"100%",overflow:"auto"},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(b,no)})}),e.jsxs("div",{className:"nice-pdf-annotation__viewport",style:{transform:`scale(${T})`,transformOrigin:"top left"},children:[e.jsx("iframe",{src:X||void 0,className:"nice-pdf-annotation__frame",title:L("pdfViewer","PDF Viewer")}),e.jsx("div",{role:"presentation",className:"nice-pdf-annotation__layer",onClick:j,children:d.map(m=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:r.clickOnActivationKey,className:`nice-pdf-annotation__mark nice-pdf-annotation__mark--${m.tool}`,style:{left:`${m.x*100}%`,top:`${m.y*100}%`,backgroundColor:m.color},onClick:A=>{A.stopPropagation(),R?.(m)},title:m.text??m.tool,children:[m.text&&e.jsx("span",{children:m.text}),!g&&e.jsx("button",{type:"button",className:"nice-pdf-annotation__mark-delete",onClick:A=>{A.stopPropagation(),_?.(m.id)},"aria-label":L("delete","Delete"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},m.id))})]})]})})}),{displayName:"NicePDFAnnotationEditor"});function tn(t,i){const a=i.getBoundingClientRect();let o,l,g;if("touches"in t){const y=t.touches[0];o=y.clientX-a.left,l=y.clientY-a.top,g=y.force}else"pressure"in t?(o=t.clientX-a.left,l=t.clientY-a.top,g=t.pressure):(o=t.clientX-a.left,l=t.clientY-a.top);return{x:o,y:l,time:Date.now(),pressure:g!==void 0?g:.5}}function nn(t,i,a,o,l){if(!i)return(a+o)/2;const g=Math.sqrt(Math.pow(t.x-i.x,2)+Math.pow(t.y-i.y,2))/Math.max(1,t.time-i.time),y=Math.min(g/5,1),M=o-y*(o-a),P=t.pressure??.5,I=a+P*(o-a);return M*.7+I*.3}function on(t,i,a,o){t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(a.x,a.y),t.lineWidth=o,t.lineCap="round",t.lineJoin="round",t.stroke()}const so=n.forwardRef(function(i,a){kt.injectStyleOnce(ro,co);const{value:o,onChange:l,onChangeDataUrl:g,label:y,width:M="100%",height:P=200,penColor:I="",penWidth:J=2,minWidth:X=.5,maxWidth:O=4,backgroundColor:$="",placeholder:Y,showClearButton:ae=!0,showUndoButton:ne=!0,showColorPicker:le=!1,showSizeSlider:G=!1,velocityFilterWeight:B=.7,throttle:k=16,disabled:s=!1,readOnly:T=!1,displayMode:F=!1,onBegin:R,onEnd:_,className:b,"data-testid":N}=i,{t:f}=r.useNiceTranslation(),E=Y||f("signature.placeholder","Sign here"),L=T||F,w=F?!1:ae,d=F?!1:ne,z=F?!1:le,j=F?!1:G,h=n.useRef(null),[c,p]=n.useState(o?.strokes??[]),[C,S]=n.useState([]),[m,A]=n.useState(!1),[D,W]=n.useState(I),[v,q]=n.useState(J),H=n.useRef(null),me=n.useRef(0),pe=r.useThemeIsDark(h),je=$||(pe?"#0f172a":"#ffffff"),ge=I||(pe?"#f8fafc":"#111827"),ue=D||ge,de=c.length===0&&C.length===0;n.useEffect(()=>{const Z=h.current;if(!Z)return;const x=Z.getContext("2d");if(!x)return;const ee=Z.getBoundingClientRect(),ie=window.devicePixelRatio||1;Z.width=ee.width*ie,Z.height=ee.height*ie,x.scale(ie,ie),he()},[M,P]);const he=n.useCallback(()=>{const Z=h.current;if(!Z)return;const x=Z.getContext("2d");if(!x)return;const ee=Z.getBoundingClientRect();x.fillStyle=je,x.fillRect(0,0,ee.width,ee.height),c.forEach(ie=>{if(x.strokeStyle=ie.color||ge,!(ie.points.length<2))for(let ce=1;ce<ie.points.length;ce++){const be=ie.points[ce-1],fe=ie.points[ce],Se=nn(fe,be,X,O);on(x,be,fe,Se)}})},[c,je,ge,X,O,B]);n.useEffect(()=>{he()},[he]),n.useEffect(()=>{o?.strokes&&p(o.strokes)},[o]),n.useEffect(()=>{const Z=h.current;if(Z)if(c.length===0)l?.(null),g?.(null);else{const x=Z.getBoundingClientRect();l?.({strokes:c,width:x.width,height:x.height,timestamp:Date.now()}),g?.(Z.toDataURL("image/png"))}},[c,l,g]);const oe=n.useCallback(Z=>{if(s||L)return;const x=h.current;if(!x)return;x.setPointerCapture(Z.pointerId);const ee=tn(Z.nativeEvent,x);A(!0),S([ee]),H.current=ee,me.current=ee.time,R?.()},[s,L,R]),ve=n.useCallback(Z=>{if(!m||s||L)return;const x=h.current;if(!x)return;const ee=x.getContext("2d");if(!ee)return;const ie=Date.now();if(ie-me.current<k)return;const ce=tn(Z.nativeEvent,x),be=H.current;if(be){ee.strokeStyle=ue;const fe=nn(ce,be,X,O);on(ee,be,ce,fe)}S(fe=>[...fe,ce]),H.current=ce,me.current=ie},[m,s,L,ue,X,O,B,k]),_e=n.useCallback(Z=>{if(!m)return;const x=h.current;if(x&&x.releasePointerCapture(Z.pointerId),C.length>0){const ee={points:C,color:ue,width:v};p(ie=>[...ie,ee])}A(!1),S([]),H.current=null,_?.()},[m,C,ue,v,_]),te=n.useCallback(()=>{p([]),S([]),he()},[he]),ke=n.useCallback(()=>{p(Z=>Z.slice(0,-1))},[]),se=n.useCallback((Z="png",x=.92)=>{const ee=h.current;if(!ee)return"";const ie=Z==="jpeg"?"image/jpeg":"image/png";return ee.toDataURL(ie,x)},[]),xe=n.useCallback(async(Z="png",x=.92)=>{const ee=h.current;return ee?new Promise(ie=>{const ce=Z==="jpeg"?"image/jpeg":"image/png";ee.toBlob(be=>ie(be),ce,x)}):null},[]),K=n.useCallback(()=>{const Z=h.current;if(!Z)return"";const x=Z.getBoundingClientRect(),ee=c.map(ie=>ie.points.length<2?"":`<path d="${ie.points.reduce((be,fe,Se)=>Se===0?`M ${fe.x} ${fe.y}`:`${be} L ${fe.x} ${fe.y}`,"")}" stroke="${ie.color||ge}" stroke-width="${ie.width}" fill="none" stroke-linecap="round" stroke-linejoin="round"/>`).join(`
307
- `);return`<svg xmlns="http://www.w3.org/2000/svg" width="${x.width}" height="${x.height}" viewBox="0 0 ${Z.width} ${Z.height}">
308
- <rect width="100%" height="100%" fill="${je}"/>
309
- ${ee}
310
- </svg>`},[c,je,ge]);n.useImperativeHandle(a,()=>({clear:te,undo:ke,isEmpty:()=>c.length===0,getData:()=>{const Z=h.current;if(!Z||c.length===0)return null;const x=Z.getBoundingClientRect();return{strokes:c,width:x.width,height:x.height,timestamp:Date.now()}},setData:Z=>{p(Z.strokes)},toDataURL:se,toBlob:xe,toSVG:K,getCanvas:()=>h.current}),[c,te,ke,se,xe,K]),n.useEffect(()=>{const Z=h.current;if(!Z)return;const x=ee=>{m&&ee.preventDefault()};return Z.addEventListener("touchmove",x,{passive:!1}),()=>Z.removeEventListener("touchmove",x)},[m]);const U=w||d||z||j;return e.jsxs("div",{className:`nice-signature ${s?"nice-signature--disabled":""} ${L?"nice-signature--readonly":""} ${b??""}`,style:{width:M},"data-testid":N,children:[y&&e.jsx("label",{className:"nice-signature__label",children:y}),U&&e.jsxs("div",{className:"nice-signature__toolbar",children:[z&&e.jsx("div",{className:"nice-signature__color-picker",children:e.jsx("input",{type:"color",value:D,onChange:Z=>W(Z.target.value),disabled:s||L,title:f("signature.penColor","Pen color")})}),j&&e.jsx("div",{className:"nice-signature__size-slider",children:e.jsx("input",{type:"range",min:X,max:O,step:.5,value:v,onChange:Z=>q(parseFloat(Z.target.value)),disabled:s||L,title:f("signature.penSize","Pen size")})}),e.jsxs("div",{className:"nice-signature__actions",children:[d&&e.jsx("button",{type:"button",onClick:ke,disabled:s||L||c.length===0,className:"nice-signature__btn",title:f("signature.undo","Undo"),"aria-label":f("signature.undo","Undo"),children:e.jsx(r.NiceIcon,{name:"reply",size:16})}),w&&e.jsx("button",{type:"button",onClick:te,disabled:s||L||de,className:"nice-signature__btn",title:f("signature.clear","Clear"),"aria-label":f("signature.clear","Clear"),children:e.jsx(r.NiceIcon,{name:"trash",size:16})})]})]}),e.jsxs("div",{className:"nice-signature__canvas-wrapper",style:{height:P},children:[e.jsx("canvas",{ref:h,className:"nice-signature__canvas",style:{width:"100%",height:"100%",cursor:s||L?"not-allowed":"crosshair",touchAction:"none"},onPointerDown:oe,onPointerMove:ve,onPointerUp:_e,onPointerLeave:_e}),de&&!m&&E&&e.jsx("div",{className:"nice-signature__placeholder",children:E}),e.jsx("div",{className:"nice-signature__line"})]})]})}),ro="nice-signature-styles",co=`
311
- .nice-signature {
312
- display: flex;
313
- flex-direction: column;
314
- border: 1px solid var(--nice-border, #e0e0e0);
315
- border-radius: var(--nice-radius-sm, 4px);
316
- overflow: hidden;
317
- background: var(--nice-bg-surface, #fff);
318
- }
319
-
320
- .nice-signature--disabled {
321
- opacity: 0.6;
322
- }
323
-
324
- .nice-signature__toolbar {
325
- display: flex;
326
- align-items: center;
327
- gap: var(--nice-space-2, 8px);
328
- padding: var(--nice-space-2, 8px);
329
- background: var(--nice-bg-tertiary, #f5f5f5);
330
- border-bottom: 1px solid var(--nice-border, #e0e0e0);
331
- }
332
-
333
- .nice-signature__color-picker input {
334
- width: 32px;
335
- height: 32px;
336
- padding: var(--nice-space-0-5, 2px);
337
- border: 1px solid var(--nice-border, #e0e0e0);
338
- border-radius: var(--nice-radius-sm, 4px);
339
- cursor: pointer;
340
- }
341
-
342
- .nice-signature__size-slider {
343
- flex: 1;
344
- max-width: 120px;
345
- }
346
-
347
- .nice-signature__size-slider input {
348
- width: 100%;
349
- }
350
-
351
- .nice-signature__actions {
352
- display: flex;
353
- gap: var(--nice-space-1, 4px);
354
- margin-left: auto;
355
- }
356
-
357
- .nice-signature__btn {
358
- padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
359
- border: 1px solid var(--nice-border, #e0e0e0);
360
- border-radius: var(--nice-radius-sm, 4px);
361
- background: var(--nice-bg-surface, #fff);
362
- cursor: pointer;
363
- font-size: 14px;
364
- }
365
-
366
- .nice-signature__btn:hover:not(:disabled) {
367
- background: var(--nice-bg-hover, #f0f0f0);
368
- }
369
-
370
- .nice-signature__btn:disabled {
371
- opacity: 0.4;
372
- cursor: not-allowed;
373
- }
374
-
375
- .nice-signature__canvas-wrapper {
376
- position: relative;
377
- background: var(--nice-bg, #FFF);
378
- }
379
-
380
- .nice-signature__canvas {
381
- display: block;
382
- }
383
-
384
- .nice-signature__placeholder {
385
- position: absolute;
386
- top: 50%;
387
- left: 50%;
388
- transform: translate(-50%, -50%);
389
- color: var(--nice-text-secondary, #999);
390
- font-size: 14px;
391
- pointer-events: none;
392
- user-select: none;
393
- }
394
-
395
- .nice-signature__line {
396
- position: absolute;
397
- /* Sit in the lower third (a natural signature baseline) rather than pinned to
398
- the very bottom. */
399
- bottom: 64px;
400
- left: 20px;
401
- right: 20px;
402
- height: 1px;
403
- background: var(--nice-border, #ccc);
404
- pointer-events: none;
405
- }
406
-
407
- /* Display component */
408
- .nice-signature-display {
409
- border: 1px solid var(--nice-border, #e0e0e0);
410
- border-radius: var(--nice-radius-sm, 4px);
411
- overflow: hidden;
412
- }
413
-
414
- .nice-signature-display__canvas-wrapper {
415
- position: relative;
416
- background: var(--nice-bg, #FFF);
417
- }
418
-
419
- .nice-signature-display__canvas {
420
- display: block;
421
- }
422
-
423
- .nice-signature-display__placeholder {
424
- position: absolute;
425
- top: 50%;
426
- left: 50%;
427
- transform: translate(-50%, -50%);
428
- color: var(--nice-text-secondary, #999);
429
- font-size: 14px;
430
- }
431
- `,lo=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,required:o,disabled:l,readOnly:g,size:y="md",id:M,className:P,style:I,accessMode:J,mode:X="manual",onScan:O,onModeChange:$,beepOnScan:Y=!0,beepFrequency:ae=1800,beepDuration:ne=150,placeholder:le,scanHistory:G=[],showHistory:B=!0,maxHistory:k=10,autoFocus:s=!0,onCameraFrame:T},F)=>{const R=r.useNiceAccessMode(J,M),_=R==="hidden";R==="disabled"&&(l=!0),R==="readOnly"&&(g=!0);const{t:b}=r.useNiceTranslation(),N=r.useControlId(M),[f,E]=n.useState(""),L=n.useRef(null),w=n.useRef(null),d=n.useCallback(()=>{if(Y)try{w.current||(w.current=new AudioContext);const h=w.current,c=h.createOscillator(),p=h.createGain();c.connect(p),p.connect(h.destination),c.frequency.value=ae,c.type="square",p.gain.value=.3,c.start(),c.stop(h.currentTime+ne/1e3)}catch{}},[Y,ae,ne]),z=n.useCallback(()=>{f.trim()&&(d(),O?.({value:f.trim(),format:"manual",scannedAt:new Date}),E(""),L.current?.focus())},[f,O,d]),j=G.slice(0,k);return _?null:e.jsxs("div",{ref:F,id:N,className:`nice-scanner nice-size-${y}${P?` ${P}`:""}${a?" nice-error":""}${l?" nice-disabled":""}`,style:I,children:[t&&e.jsxs("div",{className:"nice-scanner__label",children:[t,o&&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${X==="camera"?" nice-scanner__mode-btn--active":""}`,onClick:()=>$?.("camera"),disabled:l,children:[e.jsx(r.NiceIcon,{name:"camera",size:16})," ",b("camera","Camera")]}),e.jsxs("button",{type:"button",className:`nice-scanner__mode-btn${X==="manual"?" nice-scanner__mode-btn--active":""}`,onClick:()=>$?.("manual"),disabled:l,children:[e.jsx(r.NiceIcon,{name:"edit",size:16})," ",b("manual","Manual")]})]}),X==="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(r.NiceIcon,{name:"camera",size:32})}),e.jsx("p",{children:b("cameraPlaceholder","Camera preview — connect scanner adapter")})]})})}),X==="manual"&&!g&&e.jsxs("div",{className:"nice-scanner__manual",children:[e.jsx("input",{ref:L,className:"nice-input nice-scanner__input",type:"text",value:f,onChange:h=>E(h.target.value),onKeyDown:h=>h.key==="Enter"&&z(),placeholder:le??b("enterCode","Enter or scan code…"),disabled:l,autoFocus:s}),e.jsx("button",{type:"button",className:"nice-scanner__submit",onClick:z,disabled:l||!f.trim(),"aria-label":b("submit","Submit"),children:e.jsx(r.NiceIcon,{name:"check",size:16})})]}),B&&j.length>0&&e.jsxs("div",{className:"nice-scanner__history",children:[e.jsx("div",{className:"nice-scanner__history-label",children:b("recentScans","Recent scans")}),j.map((h,c)=>e.jsxs("div",{className:"nice-scanner__history-item",children:[e.jsx("span",{className:"nice-scanner__history-value",children:h.value}),h.format&&e.jsx("span",{className:"nice-scanner__history-format",children:h.format}),e.jsx("span",{className:"nice-scanner__history-time",children:h.scannedAt.toLocaleTimeString()})]},c))]}),i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})}),{displayName:"NiceScannerControl"}),mo=[{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 uo=1;function po(t){return{id:`new-${uo++}`,description:"",quantity:1,unitPrice:0,vatRate:t,discount:0,unit:"pcs"}}function kn(t){const a=t.quantity*t.unitPrice*(1-(t.discount??0)/100),o=Math.round(a*100)/100,l=Math.round(o*(t.vatRate??0)/100*100)/100;return{...t,netAmount:o,grossAmount:o+l}}function ho(t){const i=t.map(kn),a=i.reduce((M,P)=>M+(P.netAmount??0),0),o=i.reduce((M,P)=>M+(P.grossAmount??0),0),l=o-a,g=new Map;for(const M of i){const P=M.vatRate??0,I=g.get(P)??{base:0,amount:0};I.base+=M.netAmount??0,I.amount+=(M.grossAmount??0)-(M.netAmount??0),g.set(P,I)}const y=Array.from(g.entries()).map(([M,P])=>({rate:M,base:Math.round(P.base*100)/100,amount:Math.round(P.amount*100)/100}));return{totalNet:Math.round(a*100)/100,totalVat:Math.round(l*100)/100,totalGross:Math.round(o*100)/100,vatBreakdown:y}}const go={pl:"PLN",cs:"CZK",sk:"EUR",hu:"HUF",ro:"RON",bg:"BGN",uk:"UAH",de:"EUR",fr:"EUR",es:"EUR",it:"EUR",nl:"EUR",pt:"EUR",fi:"EUR",sv:"SEK",no:"NOK",da:"DKK",ja:"JPY",zh:"CNY",ko:"KRW",hi:"INR",th:"THB",vi:"VND",id:"IDR",ms:"MYR",fil:"PHP",bn:"BDT",ar:"AED",sw:"KES"};function fo(t){const i=go[t];if(!i)return"$";try{return new Intl.NumberFormat(t,{style:"currency",currency:i,minimumFractionDigits:0,maximumFractionDigits:0}).formatToParts(0).find(o=>o.type==="currency")?.value??"$"}catch{return"$"}}const yo=["pcs","h","kg","m","svc"],xo=Object.assign(n.forwardRef(({label:t,helperText:i,error:a,required:o,disabled:l,readOnly:g,size:y="md",name:M,id:P,className:I,style:J,accessMode:X,value:O=[],onChange:$,onTotalsChange:Y,currencySymbol:ae,defaultVatRate:ne=23,vatRates:le=[0,5,8,23],units:G,showDiscount:B=!0,showUnit:k=!0,showTotals:s=!0,editable:T=!0,maxLines:F,tutorial:R},_)=>{const b=r.useNiceAccessMode(X,P),N=b==="hidden";b==="disabled"&&(l=!0),b==="readOnly"&&(g=!0);const{t:f,lang:E}=r.useNiceTranslation(),L=r.useControlId(P),w=n.useMemo(()=>ae??fo(E),[ae,E]),d=n.useMemo(()=>G??yo.map(S=>f(`invoice.unit.${S}`,S)),[G,f]),z=n.useMemo(()=>O.map(kn),[O]),j=n.useMemo(()=>ho(O),[O]);n.useEffect(()=>{Y?.(j)},[j,Y]);const h=n.useCallback((S,m,A)=>{const D=[...O];D[S]={...D[S],[m]:A},$?.(D)},[O,$]),c=n.useCallback(()=>{F&&O.length>=F||$?.([...O,po(ne)])},[O,$,ne,F]),p=n.useCallback(S=>{$?.(O.filter((m,A)=>A!==S))},[O,$]),C=S=>`${S.toFixed(2)} ${w}`;return N?null:e.jsxs("div",{ref:_,id:L,className:`nice-invoice-lines nice-size-${y}${I?` ${I}`:""}${a?" nice-error":""}${l?" nice-disabled":""}`,style:{position:"relative",...J},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:20},children:e.jsx(r.NiceTutorialButton,{steps:r.resolveTutorial(R,mo)})}),t&&e.jsxs("label",{className:"nice-invoice-lines__label",children:[t,o&&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:f("description","Description")}),e.jsx("th",{className:"nice-il__th-qty",children:f("qty","Qty")}),k&&e.jsx("th",{className:"nice-il__th-unit",children:f("unit","Unit")}),e.jsx("th",{className:"nice-il__th-price",children:f("unitPrice","Unit Price")}),B&&e.jsx("th",{className:"nice-il__th-disc",children:f("invoice.discountPct","Disc %")}),e.jsx("th",{className:"nice-il__th-vat",children:f("invoice.vatPct","VAT %")}),e.jsx("th",{className:"nice-il__th-net",children:f("net","Net")}),e.jsx("th",{className:"nice-il__th-gross",children:f("gross","Gross")}),T&&!g&&e.jsx("th",{className:"nice-il__th-actions"})]})}),e.jsx("tbody",{children:z.map((S,m)=>e.jsxs("tr",{children:[e.jsx("td",{className:"nice-il__cell-num",children:m+1}),e.jsx("td",{className:"nice-il__cell-desc",children:e.jsx("input",{className:"nice-input",type:"text",value:S.description,onChange:A=>h(m,"description",A.target.value),disabled:l,readOnly:g,placeholder:f("itemDescription","Item description")})}),e.jsx("td",{className:"nice-il__cell-qty",children:e.jsx("input",{className:"nice-input",type:"number",value:S.quantity,onChange:A=>h(m,"quantity",parseFloat(A.target.value)||0),disabled:l,readOnly:g,min:0,step:"any"})}),k&&e.jsx("td",{className:"nice-il__cell-unit",children:e.jsx("select",{className:"nice-select",value:S.unit??"",onChange:A=>h(m,"unit",A.target.value),disabled:l,children:d.map(A=>e.jsx("option",{value:A,children:A},A))})}),e.jsx("td",{className:"nice-il__cell-price",children:e.jsx("input",{className:"nice-input",type:"number",value:S.unitPrice,onChange:A=>h(m,"unitPrice",parseFloat(A.target.value)||0),disabled:l,readOnly:g,min:0,step:"0.01"})}),B&&e.jsx("td",{className:"nice-il__cell-disc",children:e.jsx("input",{className:"nice-input",type:"number",value:S.discount??0,onChange:A=>h(m,"discount",parseFloat(A.target.value)||0),disabled:l,readOnly:g,min:0,max:100})}),e.jsx("td",{className:"nice-il__cell-vat",children:e.jsx("select",{className:"nice-select",value:S.vatRate??0,onChange:A=>h(m,"vatRate",parseInt(A.target.value,10)),disabled:l,children:le.map(A=>e.jsxs("option",{value:A,children:[A,"%"]},A))})}),e.jsx("td",{className:"nice-il__cell-net",children:C(S.netAmount??0)}),e.jsx("td",{className:"nice-il__cell-gross",children:C(S.grossAmount??0)}),T&&!g&&e.jsx("td",{className:"nice-il__cell-actions",children:e.jsx("button",{type:"button",className:"nice-btn nice-btn--icon nice-btn--sm",onClick:()=>p(m),disabled:l,title:f("remove","Remove"),"aria-label":f("remove","Remove"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})})]},S.id))})]}),T&&!g&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outlined nice-btn--sm nice-invoice-lines__add",onClick:c,disabled:l||F!=null&&O.length>=F,children:["+ ",f("addLine","Add line")]}),s&&e.jsxs("div",{className:"nice-invoice-lines__totals",children:[e.jsxs("div",{className:"nice-il__total-row",children:[e.jsxs("span",{children:[f("totalNet","Net total"),":"]}),e.jsx("span",{className:"nice-il__total-value",children:C(j.totalNet)})]}),j.vatBreakdown.map(S=>e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--vat",children:[e.jsx("span",{children:f("invoice.vat","VAT {rate}%:").replace("{rate}",String(S.rate))}),e.jsx("span",{className:"nice-il__total-value",children:C(S.amount)})]},S.rate)),e.jsxs("div",{className:"nice-il__total-row nice-il__total-row--gross",children:[e.jsxs("span",{children:[f("totalGross","Gross total"),":"]}),e.jsx("span",{className:"nice-il__total-value nice-il__total-value--gross",children:C(j.totalGross)})]})]}),i&&e.jsx("span",{className:"nice-helper-text",children:i}),a&&typeof a=="string"&&e.jsx("span",{className:"nice-error-text",children:a})]})}),{displayName:"NiceInvoiceLineEditor"}),bo=Object.assign(n.forwardRef(({value:t="",onChange:i,suggestions:a=[],onSearch:o,trigger:l="@",renderSuggestion:g,placeholder:y,rows:M=3,label:P,helperText:I,error:J,required:X,disabled:O,readOnly:$,loading:Y,labelPlacement:ae,errorPlacement:ne,labelWidth:le,controlWidth:G,size:B="md",name:k,id:s,className:T,style:F,...R},_)=>{const b=r.useControlId(s),[N,f]=n.useState(!1),[E,L]=n.useState(""),[w,d]=n.useState(0),[z,j]=n.useState({top:0,left:0}),h=n.useRef(null),c=n.useRef(-1),C=a.map(H=>typeof H=="string"?{key:H,label:H}:H).filter(H=>H.label.toLowerCase().includes(E.toLowerCase())),S=n.useCallback(()=>{f(!1),L(""),d(0),c.current=-1},[]),m=n.useCallback(H=>{const me=h.current;if(!me||c.current<0)return;const pe=t.slice(0,c.current),je=t.slice(me.selectionStart),ge=`${l}${H.label} `,ue=pe+ge+je;i?.(ue),S(),requestAnimationFrame(()=>{const de=pe.length+ge.length;me.setSelectionRange(de,de),me.focus()})},[t,i,l,S]),A=n.useCallback(H=>{const me=H.target.value;i?.(me);const pe=H.target.selectionStart,je=me.slice(0,pe),ge=je.lastIndexOf(l);if(ge>=0){const ue=ge>0?je[ge-1]:" ",de=je.slice(ge+l.length);if(/\s/.test(ue)&&!/\s/.test(de)){c.current=ge;const he=de;L(he),f(!0),d(0),o?.(he);const oe=H.target,ve=oe.getBoundingClientRect(),_e=parseInt(getComputedStyle(oe).lineHeight)||20,te=je.split(`
432
- `);j({top:ve.top+te.length*_e+4-oe.scrollTop,left:ve.left+8});return}}S()},[i,l,o,S]),D=n.useCallback(H=>{!N||C.length===0||(H.key==="ArrowDown"?(H.preventDefault(),d(me=>(me+1)%C.length)):H.key==="ArrowUp"?(H.preventDefault(),d(me=>(me-1+C.length)%C.length)):H.key==="Enter"?(H.preventDefault(),C[w]&&m(C[w])):H.key==="Escape"&&S())},[N,C,w,m,S]),W=N&&C.length>0,v=n.useRef(null),q=`${b}-suggestions`;return r.useIntent(["navigate","activate"],H=>{if(H.source==="keyboard")return!1;if(H.intent==="activate"){const pe=C[w];if(!pe)return!1;m(pe);return}if(H.direction!=="up"&&H.direction!=="down")return!1;const me=H.direction==="down"?1:-1;d(pe=>(pe+me+C.length)%C.length)},{ref:v,enabled:W}),n.useEffect(()=>{if(!N)return;const H=me=>{const pe=h.current;pe&&!pe.contains(me.target)&&S()};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[N,S]),e.jsxs("div",{className:`nice-field nice-field--${B} ${ae==="left"?"nice-field--label-left":""} ${ne==="right"?"nice-field--error-right":""} ${Y?"nice-field--loading":""} ${T||""}`,style:{...F,...le!=null&&{"--nice-field-label-width":typeof le=="number"?`${le}px`:le},...G!=null&&{"--nice-field-control-width":typeof G=="number"?`${G}px`:G}},"aria-busy":Y||void 0,...R,children:[P&&e.jsx("label",{htmlFor:b,className:`nice-field__label ${X?"nice-field__label--required":""}`,children:P}),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{ref:v,className:`nice-mention nice-mention--${B} ${J?"nice-mention--error":""} ${O?"nice-mention--disabled":""}`,children:[e.jsx("textarea",{ref:H=>{h.current=H,typeof _=="function"?_(H):_&&(_.current=H)},id:b,name:k,className:"nice-mention__input",value:t,onChange:A,onKeyDown:D,placeholder:y,rows:M,disabled:O,readOnly:$,"aria-invalid":!!J,"aria-describedby":J?`${b}-error`:I?`${b}-helper`:void 0,"aria-autocomplete":"list","aria-expanded":W,"aria-controls":W?q:void 0,"aria-activedescendant":W?`${q}-${w}`:void 0}),W&&e.jsx("ul",{id:q,className:"nice-mention__suggestions",role:"listbox",style:{position:"fixed",top:z.top,left:z.left},children:C.map((H,me)=>e.jsx("li",{id:`${q}-${me}`,role:"option","aria-selected":me===w,className:`nice-mention__suggestion ${me===w?"nice-mention__suggestion--active":""}`,onMouseDown:pe=>{pe.preventDefault(),m(H)},onMouseEnter:()=>d(me),children:g?g(H):e.jsxs(e.Fragment,{children:[H.icon&&e.jsx("span",{className:"nice-mention__suggestion-icon",children:H.icon}),e.jsx("span",{children:H.label})]})},H.key))})]}),Y&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),ne==="right"&&J&&e.jsx("div",{id:`${b}-error`,className:"nice-field__error",role:"alert",children:J}),ne==="right"&&!J&&I&&e.jsx("div",{id:`${b}-helper`,className:"nice-field__helper",children:I})]}),ne!=="right"&&J&&e.jsx("div",{id:`${b}-error`,className:"nice-field__error",role:"alert",children:J}),ne!=="right"&&!J&&I&&e.jsx("div",{id:`${b}-helper`,className:"nice-field__helper",children:I})]})}),{displayName:"NiceMention"});exports.DEFAULT_ASPECT_RATIOS=vn;exports.EMOJI_DATA=vt;exports.GRADIENT_PRESETS=xn;exports.NICE_COLOR_PRESET_KEYS=gn;exports.NiceAccountPicker=Hi;exports.NiceAddressInput=Pi;exports.NiceCodeEditorAI=_i;exports.NiceColorPalette=ti;exports.NiceContactPicker=Fi;exports.NiceCropEditor=_n;exports.NiceDateRangeBox=Un;exports.NiceDocumentEditor=bi;exports.NiceDropDownBox=Pn;exports.NiceEmojiPicker=jn;exports.NiceGradientPicker=oi;exports.NiceHtmlEditorAI=ri;exports.NiceImageAnnotator=eo;exports.NiceImageEditor=qi;exports.NiceInputOtp=Ui;exports.NiceInvoiceLineEditor=xo;exports.NiceKeyValueEditor=Ai;exports.NiceKnob=An;exports.NiceLogConsole=bn;exports.NiceLookup=Dn;exports.NiceMarkdownEditor=ui;exports.NiceMention=bo;exports.NicePDFAnnotationEditor=ao;exports.NicePickList=Fn;exports.NiceRangeSlider=Tn;exports.NiceScannerControl=lo;exports.NiceScriptRunner=Ii;exports.NiceSignature=so;exports.NiceTreeSelect=Ln;exports.NiceWiki=vi;exports.applyPreset=jt;exports.contrastRatio=xt;exports.cssToGradient=yn;exports.generateHarmony=lt;exports.generateVariations=un;exports.gradientToCss=Rt;exports.hexToHsv=Ke;exports.hexToRgb=dt;exports.hsvToHex=Pe;exports.hsvToRgb=ln;exports.randomPalette=hn;exports.rgbToHex=mn;exports.rgbToHsl=dn;exports.rgbToHsv=Dt;exports.wcagLevel=bt;