@nice2dev/ui 1.3.18 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -0
- package/README.md +27 -0
- package/dist/{NiceDataGrid-CFibAGHt.cjs → NiceDataGrid-BT6iCUgP.cjs} +1 -1
- package/dist/{NiceForm-ChRj4r3f.cjs → NiceForm-Bysp66Ef.cjs} +1 -1
- package/dist/{NiceMention-DNx3d9L7.cjs → NiceMention-sc8W-DwH.cjs} +1 -1
- package/dist/NiceModuleLifecyclePanel-DBQPCa_V.cjs +1 -0
- package/dist/{NiceSavedQueryPanel-BuRAgrBk.cjs → NiceSavedQueryPanel-BbznsXFd.cjs} +1 -1
- package/dist/{NiceScheduler-DAoo1eyo.cjs → NiceScheduler-3Ez0zSQJ.cjs} +1 -1
- package/dist/{core-lazy-DohJQ33c.cjs → core-lazy-CL4ZIxF-.cjs} +1 -1
- package/dist/data.cjs +1 -1
- package/dist/editors/pickers/pickerCommons.mjs +284 -87
- package/dist/editors/pickers/themePickerHelpers.mjs +10 -8
- package/dist/editors.cjs +1 -1
- package/dist/index.cjs +166 -166
- package/dist/index.d.ts +142 -10
- package/dist/index.mjs +1517 -1488
- package/dist/navigation/sidebarColors.mjs +61 -50
- package/dist/navigation.cjs +1 -1
- package/dist/navigation.d.ts +7 -0
- package/dist/pickerCommons-CwcCc8Qi.cjs +1 -0
- package/dist/planning/NiceResourceAllocation.mjs +31 -31
- package/dist/style.css +4 -4
- package/dist/tools/NiceThemeDesigner.mjs +781 -708
- package/dist/tools/NiceThemePreview.mjs +344 -282
- package/dist/tools/themeCatalog.mjs +28 -44
- package/dist/tools/themeCatalogArchive.mjs +38 -0
- package/dist/tools/themeDesigner/ThemeSetEditors.mjs +400 -0
- package/dist/tools/themeDesigner/ThemeValueField.mjs +146 -0
- package/dist/tools/themeDesigner/themeDesignerPaths.mjs +105 -0
- package/package.json +4 -4
- package/dist/NiceModuleLifecyclePanel-D8Q081R6.cjs +0 -1
- package/dist/pickerCommons-BWglYl6J.cjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),r=require("@nice2dev/ui-core"),n=require("react"),nt=require("react-dom"),We=require("./NiceSelect-BNPXs6FQ.cjs"),lt=require("./pickerCommons-BWglYl6J.cjs"),Je=require("./devops-cgRBnZVX.cjs"),mt=require("./NiceForm-ChRj4r3f.cjs"),tt=require("./no-code-B3BHeyG-.cjs"),on=require("@nice2dev/i18n"),In=require("./NiceHtmlEditor-C1OVtLQ6.cjs"),Ie=require("./NiceButton-DzCqkG5a.cjs"),Ot=require("./NiceColorPicker-BLwYNSXJ.cjs"),Et=require("./NiceCodeEditor-D0QZW88r.cjs"),jt=require("./injectStyleOnce-DeWaxcdf.cjs"),Mn=({min:t=0,max:i=100,step:a=1,startValue:o=t,endValue:c=i,onChange:g,showLabels:y=!0,formatLabel:T,valuePlacement:P="none",label:M,error:W,helperText:X,required:B,disabled:$,readOnly:U,loading:ie,size:ee="md",id:re,className:G,style:H,accessMode:w,showKeyboardHints:s,labelPlacement:R,errorPlacement:F,labelWidth:A,controlWidth:k})=>{const x=r.useNiceAccessMode(w,re),C=x==="hidden";(x==="disabled"||x==="readOnly")&&($=!0);const{t:f}=r.useNiceTranslation(),E=r.useControlId(re),L=n.useRef(null),N=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=u=>(u-t)/(i-t)*100,z=u=>T?T(u):String(u),b=n.useCallback(u=>{const _=Math.round(u/a)*a;return Math.max(t,Math.min(i,_))},[t,i,a]),h=n.useCallback((u,_)=>{u.preventDefault();const S=L.current;if(!S||$)return;const m=O=>{const V=S.getBoundingClientRect(),v=Math.max(0,Math.min(1,(O.clientX-V.left)/V.width)),q=b(t+v*(i-t));_==="start"?g?.(Math.min(q,c),c):g?.(o,Math.max(q,o))},D=()=>{document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",D)};document.addEventListener("pointermove",m),document.addEventListener("pointerup",D)},[t,i,b,o,c,g,$]),l=(u,_)=>{if($||U)return;const S=_==="start"?o:c,m=_==="start"?t:o,D=_==="start"?c:i,O=Math.max(a,(i-t)/10),V=u.key==="ArrowRight"||u.key==="ArrowUp"?S+a:u.key==="ArrowLeft"||u.key==="ArrowDown"?S-a:u.key==="PageUp"?S+O:u.key==="PageDown"?S-O:u.key==="Home"?m:u.key==="End"?D:null;if(V===null)return;u.preventDefault();const v=Math.max(m,Math.min(D,b(V)));_==="start"?g?.(v,c):g?.(o,v)};return C?null:e.jsxs("div",{className:`nice-field nice-field--${ee} nice-field--rangeslider ${R==="left"?"nice-field--label-left":""} ${F==="right"?"nice-field--error-right":""} ${W?"nice-field--error":""} ${ie?"nice-field--loading":""} ${G||""}`,style:{...H,...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...k!=null&&{"--nice-field-control-width":typeof k=="number"?`${k}px`:k}},"aria-busy":ie||void 0,children:[(M||P==="right"&&R!=="left")&&(R!=="left"?e.jsxs("div",{className:"nice-range-slider__header",children:[M?e.jsx("label",{className:"nice-field__label",htmlFor:E,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:N,size:"sm"})]})}):e.jsx("span",{}),P==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--header",children:[z(o)," – ",z(c)]})]}):M&&e.jsx("label",{className:"nice-field__label",htmlFor:E,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:N,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":""} ${M?"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(c)-d(o)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(o)}%`},onPointerDown:u=>U?void 0:h(u,"start"),onKeyDown:u=>l(u,"start"),role:"slider","aria-label":f("rangeSlider.min","Minimum"),"aria-valuemin":t,"aria-valuemax":c,"aria-valuenow":o,"aria-valuetext":z(o),"aria-disabled":$||void 0,"aria-readonly":U||void 0,tabIndex:$?-1:0,id:E}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(c)}%`},onPointerDown:u=>U?void 0:h(u,"end"),onKeyDown:u=>l(u,"end"),role:"slider","aria-label":f("rangeSlider.max","Maximum"),"aria-valuemin":o,"aria-valuemax":i,"aria-valuenow":c,"aria-valuetext":z(c),"aria-disabled":$||void 0,"aria-readonly":U||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(c)}%`},children:z(c)})]}),P==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[z(o)," – ",z(c)]})]}),P==="right"&&R==="left"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[z(o)," – ",z(c)]}),ie&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),F==="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),F==="right"&&!W&&X&&e.jsx("div",{className:"nice-field__helper",children:X})]}),F!=="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),F!=="right"&&!W&&X&&e.jsx("div",{className:"nice-field__helper",children:X})]})},Tn={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160,small:64,medium:80,large:100},ut=6,st=135,an=405,at=an-st;function $t(t,i,a,o){const c=(o-90)*(Math.PI/180);return{x:t+a*Math.cos(c),y:i+a*Math.sin(c)}}function Bt(t,i,a,o,c){const g=$t(t,i,a,o),y=$t(t,i,a,c),T=c-o>180?1:0;return`M ${g.x} ${g.y} A ${a} ${a} 0 ${T} 1 ${y.x} ${y.y}`}const Rn=Object.assign(n.forwardRef(({value:t=0,onChange:i,min:a=0,max:o=100,step:c=1,showValue:g=!0,valueTemplate:y="{value}",label:T,helperText:P,error:M,required:W,disabled:X,readOnly:B,size:$="md",name:U,id:ie,className:ee,style:re,labelPlacement:G="top",errorPlacement:H,labelWidth:w,controlWidth:s,loading:R,isLabelCentered:F=!0,...A},k)=>{const x=r.useControlId(ie),C=n.useRef(!1),f=n.useRef(null),E=typeof $=="number"?$:Tn[$],L=E/2,N=E/2,d=(E-ut*2)/2,z=o>a?(t-a)/(o-a):0,b=st+z*at,h=n.useCallback(m=>{let D=m-st;D<0&&(D+=360),D>at&&(D=D-at<360-D?at:0);const O=Math.max(0,Math.min(1,D/at)),V=a+O*(o-a),v=Math.round(V/c)*c;return Math.max(a,Math.min(o,v))},[a,o,c]),l=n.useCallback(m=>{if(X||B)return;const D=f.current;if(!D)return;const O=D.getBoundingClientRect(),V=m.clientX-O.left-O.width/2,v=m.clientY-O.top-O.height/2;let q=Math.atan2(V,-v)*(180/Math.PI);q<0&&(q+=360);const K=h(q);i?.(K)},[h,X,B,i]);n.useEffect(()=>{const m=O=>{C.current&&l(O)},D=()=>{C.current=!1};return window.addEventListener("pointermove",m),window.addEventListener("pointerup",D),()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",D)}},[l]);const u=n.useCallback(m=>{if(X||B)return;let D=t;const O=Math.max(c,(o-a)/10);m.key==="ArrowUp"||m.key==="ArrowRight"?(m.preventDefault(),D=Math.min(o,t+c)):m.key==="ArrowDown"||m.key==="ArrowLeft"?(m.preventDefault(),D=Math.max(a,t-c)):m.key==="PageUp"||m.key==="PageDown"?(m.preventDefault(),D=Math.max(a,Math.min(o,t+(m.key==="PageUp"?O:-O)))):(m.key==="Home"||m.key==="End")&&(m.preventDefault(),D=m.key==="Home"?a:o),D!==t&&i?.(D)},[t,i,a,o,c,X,B]),_=(y||"{value}").replace("{value}",String(t)),S=$t(L,N,d,b);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${H||"bottom"} nice-field--${typeof $=="string"?$:"md"} ${R?"nice-field--loading":""} ${ee||""}`,style:{...re,...w!=null&&{"--nice-field-label-width":typeof w=="number"?`${w}px`:w},...s!=null&&{"--nice-field-control-width":typeof s=="number"?`${s}px`:s}},"aria-busy":R||void 0,...A,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${G} ${F?"nice-knob-field--label-centered":""}`,children:[T&&e.jsx("label",{htmlFor:x,className:`nice-field__label ${W?"nice-field__label--required":""}`,children:T}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:m=>{f.current=m,typeof k=="function"?k(m):k&&(k.current=m)},className:`nice-knob nice-knob--${$} ${X?"nice-knob--disabled":""} ${M?"nice-knob--error":""}`,role:"slider",id:x,tabIndex:X?-1:0,"aria-valuenow":t,"aria-valuemin":a,"aria-valuemax":o,"aria-disabled":X,"aria-invalid":!!M,onPointerDown:m=>{X||B||(C.current=!0,l(m))},onKeyDown:u,children:[e.jsxs("svg",{width:E,height:E,viewBox:`0 0 ${E} ${E}`,children:[e.jsx("path",{d:Bt(L,N,d,st,an),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:ut,strokeLinecap:"round"}),z>0&&e.jsx("path",{d:Bt(L,N,d,st,b),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:ut,strokeLinecap:"round"}),e.jsx("circle",{cx:S.x,cy:S.y,r:ut,fill:"var(--nice-primary, #3b82f6)"})]}),g&&e.jsx("span",{className:"nice-knob__value",children:_}),U&&e.jsx("input",{type:"hidden",name:U,value:t}),R&&e.jsx("span",{className:"nice-knob__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]})})]}),M&&e.jsx("div",{className:"nice-field__error",role:"alert",children:M}),!M&&P&&e.jsx("div",{className:"nice-field__helper",children:P})]})}),{displayName:"NiceKnob"}),An=({options:t,value:i,defaultValue:a,onChange:o,searchable:c=!0,clearable:g,loading:y,placeholder:T,label:P,error:M,helperText:W,required:X,disabled:B,readOnly:$,size:U="md",id:ie,className:ee,style:re,data:G,columns:H,valueField:w="id",displayField:s,dropdownWidth:R,menuGap:F,labelPlacement:A,errorPlacement:k,labelWidth:x,controlWidth:C})=>{const f=B||$||y,E=r.useControlId(ie),{t:L}=r.useNiceTranslation(),[N,d]=r.useControllableState({value:i,defaultValue:a,fallbackValue:"",onChange:o,componentName:"NiceLookup"}),[z,b]=n.useState(!1),[h,l]=n.useState(""),u=n.useRef(null),_=n.useRef(null),{popupRef:S,coords:m,ready:D,themeClass:O,portalTarget:V}=We.useAnchoredPopup(z,_,()=>b(!1)),v=!!(G&&H&&H.length>0),q=s??(H&&H[0]?.key),K=n.useMemo(()=>!v||!G?[]:G.map(ae=>({value:String(ae[w]??""),label:q?String(ae[q]??""):""})),[v,G,w,q]),de=n.useMemo(()=>v?K:t??[],[v,K,t]),he=de.find(ae=>String(ae.value)===N),be=n.useMemo(()=>{if(!v||!G)return[];if(!h)return G;const ae=h.toLowerCase();return G.filter(ue=>H.some(I=>String(ue[I.key]??"").toLowerCase().includes(ae)))},[v,G,H,h]),ge=n.useMemo(()=>{if(v||!h)return de;const ae=h.toLowerCase();return de.filter(ue=>ue.label.toLowerCase().includes(ae))},[de,h,v]),fe=v?be:ge,{activeIndex:me,setActiveIndex:pe,handleKeyDown:te}=lt.useListKeyboardNav(fe,{open:z,onSelect:ae=>{const ue=String(v?ae[w]??"":ae.value);d(ue),b(!1),l("")},onClose:()=>b(!1),onOpen:()=>!f&&b(!0),intentRef:S}),_e=`${n.useId()}-listbox`,ne=ae=>`${_e}-opt-${ae}`,we=z&&fe.length>0?ne(me):void 0;return n.useLayoutEffect(()=>{we&&document.getElementById(we)?.scrollIntoView?.({block:"nearest"})},[we]),e.jsxs("div",{className:`nice-field nice-field--lookup nice-field--${U} ${M?"nice-field--error":""} ${A==="left"?"nice-field--label-left":""} ${k==="right"&&(M||W)?"nice-field--error-right":""} ${y?"nice-field--loading":""} ${B?"nice-field--disabled":""} ${ee||""}`,style:{...C!=null&&{"--nice-field-control-width":typeof C=="number"?`${C}px`:C},...x!=null&&{"--nice-field-label-width":typeof x=="number"?`${x}px`:x},...F!=null&&{"--nice-dropdown-gap":`${F}px`},...re},"aria-busy":y||void 0,ref:u,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:_,children:[e.jsxs("button",{type:"button",id:E,className:`nice-select__trigger ${B?"nice-select__trigger--disabled":""}`,onClick:()=>!f&&b(!z),onKeyDown:te,disabled:B,"aria-readonly":$||void 0,role:"combobox","aria-haspopup":"listbox","aria-expanded":z,"aria-controls":z?_e:void 0,"aria-activedescendant":c?void 0:we,children:[e.jsx("span",{children:he?.label||T||L("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[g&&N&&!B&&!$&&e.jsx("span",{onKeyDown:r.clickOnActivationKey,className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":L("controls.clear","Clear"),onClick:ae=>{ae.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&&V&&nt.createPortal(e.jsxs("div",{ref:S,className:`nice-dropdown nice-lookup__dropdown${O?` ${O}`:""}`,"data-theme":O==="nice-dark"?"dark":O==="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:R!=null?typeof R=="number"?`${R}px`:R:v?"max-content":m.width,opacity:D?1:0,pointerEvents:D?void 0:"none"},children:[c&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:h,onChange:ae=>{l(ae.target.value),pe(0)},onKeyDown:te,placeholder:L("controls.search","Search..."),"aria-label":L("controls.search","Search..."),"aria-controls":_e,"aria-activedescendant":we,"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:H.map(ae=>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:ae.width!=null?typeof ae.width=="number"?`${ae.width}px`:ae.width:void 0},children:ae.header},ae.key))})}),e.jsx("tbody",{children:be.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:H.length,style:{padding:12,textAlign:"center",color:"var(--nice-text-muted)"},children:L("controls.noResults","No results")})}):be.map((ae,ue)=>{const I=String(ae[w]??""),Y=I===N,le=ue===me;return e.jsx("tr",{id:ne(ue),role:"option","aria-selected":Y,onClick:()=>{d(I),b(!1),l("")},style:{cursor:"pointer",background:Y||le?"var(--nice-hover-bg)":"transparent"},onMouseEnter:()=>pe(ue),children:H.map(j=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--nice-border-color)"},children:String(ae[j.key]??"")},j.key))},I)})})]}):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((ae,ue)=>e.jsx("li",{id:ne(ue),role:"option",className:`nice-dropdown__option ${String(ae.value)===N?"nice-dropdown__option--selected":""} ${ue===me?"nice-dropdown__option--active":""}`,onClick:()=>{d(String(ae.value)),b(!1),l("")},onMouseEnter:()=>pe(ue),"aria-selected":String(ae.value)===N,children:ae.label},String(ae.value)))})]}),V)]}),y&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),k==="right"&&M&&e.jsx("div",{className:"nice-field__error",role:"alert",children:M}),k==="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]}),k!=="right"&&M&&e.jsx("div",{className:"nice-field__error",children:M}),k!=="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]})},Dn=[];function Ht(t){const i=[],a=o=>{for(const c of o)i.push(c),c.children&&a(c.children)};return a(t),i}function sn(t,i){const a=i.toLowerCase();return t.reduce((o,c)=>{const g=c.children?sn(c.children,i):[];return(c.label.toLowerCase().includes(a)||g.length>0)&&o.push({...c,children:g.length>0?g:c.children}),o},[])}const rn=({node:t,level:i,selectedKeys:a,expandedKeys:o,onToggleExpand:c,onSelect:g,selectableLeafsOnly:y,maxDepth:T})=>{const{t:P}=r.useNiceTranslation(),M=typeof T=="number"?Math.min(10,Math.max(1,T)):1/0,X=!(i+1>=M)&&t.children&&t.children.length>0,B=o.has(t.key),$=a.has(t.key),U=!X,ie=!t.disabled&&(!y||U),ee=Math.min(i+1,10),re={paddingLeft:i*16+14,"--nice-row-bg":`var(--nice-tree-level-${ee}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${ee}-text, inherit)`,"--nice-row-hover-bg":`var(--nice-tree-level-${ee}-hover-bg, var(--nice-bg-secondary, #f3f4f6))`,"--nice-row-active-bg":`var(--nice-tree-level-${ee}-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:re,"data-nice-depth":ee,onClick:()=>{t.disabled||(X?c(t.key):ie&&g(t.key))},role:"treeitem","aria-level":i+1,"aria-selected":$,"aria-expanded":X?B: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(),c(t.key)},"aria-label":P("controls.toggle","Toggle"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:12,style:{transform:B?"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&&B&&t.children.map(G=>e.jsx(rn,{node:G,level:i+1,selectedKeys:a,expandedKeys:o,onToggleExpand:c,onSelect:g,selectableLeafsOnly:y,maxDepth:T},G.key))]})},zn=Object.assign(n.forwardRef(({nodes:t=Dn,value:i,onChange:a,multiple:o=!1,searchable:c=!1,placeholder:g,selectableLeafsOnly:y=!1,clearable:T=!1,maxDepth:P,label:M,helperText:W,error:X,required:B,disabled:$,readOnly:U,size:ie="md",name:ee,id:re,className:G,style:H,controlWidth:w,menuGap:s,labelPlacement:R,errorPlacement:F,labelWidth:A,...k},x)=>{const{t:C}=r.useNiceTranslation(),f=r.useControlId(re),[E,L]=n.useState(!1),[N,d]=n.useState(""),[z,b]=n.useState(new Set),h=n.useRef(null),{popupRef:l,coords:u,ready:_,themeClass:S,portalTarget:m}=We.useAnchoredPopup(E,h,()=>L(!1)),D=n.useMemo(()=>i==null?new Set:new Set(Array.isArray(i)?i:[i]),[i]),O=n.useMemo(()=>N?sn(t,N):t,[t,N]),V=n.useMemo(()=>{const fe=Ht(t);return Array.from(D).map(me=>fe.find(pe=>pe.key===me)?.label).filter(Boolean)},[D,t]),v=n.useCallback(fe=>{b(me=>{const pe=new Set(me);return pe.has(fe)?pe.delete(fe):pe.add(fe),pe})},[]),q=n.useCallback(fe=>{if(o){const me=new Set(D);me.has(fe)?me.delete(fe):me.add(fe),a?.(Array.from(me))}else a?.(fe),L(!1)},[o,D,a]),K=n.useCallback(fe=>{fe.stopPropagation(),a?.(o?[]:"")},[a,o]),de=n.useRef(null),he=`${f}-tree`;r.useTreeFocus(de,{onToggle:(fe,me)=>{const pe=Ht(O).find(te=>String(te.key)===fe.dataset.key);pe&&z.has(pe.key)!==me&&v(pe.key)}});const be=n.useCallback(()=>(de.current?.querySelector('[role="treeitem"][tabindex="0"]')??de.current?.querySelector('[role="treeitem"]'))?.focus(),[]),ge=!!u;return n.useEffect(()=>{E&&ge&&!c&&be()},[E,ge,c,be]),e.jsxs("div",{className:`nice-field nice-field--${ie}${R?` nice-field--label-${R}`:""}${F==="right"?" nice-field--error-right":""} ${G||""}`,style:{width:"fit-content",maxWidth:"100%",...s!=null&&{"--nice-dropdown-gap":`${s}px`},...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...H},...k,children:[M&&e.jsx("label",{htmlFor:f,className:`nice-field__label ${B?"nice-field__label--required":""}`,children:M}),e.jsxs("div",{ref:h,className:"nice-tree-select",style:{position:"relative",width:w!=null&&w!==""?typeof w=="number"?`${w}px`:w:"var(--nice-field-control-width, 220px)"},children:[e.jsxs("div",{ref:x,id:f,className:`nice-input nice-input--${ie} ${X?"nice-input--error":""} ${$?"nice-input--disabled":""} ${U?"nice-input--readonly":""}`,role:"combobox","aria-expanded":E,"aria-haspopup":"tree","aria-controls":E?he:void 0,"aria-invalid":!!X,tabIndex:$?-1:0,onClick:()=>!$&&!U&&L(!E),onKeyDown:fe=>{(fe.key==="Enter"||fe.key===" "||fe.key==="ArrowDown"||fe.key==="ArrowUp")&&!$&&!U&&(fe.preventDefault(),E?be():L(!0))},children:[e.jsx("span",{className:"nice-tree-select__display",children:V.length>0?V.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:g??C("controls.select","Select...")})}),T&&D.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:K,"aria-label":C("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&&u&&m&&nt.createPortal(e.jsxs("div",{ref:l,className:`nice-tree-select__dropdown${S?` ${S}`:""}`,"data-theme":S==="nice-dark"?"dark":S==="nice-light"?"light":void 0,style:{position:"fixed",left:u.left,top:u.top,width:u.width,minWidth:u.width,zIndex:1e3,opacity:_?1:0,pointerEvents:_?void 0:"none"},children:[c&&e.jsx("div",{className:"nice-select__search",onClick:fe=>fe.stopPropagation(),role:"presentation",children:e.jsx("input",{type:"text",placeholder:C("controls.search","Search..."),"aria-label":C("controls.search","Search..."),"aria-controls":he,value:N,onChange:fe=>d(fe.target.value),onKeyDown:fe=>{fe.key==="ArrowDown"&&(fe.preventDefault(),be())},autoFocus:!0})}),e.jsx("div",{ref:de,id:he,className:"nice-tree-select__list",role:"tree","aria-label":M||g||C("controls.select","Select..."),"aria-multiselectable":o||void 0,children:O.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:C("controls.noResults","No results")}):O.map(fe=>e.jsx(rn,{node:fe,level:0,selectedKeys:D,expandedKeys:z,onToggleExpand:v,onSelect:q,selectableLeafsOnly:y,maxDepth:P},fe.key))})]}),m)]}),ee&&e.jsx("input",{type:"hidden",name:ee,value:Array.isArray(i)?i.join(","):i??""}),X&&e.jsx("div",{id:`${f}-error`,className:"nice-field__error",role:"alert",children:X}),!X&&W&&e.jsx("div",{id:`${f}-helper`,className:"nice-field__helper",children:W})]})}),{displayName:"NiceTreeSelect"}),Ln=({displayValue:t,placeholder:i,clearable:a,children:o,onClear:c,open:g,onOpenChange:y,dropdownWidth:T,searchable:P=!0,onSearch:M,searchPlaceholder:W,label:X,error:B,helperText:$,required:U,disabled:ie,size:ee="md",id:re,className:G,style:H,accessMode:w,showKeyboardHints:s,displayStyle:R})=>{r.useComponentDisplayStyle("input",R),r.useComponentDisplayClass("input",R);const F=r.useNiceAccessMode(w,re),A=F==="hidden";(F==="disabled"||F==="readOnly")&&(ie=!0);const k=r.useControlId(re),{t:x}=r.useNiceTranslation(),[C,f]=n.useState(!1),[E,L]=n.useState(""),N=n.useRef(null),d=n.useRef(null),z=g??C,b=n.useMemo(()=>[{key:"Enter",description:x("shortcuts.openDropdown","Open dropdown")},r.COMMON_SHORTCUTS.cancel],[x]),h=D=>{y?y(D):f(D)},{popupRef:l,coords:u,ready:_,themeClass:S,portalTarget:m}=We.useAnchoredPopup(z,d,()=>h(!1));return A?null:e.jsxs("div",{className:`nice-field nice-field--${ee} ${B?"nice-field--error":""} ${G||""}`,style:H,ref:N,children:[X&&e.jsxs("label",{className:"nice-field__label",htmlFor:k,children:[X,U&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:b,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",ref:d,children:[e.jsxs("button",{type:"button",id:k,className:"nice-select__trigger",onClick:()=>!ie&&h(!z),disabled:ie,children:[e.jsx("span",{children:t||i||x("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[a&&t&&!ie&&e.jsx("span",{className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":x("controls.clear","Clear"),onClick:D=>{D.stopPropagation(),c?.()},onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),D.stopPropagation(),c?.())},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&&u&&m&&nt.createPortal(e.jsxs("div",{ref:l,className:`nice-dropdown${S?` ${S}`:""}`,"data-theme":S==="nice-dark"?"dark":S==="nice-light"?"light":void 0,style:{position:"fixed",left:u.left,top:u.top,width:T??u.width,minWidth:T??u.width,zIndex:1e3,maxHeight:320,overflowY:"auto",opacity:_?1:0,pointerEvents:_?void 0:"none"},children:[P&&M&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:E,onChange:D=>{L(D.target.value),M(D.target.value)},placeholder:W??x("controls.search","Search..."),autoFocus:!0})}),o]}),m)]}),B&&e.jsx("div",{className:"nice-field__error",children:B}),$&&!B&&e.jsx("div",{className:"nice-field__hint",children:$})]})},Pn=[],On=[];function Ve(t,i){return String(t[i])}const Bn={xxs:10,xs:12,sm:12,md:14,lg:18,xl:22,xxl:26},Hn=Object.assign(n.forwardRef(({source:t=Pn,target:i=On,onChange:a,keyField:o="id",labelField:c="label",renderItem:g,filterable:y=!1,searchable:T,groupBy:P,sortable:M=!1,bulkActions:W=!0,maxRight:X,sourceHeader:B,targetHeader:$,disabled:U=!1,size:ie="md",className:ee,style:re,id:G,...H},w)=>{const{t:s}=r.useNiceTranslation(),R=Bn[ie]??14,[F,A]=n.useState(new Set),[k,x]=n.useState(new Set),[C,f]=n.useState(""),[E,L]=n.useState(""),[N,d]=n.useState(null),z=n.useRef(null),b=n.useRef(null),h={orientation:"vertical",typeahead:!0,pageSize:10};r.useRovingFocus(z,h),r.useRovingFocus(b,h);const l=n.useCallback((v,q,K)=>{q(de=>{const he=new Set(de);return he.has(K)?he.delete(K):he.add(K),he})},[]),u=n.useCallback(()=>{const v=t.filter(he=>F.has(Ve(he,o))),q=t.filter(he=>!F.has(Ve(he,o))),K=typeof X=="number"?v.slice(0,Math.max(0,X-i.length)):v,de=v.slice(K.length);a([...q,...de],[...i,...K]),A(new Set)},[t,i,F,o,a,X]),_=n.useCallback(()=>{const v=i.filter(K=>k.has(Ve(K,o))),q=i.filter(K=>!k.has(Ve(K,o)));a([...t,...v],q),x(new Set)},[t,i,k,o,a]),S=n.useCallback(()=>{if(typeof X=="number"){const v=Math.max(0,X-i.length),q=t.slice(0,v),K=t.slice(v);a(K,[...i,...q])}else a([],[...i,...t]);A(new Set)},[t,i,a,X]),m=n.useCallback(()=>{a([...t,...i],[]),x(new Set)},[t,i,a]),D=(v,q)=>{if(!q)return v;const K=q.toLowerCase();return v.filter(de=>String(de[c]).toLowerCase().includes(K))},O=W===!1?{moveAll:!1,removeAll:!1}:W===!0||W===void 0?{moveAll:!0,removeAll:!0}:{moveAll:W.moveAll??!0,removeAll:W.removeAll??!0},V=(v,q,K,de,he,be,ge,fe)=>{let me=D(v,de);M||(me=[...me].sort((ae,ue)=>String(ae[c]).localeCompare(String(ue[c]),void 0,{numeric:!0,sensitivity:"base"})));const pe=T===!0||y&&T===void 0?"both":T??!1,te=pe==="both"||pe==="left"&&ge==="left"||pe==="right"&&ge==="right",ve=(()=>{if(!P)return[{label:"",items:me}];const ae=new Map;for(const ue of me){const I=String(P(ue));let Y=ae.get(I);Y||(Y=[],ae.set(I,Y)),Y.push(ue)}return[...ae.entries()].map(([ue,I])=>({label:ue,items:I}))})(),_e=(ae,ue)=>{ae.dataTransfer.setData("text/plain",ue),ae.dataTransfer.effectAllowed="move"},ne=(ae,ue)=>{if(ae.preventDefault(),!M)return;const I=ae.currentTarget.getBoundingClientRect(),Y=ae.clientY<I.top+I.height/2;d(le=>le&&le.side===ge&&le.key===ue&&le.before===Y?le:{side:ge,key:ue,before:Y})},we=(ae,ue)=>{ae.preventDefault();const I=N?.before??!1;d(null);const Y=ae.dataTransfer.getData("text/plain");if(!Y||!M)return;const j=[...ge==="right"?i:t],Z=j.findIndex(xe=>Ve(xe,o)===Y),oe=j.findIndex(xe=>Ve(xe,o)===ue);if(Z===-1||oe===-1||Y===ue)return;let se=I?oe:oe+1;const[ye]=j.splice(Z,1);Z<se&&(se-=1),j.splice(se,0,ye),a(ge==="right"?t:j,ge==="right"?j:i)};return e.jsxs("div",{className:"nice-picklist__panel",children:[be&&e.jsx("div",{className:"nice-picklist__header",children:be}),te&&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:de,onChange:ae=>he(ae.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true","aria-label":typeof be=="string"?be:void 0,ref:fe,children:[ve.map(ae=>e.jsxs(n.Fragment,{children:[ae.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:ae.label}),ae.items.map(ue=>{const I=Ve(ue,o),Y=q.has(I),j=N&&N.side===ge&&N.key===I?N.before?"nice-picklist__item--drop-before":"nice-picklist__item--drop-after":"";return e.jsxs("div",{className:`nice-picklist__item ${Y?"nice-picklist__item--selected":""} ${j}`,role:"option","aria-selected":Y,draggable:M,onDragStart:M?Z=>_e(Z,I):void 0,onDragOver:M?Z=>ne(Z,I):void 0,onDrop:M?Z=>we(Z,I):void 0,onDragEnd:M?()=>d(null):void 0,onClick:()=>!U&&l(q,K,I),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),U||l(q,K,I))},children:[M&&e.jsx("span",{className:"nice-picklist__drag-handle","aria-hidden":"true",children:e.jsx(r.NiceIcon,{name:"grip",size:R})}),g?g(ue,ge):String(ue[c])]},I)})]},ae.label||"__none__")),me.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:s("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:w,id:G,className:`nice-picklist nice-picklist--${ie} ${U?"nice-picklist--disabled":""} ${ee||""}`,style:re,...H,children:[V(t,F,A,C,f,B??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--${ie}`,disabled:U||F.size===0,onClick:u,"aria-label":s("picklist.moveRight","Move right"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:R})}),O.moveAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ie}`,disabled:U||t.length===0,onClick:S,"aria-label":s("picklist.moveAllRight","Move all right"),children:e.jsx(r.NiceIcon,{name:"chevrons-right",size:R})}),e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ie}`,disabled:U||k.size===0,onClick:_,"aria-label":s("picklist.moveLeft","Move left"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:R})}),O.removeAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ie}`,disabled:U||i.length===0,onClick:m,"aria-label":s("picklist.moveAllLeft","Move all left"),children:e.jsx(r.NiceIcon,{name:"chevrons-left",size:R})})]}),V(i,k,x,E,L,$??s("picklist.target","Selected"),"right",b)]})}),{displayName:"NicePickList"});function Tt(t){return t?.startsWith("datetime")?"datetime":t==="week"?"week":t?.startsWith("month")?"month":"date"}function Fn(t){const i=new Date,a=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`,o=Tt(t);return o==="datetime"?`${a}T00:00`:o==="month"?a.slice(0,7):a}function Ft(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 pt(...t){return t.filter(Boolean).sort().pop()}function Nt(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 c=Tt(a);return c==="month"?o.toLocaleDateString(i,{year:"numeric",month:"2-digit"}):c==="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 Kt(t){let i=0;for(const a of t)i+=/[\p{L}\p{N}]/u.test(a)?1:.5;return i}const Kn=({startDate:t,endDate:i,defaultStartDate:a,defaultEndDate:o,onStartChange:c,onEndChange:g,min:y,max:T,clearable:P,startPlaceholder:M,endPlaceholder:W,startLabel:X,endLabel:B,layout:$="horizontal",separator:U="–",gap:ie=12,fullWidth:ee=!1,dateFormatPreset:re,locale:G,timeSelectorType:H,endCondition:w="greater-or-equal",startCondition:s="today-or-greater",singleField:R=!1,label:F,error:A,helperText:k,required:x,disabled:C,size:f="md",id:E,className:L,style:N,accessMode:d,showKeyboardHints:z,labelPlacement:b,errorPlacement:h,labelWidth:l,controlWidth:u,loading:_,readOnly:S})=>{const m=r.useNiceAccessMode(d,E),D=r.useControlId(E),{t:O}=r.useNiceTranslation(),V=m==="disabled"||m==="readOnly"||!!C,[v,q]=r.useControllableState({value:t,defaultValue:a,fallbackValue:"",onChange:c,componentName:"NiceDateRangeBox"}),[K,de]=r.useControllableState({value:i,defaultValue:o,fallbackValue:"",onChange:g,componentName:"NiceDateRangeBox"}),he=n.useMemo(()=>[{key:"Tab",description:O("shortcuts.switchField","Switch between start/end")},r.COMMON_SHORTCUTS.cancel],[O]),be=n.useRef(null),ge=n.useRef(null),[fe,me]=n.useState(!1),[pe,te]=n.useState(null),[ve,_e]=n.useState(""),we=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null);n.useLayoutEffect(()=>{if(!fe)return;const Ce=be.current?.getBoundingClientRect();Ce&&(te({left:Ce.left,top:Ce.bottom+6}),_e(Je.scopeThemeClass(be.current)))},[fe]),n.useEffect(()=>{if(!fe)return;const Ce=Be=>{const $e=Be.target;be.current?.contains($e)||ge.current?.contains($e)||me(!1)},Ne=()=>{const Be=be.current?.getBoundingClientRect();Be&&te({left:Be.left,top:Be.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)}},[fe]),r.useOverlayFocus(ge,{open:fe,modal:!1,initialFocus:'.nice-calendar__grid [tabindex="0"]',onClose:()=>me(!1)});const ae=Fn(re),ue=s==="today-or-greater"?pt(y,ae):s==="greater-than-today"?pt(y,Ft(ae,1)):y,I=w==="greater-or-equal"?pt(y,v):w==="greater"?pt(y,v?Ft(v,1):void 0):y,Y=n.useMemo(()=>{if(A)return A;if(v&&K){if(w==="greater-or-equal"&&K<v)return O("daterange.endBeforeStart","End date must be on or after the start date");if(w==="greater"&&K<=v)return O("daterange.endAfterStart","End date must be after the start date")}if(v){if(s==="today-or-greater"&&v<ae)return O("daterange.startInPast","Start date cannot be in the past");if(s==="greater-than-today"&&v<=ae)return O("daterange.startAfterToday","Start date must be after today")}},[A,v,K,s,w,ae,O]);if(m==="hidden")return null;const le=Ce=>{q(Ce),Ce&&K&&Ce>K&&de(Ce)},j=$==="horizontal",Z=Tt(re),oe=G||mt.getDefaultLocale(),se=typeof U=="string"&&U!==""?U:"–",ye=Nt(v,oe,re),xe=Nt(K,oe,re),Ee=ye||xe?`${ye||"…"} ${se} ${xe||"…"}`:"",ze=(()=>{const Ce=Nt("2026-12-30T22:58",oe,re),Ne=`${Ce} ${se} ${Ce}`;return`${(Math.max(Kt(Ne),Kt(Ee))+1.5).toFixed(1)}ch`})(),Le=(Ce,Ne)=>Z==="datetime"?Ne&&Ne.length>10?`${Ce}${Ne.slice(10)}`:`${Ce}T00:00`:Z==="month"?Ce.slice(0,7):Ce,Ye=({start:Ce,end:Ne})=>{q(Ce?Le(Ce,v):""),de(Ne?Le(Ne,K):""),Ce&&Ne&&me(!1)},Xe=()=>{q(""),de("")},Ke=()=>{!V&&!S&&me(Ce=>!Ce)},He=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--${$} ${b==="left"?"nice-field--label-left":""} ${Y?"nice-field--error":""} ${_?"nice-field--loading":""} ${L||""}`,style:{...N,...l!=null&&{"--nice-field-label-width":typeof l=="number"?`${l}px`:l},...u!=null&&{"--nice-field-control-width":typeof u=="number"?`${u}px`:u}},"aria-busy":_||void 0,children:[F&&e.jsxs("label",{className:"nice-field__label",htmlFor:D,children:[F,x&&e.jsx("span",{className:"nice-field__required",children:"*"}),z&&e.jsx(r.NiceKeyboardHint,{shortcuts:he,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[R?e.jsxs("div",{ref:be,className:`nice-input nice-input--date nice-input--${f} nice-daterange__single ${Y?"nice-input--error":""} ${V?"nice-input--disabled":""} ${S?"nice-input--readonly":""}`,style:{position:"relative",width:ee?"100%":"fit-content"},children:[e.jsx("input",{id:D,className:"nice-input__native",type:"text",readOnly:!0,value:Ee,placeholder:M||O("controls.startDate","Start date"),disabled:V||_,autoComplete:"off","aria-invalid":!!Y,"aria-label":F?void 0:O("controls.startDate","Start date"),"aria-haspopup":"dialog","aria-expanded":fe,onClick:Ke,onKeyDown:Ce=>{const Ne=!!Ce.nativeEvent.niceSource;(Ce.key==="Enter"||Ce.key===" "||Ce.key==="ArrowDown"&&!Ne)&&(Ce.preventDefault(),fe||Ke())},style:{width:ee?"100%":ze,cursor:V||S?void 0:"pointer"}}),P&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:Xe,disabled:!v&&!K||V||S,"aria-label":O("controls.clear","Clear"),tabIndex:(v||K)&&!V&&!S?0:-1,children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("button",{type:"button",className:"nice-input__picker-trigger",onClick:Ke,"aria-label":O("controls.openPicker","Open picker"),"aria-expanded":fe,tabIndex:-1,disabled:V||S,children:e.jsx(r.NiceIcon,{name:"calendar",size:16})})]}):e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:j?"row":"column",alignItems:j?b==="left"?"center":"flex-end":"stretch",gap:ie,flexWrap:j?"nowrap":"wrap"},children:[e.jsx("div",{style:{flex:ee?"1 1 0":void 0,minWidth:0},children:e.jsx(mt.NiceDateTimePicker,{id:D,dateFormatPreset:re,displayLocale:G,timeSelectorType:H,label:X,value:v,onChange:le,min:ue,max:K||T,placeholder:M||O("controls.startDate","Start date"),disabled:V,readOnly:S,size:f,clearable:P,labelPlacement:b,labelWidth:l})}),j&&U!==""&&U!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--nice-text-secondary, #666)"},"aria-hidden":"true",children:U}),e.jsx("div",{style:{flex:ee?"1 1 0":void 0,minWidth:0},children:e.jsx(mt.NiceDateTimePicker,{dateFormatPreset:re,displayLocale:G,timeSelectorType:H,label:B,value:K,onChange:Ce=>de(Ce),min:I||v||y,max:T,placeholder:W||O("controls.endDate","End date"),disabled:V,readOnly:S,size:f,clearable:P,labelPlacement:b,labelWidth:l})})]}),R&&fe&&pe&&we&&nt.createPortal(e.jsxs("div",{ref:ge,className:`nice-datetime-popup${ve?` ${ve}`:""}`,style:{position:"fixed",left:pe.left,top:pe.top,zIndex:1e3},role:"dialog","aria-label":O("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(mt.NiceCalendar,{selectionMode:"range",rangeStart:He(v),rangeEnd:He(K),onRangeChange:Ye,min:He(ue),max:He(T),size:f})})}),P&&e.jsx("div",{className:"nice-datetime-popup__footer",children:e.jsx("button",{type:"button",className:"nice-datetime-popup__btn",onClick:Xe,disabled:!v&&!K,children:O("controls.clear","Clear")})})]}),we),_&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),h==="right"&&Y&&e.jsx("div",{className:"nice-field__error",role:"alert",children:Y}),h==="right"&&!Y&&k&&e.jsx("div",{className:"nice-field__helper",children:k})]}),h!=="right"&&Y&&e.jsx("div",{className:"nice-field__error",children:Y}),h!=="right"&&!Y&&k&&e.jsx("div",{className:"nice-field__hint",children:k})]})};function Un(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 Ut(t,i={}){const a=i.size??16,o="currentColor",c="currentColor";if(i.rectangle||t==="shade-chain"||t==="monochromatic"){const X=Math.max(3,Math.min(7,i.count??5)),B=a*.1,$=a-B*2,U=Math.max(1.2,a/14),ie=a/2,ee=Array.from({length:X},(re,G)=>{const H=B+$*G/(X-1),w=.25+.75*G/(X-1);return e.jsx("circle",{cx:H,cy:ie,r:U,fill:c,opacity:w},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}),ee]})}const y=i.angles??Un(t),T=a/2,P=a/2,M=a/2-2,W=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:T,cy:P,r:M,fill:"none",stroke:o,strokeOpacity:.25}),y.map((X,B)=>{const $=(X-90)*Math.PI/180,U=T+M*Math.cos($),ie=P+M*Math.sin($);return e.jsx("circle",{cx:U,cy:ie,r:W,fill:c},B)})]})}function Yt(t,i,a){return Math.max(i,Math.min(a,t))}function cn({h:t,s:i,v:a}){t=(t%360+360)%360;const o=a*i,c=o*(1-Math.abs(t/60%2-1)),g=a-o;let y=0,T=0,P=0;return t<60?(y=o,T=c):t<120?(y=c,T=o):t<180?(T=o,P=c):t<240?(T=c,P=o):t<300?(y=c,P=o):(y=o,P=c),{r:Math.round((y+g)*255),g:Math.round((T+g)*255),b:Math.round((P+g)*255)}}function Rt({r:t,g:i,b:a}){t/=255,i/=255,a/=255;const o=Math.max(t,i,a),c=Math.min(t,i,a),g=o-c;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 ln({r:t,g:i,b:a}){t/=255,i/=255,a/=255;const o=Math.max(t,i,a),c=Math.min(t,i,a),g=(o+c)/2;if(o===c)return{h:0,s:0,l:g};const y=o-c,T=g>.5?y/(2-o-c):y/(o+c);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:T,l:g}}function ct(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 dn({r:t,g:i,b:a}){return"#"+[t,i,a].map(o=>o.toString(16).padStart(2,"0")).join("")}function Pe(t){return dn(cn(t))}function Fe(t){return Rt(ct(t))}function mn(t,i){const a=[];for(let o=0;o<i;o++){const c=i<=1?.5:o/(i-1),g=Yt(t.s*(.3+c*.7),0,1),y=Yt(t.v*(1.2-c*.7),0,1);a.push(Pe({h:t.h,s:g,v:y}))}return a}function bt(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 rt(t,i,a){return bt(i,a).map(o=>((t+o)%360+360)%360)}function Xt(t,i,a=.12){const o=Math.max(2,i),c=(o-1)/2,g=[];for(let y=0;y<o;y++){const T=(y-c)*a,P=Math.max(.05,Math.min(.98,t.v+T)),M=Math.max(.05,Math.min(1,t.s-Math.abs(T)*.25));g.push(Pe({h:t.h,s:M,v:P}))}return g}function qt({r:t,g:i,b:a}){const[o,c,g]=[t,i,a].map(y=>{const T=y/255;return T<=.03928?T/12.92:Math.pow((T+.055)/1.055,2.4)});return .2126*o+.7152*c+.0722*g}function gt(t,i){const a=qt(ct(t)),o=qt(ct(i)),c=Math.max(a,o),g=Math.min(a,o);return(c+.05)/(g+.05)}function ft(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"AA-lg":"Fail"}const un={"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 yt(t,i){const a=un[i];return t.map(o=>{const c=(a.sRange[0]+a.sRange[1])/2,g=(a.vRange[0]+a.vRange[1])/2;return Pe({h:o,s:c,v:g})})}function Yn(){return Math.floor(Math.random()*360)}function pn(t,i,a){const o=Yn(),c=rt(o,t,a),g=[];for(let y=0;y<i;y++){const T=c[y%c.length],P=.55+Math.random()*.4,M=.5+Math.random()*.45;g.push(Pe({h:T+(Math.random()-.5)*8,s:P,v:M}))}return g}const Xn=({hues:t,colors:i,baseHue:a,onBaseHueChange:o,mode:c,distance:g,disabled:y})=>{const{t:T}=r.useNiceTranslation(),P=240,M=P/2,W=P/2,X=110,B=55,$=s=>{if(y)return;const R=s.shiftKey?15:1,F=s.key==="ArrowLeft"||s.key==="ArrowDown"?-R:s.key==="ArrowRight"||s.key==="ArrowUp"?R: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))},U=n.useRef(null),ie=n.useCallback((s,R)=>{const F=U.current;if(!F)return;const A=F.getBoundingClientRect(),k=(s-A.left)/A.width*P-M,x=(R-A.top)/A.height*P-W,C=(Math.atan2(x,k)*180/Math.PI+360)%360;o(Math.round(C))},[M,W,P,o]),ee=n.useCallback(s=>{if(y)return;s.preventDefault(),ie(s.clientX,s.clientY);const R=A=>ie(A.clientX,A.clientY),F=()=>{document.removeEventListener("pointermove",R),document.removeEventListener("pointerup",F)};document.addEventListener("pointermove",R),document.addEventListener("pointerup",F)},[y,ie]),re=[];for(let s=0;s<360;s+=2){const R=(s-1)*Math.PI/180,F=(s+1)*Math.PI/180,A=Pe({h:s,s:1,v:1});re.push(e.jsx("path",{d:`M${M+B*Math.cos(R)},${W+B*Math.sin(R)} L${M+X*Math.cos(R)},${W+X*Math.sin(R)} A${X},${X} 0 0,1 ${M+X*Math.cos(F)},${W+X*Math.sin(F)} L${M+B*Math.cos(F)},${W+B*Math.sin(F)} A${B},${B} 0 0,0 ${M+B*Math.cos(R)},${W+B*Math.sin(R)} Z`,fill:A},s))}const G=`wheel-center-${c}`,H=t.map((s,R)=>{const F=(X+B)/2,A=s*Math.PI/180;return e.jsx("circle",{cx:M+F*Math.cos(A),cy:W+F*Math.sin(A),r:R===0?8:6,fill:i?.[R]??Pe({h:s,s:.85,v:.9}),stroke:R===0?"var(--nice-bg-primary, #fff)":"var(--nice-border-color, #ccc)",strokeWidth:R===0?3:2},R)});let w=null;if(c==="analogous"||c==="split-complementary"||c==="analogous-complementary"){const s=(X+B)/2,F=bt(c,g).slice(1).map((A,k)=>{const x=(a+A)*Math.PI/180;return e.jsx("line",{x1:M,y1:W,x2:M+s*Math.cos(x),y2:W+s*Math.sin(x),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${k}`)});w=e.jsx(e.Fragment,{children:F})}return e.jsxs("svg",{ref:U,className:"nice-palette__wheel",viewBox:`0 0 ${P} ${P}`,width:P,height:P,onPointerDown:ee,onKeyDown:$,role:"slider",tabIndex:y?-1:0,"aria-label":T("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"})]})}),re,e.jsx("circle",{cx:M,cy:W,r:B-2,fill:Pe({h:a,s:.6,v:.85})}),e.jsx("circle",{cx:M,cy:W,r:B-2,fill:`url(#${G})`,opacity:.4}),w,H]})},qn=({colors:t})=>{const{t:i}=r.useNiceTranslation();if(t.length<2)return null;const a=[];for(let o=0;o<t.length;o++){const c=gt(t[o],"var(--nice-bg-primary, #ffffff)"),g=gt(t[o],"var(--nice-text-primary, #000000)");a.push({a:t[o],b:"var(--nice-bg-primary, #ffffff)",ratio:c,level:ft(c)}),a.push({a:t[o],b:"var(--nice-text-primary, #000000)",ratio:g,level:ft(g)});for(let y=o+1;y<t.length;y++){const T=gt(t[o],t[y]);a.push({a:t[o],b:t[y],ratio:T,level:ft(T)})}}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,c)=>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})]},c))})]})},Gn=({hex:t})=>{const i=ct(t),a=ln(i),o=Rt(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),"%"]})]})},Vn={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"},Wn={"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"},Jn=["monochromatic","shade-chain","complementary","split-complementary","analogous","analogous-complementary","triadic","tetradic","square","custom"],hn=["lightest-pastel","bright-pastel","shiny","pastel","full","dark","deep","muted","earth"],gn="nice-palette-custom-schemes";function Zn(){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(gn);if(!t)return[];const i=JSON.parse(t);if(Array.isArray(i))return i}catch{}return[]}function Qn(t){if(!(typeof window>"u"))try{window.localStorage.setItem(gn,JSON.stringify(t))}catch{}}const ei=Object.assign(n.forwardRef(({id:t,className:i,style:a,accessMode:o,value:c,onChange:g,minColors:y=1,maxColors:T=8,harmonyMode:P,onHarmonyModeChange:M,distance:W,onDistanceChange:X,preset:B,onPresetChange:$,showWheel:U=!0,showContrast:ie=!0,showInfo:ee=!0,showPresets:re=!0,presets:G=[],showVariations:H=!0,showRandom:w=!0,variationCount:s=5,label:R,labelPlacement:F="top",disabled:A,readOnly:k,loading:x,error:C,colorCount:f,shadeStep:E,onShadeStepChange:L,customSchemes:N,onCustomSchemesChange:d,persistCustomSchemes:z=!0,"data-testid":b},h)=>{const l=r.useNiceAccessMode(o,t),u=l==="hidden";l==="disabled"&&(A=!0);const _=k||l==="readOnly",S=r.useControlId(t),{t:m}=r.useNiceTranslation(),D=Je.useNiceDialogs(),[O,V]=n.useState("analogous-complementary"),[v,q]=n.useState(30),[K,de]=n.useState(""),[he,be]=n.useState(0),[ge,fe]=n.useState(.12),[me,pe]=n.useState(null),[te,ve]=n.useState(()=>N??(z?Zn():[])),[_e,ne]=n.useState(null),[we,ae]=n.useState(!1),[ue,I]=n.useState(null),[Y,le]=n.useState(""),Z=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),oe=n.useRef(null),se=n.useRef(null),ye=P??O,xe=W??v,Ee=B??K,ze=E??ge,Le=N??te;n.useEffect(()=>{!N&&z&&Qn(te)},[te,N,z]);const Ye=n.useCallback(J=>{ve(J),d?.(J)},[d]),Xe=n.useCallback(J=>{V(J),M?.(J)},[M]),Ke=n.useCallback(J=>{q(J),X?.(J)},[X]),He=n.useCallback(J=>{de(J),J&&$?.(J)},[$]),Ce=n.useMemo(()=>["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)"],[]),Ne=c&&c.length>0?c:Ce,Be=Ne[0],$e=n.useMemo(()=>Fe(Be),[Be]),De=n.useMemo(()=>rt($e.h,ye,xe),[$e.h,ye,xe]),Re=n.useCallback((J,je,ke,Te,Ue)=>{const dt=f??Ue??me??Ne.length,Qe=dt!==void 0?Math.max(y,Math.min(T,dt)):void 0;if(je==="shade-chain"){const Oe=Qe??Math.max(y,5),Ge=Xt({h:J,s:$e.s||.7,v:$e.v||.6},Oe,ze);g?.(Ge);return}let et;const ot=je==="custom"&&_e?Le.find(Oe=>Oe.id===_e):null;ot&&ot.angles.length>0?et=ot.angles.map(Oe=>((J+Oe)%360+360)%360):et=rt(J,je,ke);let Ae;if(Te&&un[Te]?Ae=yt(et,Te):Ae=et.map(Oe=>Pe({h:Oe,s:$e.s||.7,v:$e.v||.85})),ot?.lightnessOffsets?.length&&(Ae=Ae.map((Oe,Ge)=>{const Pt=ot.lightnessOffsets?.[Ge];if(Pt==null)return Oe;const wt=Fe(Oe);return Pe({h:wt.h,s:wt.s,v:Math.max(.05,Math.min(.98,wt.v+Pt))})})),Qe!==void 0){for(;Ae.length<Qe;){const Oe=Ae[Ae.length-1]||"#888888",Ge=Fe(Oe);Ae.push(Pe({h:(Ge.h+18)%360,s:Ge.s,v:Ge.v}))}Ae=Ae.slice(0,Qe)}else{for(;Ae.length<y;)Ae.push(Ae[Ae.length-1]||"var(--nice-text-secondary, #888888)");Ae.length>T&&(Ae=Ae.slice(0,T))}g?.(Ae)},[$e.s,$e.v,y,T,g,f,me,Ne.length,ze,_e,Le]),vt=n.useCallback(J=>{if(!A){if(ye==="custom"){const je=Pe({h:J,s:$e.s||.7,v:$e.v||.85}),ke=[...Ne];ke[he]=je,g?.(ke);return}Re(J,ye,xe,Ee)}},[A,ye,xe,Ee,Re,$e.s,$e.v,Ne,he,g]),p=n.useCallback(J=>{if(A||(Xe(J),J==="custom"))return;const je=bt(J).length,ke=je<=1;if(f==null&&!ke){const Te=Math.max(y,Math.min(T,je));pe(Te),Re($e.h,J,xe,Ee,Te)}else Re($e.h,J,xe,Ee)},[A,$e.h,xe,Ee,Xe,Re,f,y,T]),Q=n.useCallback(J=>{A||(Ke(J),Re($e.h,ye,J,Ee))},[A,$e.h,ye,Ee,Ke,Re]),ce=n.useCallback(J=>{if(A)return;He(J);const je=rt($e.h,ye,xe),ke=yt(je,J);g?.(ke.slice(0,T))},[A,$e.h,ye,xe,T,He,g]),Se=n.useCallback((J,je)=>{if(A)return;const ke=[...Ne];ke[J]=je,g?.(ke)},[A,Ne,g]),Me=n.useCallback(()=>{if(A||Ne.length>=T)return;const J=Fe(Ne[Ne.length-1]),je=Pe({h:(J.h+30)%360,s:J.s,v:J.v});g?.([...Ne,je])},[A,Ne,T,g]),qe=n.useCallback(J=>{if(A||Ne.length<=y)return;const je=Ne.filter((ke,Te)=>Te!==J);g?.(je),he>=je.length&&be(Math.max(0,je.length-1))},[A,Ne,y,g,he]),Ze=n.useCallback(()=>{if(A)return;const J=Math.max(y,Math.min(T,bt(ye).length)),je=pn(ye,J,xe);g?.(je)},[A,y,T,ye,xe,g]),Dt=n.useMemo(()=>{if(!H)return[];const J=Ne[he]||Ne[0];return mn(Fe(J),s)},[H,Ne,he,s]),_t=Ne[he]||Ne[0],kt=n.useMemo(()=>{const J=Fe(_t);return Pe({h:(J.h+180)%360,s:J.s,v:J.v})},[_t]);n.useLayoutEffect(()=>{if(!we||!oe.current)return;le(Je.scopeThemeClass(oe.current));const J=()=>{const je=oe.current?.getBoundingClientRect();if(!je)return;const ke=600;let Te=je.left;Te+ke>window.innerWidth-8&&(Te=Math.max(8,window.innerWidth-ke-8));let Ue=je.bottom+6;Ue>window.innerHeight*.5&&(Ue=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,540)-8)),I({left:Te,top:Ue})};return J(),window.addEventListener("scroll",J,!0),window.addEventListener("resize",J),()=>{window.removeEventListener("scroll",J,!0),window.removeEventListener("resize",J)}},[we]),n.useEffect(()=>{if(!we)return;const J=je=>{const ke=je.target;oe.current?.contains(ke)||se.current?.contains(ke)||(ke instanceof Element?ke:ke?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"], [aria-modal="true"]')||ae(!1)};return document.addEventListener("mousedown",J),()=>{document.removeEventListener("mousedown",J)}},[we]),r.useOverlayFocus(se,{open:we,modal:!1,onClose:()=>ae(!1)});const zt=n.useRef(null);if(r.useRovingFocus(zt,{orientation:"horizontal",itemSelector:".nice-palette__variation-chip"}),u)return null;const Lt=G.length>0?G:hn,kn=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(We.NiceSelect,{label:m("colorPalette.harmony","Harmony"),labelPlacement:"left",size:"sm",disabled:A,value:ye==="custom"&&_e?`custom:${_e}`:ye,onChange:J=>{const je=Array.isArray(J)?J[0]:J;if(typeof je=="string")if(je.startsWith("custom:")){const ke=je.slice(7);ne(ke),p("custom")}else ne(null),p(je)},options:[...Jn.map(J=>({value:J,label:Vn[J]})),...Le.map(J=>({value:`custom:${J.id}`,label:J.name}))],renderOption:(J,je)=>{const ke=String(J.value),Te=ke.startsWith("custom:"),Ue=Te?Le.find(et=>et.id===ke.slice(7)):null,dt=Ue?Ue.angles:void 0,Qe=Te?"custom":ke;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:Ut(Qe,{angles:dt,size:16,count:f})}),e.jsx("span",{style:{fontWeight:je?600:400},children:J.label})]})}}),ye==="shade-chain"&&e.jsx(tt.NiceNumberInput,{label:m("colorPalette.step","Step"),labelPlacement:"left",size:"sm",min:.02,max:.5,step:.02,precision:2,value:ze,onChange:J=>{const je=typeof J=="number"?J:Number(J);Number.isNaN(je)||(fe(je),L?.(je),Re($e.h,ye,xe,Ee))},showStepper:!0,disabled:A}),e.jsx(tt.NiceNumberInput,{label:m("colorPalette.colors","Colors"),labelPlacement:"left",size:"sm",min:Math.max(2,y),max:Math.min(12,T),step:1,precision:0,value:f??me??Ne.length,onChange:J=>{const je=typeof J=="number"?J:Number(J);if(!Number.isFinite(je))return;const ke=Math.max(Math.max(2,y),Math.min(Math.min(12,T),Math.round(je)));pe(ke),ye==="shade-chain"?g?.(Xt({h:$e.h,s:$e.s||.7,v:$e.v||.6},ke,ze)):setTimeout(()=>Re($e.h,ye,xe,Ee),0)},showStepper:!0,disabled:A})]}),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((J,je)=>e.jsxs("div",{role:"presentation",className:`nice-palette__swatch-wrapper ${he===je?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>be(je),onFocus:()=>be(je),children:[e.jsx("span",{className:"nice-palette__swatch",style:{background:J}}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:J.toUpperCase(),maxLength:7,disabled:A,onClick:ke=>ke.stopPropagation(),onChange:ke=>Se(je,ke.target.value),"aria-label":m("colorPalette.colorN","Color {n}").replace("{n}",String(je+1))}),Ne.length>y&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:ke=>{ke.stopPropagation(),qe(je)},disabled:A,"aria-label":m("colorPalette.removeColor","Remove color"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},je)),Ne.length<T&&e.jsxs("button",{type:"button",className:"nice-palette__add-btn",onClick:Me,disabled:A,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:kt},title:kt.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:kt.toUpperCase()})]}),w&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:Ze,disabled:A,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")]})]})})]}),wn=e.jsx("div",{className:"nice-palette__tab",children:Dt.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:zt,className:"nice-palette__variation-strip",role:"group","aria-label":m("colorPalette.tintsShades","Tints & Shades"),children:Dt.map((J,je)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:J},title:J.toUpperCase(),onClick:()=>{A||Se(he,J)},onKeyDown:ke=>{!A&&(ke.key==="Enter"||ke.key===" ")&&(ke.preventDefault(),Se(he,J))},role:"button","aria-label":J.toUpperCase()},je))})]}):e.jsx("div",{className:"nice-palette__empty",children:m("colorPalette.noVariationsAvailable","No variations available.")})}),Nn=e.jsx("div",{className:"nice-palette__tab",children:e.jsx("div",{className:"nice-palette__preset-grid",children:Lt.map(J=>{const je=yt(De,J);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${Ee===J?"nice-palette__preset-card--active":""}`,onClick:()=>ce(J),disabled:A,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:je.map((ke,Te)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:ke}},Te))}),e.jsx("span",{className:"nice-palette__preset-label",children:Wn[J]})]},J)})})}),Cn=e.jsxs("div",{className:"nice-palette__tab",children:[ee&&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(Gn,{hex:_t})]}),ie&&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(qn,{colors:Ne})]})]}),Sn=e.jsx("div",{className:"nice-palette__tab nice-palette__custom-schemes",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[Le.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.")}),Le.map(J=>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:Ut("custom",{angles:J.angles,size:16})}),e.jsx("span",{style:{flex:1},children:J.name}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>{ne(J.id),p("custom")},disabled:A,children:m("colorPalette.use","Use")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>Ye(Le.filter(je=>je.id!==J.id)),disabled:A,"aria-label":m("colorPalette.delete","Delete {name}").replace("{name}",String(J.name)),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},J.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:A,onClick:()=>{const J=Fe(Ne[0]).h,je=Ne.map(ke=>(Fe(ke).h-J+540)%360-180);D.prompt({title:m("colorPalette.schemeNamePrompt","Scheme name"),defaultValue:`Scheme ${Le.length+1}`}).then(ke=>{if(!ke)return;const Te={id:`cs-${Date.now()}`,name:ke,angles:je};Ye([...Le,Te])})},children:m("colorPalette.saveCurrentAsScheme","+ Save current as scheme")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A||Le.length===0,onClick:()=>{typeof navigator>"u"||navigator.clipboard?.writeText(JSON.stringify(Le,null,2))},children:m("colorPalette.exportJson","Export JSON")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A,onClick:()=>{D.prompt({title:m("colorPalette.pasteSchemesPrompt","Paste the schemes JSON")}).then(J=>{if(J)try{const je=JSON.parse(J);Array.isArray(je)&&Ye(je)}catch{}})},children:m("colorPalette.importJson","Import JSON")})]})]})}),it=[{id:"colors",label:m("colorPalette.colors","Colors"),content:kn}];re&&Lt.length>0&&it.push({id:"presets",label:m("colorPalette.presets","Presets"),content:Nn}),H&&it.push({id:"variations",label:m("colorPalette.variations","Variations"),content:wn}),(ee||ie)&&it.push({id:"info",label:m("colorPalette.info","Info"),content:Cn}),it.push({id:"schemes",label:m("colorPalette.schemes","Schemes"),content:Sn});const En=e.jsxs("div",{className:"nice-palette__popup-header",children:[U&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Xn,{hues:De,colors:Ne,baseHue:$e.h,onBaseHueChange:vt,mode:ye,distance:xe,disabled:A}),(ye==="analogous"||ye==="split-complementary"||ye==="analogous-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsx("label",{children:m("colorPalette.distance","Distance: {dist}°").replace("{dist}",String(xe))}),e.jsx("input",{type:"range",min:10,max:90,value:xe,onChange:J=>Q(Number(J.target.value)),disabled:A,className:"nice-palette__distance-slider","aria-label":m("colorPalette.distanceLabel","Distance")})]})]}),e.jsx("button",{type:"button",className:"nice-palette__confirm",onClick:()=>ae(!1),"aria-label":m("controls.confirm","Confirm"),title:m("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),$n=e.jsxs("div",{className:"nice-palette nice-palette--studio",children:[En,e.jsx(lt.NiceTabs,{tabs:it,variant:"enclosed",size:"sm"})]});return e.jsxs("div",{ref:h,id:S,className:`nice-field nice-palette-field ${A?"nice-palette--disabled":""} ${F==="left"?"nice-field--label-left":""} ${x?"nice-field--loading":""} ${C?"nice-field--error":""} ${i||""}`,style:a,"data-testid":b,children:[D.element,R&&e.jsx("label",{htmlFor:S,className:"nice-field__label",children:R}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("div",{ref:oe,className:"nice-palette__field-swatches",role:"button",tabIndex:A||_?-1:0,"aria-haspopup":"dialog","aria-expanded":we,"aria-readonly":_||void 0,"aria-label":m("colorPalette.openStudio","Open palette studio"),onClick:()=>{!A&&!_&&ae(J=>!J)},onKeyDown:J=>{!A&&!_&&(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),ae(je=>!je))},children:Ne.map((J,je)=>e.jsx("span",{role:"presentation",className:"nice-palette__field-swatch",style:{background:J},title:J.toUpperCase(),onClick:ke=>{ke.stopPropagation(),!A&&!_&&(be(je),ae(!0))}},je))}),x&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),we&&ue&&Z&&nt.createPortal(e.jsx("div",{ref:se,className:`nice-palette__popup${Y?` ${Y}`:""}`,"data-theme":Y==="nice-dark"?"dark":Y==="nice-light"?"light":void 0,role:"dialog","aria-label":m("colorPalette.studio","Palette studio"),style:{position:"fixed",left:ue.left,top:ue.top,zIndex:1e3},children:$n}),Z)]}),typeof C=="string"&&C&&e.jsx("div",{className:"nice-field__error",role:"alert",children:C})]})}),{displayName:"NiceColorPalette"});function It(){return{type:"linear",angle:90,stops:[{color:"var(--nice-primary, #3b82f6)",position:0},{color:"var(--nice-accent, #8b5cf6)",position:100}]}}function Mt(t){const i=t.stops.slice().sort((o,c)=>o.position-c.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",c=t.size||"farthest-corner",g=t.positionX??50,y=t.positionY??50;return`${a}radial-gradient(${o} ${c} at ${g}% ${y}%, ${i})`}case"conic":{const o=t.angle??0,c=t.positionX??50,g=t.positionY??50;return`${a}conic-gradient(from ${o}deg at ${c}% ${g}%, ${i})`}}}function fn(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 c=o.split(",").map(M=>M.trim());let g=90,y=0;const T=c[0].match(/^(\d+)deg$/);T&&(g=parseInt(T[1]),y=1);const P=Ct(c.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 c=o.split(",").map(y=>y.trim()),g=Ct(c.filter(y=>y.includes("#")||y.includes("rgb")));return{type:"radial",angle:0,repeating:a,stops:g.length>=2?g:It().stops}}if(i.includes("conic-gradient")){const o=i.match(/conic-gradient\((.+)\)/)?.[1];if(!o)return null;const c=o.split(",").map(y=>y.trim()),g=Ct(c.filter(y=>y.includes("#")||y.includes("rgb")));return{type:"conic",angle:0,repeating:a,stops:g.length>=2?g:It().stops}}return null}function Ct(t){return t.map((i,a,o)=>{const c=i.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(c){const g=c[2]?parseFloat(c[2]):a/Math.max(1,o.length-1)*100;return{color:c[1],position:g}}return{color:i,position:a/Math.max(1,o.length-1)*100}})}function ti(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ni(t=2){const i=["linear","radial","conic"],a=i[Math.floor(Math.random()*i.length)],o=[];for(let c=0;c<t;c++)o.push({color:ti(),position:Math.round(c/(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 yn=[{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}}],ii=Object.assign(n.forwardRef(({id:t,className:i,style:a,accessMode:o,value:c,onChange:g,showCssOutput:y=!0,showPresets:T=!0,showEditor:P=!0,showRandom:M=!0,maxStops:W=10,label:X,labelPlacement:B="top",disabled:$,readOnly:U,loading:ie,error:ee,errorPlacement:re="bottom",width:G,"data-testid":H},w)=>{const s=r.useNiceAccessMode(o,t),R=s==="hidden";s==="disabled"&&($=!0);const F=U||s==="readOnly",A=r.useControlId(t),{t:k}=r.useNiceTranslation(),x=c??It(),C=n.useMemo(()=>Mt(x),[x]),[f,E]=n.useState(0),[L,N]=n.useState(""),d=n.useRef(null),[z,b]=n.useState(!1),[h,l]=n.useState(null),[u,_]=n.useState(""),m=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),D=n.useRef(null),O=n.useRef(null),V=typeof G=="number"?G:340;n.useLayoutEffect(()=>{if(!z||!D.current)return;_(Je.scopeThemeClass(D.current));const j=()=>{const Z=D.current?.getBoundingClientRect();if(!Z)return;let oe=Z.left;oe+V>window.innerWidth-8&&(oe=Math.max(8,window.innerWidth-V-8));let se=Z.bottom+6;se>window.innerHeight*.5&&(se=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,520)-8)),l({left:oe,top:se})};return j(),window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}},[z,V]),n.useEffect(()=>{if(!z)return;const j=Z=>{const oe=Z.target;D.current?.contains(oe)||O.current?.contains(oe)||(oe instanceof Element?oe:oe?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||b(!1)};return document.addEventListener("mousedown",j),()=>{document.removeEventListener("mousedown",j)}},[z]),r.useOverlayFocus(O,{open:z,modal:!1,onClose:()=>b(!1)});const v=n.useCallback(j=>{g?.(j)},[g]),q=n.useCallback(j=>{$||v({...x,type:j})},[$,x,v]),K=n.useCallback(j=>{$||v({...x,angle:j})},[$,x,v]),de=n.useCallback(j=>{$||v({...x,repeating:j})},[$,x,v]),he=n.useCallback(j=>{$||v({...x,shape:j})},[$,x,v]),be=n.useCallback((j,Z)=>{if($)return;const oe=x.stops.map((se,ye)=>ye===j?{...se,...Z}:se);v({...x,stops:oe})},[$,x,v]),ge=n.useRef(!1),fe=n.useCallback((j,Z)=>{if($||!d.current)return;j.stopPropagation(),j.preventDefault(),E(Z),ge.current=!1;const oe=ye=>{if(!d.current)return;ge.current=!0;const xe=d.current.getBoundingClientRect(),Ee=Math.round(Math.max(0,Math.min(100,(ye.clientX-xe.left)/xe.width*100)));be(Z,{position:Ee})},se=()=>{document.removeEventListener("pointermove",oe),document.removeEventListener("pointerup",se),document.removeEventListener("pointercancel",se)};document.addEventListener("pointermove",oe),document.addEventListener("pointerup",se),document.addEventListener("pointercancel",se)},[$,be]),me=n.useCallback(()=>{if($||x.stops.length>=W)return;const j=x.stops.slice().sort((xe,Ee)=>xe.position-Ee.position);let Z=0,oe=j[0];for(let xe=0;xe<j.length-1;xe++){const Ee=j[xe+1].position-j[xe].position;Ee>Z&&(Z=Ee,oe=j[xe])}const se=Math.round(oe.position+Z/2),ye="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");v({...x,stops:[...x.stops,{color:ye,position:se}]})},[$,x,W,v]),pe=n.useCallback(j=>{if($||x.stops.length<=2)return;const Z=x.stops.filter((oe,se)=>se!==j);v({...x,stops:Z}),f>=Z.length&&E(Z.length-1)},[$,x,f,v]),te=(j,Z)=>{const oe=x.stops[Z];if($||!oe)return;const se=j.shiftKey?10:1,ye=j.key==="ArrowLeft"||j.key==="ArrowDown"?oe.position-se:j.key==="ArrowRight"||j.key==="ArrowUp"?oe.position+se:j.key==="PageDown"?oe.position-10:j.key==="PageUp"?oe.position+10:j.key==="Home"?0:j.key==="End"?100:null;ye!==null?(j.preventDefault(),be(Z,{position:Math.max(0,Math.min(100,ye))})):(j.key==="Delete"||j.key==="Backspace")&&x.stops.length>2&&(j.preventDefault(),pe(Z))},ve=n.useCallback(()=>{if($)return;const j=2+Math.floor(Math.random()*3);v(ni(j))},[$,v]),_e=n.useCallback(()=>{if($||!L.trim())return;const j=fn(L);j&&v(j)},[$,L,v]),ne=n.useCallback(j=>{if($||!d.current||x.stops.length>=W)return;const Z=j.target;if(ge.current||Z.closest(".nice-gradient__stop-marker")){ge.current=!1;return}const oe=d.current.getBoundingClientRect(),se=Math.round((j.clientX-oe.left)/oe.width*100),ye="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),xe=[...x.stops,{color:ye,position:se}];v({...x,stops:xe}),E(xe.length-1)},[$,x,W,v]),we=n.useMemo(()=>x.stops.slice().sort((j,Z)=>j.position-Z.position),[x.stops]),ae=n.useMemo(()=>`linear-gradient(90deg, ${we.map(j=>`${j.color} ${j.position}%`).join(", ")})`,[we]);if(R)return null;const ue=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(j=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${x.type===j?"nice-gradient__type-btn--active":""}`,onClick:()=>q(j),disabled:$,"aria-pressed":x.type===j,children:j.charAt(0).toUpperCase()+j.slice(1)},j)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:x.repeating??!1,onChange:j=>de(j.target.checked),disabled:$}),k("controls.repeating","Repeating")]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[x.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.angle","Angle: {angle}°").replace("{angle}",String(x.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:x.angle,onChange:j=>K(Number(j.target.value)),disabled:$,className:"nice-gradient__slider","aria-label":k("gradient.angle","Angle")}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(j=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${x.angle===j?"nice-gradient__angle-btn--active":""}`,onClick:()=>K(j),disabled:$,title:`${j}°`,"aria-label":`${j}°`,"aria-pressed":x.angle===j,children:e.jsx("span",{style:{transform:`rotate(${j}deg)`,display:"inline-flex"},children:e.jsx(r.NiceIcon,{name:"arrow-right",size:14})})},j))})]}),x.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.shape","Shape:")}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(j=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(x.shape||"ellipse")===j?"nice-gradient__shape-btn--active":""}`,onClick:()=>he(j),disabled:$,"aria-pressed":(x.shape||"ellipse")===j,children:j},j))})]}),(x.type==="radial"||x.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.center","Center: {positionX}%, {positionY}%").replace("{positionX}",String(x.positionX??50)).replace("{positionY}",String(x.positionY??50))}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:x.positionX??50,onChange:j=>v({...x,positionX:Number(j.target.value)}),disabled:$,className:"nice-gradient__slider","aria-label":k("gradient.centerX","Horizontal center")}),e.jsx("input",{type:"range",min:0,max:100,value:x.positionY??50,onChange:j=>v({...x,positionY:Number(j.target.value)}),disabled:$,className:"nice-gradient__slider","aria-label":k("gradient.centerY","Vertical center")})]})]}),x.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.startAngle","Start angle: {angle}°").replace("{angle}",String(x.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:x.angle,onChange:j=>K(Number(j.target.value)),disabled:$,className:"nice-gradient__slider","aria-label":k("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:ae},onClick:ne,children:x.stops.map((j,Z)=>e.jsx("div",{className:`nice-gradient__stop-marker ${f===Z?"nice-gradient__stop-marker--active":""}`,style:{left:`${j.position}%`},onPointerDown:oe=>fe(oe,Z),onClick:oe=>{oe.stopPropagation(),E(Z),ge.current=!1},onFocus:()=>E(Z),onKeyDown:oe=>te(oe,Z),role:"slider",tabIndex:$?-1:0,"aria-label":k("gradient.stop","Stop {n}").replace("{n}",String(Z+1)),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":j.position,"aria-valuetext":`${j.color} ${j.position}%`,title:`${j.color} @ ${j.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:j.color}})},Z))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:me,disabled:$||x.stops.length>=W,title:k("controls.addStop","Add stop"),"aria-label":k("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:we.map((j,Z)=>{const oe=x.stops.indexOf(j);return e.jsxs("div",{role:"presentation",className:`nice-gradient__stop-row ${f===oe?"nice-gradient__stop-row--active":""}`,onClick:()=>E(oe),onFocus:()=>E(oe),children:[e.jsx("input",{type:"color",value:j.color,onChange:se=>be(oe,{color:se.target.value}),disabled:$,className:"nice-gradient__stop-color","aria-label":k("gradient.stopColor","Stop color")}),e.jsx("input",{type:"text",value:j.color.toUpperCase(),maxLength:7,onChange:se=>be(oe,{color:se.target.value}),disabled:$,className:"nice-gradient__stop-hex","aria-label":k("gradient.stopHex","Stop color (hex)")}),e.jsx("input",{type:"number",min:0,max:100,value:j.position,onChange:se=>be(oe,{position:Number(se.target.value)}),disabled:$,className:"nice-gradient__stop-pos","aria-label":k("gradient.stopPosition","Stop position")}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),x.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>pe(oe),disabled:$,"aria-label":k("controls.removeStop","Remove stop"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},oe)})})})]}),M&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:ve,disabled:$,title:k("controls.randomGradient","Random gradient"),"aria-label":k("controls.randomGradient","Random gradient"),children:[e.jsx(r.NiceIcon,{name:"shuffle",size:14})," ",k("controls.randomGradient2","Random Gradient")]})]}),I=e.jsx("div",{className:"nice-gradient__tab",children:e.jsx("div",{className:"nice-gradient__preset-grid",children:yn.map((j,Z)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{$||v(j.value)},disabled:$,title:j.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:Mt(j.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:j.name})]},Z))})}),Y=e.jsxs("div",{className:"nice-gradient__tab",children:[e.jsxs("div",{className:"nice-gradient__css-output",children:[e.jsx("code",{children:`background: ${C};`}),e.jsx("button",{type:"button",className:"nice-gradient__copy-btn",onClick:()=>navigator.clipboard?.writeText(`background: ${C};`),title:k("controls.copyCss","Copy CSS"),"aria-label":k("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:k("controls.pasteCssGradientToImport","Paste CSS gradient to import..."),value:L,onChange:j=>N(j.target.value),disabled:$,"aria-label":k("gradient.importCss","CSS gradient to import")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:_e,disabled:$,children:k("controls.import","Import")})]})]}),le=[{id:"editor",label:k("controls.editor","Editor"),content:ue}];return T&&le.push({id:"presets",label:k("controls.presets","Presets"),content:I}),y&&le.push({id:"css",label:"CSS",content:Y}),e.jsxs("div",{ref:w,id:A,className:`nice-field nice-gradient-field ${$?"nice-gradient--disabled":""} ${B==="left"?"nice-field--label-left":""} ${ie?"nice-field--loading":""} ${ee?"nice-field--error":""} ${re==="right"?"nice-field--error-right":""} ${i||""}`,style:a,"data-testid":H,children:[X&&e.jsx("label",{htmlFor:A,className:"nice-field__label",children:X}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("button",{ref:D,type:"button",className:"nice-gradient__swatch",style:{background:C},"aria-haspopup":"dialog","aria-expanded":z,"aria-readonly":F||void 0,"aria-label":k("controls.openGradientEditor","Open gradient editor"),disabled:$,onClick:()=>{!$&&!F&&b(j=>!j)}}),ie&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),re==="right"&&typeof ee=="string"&&ee&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ee}),z&&h&&m&&nt.createPortal(e.jsx("div",{ref:O,className:`nice-gradient__popup${u?` ${u}`:""}`,"data-theme":u==="nice-dark"?"dark":u==="nice-light"?"light":void 0,role:"dialog","aria-label":k("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:C}}),e.jsx("button",{type:"button",className:"nice-gradient__confirm",onClick:()=>b(!1),"aria-label":k("controls.confirm","Confirm"),title:k("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),e.jsx(lt.NiceTabs,{tabs:le,variant:"enclosed",size:"sm"})]})}),m)]}),re!=="right"&&typeof ee=="string"&&ee&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ee})]})}),{displayName:"NiceGradientPicker"}),oi=[{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"}],ai=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}],si=n.forwardRef(function(i,a){const{enableAI:o=!0,aiModel:c,enableImprove:g=!0,enableTranslate:y=!0,enableGenerate:T=!0,toolbar:P,languages:M=oi,textStyles:W=ai,onImprove:X,onTranslate:B,onGenerate:$,showAIToolbar:U=!0,value:ie,onChange:ee,...re}=i,G=n.useRef(null),[H,w]=n.useState(!1),[s,R]=n.useState(!1),[F,A]=n.useState(!1),[k,x]=n.useState(""),[C,f]=n.useState(""),[E,L]=n.useState("professional"),[N,d]=n.useState(""),[z,b]=n.useState(M[0]?.code||"en"),[h,l]=n.useState(""),[u,_]=n.useState(""),{t:S}=on.useNiceTranslation(),m=r.useNiceAI(),{improveText:D,translate:O,generateHtml:V,isLoading:v}=r.useTextImprovement(),q=o&&m.isConfigured,K=n.useCallback(()=>{const te=window.getSelection();return te&&te.toString().trim()?te.toString():""},[]),de=n.useCallback(te=>{const ve=window.getSelection();if(ve&&ve.rangeCount>0){const _e=ve.getRangeAt(0);_e.deleteContents();const ne=document.createElement("div");ne.innerHTML=te;const we=document.createDocumentFragment();for(;ne.firstChild;)we.appendChild(ne.firstChild);if(_e.insertNode(we),G.current){const ae=G.current.innerHTML;ee?.(ae)}}},[ee]),he=n.useCallback(async(te="professional")=>{if(!q||!g)return"";const ve=K();if(!ve)return"";x(ve),L(te),w(!0),f("");try{const _e=await D(ve,te);return f(_e),X?.(ve,_e,te),_e}catch{return f(S("htmlEditorAI.improveFailed","Failed to improve text")),""}},[q,g,K,D,X,S]),be=n.useCallback(async te=>{if(!q||!y)return"";const ve=K();if(!ve)return"";x(ve),b(te),R(!0),d("");try{const _e=M.find(we=>we.code===te)?.label||te,ne=await O(ve,_e);return d(ne),B?.(ve,ne,te),ne}catch{return d(S("htmlEditorAI.translateFailed","Failed to translate text")),""}},[q,y,K,O,M,B,S]),ge=n.useCallback(async te=>{if(!q||!T||!te.trim())return"";l(te),_("");try{const ve=await V(te);return _(ve),$?.(te,ve),ve}catch{return _(S("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[q,T,V,$,S]),fe=n.useCallback(()=>{C&&de(C),w(!1),f("")},[C,de]),me=n.useCallback(()=>{N&&de(N),R(!1),d("")},[N,de]),pe=n.useCallback(()=>{if(u&&G.current){document.execCommand("insertHTML",!1,u);const te=G.current.innerHTML;ee?.(te)}A(!1),_(""),l("")},[u,ee]);return n.useImperativeHandle(a,()=>({getEditor:()=>G.current,focus:()=>G.current?.focus(),getValue:()=>G.current?.innerHTML||"",setValue:te=>{G.current&&(G.current.innerHTML=te,ee?.(te))},getSelection:K,insertHtml:te=>{document.execCommand("insertHTML",!1,te),G.current&&ee?.(G.current.innerHTML)},improveSelection:he,translateSelection:be,generateHtml:ge})),n.useCallback(te=>{G.current=te},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":i["data-testid"],children:[U&&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:()=>he(),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:W.map(({style:te,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>he(te),children:ve},te))})]}),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:M.map(({code:te,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>be(te),children:ve},te))})]}),T&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>A(!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(In.NiceHtmlEditor,{value:ie,onChange:ee,toolbar:P,...re})}),H&&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:W.map(({style:te,label:ve})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${E===te?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{L(te),he(te)},children:ve},te))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>w(!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:k})]}),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:C})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:fe,disabled:!C||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:()=>{w(!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:te=>{b(te.target.value),be(te.target.value)},className:"nice-html-editor-ai__language-select",children:M.map(({code:te,label:ve})=>e.jsx("option",{value:te,children:ve},te))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>R(!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:k})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:M.find(te=>te.code===z)?.label||z}),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:me,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:()=>{R(!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:()=>{A(!1),_(""),l("")},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:te=>l(te.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")})]}),u&&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:u}}),e.jsx("h5",{children:S("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:u})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:pe,disabled:!u||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:()=>{A(!1),_(""),l("")},children:S("htmlEditorAI.cancel","Cancel")})]})]})]})}),ri=[{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 ci(t){let i=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return i=i.replace(/```(\w*)\n([\s\S]*?)```/g,(a,o,c)=>`<pre><code class="language-${o}">${c.trim()}</code></pre>`),i=i.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(a,o,c,g)=>{const y=o.split("|").filter(P=>P.trim()).map(P=>`<th>${P.trim()}</th>`).join(""),T=g.trim().split(`
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),r=require("@nice2dev/ui-core"),n=require("react"),nt=require("react-dom"),We=require("./NiceSelect-BNPXs6FQ.cjs"),lt=require("./pickerCommons-CwcCc8Qi.cjs"),Je=require("./devops-cgRBnZVX.cjs"),mt=require("./NiceForm-Bysp66Ef.cjs"),tt=require("./no-code-B3BHeyG-.cjs"),on=require("@nice2dev/i18n"),In=require("./NiceHtmlEditor-C1OVtLQ6.cjs"),Ie=require("./NiceButton-DzCqkG5a.cjs"),Ot=require("./NiceColorPicker-BLwYNSXJ.cjs"),Et=require("./NiceCodeEditor-D0QZW88r.cjs"),jt=require("./injectStyleOnce-DeWaxcdf.cjs"),Mn=({min:t=0,max:i=100,step:a=1,startValue:o=t,endValue:c=i,onChange:g,showLabels:y=!0,formatLabel:T,valuePlacement:P="none",label:M,error:W,helperText:X,required:B,disabled:$,readOnly:U,loading:ie,size:ee="md",id:re,className:G,style:H,accessMode:w,showKeyboardHints:s,labelPlacement:R,errorPlacement:F,labelWidth:A,controlWidth:k})=>{const x=r.useNiceAccessMode(w,re),C=x==="hidden";(x==="disabled"||x==="readOnly")&&($=!0);const{t:f}=r.useNiceTranslation(),E=r.useControlId(re),L=n.useRef(null),N=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=u=>(u-t)/(i-t)*100,z=u=>T?T(u):String(u),b=n.useCallback(u=>{const _=Math.round(u/a)*a;return Math.max(t,Math.min(i,_))},[t,i,a]),h=n.useCallback((u,_)=>{u.preventDefault();const S=L.current;if(!S||$)return;const m=O=>{const V=S.getBoundingClientRect(),v=Math.max(0,Math.min(1,(O.clientX-V.left)/V.width)),q=b(t+v*(i-t));_==="start"?g?.(Math.min(q,c),c):g?.(o,Math.max(q,o))},D=()=>{document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",D)};document.addEventListener("pointermove",m),document.addEventListener("pointerup",D)},[t,i,b,o,c,g,$]),l=(u,_)=>{if($||U)return;const S=_==="start"?o:c,m=_==="start"?t:o,D=_==="start"?c:i,O=Math.max(a,(i-t)/10),V=u.key==="ArrowRight"||u.key==="ArrowUp"?S+a:u.key==="ArrowLeft"||u.key==="ArrowDown"?S-a:u.key==="PageUp"?S+O:u.key==="PageDown"?S-O:u.key==="Home"?m:u.key==="End"?D:null;if(V===null)return;u.preventDefault();const v=Math.max(m,Math.min(D,b(V)));_==="start"?g?.(v,c):g?.(o,v)};return C?null:e.jsxs("div",{className:`nice-field nice-field--${ee} nice-field--rangeslider ${R==="left"?"nice-field--label-left":""} ${F==="right"?"nice-field--error-right":""} ${W?"nice-field--error":""} ${ie?"nice-field--loading":""} ${G||""}`,style:{...H,...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...k!=null&&{"--nice-field-control-width":typeof k=="number"?`${k}px`:k}},"aria-busy":ie||void 0,children:[(M||P==="right"&&R!=="left")&&(R!=="left"?e.jsxs("div",{className:"nice-range-slider__header",children:[M?e.jsx("label",{className:"nice-field__label",htmlFor:E,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:N,size:"sm"})]})}):e.jsx("span",{}),P==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--header",children:[z(o)," – ",z(c)]})]}):M&&e.jsx("label",{className:"nice-field__label",htmlFor:E,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:N,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":""} ${M?"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(c)-d(o)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(o)}%`},onPointerDown:u=>U?void 0:h(u,"start"),onKeyDown:u=>l(u,"start"),role:"slider","aria-label":f("rangeSlider.min","Minimum"),"aria-valuemin":t,"aria-valuemax":c,"aria-valuenow":o,"aria-valuetext":z(o),"aria-disabled":$||void 0,"aria-readonly":U||void 0,tabIndex:$?-1:0,id:E}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(c)}%`},onPointerDown:u=>U?void 0:h(u,"end"),onKeyDown:u=>l(u,"end"),role:"slider","aria-label":f("rangeSlider.max","Maximum"),"aria-valuemin":o,"aria-valuemax":i,"aria-valuenow":c,"aria-valuetext":z(c),"aria-disabled":$||void 0,"aria-readonly":U||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(c)}%`},children:z(c)})]}),P==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[z(o)," – ",z(c)]})]}),P==="right"&&R==="left"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[z(o)," – ",z(c)]}),ie&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),F==="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),F==="right"&&!W&&X&&e.jsx("div",{className:"nice-field__helper",children:X})]}),F!=="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),F!=="right"&&!W&&X&&e.jsx("div",{className:"nice-field__helper",children:X})]})},Tn={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160,small:64,medium:80,large:100},ut=6,st=135,an=405,at=an-st;function $t(t,i,a,o){const c=(o-90)*(Math.PI/180);return{x:t+a*Math.cos(c),y:i+a*Math.sin(c)}}function Bt(t,i,a,o,c){const g=$t(t,i,a,o),y=$t(t,i,a,c),T=c-o>180?1:0;return`M ${g.x} ${g.y} A ${a} ${a} 0 ${T} 1 ${y.x} ${y.y}`}const Rn=Object.assign(n.forwardRef(({value:t=0,onChange:i,min:a=0,max:o=100,step:c=1,showValue:g=!0,valueTemplate:y="{value}",label:T,helperText:P,error:M,required:W,disabled:X,readOnly:B,size:$="md",name:U,id:ie,className:ee,style:re,labelPlacement:G="top",errorPlacement:H,labelWidth:w,controlWidth:s,loading:R,isLabelCentered:F=!0,...A},k)=>{const x=r.useControlId(ie),C=n.useRef(!1),f=n.useRef(null),E=typeof $=="number"?$:Tn[$],L=E/2,N=E/2,d=(E-ut*2)/2,z=o>a?(t-a)/(o-a):0,b=st+z*at,h=n.useCallback(m=>{let D=m-st;D<0&&(D+=360),D>at&&(D=D-at<360-D?at:0);const O=Math.max(0,Math.min(1,D/at)),V=a+O*(o-a),v=Math.round(V/c)*c;return Math.max(a,Math.min(o,v))},[a,o,c]),l=n.useCallback(m=>{if(X||B)return;const D=f.current;if(!D)return;const O=D.getBoundingClientRect(),V=m.clientX-O.left-O.width/2,v=m.clientY-O.top-O.height/2;let q=Math.atan2(V,-v)*(180/Math.PI);q<0&&(q+=360);const K=h(q);i?.(K)},[h,X,B,i]);n.useEffect(()=>{const m=O=>{C.current&&l(O)},D=()=>{C.current=!1};return window.addEventListener("pointermove",m),window.addEventListener("pointerup",D),()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",D)}},[l]);const u=n.useCallback(m=>{if(X||B)return;let D=t;const O=Math.max(c,(o-a)/10);m.key==="ArrowUp"||m.key==="ArrowRight"?(m.preventDefault(),D=Math.min(o,t+c)):m.key==="ArrowDown"||m.key==="ArrowLeft"?(m.preventDefault(),D=Math.max(a,t-c)):m.key==="PageUp"||m.key==="PageDown"?(m.preventDefault(),D=Math.max(a,Math.min(o,t+(m.key==="PageUp"?O:-O)))):(m.key==="Home"||m.key==="End")&&(m.preventDefault(),D=m.key==="Home"?a:o),D!==t&&i?.(D)},[t,i,a,o,c,X,B]),_=(y||"{value}").replace("{value}",String(t)),S=$t(L,N,d,b);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${H||"bottom"} nice-field--${typeof $=="string"?$:"md"} ${R?"nice-field--loading":""} ${ee||""}`,style:{...re,...w!=null&&{"--nice-field-label-width":typeof w=="number"?`${w}px`:w},...s!=null&&{"--nice-field-control-width":typeof s=="number"?`${s}px`:s}},"aria-busy":R||void 0,...A,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${G} ${F?"nice-knob-field--label-centered":""}`,children:[T&&e.jsx("label",{htmlFor:x,className:`nice-field__label ${W?"nice-field__label--required":""}`,children:T}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:m=>{f.current=m,typeof k=="function"?k(m):k&&(k.current=m)},className:`nice-knob nice-knob--${$} ${X?"nice-knob--disabled":""} ${M?"nice-knob--error":""}`,role:"slider",id:x,tabIndex:X?-1:0,"aria-valuenow":t,"aria-valuemin":a,"aria-valuemax":o,"aria-disabled":X,"aria-invalid":!!M,onPointerDown:m=>{X||B||(C.current=!0,l(m))},onKeyDown:u,children:[e.jsxs("svg",{width:E,height:E,viewBox:`0 0 ${E} ${E}`,children:[e.jsx("path",{d:Bt(L,N,d,st,an),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:ut,strokeLinecap:"round"}),z>0&&e.jsx("path",{d:Bt(L,N,d,st,b),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:ut,strokeLinecap:"round"}),e.jsx("circle",{cx:S.x,cy:S.y,r:ut,fill:"var(--nice-primary, #3b82f6)"})]}),g&&e.jsx("span",{className:"nice-knob__value",children:_}),U&&e.jsx("input",{type:"hidden",name:U,value:t}),R&&e.jsx("span",{className:"nice-knob__spinner","aria-hidden":"true",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})})]})})]}),M&&e.jsx("div",{className:"nice-field__error",role:"alert",children:M}),!M&&P&&e.jsx("div",{className:"nice-field__helper",children:P})]})}),{displayName:"NiceKnob"}),An=({options:t,value:i,defaultValue:a,onChange:o,searchable:c=!0,clearable:g,loading:y,placeholder:T,label:P,error:M,helperText:W,required:X,disabled:B,readOnly:$,size:U="md",id:ie,className:ee,style:re,data:G,columns:H,valueField:w="id",displayField:s,dropdownWidth:R,menuGap:F,labelPlacement:A,errorPlacement:k,labelWidth:x,controlWidth:C})=>{const f=B||$||y,E=r.useControlId(ie),{t:L}=r.useNiceTranslation(),[N,d]=r.useControllableState({value:i,defaultValue:a,fallbackValue:"",onChange:o,componentName:"NiceLookup"}),[z,b]=n.useState(!1),[h,l]=n.useState(""),u=n.useRef(null),_=n.useRef(null),{popupRef:S,coords:m,ready:D,themeClass:O,portalTarget:V}=We.useAnchoredPopup(z,_,()=>b(!1)),v=!!(G&&H&&H.length>0),q=s??(H&&H[0]?.key),K=n.useMemo(()=>!v||!G?[]:G.map(ae=>({value:String(ae[w]??""),label:q?String(ae[q]??""):""})),[v,G,w,q]),de=n.useMemo(()=>v?K:t??[],[v,K,t]),he=de.find(ae=>String(ae.value)===N),be=n.useMemo(()=>{if(!v||!G)return[];if(!h)return G;const ae=h.toLowerCase();return G.filter(ue=>H.some(I=>String(ue[I.key]??"").toLowerCase().includes(ae)))},[v,G,H,h]),ge=n.useMemo(()=>{if(v||!h)return de;const ae=h.toLowerCase();return de.filter(ue=>ue.label.toLowerCase().includes(ae))},[de,h,v]),fe=v?be:ge,{activeIndex:me,setActiveIndex:pe,handleKeyDown:te}=lt.useListKeyboardNav(fe,{open:z,onSelect:ae=>{const ue=String(v?ae[w]??"":ae.value);d(ue),b(!1),l("")},onClose:()=>b(!1),onOpen:()=>!f&&b(!0),intentRef:S}),_e=`${n.useId()}-listbox`,ne=ae=>`${_e}-opt-${ae}`,we=z&&fe.length>0?ne(me):void 0;return n.useLayoutEffect(()=>{we&&document.getElementById(we)?.scrollIntoView?.({block:"nearest"})},[we]),e.jsxs("div",{className:`nice-field nice-field--lookup nice-field--${U} ${M?"nice-field--error":""} ${A==="left"?"nice-field--label-left":""} ${k==="right"&&(M||W)?"nice-field--error-right":""} ${y?"nice-field--loading":""} ${B?"nice-field--disabled":""} ${ee||""}`,style:{...C!=null&&{"--nice-field-control-width":typeof C=="number"?`${C}px`:C},...x!=null&&{"--nice-field-label-width":typeof x=="number"?`${x}px`:x},...F!=null&&{"--nice-dropdown-gap":`${F}px`},...re},"aria-busy":y||void 0,ref:u,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:_,children:[e.jsxs("button",{type:"button",id:E,className:`nice-select__trigger ${B?"nice-select__trigger--disabled":""}`,onClick:()=>!f&&b(!z),onKeyDown:te,disabled:B,"aria-readonly":$||void 0,role:"combobox","aria-haspopup":"listbox","aria-expanded":z,"aria-controls":z?_e:void 0,"aria-activedescendant":c?void 0:we,children:[e.jsx("span",{children:he?.label||T||L("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[g&&N&&!B&&!$&&e.jsx("span",{onKeyDown:r.clickOnActivationKey,className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":L("controls.clear","Clear"),onClick:ae=>{ae.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&&V&&nt.createPortal(e.jsxs("div",{ref:S,className:`nice-dropdown nice-lookup__dropdown${O?` ${O}`:""}`,"data-theme":O==="nice-dark"?"dark":O==="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:R!=null?typeof R=="number"?`${R}px`:R:v?"max-content":m.width,opacity:D?1:0,pointerEvents:D?void 0:"none"},children:[c&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:h,onChange:ae=>{l(ae.target.value),pe(0)},onKeyDown:te,placeholder:L("controls.search","Search..."),"aria-label":L("controls.search","Search..."),"aria-controls":_e,"aria-activedescendant":we,"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:H.map(ae=>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:ae.width!=null?typeof ae.width=="number"?`${ae.width}px`:ae.width:void 0},children:ae.header},ae.key))})}),e.jsx("tbody",{children:be.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:H.length,style:{padding:12,textAlign:"center",color:"var(--nice-text-muted)"},children:L("controls.noResults","No results")})}):be.map((ae,ue)=>{const I=String(ae[w]??""),Y=I===N,le=ue===me;return e.jsx("tr",{id:ne(ue),role:"option","aria-selected":Y,onClick:()=>{d(I),b(!1),l("")},style:{cursor:"pointer",background:Y||le?"var(--nice-hover-bg)":"transparent"},onMouseEnter:()=>pe(ue),children:H.map(j=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--nice-border-color)"},children:String(ae[j.key]??"")},j.key))},I)})})]}):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((ae,ue)=>e.jsx("li",{id:ne(ue),role:"option",className:`nice-dropdown__option ${String(ae.value)===N?"nice-dropdown__option--selected":""} ${ue===me?"nice-dropdown__option--active":""}`,onClick:()=>{d(String(ae.value)),b(!1),l("")},onMouseEnter:()=>pe(ue),"aria-selected":String(ae.value)===N,children:ae.label},String(ae.value)))})]}),V)]}),y&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),k==="right"&&M&&e.jsx("div",{className:"nice-field__error",role:"alert",children:M}),k==="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]}),k!=="right"&&M&&e.jsx("div",{className:"nice-field__error",children:M}),k!=="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]})},Dn=[];function Ht(t){const i=[],a=o=>{for(const c of o)i.push(c),c.children&&a(c.children)};return a(t),i}function sn(t,i){const a=i.toLowerCase();return t.reduce((o,c)=>{const g=c.children?sn(c.children,i):[];return(c.label.toLowerCase().includes(a)||g.length>0)&&o.push({...c,children:g.length>0?g:c.children}),o},[])}const rn=({node:t,level:i,selectedKeys:a,expandedKeys:o,onToggleExpand:c,onSelect:g,selectableLeafsOnly:y,maxDepth:T})=>{const{t:P}=r.useNiceTranslation(),M=typeof T=="number"?Math.min(10,Math.max(1,T)):1/0,X=!(i+1>=M)&&t.children&&t.children.length>0,B=o.has(t.key),$=a.has(t.key),U=!X,ie=!t.disabled&&(!y||U),ee=Math.min(i+1,10),re={paddingLeft:i*16+14,"--nice-row-bg":`var(--nice-tree-level-${ee}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${ee}-text, inherit)`,"--nice-row-hover-bg":`var(--nice-tree-level-${ee}-hover-bg, var(--nice-bg-secondary, #f3f4f6))`,"--nice-row-active-bg":`var(--nice-tree-level-${ee}-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:re,"data-nice-depth":ee,onClick:()=>{t.disabled||(X?c(t.key):ie&&g(t.key))},role:"treeitem","aria-level":i+1,"aria-selected":$,"aria-expanded":X?B: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(),c(t.key)},"aria-label":P("controls.toggle","Toggle"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:12,style:{transform:B?"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&&B&&t.children.map(G=>e.jsx(rn,{node:G,level:i+1,selectedKeys:a,expandedKeys:o,onToggleExpand:c,onSelect:g,selectableLeafsOnly:y,maxDepth:T},G.key))]})},zn=Object.assign(n.forwardRef(({nodes:t=Dn,value:i,onChange:a,multiple:o=!1,searchable:c=!1,placeholder:g,selectableLeafsOnly:y=!1,clearable:T=!1,maxDepth:P,label:M,helperText:W,error:X,required:B,disabled:$,readOnly:U,size:ie="md",name:ee,id:re,className:G,style:H,controlWidth:w,menuGap:s,labelPlacement:R,errorPlacement:F,labelWidth:A,...k},x)=>{const{t:C}=r.useNiceTranslation(),f=r.useControlId(re),[E,L]=n.useState(!1),[N,d]=n.useState(""),[z,b]=n.useState(new Set),h=n.useRef(null),{popupRef:l,coords:u,ready:_,themeClass:S,portalTarget:m}=We.useAnchoredPopup(E,h,()=>L(!1)),D=n.useMemo(()=>i==null?new Set:new Set(Array.isArray(i)?i:[i]),[i]),O=n.useMemo(()=>N?sn(t,N):t,[t,N]),V=n.useMemo(()=>{const fe=Ht(t);return Array.from(D).map(me=>fe.find(pe=>pe.key===me)?.label).filter(Boolean)},[D,t]),v=n.useCallback(fe=>{b(me=>{const pe=new Set(me);return pe.has(fe)?pe.delete(fe):pe.add(fe),pe})},[]),q=n.useCallback(fe=>{if(o){const me=new Set(D);me.has(fe)?me.delete(fe):me.add(fe),a?.(Array.from(me))}else a?.(fe),L(!1)},[o,D,a]),K=n.useCallback(fe=>{fe.stopPropagation(),a?.(o?[]:"")},[a,o]),de=n.useRef(null),he=`${f}-tree`;r.useTreeFocus(de,{onToggle:(fe,me)=>{const pe=Ht(O).find(te=>String(te.key)===fe.dataset.key);pe&&z.has(pe.key)!==me&&v(pe.key)}});const be=n.useCallback(()=>(de.current?.querySelector('[role="treeitem"][tabindex="0"]')??de.current?.querySelector('[role="treeitem"]'))?.focus(),[]),ge=!!u;return n.useEffect(()=>{E&&ge&&!c&&be()},[E,ge,c,be]),e.jsxs("div",{className:`nice-field nice-field--${ie}${R?` nice-field--label-${R}`:""}${F==="right"?" nice-field--error-right":""} ${G||""}`,style:{width:"fit-content",maxWidth:"100%",...s!=null&&{"--nice-dropdown-gap":`${s}px`},...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...H},...k,children:[M&&e.jsx("label",{htmlFor:f,className:`nice-field__label ${B?"nice-field__label--required":""}`,children:M}),e.jsxs("div",{ref:h,className:"nice-tree-select",style:{position:"relative",width:w!=null&&w!==""?typeof w=="number"?`${w}px`:w:"var(--nice-field-control-width, 220px)"},children:[e.jsxs("div",{ref:x,id:f,className:`nice-input nice-input--${ie} ${X?"nice-input--error":""} ${$?"nice-input--disabled":""} ${U?"nice-input--readonly":""}`,role:"combobox","aria-expanded":E,"aria-haspopup":"tree","aria-controls":E?he:void 0,"aria-invalid":!!X,tabIndex:$?-1:0,onClick:()=>!$&&!U&&L(!E),onKeyDown:fe=>{(fe.key==="Enter"||fe.key===" "||fe.key==="ArrowDown"||fe.key==="ArrowUp")&&!$&&!U&&(fe.preventDefault(),E?be():L(!0))},children:[e.jsx("span",{className:"nice-tree-select__display",children:V.length>0?V.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:g??C("controls.select","Select...")})}),T&&D.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:K,"aria-label":C("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&&u&&m&&nt.createPortal(e.jsxs("div",{ref:l,className:`nice-tree-select__dropdown${S?` ${S}`:""}`,"data-theme":S==="nice-dark"?"dark":S==="nice-light"?"light":void 0,style:{position:"fixed",left:u.left,top:u.top,width:u.width,minWidth:u.width,zIndex:1e3,opacity:_?1:0,pointerEvents:_?void 0:"none"},children:[c&&e.jsx("div",{className:"nice-select__search",onClick:fe=>fe.stopPropagation(),role:"presentation",children:e.jsx("input",{type:"text",placeholder:C("controls.search","Search..."),"aria-label":C("controls.search","Search..."),"aria-controls":he,value:N,onChange:fe=>d(fe.target.value),onKeyDown:fe=>{fe.key==="ArrowDown"&&(fe.preventDefault(),be())},autoFocus:!0})}),e.jsx("div",{ref:de,id:he,className:"nice-tree-select__list",role:"tree","aria-label":M||g||C("controls.select","Select..."),"aria-multiselectable":o||void 0,children:O.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:C("controls.noResults","No results")}):O.map(fe=>e.jsx(rn,{node:fe,level:0,selectedKeys:D,expandedKeys:z,onToggleExpand:v,onSelect:q,selectableLeafsOnly:y,maxDepth:P},fe.key))})]}),m)]}),ee&&e.jsx("input",{type:"hidden",name:ee,value:Array.isArray(i)?i.join(","):i??""}),X&&e.jsx("div",{id:`${f}-error`,className:"nice-field__error",role:"alert",children:X}),!X&&W&&e.jsx("div",{id:`${f}-helper`,className:"nice-field__helper",children:W})]})}),{displayName:"NiceTreeSelect"}),Ln=({displayValue:t,placeholder:i,clearable:a,children:o,onClear:c,open:g,onOpenChange:y,dropdownWidth:T,searchable:P=!0,onSearch:M,searchPlaceholder:W,label:X,error:B,helperText:$,required:U,disabled:ie,size:ee="md",id:re,className:G,style:H,accessMode:w,showKeyboardHints:s,displayStyle:R})=>{r.useComponentDisplayStyle("input",R),r.useComponentDisplayClass("input",R);const F=r.useNiceAccessMode(w,re),A=F==="hidden";(F==="disabled"||F==="readOnly")&&(ie=!0);const k=r.useControlId(re),{t:x}=r.useNiceTranslation(),[C,f]=n.useState(!1),[E,L]=n.useState(""),N=n.useRef(null),d=n.useRef(null),z=g??C,b=n.useMemo(()=>[{key:"Enter",description:x("shortcuts.openDropdown","Open dropdown")},r.COMMON_SHORTCUTS.cancel],[x]),h=D=>{y?y(D):f(D)},{popupRef:l,coords:u,ready:_,themeClass:S,portalTarget:m}=We.useAnchoredPopup(z,d,()=>h(!1));return A?null:e.jsxs("div",{className:`nice-field nice-field--${ee} ${B?"nice-field--error":""} ${G||""}`,style:H,ref:N,children:[X&&e.jsxs("label",{className:"nice-field__label",htmlFor:k,children:[X,U&&e.jsx("span",{className:"nice-field__required",children:"*"}),s&&e.jsx(r.NiceKeyboardHint,{shortcuts:b,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",ref:d,children:[e.jsxs("button",{type:"button",id:k,className:"nice-select__trigger",onClick:()=>!ie&&h(!z),disabled:ie,children:[e.jsx("span",{children:t||i||x("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[a&&t&&!ie&&e.jsx("span",{className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":x("controls.clear","Clear"),onClick:D=>{D.stopPropagation(),c?.()},onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),D.stopPropagation(),c?.())},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&&u&&m&&nt.createPortal(e.jsxs("div",{ref:l,className:`nice-dropdown${S?` ${S}`:""}`,"data-theme":S==="nice-dark"?"dark":S==="nice-light"?"light":void 0,style:{position:"fixed",left:u.left,top:u.top,width:T??u.width,minWidth:T??u.width,zIndex:1e3,maxHeight:320,overflowY:"auto",opacity:_?1:0,pointerEvents:_?void 0:"none"},children:[P&&M&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:E,onChange:D=>{L(D.target.value),M(D.target.value)},placeholder:W??x("controls.search","Search..."),autoFocus:!0})}),o]}),m)]}),B&&e.jsx("div",{className:"nice-field__error",children:B}),$&&!B&&e.jsx("div",{className:"nice-field__hint",children:$})]})},Pn=[],On=[];function Ve(t,i){return String(t[i])}const Bn={xxs:10,xs:12,sm:12,md:14,lg:18,xl:22,xxl:26},Hn=Object.assign(n.forwardRef(({source:t=Pn,target:i=On,onChange:a,keyField:o="id",labelField:c="label",renderItem:g,filterable:y=!1,searchable:T,groupBy:P,sortable:M=!1,bulkActions:W=!0,maxRight:X,sourceHeader:B,targetHeader:$,disabled:U=!1,size:ie="md",className:ee,style:re,id:G,...H},w)=>{const{t:s}=r.useNiceTranslation(),R=Bn[ie]??14,[F,A]=n.useState(new Set),[k,x]=n.useState(new Set),[C,f]=n.useState(""),[E,L]=n.useState(""),[N,d]=n.useState(null),z=n.useRef(null),b=n.useRef(null),h={orientation:"vertical",typeahead:!0,pageSize:10};r.useRovingFocus(z,h),r.useRovingFocus(b,h);const l=n.useCallback((v,q,K)=>{q(de=>{const he=new Set(de);return he.has(K)?he.delete(K):he.add(K),he})},[]),u=n.useCallback(()=>{const v=t.filter(he=>F.has(Ve(he,o))),q=t.filter(he=>!F.has(Ve(he,o))),K=typeof X=="number"?v.slice(0,Math.max(0,X-i.length)):v,de=v.slice(K.length);a([...q,...de],[...i,...K]),A(new Set)},[t,i,F,o,a,X]),_=n.useCallback(()=>{const v=i.filter(K=>k.has(Ve(K,o))),q=i.filter(K=>!k.has(Ve(K,o)));a([...t,...v],q),x(new Set)},[t,i,k,o,a]),S=n.useCallback(()=>{if(typeof X=="number"){const v=Math.max(0,X-i.length),q=t.slice(0,v),K=t.slice(v);a(K,[...i,...q])}else a([],[...i,...t]);A(new Set)},[t,i,a,X]),m=n.useCallback(()=>{a([...t,...i],[]),x(new Set)},[t,i,a]),D=(v,q)=>{if(!q)return v;const K=q.toLowerCase();return v.filter(de=>String(de[c]).toLowerCase().includes(K))},O=W===!1?{moveAll:!1,removeAll:!1}:W===!0||W===void 0?{moveAll:!0,removeAll:!0}:{moveAll:W.moveAll??!0,removeAll:W.removeAll??!0},V=(v,q,K,de,he,be,ge,fe)=>{let me=D(v,de);M||(me=[...me].sort((ae,ue)=>String(ae[c]).localeCompare(String(ue[c]),void 0,{numeric:!0,sensitivity:"base"})));const pe=T===!0||y&&T===void 0?"both":T??!1,te=pe==="both"||pe==="left"&&ge==="left"||pe==="right"&&ge==="right",ve=(()=>{if(!P)return[{label:"",items:me}];const ae=new Map;for(const ue of me){const I=String(P(ue));let Y=ae.get(I);Y||(Y=[],ae.set(I,Y)),Y.push(ue)}return[...ae.entries()].map(([ue,I])=>({label:ue,items:I}))})(),_e=(ae,ue)=>{ae.dataTransfer.setData("text/plain",ue),ae.dataTransfer.effectAllowed="move"},ne=(ae,ue)=>{if(ae.preventDefault(),!M)return;const I=ae.currentTarget.getBoundingClientRect(),Y=ae.clientY<I.top+I.height/2;d(le=>le&&le.side===ge&&le.key===ue&&le.before===Y?le:{side:ge,key:ue,before:Y})},we=(ae,ue)=>{ae.preventDefault();const I=N?.before??!1;d(null);const Y=ae.dataTransfer.getData("text/plain");if(!Y||!M)return;const j=[...ge==="right"?i:t],Z=j.findIndex(xe=>Ve(xe,o)===Y),oe=j.findIndex(xe=>Ve(xe,o)===ue);if(Z===-1||oe===-1||Y===ue)return;let se=I?oe:oe+1;const[ye]=j.splice(Z,1);Z<se&&(se-=1),j.splice(se,0,ye),a(ge==="right"?t:j,ge==="right"?j:i)};return e.jsxs("div",{className:"nice-picklist__panel",children:[be&&e.jsx("div",{className:"nice-picklist__header",children:be}),te&&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:de,onChange:ae=>he(ae.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true","aria-label":typeof be=="string"?be:void 0,ref:fe,children:[ve.map(ae=>e.jsxs(n.Fragment,{children:[ae.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:ae.label}),ae.items.map(ue=>{const I=Ve(ue,o),Y=q.has(I),j=N&&N.side===ge&&N.key===I?N.before?"nice-picklist__item--drop-before":"nice-picklist__item--drop-after":"";return e.jsxs("div",{className:`nice-picklist__item ${Y?"nice-picklist__item--selected":""} ${j}`,role:"option","aria-selected":Y,draggable:M,onDragStart:M?Z=>_e(Z,I):void 0,onDragOver:M?Z=>ne(Z,I):void 0,onDrop:M?Z=>we(Z,I):void 0,onDragEnd:M?()=>d(null):void 0,onClick:()=>!U&&l(q,K,I),onKeyDown:Z=>{(Z.key===" "||Z.key==="Enter")&&(Z.preventDefault(),U||l(q,K,I))},children:[M&&e.jsx("span",{className:"nice-picklist__drag-handle","aria-hidden":"true",children:e.jsx(r.NiceIcon,{name:"grip",size:R})}),g?g(ue,ge):String(ue[c])]},I)})]},ae.label||"__none__")),me.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:s("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:w,id:G,className:`nice-picklist nice-picklist--${ie} ${U?"nice-picklist--disabled":""} ${ee||""}`,style:re,...H,children:[V(t,F,A,C,f,B??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--${ie}`,disabled:U||F.size===0,onClick:u,"aria-label":s("picklist.moveRight","Move right"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:R})}),O.moveAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ie}`,disabled:U||t.length===0,onClick:S,"aria-label":s("picklist.moveAllRight","Move all right"),children:e.jsx(r.NiceIcon,{name:"chevrons-right",size:R})}),e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ie}`,disabled:U||k.size===0,onClick:_,"aria-label":s("picklist.moveLeft","Move left"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:R})}),O.removeAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${ie}`,disabled:U||i.length===0,onClick:m,"aria-label":s("picklist.moveAllLeft","Move all left"),children:e.jsx(r.NiceIcon,{name:"chevrons-left",size:R})})]}),V(i,k,x,E,L,$??s("picklist.target","Selected"),"right",b)]})}),{displayName:"NicePickList"});function Tt(t){return t?.startsWith("datetime")?"datetime":t==="week"?"week":t?.startsWith("month")?"month":"date"}function Fn(t){const i=new Date,a=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`,o=Tt(t);return o==="datetime"?`${a}T00:00`:o==="month"?a.slice(0,7):a}function Ft(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 pt(...t){return t.filter(Boolean).sort().pop()}function Nt(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 c=Tt(a);return c==="month"?o.toLocaleDateString(i,{year:"numeric",month:"2-digit"}):c==="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 Kt(t){let i=0;for(const a of t)i+=/[\p{L}\p{N}]/u.test(a)?1:.5;return i}const Kn=({startDate:t,endDate:i,defaultStartDate:a,defaultEndDate:o,onStartChange:c,onEndChange:g,min:y,max:T,clearable:P,startPlaceholder:M,endPlaceholder:W,startLabel:X,endLabel:B,layout:$="horizontal",separator:U="–",gap:ie=12,fullWidth:ee=!1,dateFormatPreset:re,locale:G,timeSelectorType:H,endCondition:w="greater-or-equal",startCondition:s="today-or-greater",singleField:R=!1,label:F,error:A,helperText:k,required:x,disabled:C,size:f="md",id:E,className:L,style:N,accessMode:d,showKeyboardHints:z,labelPlacement:b,errorPlacement:h,labelWidth:l,controlWidth:u,loading:_,readOnly:S})=>{const m=r.useNiceAccessMode(d,E),D=r.useControlId(E),{t:O}=r.useNiceTranslation(),V=m==="disabled"||m==="readOnly"||!!C,[v,q]=r.useControllableState({value:t,defaultValue:a,fallbackValue:"",onChange:c,componentName:"NiceDateRangeBox"}),[K,de]=r.useControllableState({value:i,defaultValue:o,fallbackValue:"",onChange:g,componentName:"NiceDateRangeBox"}),he=n.useMemo(()=>[{key:"Tab",description:O("shortcuts.switchField","Switch between start/end")},r.COMMON_SHORTCUTS.cancel],[O]),be=n.useRef(null),ge=n.useRef(null),[fe,me]=n.useState(!1),[pe,te]=n.useState(null),[ve,_e]=n.useState(""),we=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null);n.useLayoutEffect(()=>{if(!fe)return;const Ce=be.current?.getBoundingClientRect();Ce&&(te({left:Ce.left,top:Ce.bottom+6}),_e(Je.scopeThemeClass(be.current)))},[fe]),n.useEffect(()=>{if(!fe)return;const Ce=Be=>{const $e=Be.target;be.current?.contains($e)||ge.current?.contains($e)||me(!1)},Ne=()=>{const Be=be.current?.getBoundingClientRect();Be&&te({left:Be.left,top:Be.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)}},[fe]),r.useOverlayFocus(ge,{open:fe,modal:!1,initialFocus:'.nice-calendar__grid [tabindex="0"]',onClose:()=>me(!1)});const ae=Fn(re),ue=s==="today-or-greater"?pt(y,ae):s==="greater-than-today"?pt(y,Ft(ae,1)):y,I=w==="greater-or-equal"?pt(y,v):w==="greater"?pt(y,v?Ft(v,1):void 0):y,Y=n.useMemo(()=>{if(A)return A;if(v&&K){if(w==="greater-or-equal"&&K<v)return O("daterange.endBeforeStart","End date must be on or after the start date");if(w==="greater"&&K<=v)return O("daterange.endAfterStart","End date must be after the start date")}if(v){if(s==="today-or-greater"&&v<ae)return O("daterange.startInPast","Start date cannot be in the past");if(s==="greater-than-today"&&v<=ae)return O("daterange.startAfterToday","Start date must be after today")}},[A,v,K,s,w,ae,O]);if(m==="hidden")return null;const le=Ce=>{q(Ce),Ce&&K&&Ce>K&&de(Ce)},j=$==="horizontal",Z=Tt(re),oe=G||mt.getDefaultLocale(),se=typeof U=="string"&&U!==""?U:"–",ye=Nt(v,oe,re),xe=Nt(K,oe,re),Ee=ye||xe?`${ye||"…"} ${se} ${xe||"…"}`:"",ze=(()=>{const Ce=Nt("2026-12-30T22:58",oe,re),Ne=`${Ce} ${se} ${Ce}`;return`${(Math.max(Kt(Ne),Kt(Ee))+1.5).toFixed(1)}ch`})(),Le=(Ce,Ne)=>Z==="datetime"?Ne&&Ne.length>10?`${Ce}${Ne.slice(10)}`:`${Ce}T00:00`:Z==="month"?Ce.slice(0,7):Ce,Ye=({start:Ce,end:Ne})=>{q(Ce?Le(Ce,v):""),de(Ne?Le(Ne,K):""),Ce&&Ne&&me(!1)},Xe=()=>{q(""),de("")},Ke=()=>{!V&&!S&&me(Ce=>!Ce)},He=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--${$} ${b==="left"?"nice-field--label-left":""} ${Y?"nice-field--error":""} ${_?"nice-field--loading":""} ${L||""}`,style:{...N,...l!=null&&{"--nice-field-label-width":typeof l=="number"?`${l}px`:l},...u!=null&&{"--nice-field-control-width":typeof u=="number"?`${u}px`:u}},"aria-busy":_||void 0,children:[F&&e.jsxs("label",{className:"nice-field__label",htmlFor:D,children:[F,x&&e.jsx("span",{className:"nice-field__required",children:"*"}),z&&e.jsx(r.NiceKeyboardHint,{shortcuts:he,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[R?e.jsxs("div",{ref:be,className:`nice-input nice-input--date nice-input--${f} nice-daterange__single ${Y?"nice-input--error":""} ${V?"nice-input--disabled":""} ${S?"nice-input--readonly":""}`,style:{position:"relative",width:ee?"100%":"fit-content"},children:[e.jsx("input",{id:D,className:"nice-input__native",type:"text",readOnly:!0,value:Ee,placeholder:M||O("controls.startDate","Start date"),disabled:V||_,autoComplete:"off","aria-invalid":!!Y,"aria-label":F?void 0:O("controls.startDate","Start date"),"aria-haspopup":"dialog","aria-expanded":fe,onClick:Ke,onKeyDown:Ce=>{const Ne=!!Ce.nativeEvent.niceSource;(Ce.key==="Enter"||Ce.key===" "||Ce.key==="ArrowDown"&&!Ne)&&(Ce.preventDefault(),fe||Ke())},style:{width:ee?"100%":ze,cursor:V||S?void 0:"pointer"}}),P&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:Xe,disabled:!v&&!K||V||S,"aria-label":O("controls.clear","Clear"),tabIndex:(v||K)&&!V&&!S?0:-1,children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("button",{type:"button",className:"nice-input__picker-trigger",onClick:Ke,"aria-label":O("controls.openPicker","Open picker"),"aria-expanded":fe,tabIndex:-1,disabled:V||S,children:e.jsx(r.NiceIcon,{name:"calendar",size:16})})]}):e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:j?"row":"column",alignItems:j?b==="left"?"center":"flex-end":"stretch",gap:ie,flexWrap:j?"nowrap":"wrap"},children:[e.jsx("div",{style:{flex:ee?"1 1 0":void 0,minWidth:0},children:e.jsx(mt.NiceDateTimePicker,{id:D,dateFormatPreset:re,displayLocale:G,timeSelectorType:H,label:X,value:v,onChange:le,min:ue,max:K||T,placeholder:M||O("controls.startDate","Start date"),disabled:V,readOnly:S,size:f,clearable:P,labelPlacement:b,labelWidth:l})}),j&&U!==""&&U!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--nice-text-secondary, #666)"},"aria-hidden":"true",children:U}),e.jsx("div",{style:{flex:ee?"1 1 0":void 0,minWidth:0},children:e.jsx(mt.NiceDateTimePicker,{dateFormatPreset:re,displayLocale:G,timeSelectorType:H,label:B,value:K,onChange:Ce=>de(Ce),min:I||v||y,max:T,placeholder:W||O("controls.endDate","End date"),disabled:V,readOnly:S,size:f,clearable:P,labelPlacement:b,labelWidth:l})})]}),R&&fe&&pe&&we&&nt.createPortal(e.jsxs("div",{ref:ge,className:`nice-datetime-popup${ve?` ${ve}`:""}`,style:{position:"fixed",left:pe.left,top:pe.top,zIndex:1e3},role:"dialog","aria-label":O("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(mt.NiceCalendar,{selectionMode:"range",rangeStart:He(v),rangeEnd:He(K),onRangeChange:Ye,min:He(ue),max:He(T),size:f})})}),P&&e.jsx("div",{className:"nice-datetime-popup__footer",children:e.jsx("button",{type:"button",className:"nice-datetime-popup__btn",onClick:Xe,disabled:!v&&!K,children:O("controls.clear","Clear")})})]}),we),_&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),h==="right"&&Y&&e.jsx("div",{className:"nice-field__error",role:"alert",children:Y}),h==="right"&&!Y&&k&&e.jsx("div",{className:"nice-field__helper",children:k})]}),h!=="right"&&Y&&e.jsx("div",{className:"nice-field__error",children:Y}),h!=="right"&&!Y&&k&&e.jsx("div",{className:"nice-field__hint",children:k})]})};function Un(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 Ut(t,i={}){const a=i.size??16,o="currentColor",c="currentColor";if(i.rectangle||t==="shade-chain"||t==="monochromatic"){const X=Math.max(3,Math.min(7,i.count??5)),B=a*.1,$=a-B*2,U=Math.max(1.2,a/14),ie=a/2,ee=Array.from({length:X},(re,G)=>{const H=B+$*G/(X-1),w=.25+.75*G/(X-1);return e.jsx("circle",{cx:H,cy:ie,r:U,fill:c,opacity:w},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}),ee]})}const y=i.angles??Un(t),T=a/2,P=a/2,M=a/2-2,W=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:T,cy:P,r:M,fill:"none",stroke:o,strokeOpacity:.25}),y.map((X,B)=>{const $=(X-90)*Math.PI/180,U=T+M*Math.cos($),ie=P+M*Math.sin($);return e.jsx("circle",{cx:U,cy:ie,r:W,fill:c},B)})]})}function Yt(t,i,a){return Math.max(i,Math.min(a,t))}function cn({h:t,s:i,v:a}){t=(t%360+360)%360;const o=a*i,c=o*(1-Math.abs(t/60%2-1)),g=a-o;let y=0,T=0,P=0;return t<60?(y=o,T=c):t<120?(y=c,T=o):t<180?(T=o,P=c):t<240?(T=c,P=o):t<300?(y=c,P=o):(y=o,P=c),{r:Math.round((y+g)*255),g:Math.round((T+g)*255),b:Math.round((P+g)*255)}}function Rt({r:t,g:i,b:a}){t/=255,i/=255,a/=255;const o=Math.max(t,i,a),c=Math.min(t,i,a),g=o-c;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 ln({r:t,g:i,b:a}){t/=255,i/=255,a/=255;const o=Math.max(t,i,a),c=Math.min(t,i,a),g=(o+c)/2;if(o===c)return{h:0,s:0,l:g};const y=o-c,T=g>.5?y/(2-o-c):y/(o+c);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:T,l:g}}function ct(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 dn({r:t,g:i,b:a}){return"#"+[t,i,a].map(o=>o.toString(16).padStart(2,"0")).join("")}function Pe(t){return dn(cn(t))}function Fe(t){return Rt(ct(t))}function mn(t,i){const a=[];for(let o=0;o<i;o++){const c=i<=1?.5:o/(i-1),g=Yt(t.s*(.3+c*.7),0,1),y=Yt(t.v*(1.2-c*.7),0,1);a.push(Pe({h:t.h,s:g,v:y}))}return a}function bt(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 rt(t,i,a){return bt(i,a).map(o=>((t+o)%360+360)%360)}function Xt(t,i,a=.12){const o=Math.max(2,i),c=(o-1)/2,g=[];for(let y=0;y<o;y++){const T=(y-c)*a,P=Math.max(.05,Math.min(.98,t.v+T)),M=Math.max(.05,Math.min(1,t.s-Math.abs(T)*.25));g.push(Pe({h:t.h,s:M,v:P}))}return g}function qt({r:t,g:i,b:a}){const[o,c,g]=[t,i,a].map(y=>{const T=y/255;return T<=.03928?T/12.92:Math.pow((T+.055)/1.055,2.4)});return .2126*o+.7152*c+.0722*g}function gt(t,i){const a=qt(ct(t)),o=qt(ct(i)),c=Math.max(a,o),g=Math.min(a,o);return(c+.05)/(g+.05)}function ft(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"AA-lg":"Fail"}const un={"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 yt(t,i){const a=un[i];return t.map(o=>{const c=(a.sRange[0]+a.sRange[1])/2,g=(a.vRange[0]+a.vRange[1])/2;return Pe({h:o,s:c,v:g})})}function Yn(){return Math.floor(Math.random()*360)}function pn(t,i,a){const o=Yn(),c=rt(o,t,a),g=[];for(let y=0;y<i;y++){const T=c[y%c.length],P=.55+Math.random()*.4,M=.5+Math.random()*.45;g.push(Pe({h:T+(Math.random()-.5)*8,s:P,v:M}))}return g}const Xn=({hues:t,colors:i,baseHue:a,onBaseHueChange:o,mode:c,distance:g,disabled:y})=>{const{t:T}=r.useNiceTranslation(),P=240,M=P/2,W=P/2,X=110,B=55,$=s=>{if(y)return;const R=s.shiftKey?15:1,F=s.key==="ArrowLeft"||s.key==="ArrowDown"?-R:s.key==="ArrowRight"||s.key==="ArrowUp"?R: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))},U=n.useRef(null),ie=n.useCallback((s,R)=>{const F=U.current;if(!F)return;const A=F.getBoundingClientRect(),k=(s-A.left)/A.width*P-M,x=(R-A.top)/A.height*P-W,C=(Math.atan2(x,k)*180/Math.PI+360)%360;o(Math.round(C))},[M,W,P,o]),ee=n.useCallback(s=>{if(y)return;s.preventDefault(),ie(s.clientX,s.clientY);const R=A=>ie(A.clientX,A.clientY),F=()=>{document.removeEventListener("pointermove",R),document.removeEventListener("pointerup",F)};document.addEventListener("pointermove",R),document.addEventListener("pointerup",F)},[y,ie]),re=[];for(let s=0;s<360;s+=2){const R=(s-1)*Math.PI/180,F=(s+1)*Math.PI/180,A=Pe({h:s,s:1,v:1});re.push(e.jsx("path",{d:`M${M+B*Math.cos(R)},${W+B*Math.sin(R)} L${M+X*Math.cos(R)},${W+X*Math.sin(R)} A${X},${X} 0 0,1 ${M+X*Math.cos(F)},${W+X*Math.sin(F)} L${M+B*Math.cos(F)},${W+B*Math.sin(F)} A${B},${B} 0 0,0 ${M+B*Math.cos(R)},${W+B*Math.sin(R)} Z`,fill:A},s))}const G=`wheel-center-${c}`,H=t.map((s,R)=>{const F=(X+B)/2,A=s*Math.PI/180;return e.jsx("circle",{cx:M+F*Math.cos(A),cy:W+F*Math.sin(A),r:R===0?8:6,fill:i?.[R]??Pe({h:s,s:.85,v:.9}),stroke:R===0?"var(--nice-bg-primary, #fff)":"var(--nice-border-color, #ccc)",strokeWidth:R===0?3:2},R)});let w=null;if(c==="analogous"||c==="split-complementary"||c==="analogous-complementary"){const s=(X+B)/2,F=bt(c,g).slice(1).map((A,k)=>{const x=(a+A)*Math.PI/180;return e.jsx("line",{x1:M,y1:W,x2:M+s*Math.cos(x),y2:W+s*Math.sin(x),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${k}`)});w=e.jsx(e.Fragment,{children:F})}return e.jsxs("svg",{ref:U,className:"nice-palette__wheel",viewBox:`0 0 ${P} ${P}`,width:P,height:P,onPointerDown:ee,onKeyDown:$,role:"slider",tabIndex:y?-1:0,"aria-label":T("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"})]})}),re,e.jsx("circle",{cx:M,cy:W,r:B-2,fill:Pe({h:a,s:.6,v:.85})}),e.jsx("circle",{cx:M,cy:W,r:B-2,fill:`url(#${G})`,opacity:.4}),w,H]})},qn=({colors:t})=>{const{t:i}=r.useNiceTranslation();if(t.length<2)return null;const a=[];for(let o=0;o<t.length;o++){const c=gt(t[o],"var(--nice-bg-primary, #ffffff)"),g=gt(t[o],"var(--nice-text-primary, #000000)");a.push({a:t[o],b:"var(--nice-bg-primary, #ffffff)",ratio:c,level:ft(c)}),a.push({a:t[o],b:"var(--nice-text-primary, #000000)",ratio:g,level:ft(g)});for(let y=o+1;y<t.length;y++){const T=gt(t[o],t[y]);a.push({a:t[o],b:t[y],ratio:T,level:ft(T)})}}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,c)=>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})]},c))})]})},Gn=({hex:t})=>{const i=ct(t),a=ln(i),o=Rt(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),"%"]})]})},Vn={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"},Wn={"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"},Jn=["monochromatic","shade-chain","complementary","split-complementary","analogous","analogous-complementary","triadic","tetradic","square","custom"],hn=["lightest-pastel","bright-pastel","shiny","pastel","full","dark","deep","muted","earth"],gn="nice-palette-custom-schemes";function Zn(){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(gn);if(!t)return[];const i=JSON.parse(t);if(Array.isArray(i))return i}catch{}return[]}function Qn(t){if(!(typeof window>"u"))try{window.localStorage.setItem(gn,JSON.stringify(t))}catch{}}const ei=Object.assign(n.forwardRef(({id:t,className:i,style:a,accessMode:o,value:c,onChange:g,minColors:y=1,maxColors:T=8,harmonyMode:P,onHarmonyModeChange:M,distance:W,onDistanceChange:X,preset:B,onPresetChange:$,showWheel:U=!0,showContrast:ie=!0,showInfo:ee=!0,showPresets:re=!0,presets:G=[],showVariations:H=!0,showRandom:w=!0,variationCount:s=5,label:R,labelPlacement:F="top",disabled:A,readOnly:k,loading:x,error:C,colorCount:f,shadeStep:E,onShadeStepChange:L,customSchemes:N,onCustomSchemesChange:d,persistCustomSchemes:z=!0,"data-testid":b},h)=>{const l=r.useNiceAccessMode(o,t),u=l==="hidden";l==="disabled"&&(A=!0);const _=k||l==="readOnly",S=r.useControlId(t),{t:m}=r.useNiceTranslation(),D=Je.useNiceDialogs(),[O,V]=n.useState("analogous-complementary"),[v,q]=n.useState(30),[K,de]=n.useState(""),[he,be]=n.useState(0),[ge,fe]=n.useState(.12),[me,pe]=n.useState(null),[te,ve]=n.useState(()=>N??(z?Zn():[])),[_e,ne]=n.useState(null),[we,ae]=n.useState(!1),[ue,I]=n.useState(null),[Y,le]=n.useState(""),Z=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),oe=n.useRef(null),se=n.useRef(null),ye=P??O,xe=W??v,Ee=B??K,ze=E??ge,Le=N??te;n.useEffect(()=>{!N&&z&&Qn(te)},[te,N,z]);const Ye=n.useCallback(J=>{ve(J),d?.(J)},[d]),Xe=n.useCallback(J=>{V(J),M?.(J)},[M]),Ke=n.useCallback(J=>{q(J),X?.(J)},[X]),He=n.useCallback(J=>{de(J),J&&$?.(J)},[$]),Ce=n.useMemo(()=>["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)"],[]),Ne=c&&c.length>0?c:Ce,Be=Ne[0],$e=n.useMemo(()=>Fe(Be),[Be]),De=n.useMemo(()=>rt($e.h,ye,xe),[$e.h,ye,xe]),Re=n.useCallback((J,je,ke,Te,Ue)=>{const dt=f??Ue??me??Ne.length,Qe=dt!==void 0?Math.max(y,Math.min(T,dt)):void 0;if(je==="shade-chain"){const Oe=Qe??Math.max(y,5),Ge=Xt({h:J,s:$e.s||.7,v:$e.v||.6},Oe,ze);g?.(Ge);return}let et;const ot=je==="custom"&&_e?Le.find(Oe=>Oe.id===_e):null;ot&&ot.angles.length>0?et=ot.angles.map(Oe=>((J+Oe)%360+360)%360):et=rt(J,je,ke);let Ae;if(Te&&un[Te]?Ae=yt(et,Te):Ae=et.map(Oe=>Pe({h:Oe,s:$e.s||.7,v:$e.v||.85})),ot?.lightnessOffsets?.length&&(Ae=Ae.map((Oe,Ge)=>{const Pt=ot.lightnessOffsets?.[Ge];if(Pt==null)return Oe;const wt=Fe(Oe);return Pe({h:wt.h,s:wt.s,v:Math.max(.05,Math.min(.98,wt.v+Pt))})})),Qe!==void 0){for(;Ae.length<Qe;){const Oe=Ae[Ae.length-1]||"#888888",Ge=Fe(Oe);Ae.push(Pe({h:(Ge.h+18)%360,s:Ge.s,v:Ge.v}))}Ae=Ae.slice(0,Qe)}else{for(;Ae.length<y;)Ae.push(Ae[Ae.length-1]||"var(--nice-text-secondary, #888888)");Ae.length>T&&(Ae=Ae.slice(0,T))}g?.(Ae)},[$e.s,$e.v,y,T,g,f,me,Ne.length,ze,_e,Le]),vt=n.useCallback(J=>{if(!A){if(ye==="custom"){const je=Pe({h:J,s:$e.s||.7,v:$e.v||.85}),ke=[...Ne];ke[he]=je,g?.(ke);return}Re(J,ye,xe,Ee)}},[A,ye,xe,Ee,Re,$e.s,$e.v,Ne,he,g]),p=n.useCallback(J=>{if(A||(Xe(J),J==="custom"))return;const je=bt(J).length,ke=je<=1;if(f==null&&!ke){const Te=Math.max(y,Math.min(T,je));pe(Te),Re($e.h,J,xe,Ee,Te)}else Re($e.h,J,xe,Ee)},[A,$e.h,xe,Ee,Xe,Re,f,y,T]),Q=n.useCallback(J=>{A||(Ke(J),Re($e.h,ye,J,Ee))},[A,$e.h,ye,Ee,Ke,Re]),ce=n.useCallback(J=>{if(A)return;He(J);const je=rt($e.h,ye,xe),ke=yt(je,J);g?.(ke.slice(0,T))},[A,$e.h,ye,xe,T,He,g]),Se=n.useCallback((J,je)=>{if(A)return;const ke=[...Ne];ke[J]=je,g?.(ke)},[A,Ne,g]),Me=n.useCallback(()=>{if(A||Ne.length>=T)return;const J=Fe(Ne[Ne.length-1]),je=Pe({h:(J.h+30)%360,s:J.s,v:J.v});g?.([...Ne,je])},[A,Ne,T,g]),qe=n.useCallback(J=>{if(A||Ne.length<=y)return;const je=Ne.filter((ke,Te)=>Te!==J);g?.(je),he>=je.length&&be(Math.max(0,je.length-1))},[A,Ne,y,g,he]),Ze=n.useCallback(()=>{if(A)return;const J=Math.max(y,Math.min(T,bt(ye).length)),je=pn(ye,J,xe);g?.(je)},[A,y,T,ye,xe,g]),Dt=n.useMemo(()=>{if(!H)return[];const J=Ne[he]||Ne[0];return mn(Fe(J),s)},[H,Ne,he,s]),_t=Ne[he]||Ne[0],kt=n.useMemo(()=>{const J=Fe(_t);return Pe({h:(J.h+180)%360,s:J.s,v:J.v})},[_t]);n.useLayoutEffect(()=>{if(!we||!oe.current)return;le(Je.scopeThemeClass(oe.current));const J=()=>{const je=oe.current?.getBoundingClientRect();if(!je)return;const ke=600;let Te=je.left;Te+ke>window.innerWidth-8&&(Te=Math.max(8,window.innerWidth-ke-8));let Ue=je.bottom+6;Ue>window.innerHeight*.5&&(Ue=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,540)-8)),I({left:Te,top:Ue})};return J(),window.addEventListener("scroll",J,!0),window.addEventListener("resize",J),()=>{window.removeEventListener("scroll",J,!0),window.removeEventListener("resize",J)}},[we]),n.useEffect(()=>{if(!we)return;const J=je=>{const ke=je.target;oe.current?.contains(ke)||se.current?.contains(ke)||(ke instanceof Element?ke:ke?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"], [aria-modal="true"]')||ae(!1)};return document.addEventListener("mousedown",J),()=>{document.removeEventListener("mousedown",J)}},[we]),r.useOverlayFocus(se,{open:we,modal:!1,onClose:()=>ae(!1)});const zt=n.useRef(null);if(r.useRovingFocus(zt,{orientation:"horizontal",itemSelector:".nice-palette__variation-chip"}),u)return null;const Lt=G.length>0?G:hn,kn=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(We.NiceSelect,{label:m("colorPalette.harmony","Harmony"),labelPlacement:"left",size:"sm",disabled:A,value:ye==="custom"&&_e?`custom:${_e}`:ye,onChange:J=>{const je=Array.isArray(J)?J[0]:J;if(typeof je=="string")if(je.startsWith("custom:")){const ke=je.slice(7);ne(ke),p("custom")}else ne(null),p(je)},options:[...Jn.map(J=>({value:J,label:Vn[J]})),...Le.map(J=>({value:`custom:${J.id}`,label:J.name}))],renderOption:(J,je)=>{const ke=String(J.value),Te=ke.startsWith("custom:"),Ue=Te?Le.find(et=>et.id===ke.slice(7)):null,dt=Ue?Ue.angles:void 0,Qe=Te?"custom":ke;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:Ut(Qe,{angles:dt,size:16,count:f})}),e.jsx("span",{style:{fontWeight:je?600:400},children:J.label})]})}}),ye==="shade-chain"&&e.jsx(tt.NiceNumberInput,{label:m("colorPalette.step","Step"),labelPlacement:"left",size:"sm",min:.02,max:.5,step:.02,precision:2,value:ze,onChange:J=>{const je=typeof J=="number"?J:Number(J);Number.isNaN(je)||(fe(je),L?.(je),Re($e.h,ye,xe,Ee))},showStepper:!0,disabled:A}),e.jsx(tt.NiceNumberInput,{label:m("colorPalette.colors","Colors"),labelPlacement:"left",size:"sm",min:Math.max(2,y),max:Math.min(12,T),step:1,precision:0,value:f??me??Ne.length,onChange:J=>{const je=typeof J=="number"?J:Number(J);if(!Number.isFinite(je))return;const ke=Math.max(Math.max(2,y),Math.min(Math.min(12,T),Math.round(je)));pe(ke),ye==="shade-chain"?g?.(Xt({h:$e.h,s:$e.s||.7,v:$e.v||.6},ke,ze)):setTimeout(()=>Re($e.h,ye,xe,Ee),0)},showStepper:!0,disabled:A})]}),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((J,je)=>e.jsxs("div",{role:"presentation",className:`nice-palette__swatch-wrapper ${he===je?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>be(je),onFocus:()=>be(je),children:[e.jsx("span",{className:"nice-palette__swatch",style:{background:J}}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:J.toUpperCase(),maxLength:7,disabled:A,onClick:ke=>ke.stopPropagation(),onChange:ke=>Se(je,ke.target.value),"aria-label":m("colorPalette.colorN","Color {n}").replace("{n}",String(je+1))}),Ne.length>y&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:ke=>{ke.stopPropagation(),qe(je)},disabled:A,"aria-label":m("colorPalette.removeColor","Remove color"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},je)),Ne.length<T&&e.jsxs("button",{type:"button",className:"nice-palette__add-btn",onClick:Me,disabled:A,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:kt},title:kt.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:kt.toUpperCase()})]}),w&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:Ze,disabled:A,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")]})]})})]}),wn=e.jsx("div",{className:"nice-palette__tab",children:Dt.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:zt,className:"nice-palette__variation-strip",role:"group","aria-label":m("colorPalette.tintsShades","Tints & Shades"),children:Dt.map((J,je)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:J},title:J.toUpperCase(),onClick:()=>{A||Se(he,J)},onKeyDown:ke=>{!A&&(ke.key==="Enter"||ke.key===" ")&&(ke.preventDefault(),Se(he,J))},role:"button","aria-label":J.toUpperCase()},je))})]}):e.jsx("div",{className:"nice-palette__empty",children:m("colorPalette.noVariationsAvailable","No variations available.")})}),Nn=e.jsx("div",{className:"nice-palette__tab",children:e.jsx("div",{className:"nice-palette__preset-grid",children:Lt.map(J=>{const je=yt(De,J);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${Ee===J?"nice-palette__preset-card--active":""}`,onClick:()=>ce(J),disabled:A,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:je.map((ke,Te)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:ke}},Te))}),e.jsx("span",{className:"nice-palette__preset-label",children:Wn[J]})]},J)})})}),Cn=e.jsxs("div",{className:"nice-palette__tab",children:[ee&&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(Gn,{hex:_t})]}),ie&&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(qn,{colors:Ne})]})]}),Sn=e.jsx("div",{className:"nice-palette__tab nice-palette__custom-schemes",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[Le.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.")}),Le.map(J=>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:Ut("custom",{angles:J.angles,size:16})}),e.jsx("span",{style:{flex:1},children:J.name}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>{ne(J.id),p("custom")},disabled:A,children:m("colorPalette.use","Use")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>Ye(Le.filter(je=>je.id!==J.id)),disabled:A,"aria-label":m("colorPalette.delete","Delete {name}").replace("{name}",String(J.name)),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},J.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:A,onClick:()=>{const J=Fe(Ne[0]).h,je=Ne.map(ke=>(Fe(ke).h-J+540)%360-180);D.prompt({title:m("colorPalette.schemeNamePrompt","Scheme name"),defaultValue:`Scheme ${Le.length+1}`}).then(ke=>{if(!ke)return;const Te={id:`cs-${Date.now()}`,name:ke,angles:je};Ye([...Le,Te])})},children:m("colorPalette.saveCurrentAsScheme","+ Save current as scheme")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A||Le.length===0,onClick:()=>{typeof navigator>"u"||navigator.clipboard?.writeText(JSON.stringify(Le,null,2))},children:m("colorPalette.exportJson","Export JSON")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A,onClick:()=>{D.prompt({title:m("colorPalette.pasteSchemesPrompt","Paste the schemes JSON")}).then(J=>{if(J)try{const je=JSON.parse(J);Array.isArray(je)&&Ye(je)}catch{}})},children:m("colorPalette.importJson","Import JSON")})]})]})}),it=[{id:"colors",label:m("colorPalette.colors","Colors"),content:kn}];re&&Lt.length>0&&it.push({id:"presets",label:m("colorPalette.presets","Presets"),content:Nn}),H&&it.push({id:"variations",label:m("colorPalette.variations","Variations"),content:wn}),(ee||ie)&&it.push({id:"info",label:m("colorPalette.info","Info"),content:Cn}),it.push({id:"schemes",label:m("colorPalette.schemes","Schemes"),content:Sn});const En=e.jsxs("div",{className:"nice-palette__popup-header",children:[U&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Xn,{hues:De,colors:Ne,baseHue:$e.h,onBaseHueChange:vt,mode:ye,distance:xe,disabled:A}),(ye==="analogous"||ye==="split-complementary"||ye==="analogous-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsx("label",{children:m("colorPalette.distance","Distance: {dist}°").replace("{dist}",String(xe))}),e.jsx("input",{type:"range",min:10,max:90,value:xe,onChange:J=>Q(Number(J.target.value)),disabled:A,className:"nice-palette__distance-slider","aria-label":m("colorPalette.distanceLabel","Distance")})]})]}),e.jsx("button",{type:"button",className:"nice-palette__confirm",onClick:()=>ae(!1),"aria-label":m("controls.confirm","Confirm"),title:m("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),$n=e.jsxs("div",{className:"nice-palette nice-palette--studio",children:[En,e.jsx(lt.NiceTabs,{tabs:it,variant:"enclosed",size:"sm"})]});return e.jsxs("div",{ref:h,id:S,className:`nice-field nice-palette-field ${A?"nice-palette--disabled":""} ${F==="left"?"nice-field--label-left":""} ${x?"nice-field--loading":""} ${C?"nice-field--error":""} ${i||""}`,style:a,"data-testid":b,children:[D.element,R&&e.jsx("label",{htmlFor:S,className:"nice-field__label",children:R}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("div",{ref:oe,className:"nice-palette__field-swatches",role:"button",tabIndex:A||_?-1:0,"aria-haspopup":"dialog","aria-expanded":we,"aria-readonly":_||void 0,"aria-label":m("colorPalette.openStudio","Open palette studio"),onClick:()=>{!A&&!_&&ae(J=>!J)},onKeyDown:J=>{!A&&!_&&(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),ae(je=>!je))},children:Ne.map((J,je)=>e.jsx("span",{role:"presentation",className:"nice-palette__field-swatch",style:{background:J},title:J.toUpperCase(),onClick:ke=>{ke.stopPropagation(),!A&&!_&&(be(je),ae(!0))}},je))}),x&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),we&&ue&&Z&&nt.createPortal(e.jsx("div",{ref:se,className:`nice-palette__popup${Y?` ${Y}`:""}`,"data-theme":Y==="nice-dark"?"dark":Y==="nice-light"?"light":void 0,role:"dialog","aria-label":m("colorPalette.studio","Palette studio"),style:{position:"fixed",left:ue.left,top:ue.top,zIndex:1e3},children:$n}),Z)]}),typeof C=="string"&&C&&e.jsx("div",{className:"nice-field__error",role:"alert",children:C})]})}),{displayName:"NiceColorPalette"});function It(){return{type:"linear",angle:90,stops:[{color:"var(--nice-primary, #3b82f6)",position:0},{color:"var(--nice-accent, #8b5cf6)",position:100}]}}function Mt(t){const i=t.stops.slice().sort((o,c)=>o.position-c.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",c=t.size||"farthest-corner",g=t.positionX??50,y=t.positionY??50;return`${a}radial-gradient(${o} ${c} at ${g}% ${y}%, ${i})`}case"conic":{const o=t.angle??0,c=t.positionX??50,g=t.positionY??50;return`${a}conic-gradient(from ${o}deg at ${c}% ${g}%, ${i})`}}}function fn(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 c=o.split(",").map(M=>M.trim());let g=90,y=0;const T=c[0].match(/^(\d+)deg$/);T&&(g=parseInt(T[1]),y=1);const P=Ct(c.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 c=o.split(",").map(y=>y.trim()),g=Ct(c.filter(y=>y.includes("#")||y.includes("rgb")));return{type:"radial",angle:0,repeating:a,stops:g.length>=2?g:It().stops}}if(i.includes("conic-gradient")){const o=i.match(/conic-gradient\((.+)\)/)?.[1];if(!o)return null;const c=o.split(",").map(y=>y.trim()),g=Ct(c.filter(y=>y.includes("#")||y.includes("rgb")));return{type:"conic",angle:0,repeating:a,stops:g.length>=2?g:It().stops}}return null}function Ct(t){return t.map((i,a,o)=>{const c=i.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(c){const g=c[2]?parseFloat(c[2]):a/Math.max(1,o.length-1)*100;return{color:c[1],position:g}}return{color:i,position:a/Math.max(1,o.length-1)*100}})}function ti(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ni(t=2){const i=["linear","radial","conic"],a=i[Math.floor(Math.random()*i.length)],o=[];for(let c=0;c<t;c++)o.push({color:ti(),position:Math.round(c/(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 yn=[{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}}],ii=Object.assign(n.forwardRef(({id:t,className:i,style:a,accessMode:o,value:c,onChange:g,showCssOutput:y=!0,showPresets:T=!0,showEditor:P=!0,showRandom:M=!0,maxStops:W=10,label:X,labelPlacement:B="top",disabled:$,readOnly:U,loading:ie,error:ee,errorPlacement:re="bottom",width:G,"data-testid":H},w)=>{const s=r.useNiceAccessMode(o,t),R=s==="hidden";s==="disabled"&&($=!0);const F=U||s==="readOnly",A=r.useControlId(t),{t:k}=r.useNiceTranslation(),x=c??It(),C=n.useMemo(()=>Mt(x),[x]),[f,E]=n.useState(0),[L,N]=n.useState(""),d=n.useRef(null),[z,b]=n.useState(!1),[h,l]=n.useState(null),[u,_]=n.useState(""),m=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),D=n.useRef(null),O=n.useRef(null),V=typeof G=="number"?G:340;n.useLayoutEffect(()=>{if(!z||!D.current)return;_(Je.scopeThemeClass(D.current));const j=()=>{const Z=D.current?.getBoundingClientRect();if(!Z)return;let oe=Z.left;oe+V>window.innerWidth-8&&(oe=Math.max(8,window.innerWidth-V-8));let se=Z.bottom+6;se>window.innerHeight*.5&&(se=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,520)-8)),l({left:oe,top:se})};return j(),window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}},[z,V]),n.useEffect(()=>{if(!z)return;const j=Z=>{const oe=Z.target;D.current?.contains(oe)||O.current?.contains(oe)||(oe instanceof Element?oe:oe?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||b(!1)};return document.addEventListener("mousedown",j),()=>{document.removeEventListener("mousedown",j)}},[z]),r.useOverlayFocus(O,{open:z,modal:!1,onClose:()=>b(!1)});const v=n.useCallback(j=>{g?.(j)},[g]),q=n.useCallback(j=>{$||v({...x,type:j})},[$,x,v]),K=n.useCallback(j=>{$||v({...x,angle:j})},[$,x,v]),de=n.useCallback(j=>{$||v({...x,repeating:j})},[$,x,v]),he=n.useCallback(j=>{$||v({...x,shape:j})},[$,x,v]),be=n.useCallback((j,Z)=>{if($)return;const oe=x.stops.map((se,ye)=>ye===j?{...se,...Z}:se);v({...x,stops:oe})},[$,x,v]),ge=n.useRef(!1),fe=n.useCallback((j,Z)=>{if($||!d.current)return;j.stopPropagation(),j.preventDefault(),E(Z),ge.current=!1;const oe=ye=>{if(!d.current)return;ge.current=!0;const xe=d.current.getBoundingClientRect(),Ee=Math.round(Math.max(0,Math.min(100,(ye.clientX-xe.left)/xe.width*100)));be(Z,{position:Ee})},se=()=>{document.removeEventListener("pointermove",oe),document.removeEventListener("pointerup",se),document.removeEventListener("pointercancel",se)};document.addEventListener("pointermove",oe),document.addEventListener("pointerup",se),document.addEventListener("pointercancel",se)},[$,be]),me=n.useCallback(()=>{if($||x.stops.length>=W)return;const j=x.stops.slice().sort((xe,Ee)=>xe.position-Ee.position);let Z=0,oe=j[0];for(let xe=0;xe<j.length-1;xe++){const Ee=j[xe+1].position-j[xe].position;Ee>Z&&(Z=Ee,oe=j[xe])}const se=Math.round(oe.position+Z/2),ye="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");v({...x,stops:[...x.stops,{color:ye,position:se}]})},[$,x,W,v]),pe=n.useCallback(j=>{if($||x.stops.length<=2)return;const Z=x.stops.filter((oe,se)=>se!==j);v({...x,stops:Z}),f>=Z.length&&E(Z.length-1)},[$,x,f,v]),te=(j,Z)=>{const oe=x.stops[Z];if($||!oe)return;const se=j.shiftKey?10:1,ye=j.key==="ArrowLeft"||j.key==="ArrowDown"?oe.position-se:j.key==="ArrowRight"||j.key==="ArrowUp"?oe.position+se:j.key==="PageDown"?oe.position-10:j.key==="PageUp"?oe.position+10:j.key==="Home"?0:j.key==="End"?100:null;ye!==null?(j.preventDefault(),be(Z,{position:Math.max(0,Math.min(100,ye))})):(j.key==="Delete"||j.key==="Backspace")&&x.stops.length>2&&(j.preventDefault(),pe(Z))},ve=n.useCallback(()=>{if($)return;const j=2+Math.floor(Math.random()*3);v(ni(j))},[$,v]),_e=n.useCallback(()=>{if($||!L.trim())return;const j=fn(L);j&&v(j)},[$,L,v]),ne=n.useCallback(j=>{if($||!d.current||x.stops.length>=W)return;const Z=j.target;if(ge.current||Z.closest(".nice-gradient__stop-marker")){ge.current=!1;return}const oe=d.current.getBoundingClientRect(),se=Math.round((j.clientX-oe.left)/oe.width*100),ye="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),xe=[...x.stops,{color:ye,position:se}];v({...x,stops:xe}),E(xe.length-1)},[$,x,W,v]),we=n.useMemo(()=>x.stops.slice().sort((j,Z)=>j.position-Z.position),[x.stops]),ae=n.useMemo(()=>`linear-gradient(90deg, ${we.map(j=>`${j.color} ${j.position}%`).join(", ")})`,[we]);if(R)return null;const ue=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(j=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${x.type===j?"nice-gradient__type-btn--active":""}`,onClick:()=>q(j),disabled:$,"aria-pressed":x.type===j,children:j.charAt(0).toUpperCase()+j.slice(1)},j)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:x.repeating??!1,onChange:j=>de(j.target.checked),disabled:$}),k("controls.repeating","Repeating")]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[x.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.angle","Angle: {angle}°").replace("{angle}",String(x.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:x.angle,onChange:j=>K(Number(j.target.value)),disabled:$,className:"nice-gradient__slider","aria-label":k("gradient.angle","Angle")}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(j=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${x.angle===j?"nice-gradient__angle-btn--active":""}`,onClick:()=>K(j),disabled:$,title:`${j}°`,"aria-label":`${j}°`,"aria-pressed":x.angle===j,children:e.jsx("span",{style:{transform:`rotate(${j}deg)`,display:"inline-flex"},children:e.jsx(r.NiceIcon,{name:"arrow-right",size:14})})},j))})]}),x.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.shape","Shape:")}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(j=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(x.shape||"ellipse")===j?"nice-gradient__shape-btn--active":""}`,onClick:()=>he(j),disabled:$,"aria-pressed":(x.shape||"ellipse")===j,children:j},j))})]}),(x.type==="radial"||x.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.center","Center: {positionX}%, {positionY}%").replace("{positionX}",String(x.positionX??50)).replace("{positionY}",String(x.positionY??50))}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:x.positionX??50,onChange:j=>v({...x,positionX:Number(j.target.value)}),disabled:$,className:"nice-gradient__slider","aria-label":k("gradient.centerX","Horizontal center")}),e.jsx("input",{type:"range",min:0,max:100,value:x.positionY??50,onChange:j=>v({...x,positionY:Number(j.target.value)}),disabled:$,className:"nice-gradient__slider","aria-label":k("gradient.centerY","Vertical center")})]})]}),x.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:k("controls.startAngle","Start angle: {angle}°").replace("{angle}",String(x.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:x.angle,onChange:j=>K(Number(j.target.value)),disabled:$,className:"nice-gradient__slider","aria-label":k("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:ae},onClick:ne,children:x.stops.map((j,Z)=>e.jsx("div",{className:`nice-gradient__stop-marker ${f===Z?"nice-gradient__stop-marker--active":""}`,style:{left:`${j.position}%`},onPointerDown:oe=>fe(oe,Z),onClick:oe=>{oe.stopPropagation(),E(Z),ge.current=!1},onFocus:()=>E(Z),onKeyDown:oe=>te(oe,Z),role:"slider",tabIndex:$?-1:0,"aria-label":k("gradient.stop","Stop {n}").replace("{n}",String(Z+1)),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":j.position,"aria-valuetext":`${j.color} ${j.position}%`,title:`${j.color} @ ${j.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:j.color}})},Z))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:me,disabled:$||x.stops.length>=W,title:k("controls.addStop","Add stop"),"aria-label":k("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:we.map((j,Z)=>{const oe=x.stops.indexOf(j);return e.jsxs("div",{role:"presentation",className:`nice-gradient__stop-row ${f===oe?"nice-gradient__stop-row--active":""}`,onClick:()=>E(oe),onFocus:()=>E(oe),children:[e.jsx("input",{type:"color",value:j.color,onChange:se=>be(oe,{color:se.target.value}),disabled:$,className:"nice-gradient__stop-color","aria-label":k("gradient.stopColor","Stop color")}),e.jsx("input",{type:"text",value:j.color.toUpperCase(),maxLength:7,onChange:se=>be(oe,{color:se.target.value}),disabled:$,className:"nice-gradient__stop-hex","aria-label":k("gradient.stopHex","Stop color (hex)")}),e.jsx("input",{type:"number",min:0,max:100,value:j.position,onChange:se=>be(oe,{position:Number(se.target.value)}),disabled:$,className:"nice-gradient__stop-pos","aria-label":k("gradient.stopPosition","Stop position")}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),x.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>pe(oe),disabled:$,"aria-label":k("controls.removeStop","Remove stop"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},oe)})})})]}),M&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:ve,disabled:$,title:k("controls.randomGradient","Random gradient"),"aria-label":k("controls.randomGradient","Random gradient"),children:[e.jsx(r.NiceIcon,{name:"shuffle",size:14})," ",k("controls.randomGradient2","Random Gradient")]})]}),I=e.jsx("div",{className:"nice-gradient__tab",children:e.jsx("div",{className:"nice-gradient__preset-grid",children:yn.map((j,Z)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{$||v(j.value)},disabled:$,title:j.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:Mt(j.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:j.name})]},Z))})}),Y=e.jsxs("div",{className:"nice-gradient__tab",children:[e.jsxs("div",{className:"nice-gradient__css-output",children:[e.jsx("code",{children:`background: ${C};`}),e.jsx("button",{type:"button",className:"nice-gradient__copy-btn",onClick:()=>navigator.clipboard?.writeText(`background: ${C};`),title:k("controls.copyCss","Copy CSS"),"aria-label":k("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:k("controls.pasteCssGradientToImport","Paste CSS gradient to import..."),value:L,onChange:j=>N(j.target.value),disabled:$,"aria-label":k("gradient.importCss","CSS gradient to import")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:_e,disabled:$,children:k("controls.import","Import")})]})]}),le=[{id:"editor",label:k("controls.editor","Editor"),content:ue}];return T&&le.push({id:"presets",label:k("controls.presets","Presets"),content:I}),y&&le.push({id:"css",label:"CSS",content:Y}),e.jsxs("div",{ref:w,id:A,className:`nice-field nice-gradient-field ${$?"nice-gradient--disabled":""} ${B==="left"?"nice-field--label-left":""} ${ie?"nice-field--loading":""} ${ee?"nice-field--error":""} ${re==="right"?"nice-field--error-right":""} ${i||""}`,style:a,"data-testid":H,children:[X&&e.jsx("label",{htmlFor:A,className:"nice-field__label",children:X}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("button",{ref:D,type:"button",className:"nice-gradient__swatch",style:{background:C},"aria-haspopup":"dialog","aria-expanded":z,"aria-readonly":F||void 0,"aria-label":k("controls.openGradientEditor","Open gradient editor"),disabled:$,onClick:()=>{!$&&!F&&b(j=>!j)}}),ie&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),re==="right"&&typeof ee=="string"&&ee&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ee}),z&&h&&m&&nt.createPortal(e.jsx("div",{ref:O,className:`nice-gradient__popup${u?` ${u}`:""}`,"data-theme":u==="nice-dark"?"dark":u==="nice-light"?"light":void 0,role:"dialog","aria-label":k("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:C}}),e.jsx("button",{type:"button",className:"nice-gradient__confirm",onClick:()=>b(!1),"aria-label":k("controls.confirm","Confirm"),title:k("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),e.jsx(lt.NiceTabs,{tabs:le,variant:"enclosed",size:"sm"})]})}),m)]}),re!=="right"&&typeof ee=="string"&&ee&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ee})]})}),{displayName:"NiceGradientPicker"}),oi=[{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"}],ai=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}],si=n.forwardRef(function(i,a){const{enableAI:o=!0,aiModel:c,enableImprove:g=!0,enableTranslate:y=!0,enableGenerate:T=!0,toolbar:P,languages:M=oi,textStyles:W=ai,onImprove:X,onTranslate:B,onGenerate:$,showAIToolbar:U=!0,value:ie,onChange:ee,...re}=i,G=n.useRef(null),[H,w]=n.useState(!1),[s,R]=n.useState(!1),[F,A]=n.useState(!1),[k,x]=n.useState(""),[C,f]=n.useState(""),[E,L]=n.useState("professional"),[N,d]=n.useState(""),[z,b]=n.useState(M[0]?.code||"en"),[h,l]=n.useState(""),[u,_]=n.useState(""),{t:S}=on.useNiceTranslation(),m=r.useNiceAI(),{improveText:D,translate:O,generateHtml:V,isLoading:v}=r.useTextImprovement(),q=o&&m.isConfigured,K=n.useCallback(()=>{const te=window.getSelection();return te&&te.toString().trim()?te.toString():""},[]),de=n.useCallback(te=>{const ve=window.getSelection();if(ve&&ve.rangeCount>0){const _e=ve.getRangeAt(0);_e.deleteContents();const ne=document.createElement("div");ne.innerHTML=te;const we=document.createDocumentFragment();for(;ne.firstChild;)we.appendChild(ne.firstChild);if(_e.insertNode(we),G.current){const ae=G.current.innerHTML;ee?.(ae)}}},[ee]),he=n.useCallback(async(te="professional")=>{if(!q||!g)return"";const ve=K();if(!ve)return"";x(ve),L(te),w(!0),f("");try{const _e=await D(ve,te);return f(_e),X?.(ve,_e,te),_e}catch{return f(S("htmlEditorAI.improveFailed","Failed to improve text")),""}},[q,g,K,D,X,S]),be=n.useCallback(async te=>{if(!q||!y)return"";const ve=K();if(!ve)return"";x(ve),b(te),R(!0),d("");try{const _e=M.find(we=>we.code===te)?.label||te,ne=await O(ve,_e);return d(ne),B?.(ve,ne,te),ne}catch{return d(S("htmlEditorAI.translateFailed","Failed to translate text")),""}},[q,y,K,O,M,B,S]),ge=n.useCallback(async te=>{if(!q||!T||!te.trim())return"";l(te),_("");try{const ve=await V(te);return _(ve),$?.(te,ve),ve}catch{return _(S("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[q,T,V,$,S]),fe=n.useCallback(()=>{C&&de(C),w(!1),f("")},[C,de]),me=n.useCallback(()=>{N&&de(N),R(!1),d("")},[N,de]),pe=n.useCallback(()=>{if(u&&G.current){document.execCommand("insertHTML",!1,u);const te=G.current.innerHTML;ee?.(te)}A(!1),_(""),l("")},[u,ee]);return n.useImperativeHandle(a,()=>({getEditor:()=>G.current,focus:()=>G.current?.focus(),getValue:()=>G.current?.innerHTML||"",setValue:te=>{G.current&&(G.current.innerHTML=te,ee?.(te))},getSelection:K,insertHtml:te=>{document.execCommand("insertHTML",!1,te),G.current&&ee?.(G.current.innerHTML)},improveSelection:he,translateSelection:be,generateHtml:ge})),n.useCallback(te=>{G.current=te},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":i["data-testid"],children:[U&&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:()=>he(),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:W.map(({style:te,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>he(te),children:ve},te))})]}),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:M.map(({code:te,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>be(te),children:ve},te))})]}),T&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>A(!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(In.NiceHtmlEditor,{value:ie,onChange:ee,toolbar:P,...re})}),H&&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:W.map(({style:te,label:ve})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${E===te?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{L(te),he(te)},children:ve},te))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>w(!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:k})]}),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:C})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:fe,disabled:!C||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:()=>{w(!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:te=>{b(te.target.value),be(te.target.value)},className:"nice-html-editor-ai__language-select",children:M.map(({code:te,label:ve})=>e.jsx("option",{value:te,children:ve},te))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":S("htmlEditorAI.close","Close"),onClick:()=>R(!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:k})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:M.find(te=>te.code===z)?.label||z}),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:me,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:()=>{R(!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:()=>{A(!1),_(""),l("")},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:te=>l(te.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")})]}),u&&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:u}}),e.jsx("h5",{children:S("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:u})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:pe,disabled:!u||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:()=>{A(!1),_(""),l("")},children:S("htmlEditorAI.cancel","Cancel")})]})]})]})}),ri=[{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 ci(t){let i=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return i=i.replace(/```(\w*)\n([\s\S]*?)```/g,(a,o,c)=>`<pre><code class="language-${o}">${c.trim()}</code></pre>`),i=i.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(a,o,c,g)=>{const y=o.split("|").filter(P=>P.trim()).map(P=>`<th>${P.trim()}</th>`).join(""),T=g.trim().split(`
|
|
2
2
|
`).map(P=>`<tr>${P.split("|").filter(W=>W.trim()).map(W=>`<td>${W.trim()}</td>`).join("")}</tr>`).join("");return`<table><thead><tr>${y}</tr></thead><tbody>${T}</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(/^> (.+)$/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 li=[{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
3
|
`,tip:"Horizontal rule",group:"block"},{key:"link",icon:"link",md:"[](url)",tip:"Link",shortcut:"Ctrl+K",group:"insert"},{key:"image",icon:"image",md:"",tip:"Image",group:"insert"},{key:"table",icon:"table",md:`| H1 | H2 | H3 |
|
|
4
4
|
| --- | --- | --- |
|