@nice2dev/ui 1.4.16 → 1.4.18

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/NiceAlert-RVTgQxCE.cjs +1 -0
  3. package/dist/NiceDataGrid-Cszjz8NV.cjs +10 -0
  4. package/dist/NiceForm-DM2tARZT.cjs +1 -0
  5. package/dist/{NiceHtmlEditor-By7R1wRo.cjs → NiceHtmlEditor-BEWNA_UI.cjs} +1 -1
  6. package/dist/NiceLoginForm-Bkm5j80r.cjs +1 -0
  7. package/dist/{NiceMention-i7n2BoMw.cjs → NiceMention-DhaTUqvR.cjs} +1 -1
  8. package/dist/NiceModuleLifecyclePanel-DAIbzfZd.cjs +1 -0
  9. package/dist/{NicePagination-D9JguOl0.cjs → NicePagination-CnKYyKI5.cjs} +1 -1
  10. package/dist/{NicePivotGrid-B_7iQJys.cjs → NicePivotGrid-BshofJh1.cjs} +1 -1
  11. package/dist/NiceSavedQueryPanel-DJKEOqy5.cjs +587 -0
  12. package/dist/{NiceScheduler-B2DamQ_L.cjs → NiceScheduler-Dff8fuq_.cjs} +1 -1
  13. package/dist/{core-lazy-ChKRuEPb.cjs → core-lazy-BhQxFuLf.cjs} +1 -1
  14. package/dist/data/NiceRowEditDialog.mjs +42 -35
  15. package/dist/data/NiceTreeGrid.mjs +512 -474
  16. package/dist/data.cjs +1 -1
  17. package/dist/data.d.ts +30 -3
  18. package/dist/editors/forms/NiceForm.mjs +55 -52
  19. package/dist/editors/inputs/NiceRadioGroup.mjs +12 -12
  20. package/dist/editors/inputs/NiceSelect.mjs +51 -51
  21. package/dist/editors/pickers/NiceLanguagePicker.mjs +129 -125
  22. package/dist/editors/pickers/NiceThemePicker.mjs +1 -1
  23. package/dist/editors/pickers/pickerCommons.mjs +155 -203
  24. package/dist/editors.cjs +1 -1
  25. package/dist/feedback.cjs +1 -1
  26. package/dist/index.cjs +96 -96
  27. package/dist/index.d.ts +41 -7
  28. package/dist/lazy.cjs +1 -1
  29. package/dist/navigation.cjs +1 -1
  30. package/dist/navigation.d.ts +6 -0
  31. package/dist/{no-code-CN_q6TcB.cjs → no-code-DPc82kyy.cjs} +11 -11
  32. package/dist/no-code.cjs +1 -1
  33. package/dist/pickerCommons-CQnae2FM.cjs +1 -0
  34. package/dist/style.css +2 -2
  35. package/dist/tools/NiceThemeGalleryPicker.mjs +168 -265
  36. package/package.json +4 -4
  37. package/dist/NiceDataGrid-B1AOjgjm.cjs +0 -10
  38. package/dist/NiceForm-fmePSeA9.cjs +0 -1
  39. package/dist/NiceLoginForm-C2-WgRn0.cjs +0 -1
  40. package/dist/NiceModuleLifecyclePanel-DVHQuhc-.cjs +0 -1
  41. package/dist/NiceSavedQueryPanel-ChY4HwpM.cjs +0 -587
  42. package/dist/pickerCommons-CwcCc8Qi.cjs +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";const e=require("react/jsx-runtime"),r=require("@nice2dev/ui-core"),n=require("react"),ot=require("react-dom"),Fe=require("./no-code-CN_q6TcB.cjs"),pt=require("./pickerCommons-CwcCc8Qi.cjs"),tt=require("./devops-o6Zm0VKB.cjs"),Ue=require("./NiceForm-fmePSeA9.cjs"),an=require("@nice2dev/i18n"),sn=require("./NiceHtmlEditor-By7R1wRo.cjs"),Ie=require("./NiceButton-DzCqkG5a.cjs"),Pt=require("./NiceColorPicker-79rkvaSk.cjs"),Et=require("./NiceCodeEditor-DhdjnDLV.cjs"),kt=require("./injectStyleOnce-DeWaxcdf.cjs"),zn=({min:t=0,max:i=100,step:o=1,startValue:a=t,endValue:s=i,onChange:g,showLabels:x=!0,formatLabel:$,valuePlacement:P="none",label:M,error:W,helperText:J,required:B,disabled:I,readOnly:q,loading:se,size:oe="md",id:ce,className:Z,style:F,accessMode:k,showKeyboardHints:l,labelPlacement:T,errorPlacement:Y,labelWidth:A,controlWidth:_})=>{const b=r.useNiceAccessMode(k,ce),C=b==="hidden";(b==="disabled"||b==="readOnly")&&(I=!0);const{t:f}=r.useNiceTranslation(),S=r.useControlId(ce),K=n.useRef(null),w=n.useMemo(()=>[r.COMMON_SHORTCUTS.increment,r.COMMON_SHORTCUTS.decrement,r.COMMON_SHORTCUTS.first,r.COMMON_SHORTCUTS.last,{key:"Tab",description:f("shortcuts.switchThumb","Switch thumb")}],[f]),d=p=>(p-t)/(i-t)*100,D=p=>$?$(p):String(p),j=n.useCallback(p=>{const E=Math.round(p/o)*o;return Math.max(t,Math.min(i,E))},[t,i,o]),h=n.useCallback((p,E)=>{p.preventDefault();const N=K.current;if(!N||I)return;const m=z=>{const ie=N.getBoundingClientRect(),v=Math.max(0,Math.min(1,(z.clientX-ie.left)/ie.width)),ee=j(t+v*(i-t));E==="start"?g?.(Math.min(ee,s),s):g?.(a,Math.max(ee,a))},R=()=>{document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",R)};document.addEventListener("pointermove",m),document.addEventListener("pointerup",R)},[t,i,j,a,s,g,I]),c=(p,E)=>{if(I||q)return;const N=E==="start"?a:s,m=E==="start"?t:a,R=E==="start"?s:i,z=Math.max(o,(i-t)/10),ie=p.key==="ArrowRight"||p.key==="ArrowUp"?N+o:p.key==="ArrowLeft"||p.key==="ArrowDown"?N-o:p.key==="PageUp"?N+z:p.key==="PageDown"?N-z:p.key==="Home"?m:p.key==="End"?R:null;if(ie===null)return;p.preventDefault();const v=Math.max(m,Math.min(R,j(ie)));E==="start"?g?.(v,s):g?.(a,v)};return C?null:e.jsxs("div",{className:`nice-field nice-field--${oe} nice-field--rangeslider ${T==="left"?"nice-field--label-left":""} ${Y==="right"?"nice-field--error-right":""} ${W?"nice-field--error":""} ${se?"nice-field--loading":""} ${Z||""}`,style:{...F,...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},..._!=null&&{"--nice-field-control-width":typeof _=="number"?`${_}px`:_}},"aria-busy":se||void 0,children:[(M||P==="right"&&T!=="left")&&(T!=="left"?e.jsxs("div",{className:"nice-range-slider__header",children:[M?e.jsx("label",{className:"nice-field__label",htmlFor:S,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),l&&e.jsx(r.NiceKeyboardHint,{shortcuts:w,size:"sm"})]})}):e.jsx("span",{}),P==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--header",children:[D(a)," – ",D(s)]})]}):M&&e.jsx("label",{className:"nice-field__label",htmlFor:S,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),l&&e.jsx(r.NiceKeyboardHint,{shortcuts:w,size:"sm"})]})})),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-range-slider__stack",children:[e.jsxs("div",{className:`nice-range-slider ${x?"nice-range-slider--with-labels":""} ${M?"nice-range-slider--has-field-label":""}`,ref:K,children:[e.jsx("div",{className:"nice-range-slider__track",children:e.jsx("div",{className:"nice-range-slider__fill",style:{left:`${d(a)}%`,width:`${d(s)-d(a)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(a)}%`},onPointerDown:p=>q?void 0:h(p,"start"),onKeyDown:p=>c(p,"start"),role:"slider","aria-label":f("rangeSlider.min","Minimum"),"aria-valuemin":t,"aria-valuemax":s,"aria-valuenow":a,"aria-valuetext":D(a),"aria-disabled":I||void 0,"aria-readonly":q||void 0,tabIndex:I?-1:0,id:S}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(s)}%`},onPointerDown:p=>q?void 0:h(p,"end"),onKeyDown:p=>c(p,"end"),role:"slider","aria-label":f("rangeSlider.max","Maximum"),"aria-valuemin":a,"aria-valuemax":i,"aria-valuenow":s,"aria-valuetext":D(s),"aria-disabled":I||void 0,"aria-readonly":q||void 0,tabIndex:I?-1:0})]}),x&&e.jsxs("div",{className:"nice-range-slider__values",children:[e.jsx("span",{className:"nice-range-slider__values-start",style:{left:`${d(a)}%`},children:D(a)}),e.jsx("span",{className:"nice-range-slider__values-end",style:{left:`${d(s)}%`},children:D(s)})]}),P==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[D(a)," – ",D(s)]})]}),P==="right"&&T==="left"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[D(a)," – ",D(s)]}),se&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),Y==="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),Y==="right"&&!W&&J&&e.jsx("div",{className:"nice-field__helper",children:J})]}),Y!=="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),Y!=="right"&&!W&&J&&e.jsx("div",{className:"nice-field__helper",children:J})]})},Ln={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160,small:64,medium:80,large:100},gt=6,dt=135,rn=405,ct=rn-dt;function $t(t,i,o,a){const s=(a-90)*(Math.PI/180);return{x:t+o*Math.cos(s),y:i+o*Math.sin(s)}}function Ot(t,i,o,a,s){const g=$t(t,i,o,a),x=$t(t,i,o,s),$=s-a>180?1:0;return`M ${g.x} ${g.y} A ${o} ${o} 0 ${$} 1 ${x.x} ${x.y}`}const Pn=Object.assign(n.forwardRef(({value:t=0,onChange:i,min:o=0,max:a=100,step:s=1,showValue:g=!0,valueTemplate:x="{value}",label:$,helperText:P,error:M,required:W,disabled:J,readOnly:B,size:I="md",name:q,id:se,className:oe,style:ce,labelPlacement:Z="top",errorPlacement:F,labelWidth:k,controlWidth:l,loading:T,isLabelCentered:Y=!0,...A},_)=>{const b=r.useControlId(se),C=n.useRef(!1),f=n.useRef(null),S=typeof I=="number"?I:Ln[I],K=S/2,w=S/2,d=(S-gt*2)/2,D=a>o?(t-o)/(a-o):0,j=dt+D*ct,h=n.useCallback(m=>{let R=m-dt;R<0&&(R+=360),R>ct&&(R=R-ct<360-R?ct:0);const z=Math.max(0,Math.min(1,R/ct)),ie=o+z*(a-o),v=Math.round(ie/s)*s;return Math.max(o,Math.min(a,v))},[o,a,s]),c=n.useCallback(m=>{if(J||B)return;const R=f.current;if(!R)return;const z=R.getBoundingClientRect(),ie=m.clientX-z.left-z.width/2,v=m.clientY-z.top-z.height/2;let ee=Math.atan2(ie,-v)*(180/Math.PI);ee<0&&(ee+=360);const U=h(ee);i?.(U)},[h,J,B,i]);n.useEffect(()=>{const m=z=>{C.current&&c(z)},R=()=>{C.current=!1};return window.addEventListener("pointermove",m),window.addEventListener("pointerup",R),()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",R)}},[c]);const p=n.useCallback(m=>{if(J||B)return;let R=t;const z=Math.max(s,(a-o)/10);m.key==="ArrowUp"||m.key==="ArrowRight"?(m.preventDefault(),R=Math.min(a,t+s)):m.key==="ArrowDown"||m.key==="ArrowLeft"?(m.preventDefault(),R=Math.max(o,t-s)):m.key==="PageUp"||m.key==="PageDown"?(m.preventDefault(),R=Math.max(o,Math.min(a,t+(m.key==="PageUp"?z:-z)))):(m.key==="Home"||m.key==="End")&&(m.preventDefault(),R=m.key==="Home"?o:a),R!==t&&i?.(R)},[t,i,o,a,s,J,B]),E=(x||"{value}").replace("{value}",String(t)),N=$t(K,w,d,j);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${F||"bottom"} nice-field--${typeof I=="string"?I:"md"} ${T?"nice-field--loading":""} ${oe||""}`,style:{...ce,...k!=null&&{"--nice-field-label-width":typeof k=="number"?`${k}px`:k},...l!=null&&{"--nice-field-control-width":typeof l=="number"?`${l}px`:l}},"aria-busy":T||void 0,...A,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${Z} ${Y?"nice-knob-field--label-centered":""}`,children:[$&&e.jsx("label",{htmlFor:b,className:`nice-field__label ${W?"nice-field__label--required":""}`,children:$}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:m=>{f.current=m,typeof _=="function"?_(m):_&&(_.current=m)},className:`nice-knob nice-knob--${I} ${J?"nice-knob--disabled":""} ${M?"nice-knob--error":""}`,role:"slider",id:b,tabIndex:J?-1:0,"aria-valuenow":t,"aria-valuemin":o,"aria-valuemax":a,"aria-disabled":J,"aria-invalid":!!M,onPointerDown:m=>{J||B||(C.current=!0,c(m))},onKeyDown:p,children:[e.jsxs("svg",{width:S,height:S,viewBox:`0 0 ${S} ${S}`,children:[e.jsx("path",{d:Ot(K,w,d,dt,rn),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:gt,strokeLinecap:"round"}),D>0&&e.jsx("path",{d:Ot(K,w,d,dt,j),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:gt,strokeLinecap:"round"}),e.jsx("circle",{cx:N.x,cy:N.y,r:gt,fill:"var(--nice-primary, #3b82f6)"})]}),g&&e.jsx("span",{className:"nice-knob__value",children:E}),q&&e.jsx("input",{type:"hidden",name:q,value:t}),T&&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"}),On=({options:t,value:i,defaultValue:o,onChange:a,searchable:s=!0,clearable:g,loading:x,placeholder:$,label:P,error:M,helperText:W,required:J,disabled:B,readOnly:I,size:q="md",id:se,className:oe,style:ce,data:Z,columns:F,valueField:k="id",displayField:l,dropdownWidth:T,menuGap:Y,labelPlacement:A,errorPlacement:_,labelWidth:b,controlWidth:C})=>{const f=B||I||x,S=r.useControlId(se),{t:K}=r.useNiceTranslation(),[w,d]=r.useControllableState({value:i,defaultValue:o,fallbackValue:"",onChange:a,componentName:"NiceLookup"}),[D,j]=n.useState(!1),[h,c]=n.useState(""),p=n.useRef(null),E=n.useRef(null),{popupRef:N,coords:m,ready:R,themeClass:z,portalTarget:ie}=Fe.useAnchoredPopup(D,E,()=>j(!1)),v=!!(Z&&F&&F.length>0),ee=l??(F&&F[0]?.key),U=n.useMemo(()=>!v||!Z?[]:Z.map(re=>({value:String(re[k]??""),label:ee?String(re[ee]??""):""})),[v,Z,k,ee]),me=n.useMemo(()=>v?U:t??[],[v,U,t]),pe=me.find(re=>String(re.value)===w),ye=n.useMemo(()=>{if(!v||!Z)return[];if(!h)return Z;const re=h.toLowerCase();return Z.filter(fe=>F.some(H=>String(fe[H.key]??"").toLowerCase().includes(re)))},[v,Z,F,h]),ue=n.useMemo(()=>{if(v||!h)return me;const re=h.toLowerCase();return me.filter(fe=>fe.label.toLowerCase().includes(re))},[me,h,v]),he=v?ye:ue,{activeIndex:de,setActiveIndex:ge,handleKeyDown:ae}=pt.useListKeyboardNav(he,{open:D,onSelect:re=>{const fe=String(v?re[k]??"":re.value);d(fe),j(!1),c("")},onClose:()=>j(!1),onOpen:()=>!f&&j(!0),intentRef:N}),_e=`${n.useId()}-listbox`,te=re=>`${_e}-opt-${re}`,we=D&&he.length>0?te(de):void 0;return n.useLayoutEffect(()=>{we&&document.getElementById(we)?.scrollIntoView?.({block:"nearest"})},[we]),e.jsxs("div",{className:`nice-field nice-field--lookup nice-field--${q} ${M?"nice-field--error":""} ${A==="left"?"nice-field--label-left":""} ${_==="right"&&(M||W)?"nice-field--error-right":""} ${x?"nice-field--loading":""} ${B?"nice-field--disabled":""} ${oe||""}`,style:{...C!=null&&{"--nice-field-control-width":typeof C=="number"?`${C}px`:C},...b!=null&&{"--nice-field-label-width":typeof b=="number"?`${b}px`:b},...Y!=null&&{"--nice-dropdown-gap":`${Y}px`},...ce},"aria-busy":x||void 0,ref:p,children:[P&&e.jsxs("label",{className:"nice-field__label",htmlFor:S,children:[P,J&&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:E,children:[e.jsxs("button",{type:"button",id:S,className:`nice-select__trigger ${B?"nice-select__trigger--disabled":""}`,onClick:()=>!f&&j(!D),onKeyDown:ae,disabled:B,"aria-readonly":I||void 0,role:"combobox","aria-haspopup":"listbox","aria-expanded":D,"aria-controls":D?_e:void 0,"aria-activedescendant":s?void 0:we,children:[e.jsx("span",{children:pe?.label||$||K("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[g&&w&&!B&&!I&&e.jsx("span",{onKeyDown:r.clickOnActivationKey,className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":K("controls.clear","Clear"),onClick:re=>{re.stopPropagation(),d("")},children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:`nice-select__arrow${I?" nice-select__arrow--hidden":""}`,children:e.jsx(r.NiceIcon,{name:"chevron-down",size:16})})]})]}),D&&m&&ie&&ot.createPortal(e.jsxs("div",{ref:N,className:`nice-dropdown nice-lookup__dropdown${z?` ${z}`:""}`,"data-theme":z==="nice-dark"?"dark":z==="nice-light"?"light":void 0,style:{position:"fixed",top:m.top,left:m.left,zIndex:1e3,marginTop:"var(--nice-dropdown-gap, 0px)",background:"var(--nice-bg-primary)",border:"1px solid var(--nice-border-color)",borderRadius:"var(--nice-radius-md)",boxShadow:"0 4px 16px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",minWidth:m.width,width:T!=null?typeof T=="number"?`${T}px`:T:v?"max-content":m.width,opacity:R?1:0,pointerEvents:R?void 0:"none"},children:[s&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:h,onChange:re=>{c(re.target.value),ge(0)},onKeyDown:ae,placeholder:K("controls.search","Search..."),"aria-label":K("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:F.map(re=>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:re.width!=null?typeof re.width=="number"?`${re.width}px`:re.width:void 0},children:re.header},re.key))})}),e.jsx("tbody",{children:ye.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:F.length,style:{padding:12,textAlign:"center",color:"var(--nice-text-muted)"},children:K("controls.noResults","No results")})}):ye.map((re,fe)=>{const H=String(re[k]??""),X=H===w,O=fe===de;return e.jsx("tr",{id:te(fe),role:"option","aria-selected":X,onClick:()=>{d(H),j(!1),c("")},style:{cursor:"pointer",background:X||O?"var(--nice-hover-bg)":"transparent"},onMouseEnter:()=>ge(fe),children:F.map(y=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--nice-border-color)"},children:String(re[y.key]??"")},y.key))},H)})})]}):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:ue.length===0?e.jsx("li",{className:"nice-dropdown__empty",style:{padding:8,color:"var(--nice-text-muted)"},children:K("controls.noResults","No results")}):ue.map((re,fe)=>e.jsx("li",{id:te(fe),role:"option",className:`nice-dropdown__option ${String(re.value)===w?"nice-dropdown__option--selected":""} ${fe===de?"nice-dropdown__option--active":""}`,onClick:()=>{d(String(re.value)),j(!1),c("")},onMouseEnter:()=>ge(fe),"aria-selected":String(re.value)===w,children:re.label},String(re.value)))})]}),ie)]}),x&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),_==="right"&&M&&e.jsx("div",{className:"nice-field__error",role:"alert",children:M}),_==="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]}),_!=="right"&&M&&e.jsx("div",{className:"nice-field__error",children:M}),_!=="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]})},Bn=[];function Bt(t){const i=[],o=a=>{for(const s of a)i.push(s),s.children&&o(s.children)};return o(t),i}function cn(t,i){const o=i.toLowerCase();return t.reduce((a,s)=>{const g=s.children?cn(s.children,i):[];return(s.label.toLowerCase().includes(o)||g.length>0)&&a.push({...s,children:g.length>0?g:s.children}),a},[])}const ln=({node:t,level:i,selectedKeys:o,expandedKeys:a,onToggleExpand:s,onSelect:g,selectableLeafsOnly:x,maxDepth:$})=>{const{t:P}=r.useNiceTranslation(),M=typeof $=="number"?Math.min(10,Math.max(1,$)):1/0,J=!(i+1>=M)&&t.children&&t.children.length>0,B=a.has(t.key),I=o.has(t.key),q=!J,se=!t.disabled&&(!x||q),oe=Math.min(i+1,10),ce={paddingLeft:i*16+14,"--nice-row-bg":`var(--nice-tree-level-${oe}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${oe}-text, inherit)`,"--nice-row-hover-bg":`var(--nice-tree-level-${oe}-hover-bg, var(--nice-bg-secondary, #f3f4f6))`,"--nice-row-active-bg":`var(--nice-tree-level-${oe}-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 ${I?"nice-tree-select__node--selected":""} ${t.disabled?"nice-tree-select__node--disabled":""}`,style:ce,"data-nice-depth":oe,onClick:()=>{t.disabled||(J?s(t.key):se&&g(t.key))},role:"treeitem","aria-level":i+1,"aria-selected":I,"aria-expanded":J?B:void 0,"aria-disabled":t.disabled,"data-key":String(t.key),children:[J?e.jsx("button",{type:"button",className:"nice-tree-select__toggle-btn",tabIndex:-1,onClick:Z=>{Z.stopPropagation(),s(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})]}),J&&B&&t.children.map(Z=>e.jsx(ln,{node:Z,level:i+1,selectedKeys:o,expandedKeys:a,onToggleExpand:s,onSelect:g,selectableLeafsOnly:x,maxDepth:$},Z.key))]})},Hn=Object.assign(n.forwardRef(({nodes:t=Bn,value:i,onChange:o,multiple:a=!1,searchable:s=!1,placeholder:g,selectableLeafsOnly:x=!1,clearable:$=!1,maxDepth:P,label:M,helperText:W,error:J,required:B,disabled:I,readOnly:q,size:se="md",name:oe,id:ce,className:Z,style:F,controlWidth:k,menuGap:l,labelPlacement:T,errorPlacement:Y,labelWidth:A,..._},b)=>{const{t:C}=r.useNiceTranslation(),f=r.useControlId(ce),[S,K]=n.useState(!1),[w,d]=n.useState(""),[D,j]=n.useState(new Set),h=n.useRef(null),{popupRef:c,coords:p,ready:E,themeClass:N,portalTarget:m}=Fe.useAnchoredPopup(S,h,()=>K(!1)),R=n.useMemo(()=>i==null?new Set:new Set(Array.isArray(i)?i:[i]),[i]),z=n.useMemo(()=>w?cn(t,w):t,[t,w]),ie=n.useMemo(()=>{const he=Bt(t);return Array.from(R).map(de=>he.find(ge=>ge.key===de)?.label).filter(Boolean)},[R,t]),v=n.useCallback(he=>{j(de=>{const ge=new Set(de);return ge.has(he)?ge.delete(he):ge.add(he),ge})},[]),ee=n.useCallback(he=>{if(a){const de=new Set(R);de.has(he)?de.delete(he):de.add(he),o?.(Array.from(de))}else o?.(he),K(!1)},[a,R,o]),U=n.useCallback(he=>{he.stopPropagation(),o?.(a?[]:"")},[o,a]),me=n.useRef(null),pe=`${f}-tree`;r.useTreeFocus(me,{onToggle:(he,de)=>{const ge=Bt(z).find(ae=>String(ae.key)===he.dataset.key);ge&&D.has(ge.key)!==de&&v(ge.key)}});const ye=n.useCallback(()=>(me.current?.querySelector('[role="treeitem"][tabindex="0"]')??me.current?.querySelector('[role="treeitem"]'))?.focus(),[]),ue=!!p;return n.useEffect(()=>{S&&ue&&!s&&ye()},[S,ue,s,ye]),e.jsxs("div",{className:`nice-field nice-field--${se}${T?` nice-field--label-${T}`:""}${Y==="right"?" nice-field--error-right":""} ${Z||""}`,style:{width:"fit-content",maxWidth:"100%",...l!=null&&{"--nice-dropdown-gap":`${l}px`},...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...F},..._,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:k!=null&&k!==""?typeof k=="number"?`${k}px`:k:"var(--nice-field-control-width, 220px)"},children:[e.jsxs("div",{ref:b,id:f,className:`nice-input nice-input--${se} ${J?"nice-input--error":""} ${I?"nice-input--disabled":""} ${q?"nice-input--readonly":""}`,role:"combobox","aria-expanded":S,"aria-haspopup":"tree","aria-controls":S?pe:void 0,"aria-invalid":!!J,tabIndex:I?-1:0,onClick:()=>!I&&!q&&K(!S),onKeyDown:he=>{(he.key==="Enter"||he.key===" "||he.key==="ArrowDown"||he.key==="ArrowUp")&&!I&&!q&&(he.preventDefault(),S?ye():K(!0))},children:[e.jsx("span",{className:"nice-tree-select__display",children:ie.length>0?ie.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:g??C("controls.select","Select...")})}),$&&R.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:U,"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:S?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx(r.NiceIcon,{name:"chevron-down",size:14})})]}),S&&p&&m&&ot.createPortal(e.jsxs("div",{ref:c,className:`nice-tree-select__dropdown${N?` ${N}`:""}`,"data-theme":N==="nice-dark"?"dark":N==="nice-light"?"light":void 0,style:{position:"fixed",left:p.left,top:p.top,width:p.width,minWidth:p.width,zIndex:1e3,opacity:E?1:0,pointerEvents:E?void 0:"none"},children:[s&&e.jsx("div",{className:"nice-select__search",onClick:he=>he.stopPropagation(),role:"presentation",children:e.jsx("input",{type:"text",placeholder:C("controls.search","Search..."),"aria-label":C("controls.search","Search..."),"aria-controls":pe,value:w,onChange:he=>d(he.target.value),onKeyDown:he=>{he.key==="ArrowDown"&&(he.preventDefault(),ye())},autoFocus:!0})}),e.jsx("div",{ref:me,id:pe,className:"nice-tree-select__list",role:"tree","aria-label":M||g||C("controls.select","Select..."),"aria-multiselectable":a||void 0,children:z.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:C("controls.noResults","No results")}):z.map(he=>e.jsx(ln,{node:he,level:0,selectedKeys:R,expandedKeys:D,onToggleExpand:v,onSelect:ee,selectableLeafsOnly:x,maxDepth:P},he.key))})]}),m)]}),oe&&e.jsx("input",{type:"hidden",name:oe,value:Array.isArray(i)?i.join(","):i??""}),J&&e.jsx("div",{id:`${f}-error`,className:"nice-field__error",role:"alert",children:J}),!J&&W&&e.jsx("div",{id:`${f}-helper`,className:"nice-field__helper",children:W})]})}),{displayName:"NiceTreeSelect"}),Fn=({displayValue:t,placeholder:i,clearable:o,children:a,onClear:s,open:g,onOpenChange:x,dropdownWidth:$,searchable:P=!0,onSearch:M,searchPlaceholder:W,label:J,error:B,helperText:I,required:q,disabled:se,size:oe="md",id:ce,className:Z,style:F,accessMode:k,showKeyboardHints:l,displayStyle:T})=>{r.useComponentDisplayStyle("input",T),r.useComponentDisplayClass("input",T);const Y=r.useNiceAccessMode(k,ce),A=Y==="hidden";(Y==="disabled"||Y==="readOnly")&&(se=!0);const _=r.useControlId(ce),{t:b}=r.useNiceTranslation(),[C,f]=n.useState(!1),[S,K]=n.useState(""),w=n.useRef(null),d=n.useRef(null),D=g??C,j=n.useMemo(()=>[{key:"Enter",description:b("shortcuts.openDropdown","Open dropdown")},r.COMMON_SHORTCUTS.cancel],[b]),h=R=>{x?x(R):f(R)},{popupRef:c,coords:p,ready:E,themeClass:N,portalTarget:m}=Fe.useAnchoredPopup(D,d,()=>h(!1));return A?null:e.jsxs("div",{className:`nice-field nice-field--${oe} ${B?"nice-field--error":""} ${Z||""}`,style:F,ref:w,children:[J&&e.jsxs("label",{className:"nice-field__label",htmlFor:_,children:[J,q&&e.jsx("span",{className:"nice-field__required",children:"*"}),l&&e.jsx(r.NiceKeyboardHint,{shortcuts:j,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",ref:d,children:[e.jsxs("button",{type:"button",id:_,className:"nice-select__trigger",onClick:()=>!se&&h(!D),disabled:se,children:[e.jsx("span",{children:t||i||b("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[o&&t&&!se&&e.jsx("span",{className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":b("controls.clear","Clear"),onClick:R=>{R.stopPropagation(),s?.()},onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),R.stopPropagation(),s?.())},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})})]})]}),D&&p&&m&&ot.createPortal(e.jsxs("div",{ref:c,className:`nice-dropdown${N?` ${N}`:""}`,"data-theme":N==="nice-dark"?"dark":N==="nice-light"?"light":void 0,style:{position:"fixed",left:p.left,top:p.top,width:$??p.width,minWidth:$??p.width,zIndex:1e3,maxHeight:320,overflowY:"auto",opacity:E?1:0,pointerEvents:E?void 0:"none"},children:[P&&M&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:S,onChange:R=>{K(R.target.value),M(R.target.value)},placeholder:W??b("controls.search","Search..."),autoFocus:!0})}),a]}),m)]}),B&&e.jsx("div",{className:"nice-field__error",children:B}),I&&!B&&e.jsx("div",{className:"nice-field__hint",children:I})]})},Kn=[],Un=[];function et(t,i){return String(t[i])}const Yn={xxs:10,xs:12,sm:12,md:14,lg:18,xl:22,xxl:26},Xn=Object.assign(n.forwardRef(({source:t=Kn,target:i=Un,onChange:o,keyField:a="id",labelField:s="label",renderItem:g,filterable:x=!1,searchable:$,groupBy:P,sortable:M=!1,bulkActions:W=!0,maxRight:J,sourceHeader:B,targetHeader:I,disabled:q=!1,size:se="md",className:oe,style:ce,id:Z,...F},k)=>{const{t:l}=r.useNiceTranslation(),T=Yn[se]??14,[Y,A]=n.useState(new Set),[_,b]=n.useState(new Set),[C,f]=n.useState(""),[S,K]=n.useState(""),[w,d]=n.useState(null),D=n.useRef(null),j=n.useRef(null),h={orientation:"vertical",typeahead:!0,pageSize:10};r.useRovingFocus(D,h),r.useRovingFocus(j,h);const c=n.useCallback((v,ee,U)=>{ee(me=>{const pe=new Set(me);return pe.has(U)?pe.delete(U):pe.add(U),pe})},[]),p=n.useCallback(()=>{const v=t.filter(pe=>Y.has(et(pe,a))),ee=t.filter(pe=>!Y.has(et(pe,a))),U=typeof J=="number"?v.slice(0,Math.max(0,J-i.length)):v,me=v.slice(U.length);o([...ee,...me],[...i,...U]),A(new Set)},[t,i,Y,a,o,J]),E=n.useCallback(()=>{const v=i.filter(U=>_.has(et(U,a))),ee=i.filter(U=>!_.has(et(U,a)));o([...t,...v],ee),b(new Set)},[t,i,_,a,o]),N=n.useCallback(()=>{if(typeof J=="number"){const v=Math.max(0,J-i.length),ee=t.slice(0,v),U=t.slice(v);o(U,[...i,...ee])}else o([],[...i,...t]);A(new Set)},[t,i,o,J]),m=n.useCallback(()=>{o([...t,...i],[]),b(new Set)},[t,i,o]),R=(v,ee)=>{if(!ee)return v;const U=ee.toLowerCase();return v.filter(me=>String(me[s]).toLowerCase().includes(U))},z=W===!1?{moveAll:!1,removeAll:!1}:W===!0||W===void 0?{moveAll:!0,removeAll:!0}:{moveAll:W.moveAll??!0,removeAll:W.removeAll??!0},ie=(v,ee,U,me,pe,ye,ue,he)=>{let de=R(v,me);M||(de=[...de].sort((re,fe)=>String(re[s]).localeCompare(String(fe[s]),void 0,{numeric:!0,sensitivity:"base"})));const ge=$===!0||x&&$===void 0?"both":$??!1,ae=ge==="both"||ge==="left"&&ue==="left"||ge==="right"&&ue==="right",ve=(()=>{if(!P)return[{label:"",items:de}];const re=new Map;for(const fe of de){const H=String(P(fe));let X=re.get(H);X||(X=[],re.set(H,X)),X.push(fe)}return[...re.entries()].map(([fe,H])=>({label:fe,items:H}))})(),_e=(re,fe)=>{re.dataTransfer.setData("text/plain",fe),re.dataTransfer.effectAllowed="move"},te=(re,fe)=>{if(re.preventDefault(),!M)return;const H=re.currentTarget.getBoundingClientRect(),X=re.clientY<H.top+H.height/2;d(O=>O&&O.side===ue&&O.key===fe&&O.before===X?O:{side:ue,key:fe,before:X})},we=(re,fe)=>{re.preventDefault();const H=w?.before??!1;d(null);const X=re.dataTransfer.getData("text/plain");if(!X||!M)return;const y=[...ue==="right"?i:t],G=y.findIndex(xe=>et(xe,a)===X),ne=y.findIndex(xe=>et(xe,a)===fe);if(G===-1||ne===-1||X===fe)return;let le=H?ne:ne+1;const[be]=y.splice(G,1);G<le&&(le-=1),y.splice(le,0,be),o(ue==="right"?t:y,ue==="right"?y:i)};return e.jsxs("div",{className:"nice-picklist__panel",children:[ye&&e.jsx("div",{className:"nice-picklist__header",children:ye}),ae&&e.jsx("div",{className:"nice-picklist__filter",children:e.jsx("input",{className:"nice-input__native",type:"text",size:1,placeholder:l("controls.search","Search..."),value:me,onChange:re=>pe(re.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true","aria-label":typeof ye=="string"?ye:void 0,ref:he,children:[ve.map(re=>e.jsxs(n.Fragment,{children:[re.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:re.label}),re.items.map(fe=>{const H=et(fe,a),X=ee.has(H),y=w&&w.side===ue&&w.key===H?w.before?"nice-picklist__item--drop-before":"nice-picklist__item--drop-after":"";return e.jsxs("div",{className:`nice-picklist__item ${X?"nice-picklist__item--selected":""} ${y}`,role:"option","aria-selected":X,draggable:M,onDragStart:M?G=>_e(G,H):void 0,onDragOver:M?G=>te(G,H):void 0,onDrop:M?G=>we(G,H):void 0,onDragEnd:M?()=>d(null):void 0,onClick:()=>!q&&c(ee,U,H),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),q||c(ee,U,H))},children:[M&&e.jsx("span",{className:"nice-picklist__drag-handle","aria-hidden":"true",children:e.jsx(r.NiceIcon,{name:"grip",size:T})}),g?g(fe,ue):String(fe[s])]},H)})]},re.label||"__none__")),de.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:l("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:k,id:Z,className:`nice-picklist nice-picklist--${se} ${q?"nice-picklist--disabled":""} ${oe||""}`,style:ce,...F,children:[ie(t,Y,A,C,f,B??l("picklist.source","Available"),"left",D),e.jsxs("div",{className:"nice-picklist__controls",children:[e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||Y.size===0,onClick:p,"aria-label":l("picklist.moveRight","Move right"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:T})}),z.moveAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||t.length===0,onClick:N,"aria-label":l("picklist.moveAllRight","Move all right"),children:e.jsx(r.NiceIcon,{name:"chevrons-right",size:T})}),e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||_.size===0,onClick:E,"aria-label":l("picklist.moveLeft","Move left"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:T})}),z.removeAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||i.length===0,onClick:m,"aria-label":l("picklist.moveAllLeft","Move all left"),children:e.jsx(r.NiceIcon,{name:"chevrons-left",size:T})})]}),ie(i,_,b,S,K,I??l("picklist.target","Selected"),"right",j)]})}),{displayName:"NicePickList"});function Tt(t){return t?.startsWith("datetime")?"datetime":t==="week"?"week":t?.startsWith("month")?"month":"date"}function qn(t){const i=new Date,o=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`,a=Tt(t);return a==="datetime"?`${o}T00:00`:a==="month"?o.slice(0,7):o}function Ht(t,i){if(!t)return t;const o=new Date(t.length<=10?`${t}T00:00`:t);if(Number.isNaN(o.getTime()))return t;o.setDate(o.getDate()+i);const a=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`;return t.length<=10?a.slice(0,t.length):a+t.slice(10)}function ft(...t){return t.filter(Boolean).sort().pop()}function Ft(t,i,o){if(!t)return"";const a=new Date(t.length<=10?`${t}T00:00`:t);if(Number.isNaN(a.getTime()))return t;const s=Tt(o);return s==="month"?a.toLocaleDateString(i,{year:"numeric",month:"2-digit"}):s==="datetime"?a.toLocaleString(i,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):a.toLocaleDateString(i,{year:"numeric",month:"2-digit",day:"2-digit"})}function Kt(t){let i=0;for(const o of t)i+=/[\p{L}\p{N}]/u.test(o)?1:.5;return i}function Ut(t){const i=/^(\d{4})-(\d{2})(?:-(\d{2}))?(?:T(\d{2}):(\d{2}))?$/.exec(t);if(!i)return!1;const[,o,a,s="01",g="00",x="00"]=i,$=new Date(Number(o),Number(a)-1,Number(s));return $.getMonth()===Number(a)-1&&$.getDate()===Number(s)&&Number(g)<24&&Number(x)<60}const Vn=({startDate:t,endDate:i,defaultStartDate:o,defaultEndDate:a,onStartChange:s,onEndChange:g,min:x,max:$,clearable:P,startPlaceholder:M,endPlaceholder:W,startLabel:J,endLabel:B,layout:I="horizontal",separator:q="–",gap:se=12,fullWidth:oe=!1,dateFormatPreset:ce,locale:Z,timeSelectorType:F,endCondition:k="greater-or-equal",startCondition:l="today-or-greater",singleField:T=!1,label:Y,error:A,helperText:_,required:b,disabled:C,size:f="md",id:S,className:K,style:w,accessMode:d,showKeyboardHints:D,labelPlacement:j,errorPlacement:h,labelWidth:c,controlWidth:p,loading:E,readOnly:N})=>{const m=r.useNiceAccessMode(d,S),R=r.useControlId(S),{t:z}=r.useNiceTranslation(),ie=m==="disabled"||m==="readOnly"||!!C,[v,ee]=r.useControllableState({value:t,defaultValue:o,fallbackValue:"",onChange:s,componentName:"NiceDateRangeBox"}),[U,me]=r.useControllableState({value:i,defaultValue:a,fallbackValue:"",onChange:g,componentName:"NiceDateRangeBox"}),pe=n.useMemo(()=>[{key:"Tab",description:z("shortcuts.switchField","Switch between start/end")},r.COMMON_SHORTCUTS.cancel],[z]),ye=n.useRef(null),ue=n.useRef(null),[he,de]=n.useState(!1),[ge,ae]=n.useState(null),[ve,_e]=n.useState(""),te=n.useContext(r.NiceThemeContext),we=te?.portalTarget??(typeof document<"u"?document.body:null),re=Z||Ue.getDefaultLocale(),fe=n.useMemo(()=>Ue.rangeMaskSpec(ce,re),[ce,re]),[H,X]=n.useState(null);n.useLayoutEffect(()=>{if(!he)return;const L=ye.current?.getBoundingClientRect();L&&(ae({left:L.left,top:L.bottom+6}),_e(te?.portalTarget?"":tt.scopeThemeClass(ye.current)))},[he,te?.portalTarget]),n.useEffect(()=>{if(!he)return;const L=Ce=>{const Pe=Ce.target;ye.current?.contains(Pe)||ue.current?.contains(Pe)||de(!1)},ke=()=>{const Ce=ye.current?.getBoundingClientRect();Ce&&ae({left:Ce.left,top:Ce.bottom+6})};return document.addEventListener("mousedown",L),window.addEventListener("scroll",ke,!0),window.addEventListener("resize",ke),()=>{document.removeEventListener("mousedown",L),window.removeEventListener("scroll",ke,!0),window.removeEventListener("resize",ke)}},[he]),r.useOverlayFocus(ue,{open:he,modal:!1,initialFocus:'.nice-calendar__grid [tabindex="0"]',onClose:()=>de(!1)});const O=qn(ce),y=l==="today-or-greater"?ft(x,O):l==="greater-than-today"?ft(x,Ht(O,1)):x,G=k==="greater-or-equal"?ft(x,v):k==="greater"?ft(x,v?Ht(v,1):void 0):x,ne=n.useMemo(()=>{if(A)return A;if(v&&U){if(k==="greater-or-equal"&&U<v)return z("daterange.endBeforeStart","End date must be on or after the start date");if(k==="greater"&&U<=v)return z("daterange.endAfterStart","End date must be after the start date")}if(v){if(l==="today-or-greater"&&v<O)return z("daterange.startInPast","Start date cannot be in the past");if(l==="greater-than-today"&&v<=O)return z("daterange.startAfterToday","Start date must be after today")}},[A,v,U,l,k,O,z]);if(m==="hidden")return null;const le=L=>{ee(L),L&&U&&L>U&&me(L)},be=I==="horizontal",xe=Tt(ce),Se=re,Te=typeof q=="string"&&q!==""?q:"–",Me=xe!=="week"&&ce!=="time",ze=Ue.dateMaskDigits.slots(fe),qe=L=>L?Me?Ue.dateMaskDigits.render(fe,Ue.dateMaskDigits.fromIso(fe,L)):Ft(L,Se,ce):"",Ve=qe(v),Ge=qe(U),We=Ve||Ge?`${Ve||"…"} ${Te} ${Ge||"…"}`:"",Ee=L=>{const ke=Ue.dateMaskDigits.render(fe,L.slice(0,ze));return L.length<ze?ke:`${ke} ${Te} ${Ue.dateMaskDigits.render(fe,L.slice(ze))}`},Je=`${fe.placeholder} ${Te} ${fe.placeholder}`,$e=(()=>{const L=Me?fe.placeholder:Ft("2026-12-30T22:58",Se,ce),ke=`${L} ${Te} ${L}`;return`${(Math.max(Kt(ke),Kt(We))+1.5).toFixed(1)}ch`})(),Ze=(L,ke)=>xe==="datetime"?ke&&ke.length>10?`${L}${ke.slice(10)}`:`${L}T00:00`:xe==="month"?L.slice(0,7):L,Le=({start:L,end:ke})=>{X(null),ee(L?Ze(L,v):""),me(ke?Ze(ke,U):""),L&&ke&&de(!1)},Ae=()=>{X(null),ee(""),me("")},Oe=L=>{const ke=H!==null?Ee(H):We;let Ce=L.replace(/\D/g,"").slice(0,ze*2);if(L.length<ke.length&&Ce===ke.replace(/\D/g,"")&&(Ce=Ce.slice(0,-1)),Ce.length===0){Ae();return}X(Ce);const Pe=Ce.length>=ze?Ue.dateMaskDigits.toIso(fe,Ce.slice(0,ze)):"";Pe&&Ut(Pe)&&Pe!==v&&ee(Pe);const He=Ce.length===ze*2?Ue.dateMaskDigits.toIso(fe,Ce.slice(ze)):"";He&&Ut(He)&&He!==U&&me(He)},at=()=>{H!==null&&(H.length<ze&&ee(""),H.length<ze*2&&me(""),X(null))},u=()=>{!ie&&!N&&de(L=>!L)},V=L=>L&&L.length>=10?L.slice(0,10):L||void 0;return e.jsxs("div",{className:`nice-field nice-field--${f} nice-daterange nice-daterange--${I} ${j==="left"?"nice-field--label-left":""} ${ne?"nice-field--error":""} ${E?"nice-field--loading":""} ${K||""}`,style:{...w,...c!=null&&{"--nice-field-label-width":typeof c=="number"?`${c}px`:c},...p!=null&&{"--nice-field-control-width":typeof p=="number"?`${p}px`:p}},"aria-busy":E||void 0,children:[Y&&e.jsxs("label",{className:"nice-field__label",htmlFor:R,children:[Y,b&&e.jsx("span",{className:"nice-field__required",children:"*"}),D&&e.jsx(r.NiceKeyboardHint,{shortcuts:pe,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[T?e.jsxs("div",{ref:ye,className:`nice-input nice-input--date nice-input--${f} nice-daterange__single ${ne?"nice-input--error":""} ${ie?"nice-input--disabled":""} ${N?"nice-input--readonly":""}`,style:{position:"relative",width:oe?"100%":"fit-content"},children:[e.jsx("input",{id:R,className:"nice-input__native",type:"text",readOnly:!Me||N,value:H!==null?Ee(H):We,placeholder:M||(Me?Je:z("controls.startDate","Start date")),disabled:ie||E,autoComplete:"off",spellCheck:!1,inputMode:Me?"numeric":void 0,"aria-invalid":!!ne,"aria-label":Y?void 0:z("controls.startDate","Start date"),"aria-haspopup":"dialog","aria-expanded":he,onClick:Me?void 0:u,onChange:Me?L=>Oe(L.target.value):void 0,onBlur:Me?at:void 0,onKeyDown:L=>{const ke=!!L.nativeEvent.niceSource;(L.key==="Enter"||L.key===" "&&!Me||L.key==="ArrowDown"&&!ke)&&(L.preventDefault(),he||u())},style:{width:oe?"100%":$e,cursor:ie||N?void 0:Me?"text":"pointer"}}),P&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:Ae,disabled:!v&&!U||ie||N,"aria-label":z("controls.clear","Clear"),tabIndex:(v||U)&&!ie&&!N?0:-1,children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("button",{type:"button",className:"nice-input__picker-trigger",onClick:u,"aria-label":z("controls.openPicker","Open picker"),"aria-expanded":he,tabIndex:-1,disabled:ie||N,children:e.jsx(r.NiceIcon,{name:"calendar",size:16})})]}):e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:be?"row":"column",alignItems:be?j==="left"?"center":"flex-end":"stretch",gap:se,flexWrap:be?"nowrap":"wrap"},children:[e.jsx("div",{style:{flex:oe?"1 1 0":void 0,minWidth:0},children:e.jsx(Ue.NiceDateTimePicker,{id:R,dateFormatPreset:ce,displayLocale:Z,timeSelectorType:F,label:J,value:v,onChange:le,min:y,max:U||$,placeholder:M,disabled:ie,readOnly:N,size:f,clearable:P,labelPlacement:j,labelWidth:c})}),be&&q!==""&&q!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--nice-text-secondary, #666)"},"aria-hidden":"true",children:q}),e.jsx("div",{style:{flex:oe?"1 1 0":void 0,minWidth:0},children:e.jsx(Ue.NiceDateTimePicker,{dateFormatPreset:ce,displayLocale:Z,timeSelectorType:F,label:B,value:U,onChange:L=>me(L),min:G||v||x,max:$,placeholder:W,disabled:ie,readOnly:N,size:f,clearable:P,labelPlacement:j,labelWidth:c})})]}),T&&he&&ge&&we&&ot.createPortal(e.jsxs("div",{ref:ue,className:`nice-datetime-popup${ve?` ${ve}`:""}`,style:{position:"fixed",left:ge.left,top:ge.top,zIndex:1e3},role:"dialog","aria-label":z("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(Ue.NiceCalendar,{selectionMode:"range",rangeStart:V(v),rangeEnd:V(U),onRangeChange:Le,min:V(y),max:V($),size:f})})}),P&&e.jsx("div",{className:"nice-datetime-popup__footer",children:e.jsx("button",{type:"button",className:"nice-datetime-popup__btn",onClick:Ae,disabled:!v&&!U,children:z("controls.clear","Clear")})})]}),we),E&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),h==="right"&&ne&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ne}),h==="right"&&!ne&&_&&e.jsx("div",{className:"nice-field__helper",children:_})]}),h!=="right"&&ne&&e.jsx("div",{className:"nice-field__error",children:ne}),h!=="right"&&!ne&&_&&e.jsx("div",{className:"nice-field__hint",children:_})]})};function Gn(t,i=30){switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-i,180+i];case"analogous":return[0,-i,i];case"analogous-complementary":return[0,-i,i,180];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270];case"shade-chain":return[];case"custom":return[0,60,200];default:return[0]}}function Yt(t,i={}){const o=i.size??16,a="currentColor",s="currentColor";if(i.rectangle||t==="shade-chain"||t==="monochromatic"){const J=Math.max(3,Math.min(7,i.count??5)),B=o*.1,I=o-B*2,q=Math.max(1.2,o/14),se=o/2,oe=Array.from({length:J},(ce,Z)=>{const F=B+I*Z/(J-1),k=.25+.75*Z/(J-1);return e.jsx("circle",{cx:F,cy:se,r:q,fill:s,opacity:k},Z)});return e.jsxs("svg",{width:o,height:o,viewBox:`0 0 ${o} ${o}`,"aria-hidden":!0,children:[e.jsx("rect",{x:1,y:o/2-o/6,width:o-2,height:o/3,rx:o/6,fill:"none",stroke:a,strokeOpacity:.25}),oe]})}const x=i.angles??Gn(t),$=o/2,P=o/2,M=o/2-2,W=Math.max(1.4,o/9);return e.jsxs("svg",{width:o,height:o,viewBox:`0 0 ${o} ${o}`,"aria-hidden":!0,children:[e.jsx("circle",{cx:$,cy:P,r:M,fill:"none",stroke:a,strokeOpacity:.25}),x.map((J,B)=>{const I=(J-90)*Math.PI/180,q=$+M*Math.cos(I),se=P+M*Math.sin(I);return e.jsx("circle",{cx:q,cy:se,r:W,fill:s},B)})]})}function Xt(t,i,o){return Math.max(i,Math.min(o,t))}function dn({h:t,s:i,v:o}){t=(t%360+360)%360;const a=o*i,s=a*(1-Math.abs(t/60%2-1)),g=o-a;let x=0,$=0,P=0;return t<60?(x=a,$=s):t<120?(x=s,$=a):t<180?($=a,P=s):t<240?($=s,P=a):t<300?(x=s,P=a):(x=a,P=s),{r:Math.round((x+g)*255),g:Math.round(($+g)*255),b:Math.round((P+g)*255)}}function Rt({r:t,g:i,b:o}){t/=255,i/=255,o/=255;const a=Math.max(t,i,o),s=Math.min(t,i,o),g=a-s;let x=0;return g!==0&&(a===t?x=(i-o)/g%6:a===i?x=(o-t)/g+2:x=(t-i)/g+4,x=(x*60+360)%360),{h:x,s:a===0?0:g/a,v:a}}function mn({r:t,g:i,b:o}){t/=255,i/=255,o/=255;const a=Math.max(t,i,o),s=Math.min(t,i,o),g=(a+s)/2;if(a===s)return{h:0,s:0,l:g};const x=a-s,$=g>.5?x/(2-a-s):x/(a+s);let P=0;return a===t?P=((i-o)/x+(i<o?6:0))/6:a===i?P=((o-t)/x+2)/6:P=((t-i)/x+4)/6,{h:P*360,s:$,l:g}}function ut(t){const i=t.replace("#",""),o=i.length===3?i[0]+i[0]+i[1]+i[1]+i[2]+i[2]:i,a=parseInt(o,16);return{r:a>>16&255,g:a>>8&255,b:a&255}}function un({r:t,g:i,b:o}){return"#"+[t,i,o].map(a=>a.toString(16).padStart(2,"0")).join("")}function Be(t){return un(dn(t))}function Ye(t){return Rt(ut(t))}function pn(t,i){const o=[];for(let a=0;a<i;a++){const s=i<=1?.5:a/(i-1),g=Xt(t.s*(.3+s*.7),0,1),x=Xt(t.v*(1.2-s*.7),0,1);o.push(Be({h:t.h,s:g,v:x}))}return o}function _t(t,i){if(t==="custom"||t==="shade-chain")return[0];const o=i??30;switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-o,180+o];case"analogous":return[0,-o,o];case"analogous-complementary":return[0,-o,o,180];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270]}return[0]}function mt(t,i,o){return _t(i,o).map(a=>((t+a)%360+360)%360)}function qt(t,i,o=.12){const a=Math.max(2,i),s=(a-1)/2,g=[];for(let x=0;x<a;x++){const $=(x-s)*o,P=Math.max(.05,Math.min(.98,t.v+$)),M=Math.max(.05,Math.min(1,t.s-Math.abs($)*.25));g.push(Be({h:t.h,s:M,v:P}))}return g}function Vt({r:t,g:i,b:o}){const[a,s,g]=[t,i,o].map(x=>{const $=x/255;return $<=.03928?$/12.92:Math.pow(($+.055)/1.055,2.4)});return .2126*a+.7152*s+.0722*g}function xt(t,i){const o=Vt(ut(t)),a=Vt(ut(i)),s=Math.max(o,a),g=Math.min(o,a);return(s+.05)/(g+.05)}function bt(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"AA-lg":"Fail"}const hn={"lightest-pastel":{sRange:[.1,.25],vRange:[.92,1]},"bright-pastel":{sRange:[.25,.45],vRange:[.9,1]},shiny:{sRange:[.7,.95],vRange:[.9,1]},pastel:{sRange:[.3,.55],vRange:[.75,.92]},full:{sRange:[.75,1],vRange:[.75,1]},dark:{sRange:[.6,.9],vRange:[.3,.55]},deep:{sRange:[.85,1],vRange:[.45,.65]},muted:{sRange:[.15,.35],vRange:[.5,.7]},earth:{sRange:[.3,.6],vRange:[.4,.65]}};function jt(t,i){const o=hn[i];return t.map(a=>{const s=(o.sRange[0]+o.sRange[1])/2,g=(o.vRange[0]+o.vRange[1])/2;return Be({h:a,s,v:g})})}function Wn(){return Math.floor(Math.random()*360)}function gn(t,i,o){const a=Wn(),s=mt(a,t,o),g=[];for(let x=0;x<i;x++){const $=s[x%s.length],P=.55+Math.random()*.4,M=.5+Math.random()*.45;g.push(Be({h:$+(Math.random()-.5)*8,s:P,v:M}))}return g}const Jn=({hues:t,colors:i,baseHue:o,onBaseHueChange:a,mode:s,distance:g,disabled:x})=>{const{t:$}=r.useNiceTranslation(),P=240,M=P/2,W=P/2,J=110,B=55,I=l=>{if(x)return;const T=l.shiftKey?15:1,Y=l.key==="ArrowLeft"||l.key==="ArrowDown"?-T:l.key==="ArrowRight"||l.key==="ArrowUp"?T:l.key==="PageDown"?-15:l.key==="PageUp"?15:null;Y!==null?(l.preventDefault(),a(((o+Y)%360+360)%360)):(l.key==="Home"||l.key==="End")&&(l.preventDefault(),a(l.key==="Home"?0:359))},q=n.useRef(null),se=n.useCallback((l,T)=>{const Y=q.current;if(!Y)return;const A=Y.getBoundingClientRect(),_=(l-A.left)/A.width*P-M,b=(T-A.top)/A.height*P-W,C=(Math.atan2(b,_)*180/Math.PI+360)%360;a(Math.round(C))},[M,W,P,a]),oe=n.useCallback(l=>{if(x)return;l.preventDefault(),se(l.clientX,l.clientY);const T=A=>se(A.clientX,A.clientY),Y=()=>{document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",Y)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",Y)},[x,se]),ce=[];for(let l=0;l<360;l+=2){const T=(l-1)*Math.PI/180,Y=(l+1)*Math.PI/180,A=Be({h:l,s:1,v:1});ce.push(e.jsx("path",{d:`M${M+B*Math.cos(T)},${W+B*Math.sin(T)} L${M+J*Math.cos(T)},${W+J*Math.sin(T)} A${J},${J} 0 0,1 ${M+J*Math.cos(Y)},${W+J*Math.sin(Y)} L${M+B*Math.cos(Y)},${W+B*Math.sin(Y)} A${B},${B} 0 0,0 ${M+B*Math.cos(T)},${W+B*Math.sin(T)} Z`,fill:A},l))}const Z=`wheel-center-${s}`,F=t.map((l,T)=>{const Y=(J+B)/2,A=l*Math.PI/180;return e.jsx("circle",{cx:M+Y*Math.cos(A),cy:W+Y*Math.sin(A),r:T===0?8:6,fill:i?.[T]??Be({h:l,s:.85,v:.9}),stroke:T===0?"var(--nice-bg-primary, #fff)":"var(--nice-border-color, #ccc)",strokeWidth:T===0?3:2},T)});let k=null;if(s==="analogous"||s==="split-complementary"||s==="analogous-complementary"){const l=(J+B)/2,Y=_t(s,g).slice(1).map((A,_)=>{const b=(o+A)*Math.PI/180;return e.jsx("line",{x1:M,y1:W,x2:M+l*Math.cos(b),y2:W+l*Math.sin(b),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${_}`)});k=e.jsx(e.Fragment,{children:Y})}return e.jsxs("svg",{ref:q,className:"nice-palette__wheel",viewBox:`0 0 ${P} ${P}`,width:P,height:P,onPointerDown:oe,onKeyDown:I,role:"slider",tabIndex:x?-1:0,"aria-label":$("colorPalette.baseHue","Base hue"),"aria-valuemin":0,"aria-valuemax":359,"aria-valuenow":Math.round(o),"aria-valuetext":`${Math.round(o)}°`,style:{cursor:x?"default":"crosshair",touchAction:"none"},children:[e.jsx("defs",{children:e.jsxs("radialGradient",{id:Z,children:[e.jsx("stop",{offset:"0%",stopColor:"var(--nice-bg, #fff)"}),e.jsx("stop",{offset:"100%",stopColor:"transparent"})]})}),ce,e.jsx("circle",{cx:M,cy:W,r:B-2,fill:Be({h:o,s:.6,v:.85})}),e.jsx("circle",{cx:M,cy:W,r:B-2,fill:`url(#${Z})`,opacity:.4}),k,F]})},Zn=({colors:t})=>{const{t:i}=r.useNiceTranslation();if(t.length<2)return null;const o=[];for(let a=0;a<t.length;a++){const s=xt(t[a],"var(--nice-bg-primary, #ffffff)"),g=xt(t[a],"var(--nice-text-primary, #000000)");o.push({a:t[a],b:"var(--nice-bg-primary, #ffffff)",ratio:s,level:bt(s)}),o.push({a:t[a],b:"var(--nice-text-primary, #000000)",ratio:g,level:bt(g)});for(let x=a+1;x<t.length;x++){const $=xt(t[a],t[x]);o.push({a:t[a],b:t[x],ratio:$,level:bt($)})}}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:o.map((a,s)=>e.jsxs("div",{className:"nice-palette__contrast-pair",children:[e.jsxs("div",{className:"nice-palette__contrast-swatches",children:[e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:a.a}}),e.jsx("span",{className:"nice-palette__contrast-vs",children:i("colorPalette.vs","vs")}),e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:a.b}})]}),e.jsxs("span",{className:"nice-palette__contrast-ratio",children:[a.ratio.toFixed(1),":1"]}),e.jsx("span",{className:`nice-palette__contrast-level nice-palette__contrast-level--${a.level.toLowerCase().replace("-","")}`,children:a.level})]},s))})]})},Qn=({hex:t})=>{const i=ut(t),o=mn(i),a=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(o.h),"°, ",Math.round(o.s*100),"%,"," ",Math.round(o.l*100),"%"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSV"})," ",Math.round(a.h),"°, ",Math.round(a.s*100),"%,"," ",Math.round(a.v*100),"%"]})]})},ei={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"},ti={"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"},ni=["monochromatic","shade-chain","complementary","split-complementary","analogous","analogous-complementary","triadic","tetradic","square","custom"],fn=["lightest-pastel","bright-pastel","shiny","pastel","full","dark","deep","muted","earth"],yn="nice-palette-custom-schemes";function ii(){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(yn);if(!t)return[];const i=JSON.parse(t);if(Array.isArray(i))return i}catch{}return[]}function oi(t){if(!(typeof window>"u"))try{window.localStorage.setItem(yn,JSON.stringify(t))}catch{}}const ai=Object.assign(n.forwardRef(({id:t,className:i,style:o,accessMode:a,value:s,onChange:g,minColors:x=1,maxColors:$=8,harmonyMode:P,onHarmonyModeChange:M,distance:W,onDistanceChange:J,preset:B,onPresetChange:I,showWheel:q=!0,showContrast:se=!0,showInfo:oe=!0,showPresets:ce=!0,presets:Z=[],showVariations:F=!0,showRandom:k=!0,variationCount:l=5,label:T,labelPlacement:Y="top",disabled:A,readOnly:_,loading:b,error:C,colorCount:f,shadeStep:S,onShadeStepChange:K,customSchemes:w,onCustomSchemesChange:d,persistCustomSchemes:D=!0,"data-testid":j},h)=>{const c=r.useNiceAccessMode(a,t),p=c==="hidden";c==="disabled"&&(A=!0);const E=_||c==="readOnly",N=r.useControlId(t),{t:m}=r.useNiceTranslation(),R=tt.useNiceDialogs(),[z,ie]=n.useState("analogous-complementary"),[v,ee]=n.useState(30),[U,me]=n.useState(""),[pe,ye]=n.useState(0),[ue,he]=n.useState(.12),[de,ge]=n.useState(null),[ae,ve]=n.useState(()=>w??(D?ii():[])),[_e,te]=n.useState(null),[we,re]=n.useState(!1),[fe,H]=n.useState(null),[X,O]=n.useState(""),G=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),ne=n.useRef(null),le=n.useRef(null),be=P??z,xe=W??v,Se=B??U,Te=S??ue,Me=w??ae;n.useEffect(()=>{!w&&D&&oi(ae)},[ae,w,D]);const ze=n.useCallback(Q=>{ve(Q),d?.(Q)},[d]),qe=n.useCallback(Q=>{ie(Q),M?.(Q)},[M]),Ve=n.useCallback(Q=>{ee(Q),J?.(Q)},[J]),Ge=n.useCallback(Q=>{me(Q),Q&&I?.(Q)},[I]),We=n.useMemo(()=>["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)"],[]),Ee=s&&s.length>0?s:We,Je=Ee[0],$e=n.useMemo(()=>Ye(Je),[Je]),Ze=n.useMemo(()=>mt($e.h,be,xe),[$e.h,be,xe]),Le=n.useCallback((Q,je,Ne,Re,Xe)=>{const ht=f??Xe??de??Ee.length,nt=ht!==void 0?Math.max(x,Math.min($,ht)):void 0;if(je==="shade-chain"){const Ke=nt??Math.max(x,5),Qe=qt({h:Q,s:$e.s||.7,v:$e.v||.6},Ke,Te);g?.(Qe);return}let it;const rt=je==="custom"&&_e?Me.find(Ke=>Ke.id===_e):null;rt&&rt.angles.length>0?it=rt.angles.map(Ke=>((Q+Ke)%360+360)%360):it=mt(Q,je,Ne);let De;if(Re&&hn[Re]?De=jt(it,Re):De=it.map(Ke=>Be({h:Ke,s:$e.s||.7,v:$e.v||.85})),rt?.lightnessOffsets?.length&&(De=De.map((Ke,Qe)=>{const Lt=rt.lightnessOffsets?.[Qe];if(Lt==null)return Ke;const Nt=Ye(Ke);return Be({h:Nt.h,s:Nt.s,v:Math.max(.05,Math.min(.98,Nt.v+Lt))})})),nt!==void 0){for(;De.length<nt;){const Ke=De[De.length-1]||"#888888",Qe=Ye(Ke);De.push(Be({h:(Qe.h+18)%360,s:Qe.s,v:Qe.v}))}De=De.slice(0,nt)}else{for(;De.length<x;)De.push(De[De.length-1]||"var(--nice-text-secondary, #888888)");De.length>$&&(De=De.slice(0,$))}g?.(De)},[$e.s,$e.v,x,$,g,f,de,Ee.length,Te,_e,Me]),Ae=n.useCallback(Q=>{if(!A){if(be==="custom"){const je=Be({h:Q,s:$e.s||.7,v:$e.v||.85}),Ne=[...Ee];Ne[pe]=je,g?.(Ne);return}Le(Q,be,xe,Se)}},[A,be,xe,Se,Le,$e.s,$e.v,Ee,pe,g]),Oe=n.useCallback(Q=>{if(A||(qe(Q),Q==="custom"))return;const je=_t(Q).length,Ne=je<=1;if(f==null&&!Ne){const Re=Math.max(x,Math.min($,je));ge(Re),Le($e.h,Q,xe,Se,Re)}else Le($e.h,Q,xe,Se)},[A,$e.h,xe,Se,qe,Le,f,x,$]),at=n.useCallback(Q=>{A||(Ve(Q),Le($e.h,be,Q,Se))},[A,$e.h,be,Se,Ve,Le]),u=n.useCallback(Q=>{if(A)return;Ge(Q);const je=mt($e.h,be,xe),Ne=jt(je,Q);g?.(Ne.slice(0,$))},[A,$e.h,be,xe,$,Ge,g]),V=n.useCallback((Q,je)=>{if(A)return;const Ne=[...Ee];Ne[Q]=je,g?.(Ne)},[A,Ee,g]),L=n.useCallback(()=>{if(A||Ee.length>=$)return;const Q=Ye(Ee[Ee.length-1]),je=Be({h:(Q.h+30)%360,s:Q.s,v:Q.v});g?.([...Ee,je])},[A,Ee,$,g]),ke=n.useCallback(Q=>{if(A||Ee.length<=x)return;const je=Ee.filter((Ne,Re)=>Re!==Q);g?.(je),pe>=je.length&&ye(Math.max(0,je.length-1))},[A,Ee,x,g,pe]),Ce=n.useCallback(()=>{if(A)return;const Q=Math.max(x,Math.min($,_t(be).length)),je=gn(be,Q,xe);g?.(je)},[A,x,$,be,xe,g]),Pe=n.useMemo(()=>{if(!F)return[];const Q=Ee[pe]||Ee[0];return pn(Ye(Q),l)},[F,Ee,pe,l]),He=Ee[pe]||Ee[0],wt=n.useMemo(()=>{const Q=Ye(He);return Be({h:(Q.h+180)%360,s:Q.s,v:Q.v})},[He]);n.useLayoutEffect(()=>{if(!we||!ne.current)return;O(tt.scopeThemeClass(ne.current));const Q=()=>{const je=ne.current?.getBoundingClientRect();if(!je)return;const Ne=600;let Re=je.left;Re+Ne>window.innerWidth-8&&(Re=Math.max(8,window.innerWidth-Ne-8));let Xe=je.bottom+6;Xe>window.innerHeight*.5&&(Xe=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,540)-8)),H({left:Re,top:Xe})};return Q(),window.addEventListener("scroll",Q,!0),window.addEventListener("resize",Q),()=>{window.removeEventListener("scroll",Q,!0),window.removeEventListener("resize",Q)}},[we]),n.useEffect(()=>{if(!we)return;const Q=je=>{const Ne=je.target;ne.current?.contains(Ne)||le.current?.contains(Ne)||(Ne instanceof Element?Ne:Ne?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"], [aria-modal="true"]')||re(!1)};return document.addEventListener("mousedown",Q),()=>{document.removeEventListener("mousedown",Q)}},[we]),r.useOverlayFocus(le,{open:we,modal:!1,onClose:()=>re(!1)});const Dt=n.useRef(null);if(r.useRovingFocus(Dt,{orientation:"horizontal",itemSelector:".nice-palette__variation-chip"}),p)return null;const zt=Z.length>0?Z:fn,$n=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(Fe.NiceSelect,{label:m("colorPalette.harmony","Harmony"),labelPlacement:"left",size:"sm",disabled:A,value:be==="custom"&&_e?`custom:${_e}`:be,onChange:Q=>{const je=Array.isArray(Q)?Q[0]:Q;if(typeof je=="string")if(je.startsWith("custom:")){const Ne=je.slice(7);te(Ne),Oe("custom")}else te(null),Oe(je)},options:[...ni.map(Q=>({value:Q,label:ei[Q]})),...Me.map(Q=>({value:`custom:${Q.id}`,label:Q.name}))],renderOption:(Q,je)=>{const Ne=String(Q.value),Re=Ne.startsWith("custom:"),Xe=Re?Me.find(it=>it.id===Ne.slice(7)):null,ht=Xe?Xe.angles:void 0,nt=Re?"custom":Ne;return e.jsxs("span",{style:{display:"inline-flex",gap:8,alignItems:"center"},children:[e.jsx("span",{style:{width:16,height:16,display:"inline-flex",color:"currentColor"},children:Yt(nt,{angles:ht,size:16,count:f})}),e.jsx("span",{style:{fontWeight:je?600:400},children:Q.label})]})}}),be==="shade-chain"&&e.jsx(Fe.NiceNumberInput,{label:m("colorPalette.step","Step"),labelPlacement:"left",size:"sm",min:.02,max:.5,step:.02,precision:2,value:Te,onChange:Q=>{const je=typeof Q=="number"?Q:Number(Q);Number.isNaN(je)||(he(je),K?.(je),Le($e.h,be,xe,Se))},showStepper:!0,disabled:A}),e.jsx(Fe.NiceNumberInput,{label:m("colorPalette.colors","Colors"),labelPlacement:"left",size:"sm",min:Math.max(2,x),max:Math.min(12,$),step:1,precision:0,value:f??de??Ee.length,onChange:Q=>{const je=typeof Q=="number"?Q:Number(Q);if(!Number.isFinite(je))return;const Ne=Math.max(Math.max(2,x),Math.min(Math.min(12,$),Math.round(je)));ge(Ne),be==="shade-chain"?g?.(qt({h:$e.h,s:$e.s||.7,v:$e.v||.6},Ne,Te)):setTimeout(()=>Le($e.h,be,xe,Se),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:[Ee.map((Q,je)=>e.jsxs("div",{role:"presentation",className:`nice-palette__swatch-wrapper ${pe===je?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>ye(je),onFocus:()=>ye(je),children:[e.jsx("span",{className:"nice-palette__swatch",style:{background:Q}}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:Q.toUpperCase(),maxLength:7,disabled:A,onClick:Ne=>Ne.stopPropagation(),onChange:Ne=>V(je,Ne.target.value),"aria-label":m("colorPalette.colorN","Color {n}").replace("{n}",String(je+1))}),Ee.length>x&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:Ne=>{Ne.stopPropagation(),ke(je)},disabled:A,"aria-label":m("colorPalette.removeColor","Remove color"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},je)),Ee.length<$&&e.jsxs("button",{type:"button",className:"nice-palette__add-btn",onClick:L,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:wt},title:wt.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:wt.toUpperCase()})]}),k&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:Ce,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")]})]})})]}),In=e.jsx("div",{className:"nice-palette__tab",children:Pe.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:Dt,className:"nice-palette__variation-strip",role:"group","aria-label":m("colorPalette.tintsShades","Tints & Shades"),children:Pe.map((Q,je)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:Q},title:Q.toUpperCase(),onClick:()=>{A||V(pe,Q)},onKeyDown:Ne=>{!A&&(Ne.key==="Enter"||Ne.key===" ")&&(Ne.preventDefault(),V(pe,Q))},role:"button","aria-label":Q.toUpperCase()},je))})]}):e.jsx("div",{className:"nice-palette__empty",children:m("colorPalette.noVariationsAvailable","No variations available.")})}),Mn=e.jsx("div",{className:"nice-palette__tab",children:e.jsx("div",{className:"nice-palette__preset-grid",children:zt.map(Q=>{const je=jt(Ze,Q);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${Se===Q?"nice-palette__preset-card--active":""}`,onClick:()=>u(Q),disabled:A,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:je.map((Ne,Re)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:Ne}},Re))}),e.jsx("span",{className:"nice-palette__preset-label",children:ti[Q]})]},Q)})})}),Tn=e.jsxs("div",{className:"nice-palette__tab",children:[oe&&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(Qn,{hex:He})]}),se&&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(Zn,{colors:Ee})]})]}),Rn=e.jsx("div",{className:"nice-palette__tab nice-palette__custom-schemes",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[Me.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.")}),Me.map(Q=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12},children:[e.jsx("span",{style:{width:16,height:16,display:"inline-flex"},children:Yt("custom",{angles:Q.angles,size:16})}),e.jsx("span",{style:{flex:1},children:Q.name}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>{te(Q.id),Oe("custom")},disabled:A,children:m("colorPalette.use","Use")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>ze(Me.filter(je=>je.id!==Q.id)),disabled:A,"aria-label":m("colorPalette.delete","Delete {name}").replace("{name}",String(Q.name)),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},Q.id)),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A,onClick:()=>{const Q=Ye(Ee[0]).h,je=Ee.map(Ne=>(Ye(Ne).h-Q+540)%360-180);R.prompt({title:m("colorPalette.schemeNamePrompt","Scheme name"),defaultValue:`Scheme ${Me.length+1}`}).then(Ne=>{if(!Ne)return;const Re={id:`cs-${Date.now()}`,name:Ne,angles:je};ze([...Me,Re])})},children:m("colorPalette.saveCurrentAsScheme","+ Save current as scheme")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A||Me.length===0,onClick:()=>{typeof navigator>"u"||navigator.clipboard?.writeText(JSON.stringify(Me,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:()=>{R.prompt({title:m("colorPalette.pasteSchemesPrompt","Paste the schemes JSON")}).then(Q=>{if(Q)try{const je=JSON.parse(Q);Array.isArray(je)&&ze(je)}catch{}})},children:m("colorPalette.importJson","Import JSON")})]})]})}),st=[{id:"colors",label:m("colorPalette.colors","Colors"),content:$n}];ce&&zt.length>0&&st.push({id:"presets",label:m("colorPalette.presets","Presets"),content:Mn}),F&&st.push({id:"variations",label:m("colorPalette.variations","Variations"),content:In}),(oe||se)&&st.push({id:"info",label:m("colorPalette.info","Info"),content:Tn}),st.push({id:"schemes",label:m("colorPalette.schemes","Schemes"),content:Rn});const An=e.jsxs("div",{className:"nice-palette__popup-header",children:[q&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Jn,{hues:Ze,colors:Ee,baseHue:$e.h,onBaseHueChange:Ae,mode:be,distance:xe,disabled:A}),(be==="analogous"||be==="split-complementary"||be==="analogous-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsx("label",{children:m("colorPalette.distance","Distance: {dist}°").replace("{dist}",String(xe))}),e.jsx("input",{type:"range",min:10,max:90,value:xe,onChange:Q=>at(Number(Q.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:()=>re(!1),"aria-label":m("controls.confirm","Confirm"),title:m("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),Dn=e.jsxs("div",{className:"nice-palette nice-palette--studio",children:[An,e.jsx(pt.NiceTabs,{tabs:st,variant:"enclosed",size:"sm"})]});return e.jsxs("div",{ref:h,id:N,className:`nice-field nice-palette-field ${A?"nice-palette--disabled":""} ${Y==="left"?"nice-field--label-left":""} ${b?"nice-field--loading":""} ${C?"nice-field--error":""} ${i||""}`,style:o,"data-testid":j,children:[R.element,T&&e.jsx("label",{htmlFor:N,className:"nice-field__label",children:T}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("div",{ref:ne,className:"nice-palette__field-swatches",role:"button",tabIndex:A||E?-1:0,"aria-haspopup":"dialog","aria-expanded":we,"aria-readonly":E||void 0,"aria-label":m("colorPalette.openStudio","Open palette studio"),onClick:()=>{!A&&!E&&re(Q=>!Q)},onKeyDown:Q=>{!A&&!E&&(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),re(je=>!je))},children:Ee.map((Q,je)=>e.jsx("span",{role:"presentation",className:"nice-palette__field-swatch",style:{background:Q},title:Q.toUpperCase(),onClick:Ne=>{Ne.stopPropagation(),!A&&!E&&(ye(je),re(!0))}},je))}),b&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),we&&fe&&G&&ot.createPortal(e.jsx("div",{ref:le,className:`nice-palette__popup${X?` ${X}`:""}`,"data-theme":X==="nice-dark"?"dark":X==="nice-light"?"light":void 0,role:"dialog","aria-label":m("colorPalette.studio","Palette studio"),style:{position:"fixed",left:fe.left,top:fe.top,zIndex:1e3},children:Dn}),G)]}),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((a,s)=>a.position-s.position).map(a=>`${a.color} ${a.position}%`).join(", "),o=t.repeating?"repeating-":"";switch(t.type){case"linear":return`${o}linear-gradient(${t.angle}deg, ${i})`;case"radial":{const a=t.shape||"ellipse",s=t.size||"farthest-corner",g=t.positionX??50,x=t.positionY??50;return`${o}radial-gradient(${a} ${s} at ${g}% ${x}%, ${i})`}case"conic":{const a=t.angle??0,s=t.positionX??50,g=t.positionY??50;return`${o}conic-gradient(from ${a}deg at ${s}% ${g}%, ${i})`}}}function xn(t){const i=t.trim(),o=i.startsWith("repeating-");if(i.includes("linear-gradient")){const a=i.match(/linear-gradient\((.+)\)/)?.[1];if(!a)return null;const s=a.split(",").map(M=>M.trim());let g=90,x=0;const $=s[0].match(/^(\d+)deg$/);$&&(g=parseInt($[1]),x=1);const P=Ct(s.slice(x));return{type:"linear",angle:g,repeating:o,stops:P}}if(i.includes("radial-gradient")){const a=i.match(/radial-gradient\((.+)\)/)?.[1];if(!a)return null;const s=a.split(",").map(x=>x.trim()),g=Ct(s.filter(x=>x.includes("#")||x.includes("rgb")));return{type:"radial",angle:0,repeating:o,stops:g.length>=2?g:It().stops}}if(i.includes("conic-gradient")){const a=i.match(/conic-gradient\((.+)\)/)?.[1];if(!a)return null;const s=a.split(",").map(x=>x.trim()),g=Ct(s.filter(x=>x.includes("#")||x.includes("rgb")));return{type:"conic",angle:0,repeating:o,stops:g.length>=2?g:It().stops}}return null}function Ct(t){return t.map((i,o,a)=>{const s=i.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(s){const g=s[2]?parseFloat(s[2]):o/Math.max(1,a.length-1)*100;return{color:s[1],position:g}}return{color:i,position:o/Math.max(1,a.length-1)*100}})}function si(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ri(t=2){const i=["linear","radial","conic"],o=i[Math.floor(Math.random()*i.length)],a=[];for(let s=0;s<t;s++)a.push({color:si(),position:Math.round(s/(t-1)*100)});return{type:o,angle:Math.floor(Math.random()*360),stops:a,shape:o==="radial"?Math.random()>.5?"circle":"ellipse":void 0,positionX:o!=="linear"?Math.round(Math.random()*100):void 0,positionY:o!=="linear"?Math.round(Math.random()*100):void 0}}const bn=[{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}}],ci=Object.assign(n.forwardRef(({id:t,className:i,style:o,accessMode:a,value:s,onChange:g,showCssOutput:x=!0,showPresets:$=!0,showEditor:P=!0,showRandom:M=!0,maxStops:W=10,label:J,labelPlacement:B="top",disabled:I,readOnly:q,loading:se,error:oe,errorPlacement:ce="bottom",width:Z,"data-testid":F},k)=>{const l=r.useNiceAccessMode(a,t),T=l==="hidden";l==="disabled"&&(I=!0);const Y=q||l==="readOnly",A=r.useControlId(t),{t:_}=r.useNiceTranslation(),b=s??It(),C=n.useMemo(()=>Mt(b),[b]),[f,S]=n.useState(0),[K,w]=n.useState(""),d=n.useRef(null),[D,j]=n.useState(!1),[h,c]=n.useState(null),[p,E]=n.useState(""),m=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),R=n.useRef(null),z=n.useRef(null),ie=typeof Z=="number"?Z:340;n.useLayoutEffect(()=>{if(!D||!R.current)return;E(tt.scopeThemeClass(R.current));const y=()=>{const G=R.current?.getBoundingClientRect();if(!G)return;let ne=G.left;ne+ie>window.innerWidth-8&&(ne=Math.max(8,window.innerWidth-ie-8));let le=G.bottom+6;le>window.innerHeight*.5&&(le=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,520)-8)),c({left:ne,top:le})};return y(),window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[D,ie]),n.useEffect(()=>{if(!D)return;const y=G=>{const ne=G.target;R.current?.contains(ne)||z.current?.contains(ne)||(ne instanceof Element?ne:ne?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||j(!1)};return document.addEventListener("mousedown",y),()=>{document.removeEventListener("mousedown",y)}},[D]),r.useOverlayFocus(z,{open:D,modal:!1,onClose:()=>j(!1)});const v=n.useCallback(y=>{g?.(y)},[g]),ee=n.useCallback(y=>{I||v({...b,type:y})},[I,b,v]),U=n.useCallback(y=>{I||v({...b,angle:y})},[I,b,v]),me=n.useCallback(y=>{I||v({...b,repeating:y})},[I,b,v]),pe=n.useCallback(y=>{I||v({...b,shape:y})},[I,b,v]),ye=n.useCallback((y,G)=>{if(I)return;const ne=b.stops.map((le,be)=>be===y?{...le,...G}:le);v({...b,stops:ne})},[I,b,v]),ue=n.useRef(!1),he=n.useCallback((y,G)=>{if(I||!d.current)return;y.stopPropagation(),y.preventDefault(),S(G),ue.current=!1;const ne=be=>{if(!d.current)return;ue.current=!0;const xe=d.current.getBoundingClientRect(),Se=Math.round(Math.max(0,Math.min(100,(be.clientX-xe.left)/xe.width*100)));ye(G,{position:Se})},le=()=>{document.removeEventListener("pointermove",ne),document.removeEventListener("pointerup",le),document.removeEventListener("pointercancel",le)};document.addEventListener("pointermove",ne),document.addEventListener("pointerup",le),document.addEventListener("pointercancel",le)},[I,ye]),de=n.useCallback(()=>{if(I||b.stops.length>=W)return;const y=b.stops.slice().sort((xe,Se)=>xe.position-Se.position);let G=0,ne=y[0];for(let xe=0;xe<y.length-1;xe++){const Se=y[xe+1].position-y[xe].position;Se>G&&(G=Se,ne=y[xe])}const le=Math.round(ne.position+G/2),be="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");v({...b,stops:[...b.stops,{color:be,position:le}]})},[I,b,W,v]),ge=n.useCallback(y=>{if(I||b.stops.length<=2)return;const G=b.stops.filter((ne,le)=>le!==y);v({...b,stops:G}),f>=G.length&&S(G.length-1)},[I,b,f,v]),ae=(y,G)=>{const ne=b.stops[G];if(I||!ne)return;const le=y.shiftKey?10:1,be=y.key==="ArrowLeft"||y.key==="ArrowDown"?ne.position-le:y.key==="ArrowRight"||y.key==="ArrowUp"?ne.position+le:y.key==="PageDown"?ne.position-10:y.key==="PageUp"?ne.position+10:y.key==="Home"?0:y.key==="End"?100:null;be!==null?(y.preventDefault(),ye(G,{position:Math.max(0,Math.min(100,be))})):(y.key==="Delete"||y.key==="Backspace")&&b.stops.length>2&&(y.preventDefault(),ge(G))},ve=n.useCallback(()=>{if(I)return;const y=2+Math.floor(Math.random()*3);v(ri(y))},[I,v]),_e=n.useCallback(()=>{if(I||!K.trim())return;const y=xn(K);y&&v(y)},[I,K,v]),te=n.useCallback(y=>{if(I||!d.current||b.stops.length>=W)return;const G=y.target;if(ue.current||G.closest(".nice-gradient__stop-marker")){ue.current=!1;return}const ne=d.current.getBoundingClientRect(),le=Math.round((y.clientX-ne.left)/ne.width*100),be="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),xe=[...b.stops,{color:be,position:le}];v({...b,stops:xe}),S(xe.length-1)},[I,b,W,v]),we=n.useMemo(()=>b.stops.slice().sort((y,G)=>y.position-G.position),[b.stops]),re=n.useMemo(()=>`linear-gradient(90deg, ${we.map(y=>`${y.color} ${y.position}%`).join(", ")})`,[we]);if(T)return null;const fe=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(y=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${b.type===y?"nice-gradient__type-btn--active":""}`,onClick:()=>ee(y),disabled:I,"aria-pressed":b.type===y,children:y.charAt(0).toUpperCase()+y.slice(1)},y)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:b.repeating??!1,onChange:y=>me(y.target.checked),disabled:I}),_("controls.repeating","Repeating")]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[b.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.angle","Angle: {angle}°").replace("{angle}",String(b.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:b.angle,onChange:y=>U(Number(y.target.value)),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.angle","Angle")}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(y=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${b.angle===y?"nice-gradient__angle-btn--active":""}`,onClick:()=>U(y),disabled:I,title:`${y}°`,"aria-label":`${y}°`,"aria-pressed":b.angle===y,children:e.jsx("span",{style:{transform:`rotate(${y}deg)`,display:"inline-flex"},children:e.jsx(r.NiceIcon,{name:"arrow-right",size:14})})},y))})]}),b.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.shape","Shape:")}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(y=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(b.shape||"ellipse")===y?"nice-gradient__shape-btn--active":""}`,onClick:()=>pe(y),disabled:I,"aria-pressed":(b.shape||"ellipse")===y,children:y},y))})]}),(b.type==="radial"||b.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.center","Center: {positionX}%, {positionY}%").replace("{positionX}",String(b.positionX??50)).replace("{positionY}",String(b.positionY??50))}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:b.positionX??50,onChange:y=>v({...b,positionX:Number(y.target.value)}),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.centerX","Horizontal center")}),e.jsx("input",{type:"range",min:0,max:100,value:b.positionY??50,onChange:y=>v({...b,positionY:Number(y.target.value)}),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.centerY","Vertical center")})]})]}),b.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.startAngle","Start angle: {angle}°").replace("{angle}",String(b.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:b.angle,onChange:y=>U(Number(y.target.value)),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.startAngle","Start angle")})]})]}),e.jsxs("div",{className:"nice-gradient__bar-container",children:[e.jsx("div",{role:"presentation",ref:d,className:"nice-gradient__bar",style:{background:re},onClick:te,children:b.stops.map((y,G)=>e.jsx("div",{className:`nice-gradient__stop-marker ${f===G?"nice-gradient__stop-marker--active":""}`,style:{left:`${y.position}%`},onPointerDown:ne=>he(ne,G),onClick:ne=>{ne.stopPropagation(),S(G),ue.current=!1},onFocus:()=>S(G),onKeyDown:ne=>ae(ne,G),role:"slider",tabIndex:I?-1:0,"aria-label":_("gradient.stop","Stop {n}").replace("{n}",String(G+1)),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":y.position,"aria-valuetext":`${y.color} ${y.position}%`,title:`${y.color} @ ${y.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:y.color}})},G))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:de,disabled:I||b.stops.length>=W,title:_("controls.addStop","Add stop"),"aria-label":_("controls.addStop","Add stop"),children:e.jsx(r.NiceIcon,{name:"plus",size:14})})]}),e.jsx("div",{className:"nice-gradient__stop-editor",children:e.jsx("div",{className:"nice-gradient__stop-list",children:we.map((y,G)=>{const ne=b.stops.indexOf(y);return e.jsxs("div",{role:"presentation",className:`nice-gradient__stop-row ${f===ne?"nice-gradient__stop-row--active":""}`,onClick:()=>S(ne),onFocus:()=>S(ne),children:[e.jsx("input",{type:"color",value:y.color,onChange:le=>ye(ne,{color:le.target.value}),disabled:I,className:"nice-gradient__stop-color","aria-label":_("gradient.stopColor","Stop color")}),e.jsx("input",{type:"text",value:y.color.toUpperCase(),maxLength:7,onChange:le=>ye(ne,{color:le.target.value}),disabled:I,className:"nice-gradient__stop-hex","aria-label":_("gradient.stopHex","Stop color (hex)")}),e.jsx("input",{type:"number",min:0,max:100,value:y.position,onChange:le=>ye(ne,{position:Number(le.target.value)}),disabled:I,className:"nice-gradient__stop-pos","aria-label":_("gradient.stopPosition","Stop position")}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),b.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>ge(ne),disabled:I,"aria-label":_("controls.removeStop","Remove stop"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},ne)})})})]}),M&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:ve,disabled:I,title:_("controls.randomGradient","Random gradient"),"aria-label":_("controls.randomGradient","Random gradient"),children:[e.jsx(r.NiceIcon,{name:"shuffle",size:14})," ",_("controls.randomGradient2","Random Gradient")]})]}),H=e.jsx("div",{className:"nice-gradient__tab",children:e.jsx("div",{className:"nice-gradient__preset-grid",children:bn.map((y,G)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{I||v(y.value)},disabled:I,title:y.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:Mt(y.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:y.name})]},G))})}),X=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:_("controls.copyCss","Copy CSS"),"aria-label":_("controls.copyCss","Copy CSS"),children:e.jsx(r.NiceIcon,{name:"clipboard",size:16})})]}),e.jsxs("div",{className:"nice-gradient__css-import",children:[e.jsx("input",{type:"text",className:"nice-gradient__css-input",placeholder:_("controls.pasteCssGradientToImport","Paste CSS gradient to import..."),value:K,onChange:y=>w(y.target.value),disabled:I,"aria-label":_("gradient.importCss","CSS gradient to import")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:_e,disabled:I,children:_("controls.import","Import")})]})]}),O=[{id:"editor",label:_("controls.editor","Editor"),content:fe}];return $&&O.push({id:"presets",label:_("controls.presets","Presets"),content:H}),x&&O.push({id:"css",label:"CSS",content:X}),e.jsxs("div",{ref:k,id:A,className:`nice-field nice-gradient-field ${I?"nice-gradient--disabled":""} ${B==="left"?"nice-field--label-left":""} ${se?"nice-field--loading":""} ${oe?"nice-field--error":""} ${ce==="right"?"nice-field--error-right":""} ${i||""}`,style:o,"data-testid":F,children:[J&&e.jsx("label",{htmlFor:A,className:"nice-field__label",children:J}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("button",{ref:R,type:"button",className:"nice-gradient__swatch",style:{background:C},"aria-haspopup":"dialog","aria-expanded":D,"aria-readonly":Y||void 0,"aria-label":_("controls.openGradientEditor","Open gradient editor"),disabled:I,onClick:()=>{!I&&!Y&&j(y=>!y)}}),se&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),ce==="right"&&typeof oe=="string"&&oe&&e.jsx("div",{className:"nice-field__error",role:"alert",children:oe}),D&&h&&m&&ot.createPortal(e.jsx("div",{ref:z,className:`nice-gradient__popup${p?` ${p}`:""}`,"data-theme":p==="nice-dark"?"dark":p==="nice-light"?"light":void 0,role:"dialog","aria-label":_("controls.gradientEditor","Gradient editor"),style:{position:"fixed",left:h.left,top:h.top,width:Z!=null?typeof Z=="number"?`${Z}px`:Z: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:()=>j(!1),"aria-label":_("controls.confirm","Confirm"),title:_("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),e.jsx(pt.NiceTabs,{tabs:O,variant:"enclosed",size:"sm"})]})}),m)]}),ce!=="right"&&typeof oe=="string"&&oe&&e.jsx("div",{className:"nice-field__error",role:"alert",children:oe})]})}),{displayName:"NiceGradientPicker"}),li=[{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"}],di=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}],mi=n.forwardRef(function(i,o){const{enableAI:a=!0,aiModel:s,enableImprove:g=!0,enableTranslate:x=!0,enableGenerate:$=!0,toolbar:P,languages:M=li,textStyles:W=di,onImprove:J,onTranslate:B,onGenerate:I,showAIToolbar:q=!0,value:se,onChange:oe,...ce}=i,Z=n.useRef(null),[F,k]=n.useState(!1),[l,T]=n.useState(!1),[Y,A]=n.useState(!1),[_,b]=n.useState(""),[C,f]=n.useState(""),[S,K]=n.useState("professional"),[w,d]=n.useState(""),[D,j]=n.useState(M[0]?.code||"en"),[h,c]=n.useState(""),[p,E]=n.useState(""),{t:N}=an.useNiceTranslation(),m=r.useNiceAI(),{improveText:R,translate:z,generateHtml:ie,isLoading:v}=r.useTextImprovement(),ee=a&&m.isConfigured,U=n.useCallback(()=>{const ae=window.getSelection();return ae&&ae.toString().trim()?ae.toString():""},[]),me=n.useCallback(ae=>{const ve=window.getSelection();if(ve&&ve.rangeCount>0){const _e=ve.getRangeAt(0);_e.deleteContents();const te=document.createElement("div");te.innerHTML=ae;const we=document.createDocumentFragment();for(;te.firstChild;)we.appendChild(te.firstChild);if(_e.insertNode(we),Z.current){const re=Z.current.innerHTML;oe?.(re)}}},[oe]),pe=n.useCallback(async(ae="professional")=>{if(!ee||!g)return"";const ve=U();if(!ve)return"";b(ve),K(ae),k(!0),f("");try{const _e=await R(ve,ae);return f(_e),J?.(ve,_e,ae),_e}catch{return f(N("htmlEditorAI.improveFailed","Failed to improve text")),""}},[ee,g,U,R,J,N]),ye=n.useCallback(async ae=>{if(!ee||!x)return"";const ve=U();if(!ve)return"";b(ve),j(ae),T(!0),d("");try{const _e=M.find(we=>we.code===ae)?.label||ae,te=await z(ve,_e);return d(te),B?.(ve,te,ae),te}catch{return d(N("htmlEditorAI.translateFailed","Failed to translate text")),""}},[ee,x,U,z,M,B,N]),ue=n.useCallback(async ae=>{if(!ee||!$||!ae.trim())return"";c(ae),E("");try{const ve=await ie(ae);return E(ve),I?.(ae,ve),ve}catch{return E(N("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[ee,$,ie,I,N]),he=n.useCallback(()=>{C&&me(C),k(!1),f("")},[C,me]),de=n.useCallback(()=>{w&&me(w),T(!1),d("")},[w,me]),ge=n.useCallback(()=>{if(p&&Z.current){document.execCommand("insertHTML",!1,p);const ae=Z.current.innerHTML;oe?.(ae)}A(!1),E(""),c("")},[p,oe]);return n.useImperativeHandle(o,()=>({getEditor:()=>Z.current,focus:()=>Z.current?.focus(),getValue:()=>Z.current?.innerHTML||"",setValue:ae=>{Z.current&&(Z.current.innerHTML=ae,oe?.(ae))},getSelection:U,insertHtml:ae=>{document.execCommand("insertHTML",!1,ae),Z.current&&oe?.(Z.current.innerHTML)},improveSelection:pe,translateSelection:ye,generateHtml:ue})),n.useCallback(ae=>{Z.current=ae},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":i["data-testid"],children:[q&&ee&&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:N("htmlEditorAI.ai","AI")}),v&&e.jsx("span",{className:"nice-html-editor-ai__loading",children:N("htmlEditorAI.processing","Processing...")})]}),e.jsxs("div",{className:"nice-html-editor-ai__toolbar-right",children:[g&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>pe(),disabled:v,title:N("htmlEditorAI.improveText","Improve selected text"),children:[e.jsx(r.NiceIcon,{name:"star",size:14})," ",N("htmlEditorAI.improve","Improve")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu",children:W.map(({style:ae,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>pe(ae),children:ve},ae))})]}),x&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",disabled:v,title:N("htmlEditorAI.translateText","Translate selected text"),children:[e.jsx(r.NiceIcon,{name:"globe",size:14})," ",N("htmlEditorAI.translate","Translate")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu nice-html-editor-ai__dropdown-menu--languages",children:M.map(({code:ae,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>ye(ae),children:ve},ae))})]}),$&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>A(!0),disabled:v,title:N("htmlEditorAI.generateHtml","Generate HTML from description"),children:[e.jsx(r.NiceIcon,{name:"zap",size:14})," ",N("htmlEditorAI.generate","Generate")]})]})]}),e.jsx("div",{className:"nice-html-editor-ai__editor-wrapper",children:e.jsx(sn.NiceHtmlEditor,{value:se,onChange:oe,toolbar:P,...ce})}),F&&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})," ",N("htmlEditorAI.improveText","Improve Text")]}),e.jsx("div",{className:"nice-html-editor-ai__style-selector",children:W.map(({style:ae,label:ve})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${S===ae?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{K(ae),pe(ae)},children:ve},ae))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":N("htmlEditorAI.close","Close"),onClick:()=>k(!1),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:v?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:N("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:N("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:_})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--improved",children:[e.jsx("h5",{children:N("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:he,disabled:!C||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",N("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{k(!1),f("")},children:N("htmlEditorAI.cancel","Cancel")})]})]}),l&&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})," ",N("htmlEditorAI.translateText","Translate Text")]}),e.jsx("div",{className:"nice-html-editor-ai__language-selector",children:e.jsx("select",{value:D,onChange:ae=>{j(ae.target.value),ye(ae.target.value)},className:"nice-html-editor-ai__language-select",children:M.map(({code:ae,label:ve})=>e.jsx("option",{value:ae,children:ve},ae))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":N("htmlEditorAI.close","Close"),onClick:()=>T(!1),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:v?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:N("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:N("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:_})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:M.find(ae=>ae.code===D)?.label||D}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:w})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:de,disabled:!w||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",N("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{T(!1),d("")},children:N("htmlEditorAI.cancel","Cancel")})]})]}),Y&&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})," ",N("htmlEditorAI.generateHtml","Generate HTML")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":N("htmlEditorAI.close","Close"),onClick:()=>{A(!1),E(""),c("")},children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-body",children:[e.jsxs("div",{className:"nice-html-editor-ai__generate-input",children:[e.jsx("textarea",{placeholder:N("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:ae=>c(ae.target.value),className:"nice-html-editor-ai__generate-textarea",rows:3}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__generate-btn",onClick:()=>ue(h),disabled:v||!h.trim(),children:v?N("htmlEditorAI.generating","Generating..."):N("htmlEditorAI.generate","Generate")})]}),p&&e.jsxs("div",{className:"nice-html-editor-ai__generate-result",children:[e.jsx("h5",{children:N("htmlEditorAI.preview","Preview")}),e.jsx("div",{className:"nice-html-editor-ai__preview",dangerouslySetInnerHTML:{__html:p}}),e.jsx("h5",{children:N("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:p})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ge,disabled:!p||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",N("htmlEditorAI.insert","Insert")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{A(!1),E(""),c("")},children:N("htmlEditorAI.cancel","Cancel")})]})]})]})}),ui=[{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 jn(t){let i=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return i=i.replace(/```(\w*)\n([\s\S]*?)```/g,(o,a,s)=>`<pre><code class="language-${a}">${s.trim()}</code></pre>`),i=i.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(o,a,s,g)=>{const x=a.split("|").filter(P=>P.trim()).map(P=>`<th>${P.trim()}</th>`).join(""),$=g.trim().split(`
1
+ "use strict";const e=require("react/jsx-runtime"),r=require("@nice2dev/ui-core"),n=require("react"),ot=require("react-dom"),Fe=require("./no-code-DPc82kyy.cjs"),pt=require("./pickerCommons-CQnae2FM.cjs"),tt=require("./devops-o6Zm0VKB.cjs"),Ue=require("./NiceForm-DM2tARZT.cjs"),an=require("@nice2dev/i18n"),sn=require("./NiceHtmlEditor-BEWNA_UI.cjs"),Ie=require("./NiceButton-DzCqkG5a.cjs"),Pt=require("./NiceColorPicker-79rkvaSk.cjs"),Et=require("./NiceCodeEditor-DhdjnDLV.cjs"),kt=require("./injectStyleOnce-DeWaxcdf.cjs"),zn=({min:t=0,max:i=100,step:o=1,startValue:a=t,endValue:s=i,onChange:g,showLabels:x=!0,formatLabel:$,valuePlacement:P="none",label:M,error:W,helperText:J,required:B,disabled:I,readOnly:q,loading:se,size:oe="md",id:ce,className:Z,style:F,accessMode:k,showKeyboardHints:l,labelPlacement:T,errorPlacement:Y,labelWidth:A,controlWidth:_})=>{const b=r.useNiceAccessMode(k,ce),C=b==="hidden";(b==="disabled"||b==="readOnly")&&(I=!0);const{t:f}=r.useNiceTranslation(),S=r.useControlId(ce),K=n.useRef(null),w=n.useMemo(()=>[r.COMMON_SHORTCUTS.increment,r.COMMON_SHORTCUTS.decrement,r.COMMON_SHORTCUTS.first,r.COMMON_SHORTCUTS.last,{key:"Tab",description:f("shortcuts.switchThumb","Switch thumb")}],[f]),d=p=>(p-t)/(i-t)*100,D=p=>$?$(p):String(p),j=n.useCallback(p=>{const E=Math.round(p/o)*o;return Math.max(t,Math.min(i,E))},[t,i,o]),h=n.useCallback((p,E)=>{p.preventDefault();const N=K.current;if(!N||I)return;const m=z=>{const ie=N.getBoundingClientRect(),v=Math.max(0,Math.min(1,(z.clientX-ie.left)/ie.width)),ee=j(t+v*(i-t));E==="start"?g?.(Math.min(ee,s),s):g?.(a,Math.max(ee,a))},R=()=>{document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",R)};document.addEventListener("pointermove",m),document.addEventListener("pointerup",R)},[t,i,j,a,s,g,I]),c=(p,E)=>{if(I||q)return;const N=E==="start"?a:s,m=E==="start"?t:a,R=E==="start"?s:i,z=Math.max(o,(i-t)/10),ie=p.key==="ArrowRight"||p.key==="ArrowUp"?N+o:p.key==="ArrowLeft"||p.key==="ArrowDown"?N-o:p.key==="PageUp"?N+z:p.key==="PageDown"?N-z:p.key==="Home"?m:p.key==="End"?R:null;if(ie===null)return;p.preventDefault();const v=Math.max(m,Math.min(R,j(ie)));E==="start"?g?.(v,s):g?.(a,v)};return C?null:e.jsxs("div",{className:`nice-field nice-field--${oe} nice-field--rangeslider ${T==="left"?"nice-field--label-left":""} ${Y==="right"?"nice-field--error-right":""} ${W?"nice-field--error":""} ${se?"nice-field--loading":""} ${Z||""}`,style:{...F,...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},..._!=null&&{"--nice-field-control-width":typeof _=="number"?`${_}px`:_}},"aria-busy":se||void 0,children:[(M||P==="right"&&T!=="left")&&(T!=="left"?e.jsxs("div",{className:"nice-range-slider__header",children:[M?e.jsx("label",{className:"nice-field__label",htmlFor:S,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),l&&e.jsx(r.NiceKeyboardHint,{shortcuts:w,size:"sm"})]})}):e.jsx("span",{}),P==="right"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--header",children:[D(a)," – ",D(s)]})]}):M&&e.jsx("label",{className:"nice-field__label",htmlFor:S,children:e.jsxs("span",{className:"nice-field__label-text",children:[M,B&&e.jsx("span",{className:"nice-field__required",children:"*"}),l&&e.jsx(r.NiceKeyboardHint,{shortcuts:w,size:"sm"})]})})),e.jsxs("div",{className:"nice-field__control",children:[e.jsxs("div",{className:"nice-range-slider__stack",children:[e.jsxs("div",{className:`nice-range-slider ${x?"nice-range-slider--with-labels":""} ${M?"nice-range-slider--has-field-label":""}`,ref:K,children:[e.jsx("div",{className:"nice-range-slider__track",children:e.jsx("div",{className:"nice-range-slider__fill",style:{left:`${d(a)}%`,width:`${d(s)-d(a)}%`}})}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(a)}%`},onPointerDown:p=>q?void 0:h(p,"start"),onKeyDown:p=>c(p,"start"),role:"slider","aria-label":f("rangeSlider.min","Minimum"),"aria-valuemin":t,"aria-valuemax":s,"aria-valuenow":a,"aria-valuetext":D(a),"aria-disabled":I||void 0,"aria-readonly":q||void 0,tabIndex:I?-1:0,id:S}),e.jsx("div",{className:"nice-range-slider__thumb",style:{left:`${d(s)}%`},onPointerDown:p=>q?void 0:h(p,"end"),onKeyDown:p=>c(p,"end"),role:"slider","aria-label":f("rangeSlider.max","Maximum"),"aria-valuemin":a,"aria-valuemax":i,"aria-valuenow":s,"aria-valuetext":D(s),"aria-disabled":I||void 0,"aria-readonly":q||void 0,tabIndex:I?-1:0})]}),x&&e.jsxs("div",{className:"nice-range-slider__values",children:[e.jsx("span",{className:"nice-range-slider__values-start",style:{left:`${d(a)}%`},children:D(a)}),e.jsx("span",{className:"nice-range-slider__values-end",style:{left:`${d(s)}%`},children:D(s)})]}),P==="bottom"&&e.jsxs("div",{className:"nice-range-slider__value nice-range-slider__value--bottom",children:[D(a)," – ",D(s)]})]}),P==="right"&&T==="left"&&e.jsxs("span",{className:"nice-range-slider__value nice-range-slider__value--inline",children:[D(a)," – ",D(s)]}),se&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),Y==="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),Y==="right"&&!W&&J&&e.jsx("div",{className:"nice-field__helper",children:J})]}),Y!=="right"&&W&&e.jsx("div",{className:"nice-field__error",role:"alert",children:W}),Y!=="right"&&!W&&J&&e.jsx("div",{className:"nice-field__helper",children:J})]})},Ln={xxs:36,xs:48,sm:64,md:80,lg:100,xl:128,xxl:160,small:64,medium:80,large:100},gt=6,dt=135,rn=405,ct=rn-dt;function $t(t,i,o,a){const s=(a-90)*(Math.PI/180);return{x:t+o*Math.cos(s),y:i+o*Math.sin(s)}}function Ot(t,i,o,a,s){const g=$t(t,i,o,a),x=$t(t,i,o,s),$=s-a>180?1:0;return`M ${g.x} ${g.y} A ${o} ${o} 0 ${$} 1 ${x.x} ${x.y}`}const Pn=Object.assign(n.forwardRef(({value:t=0,onChange:i,min:o=0,max:a=100,step:s=1,showValue:g=!0,valueTemplate:x="{value}",label:$,helperText:P,error:M,required:W,disabled:J,readOnly:B,size:I="md",name:q,id:se,className:oe,style:ce,labelPlacement:Z="top",errorPlacement:F,labelWidth:k,controlWidth:l,loading:T,isLabelCentered:Y=!0,...A},_)=>{const b=r.useControlId(se),C=n.useRef(!1),f=n.useRef(null),S=typeof I=="number"?I:Ln[I],K=S/2,w=S/2,d=(S-gt*2)/2,D=a>o?(t-o)/(a-o):0,j=dt+D*ct,h=n.useCallback(m=>{let R=m-dt;R<0&&(R+=360),R>ct&&(R=R-ct<360-R?ct:0);const z=Math.max(0,Math.min(1,R/ct)),ie=o+z*(a-o),v=Math.round(ie/s)*s;return Math.max(o,Math.min(a,v))},[o,a,s]),c=n.useCallback(m=>{if(J||B)return;const R=f.current;if(!R)return;const z=R.getBoundingClientRect(),ie=m.clientX-z.left-z.width/2,v=m.clientY-z.top-z.height/2;let ee=Math.atan2(ie,-v)*(180/Math.PI);ee<0&&(ee+=360);const U=h(ee);i?.(U)},[h,J,B,i]);n.useEffect(()=>{const m=z=>{C.current&&c(z)},R=()=>{C.current=!1};return window.addEventListener("pointermove",m),window.addEventListener("pointerup",R),()=>{window.removeEventListener("pointermove",m),window.removeEventListener("pointerup",R)}},[c]);const p=n.useCallback(m=>{if(J||B)return;let R=t;const z=Math.max(s,(a-o)/10);m.key==="ArrowUp"||m.key==="ArrowRight"?(m.preventDefault(),R=Math.min(a,t+s)):m.key==="ArrowDown"||m.key==="ArrowLeft"?(m.preventDefault(),R=Math.max(o,t-s)):m.key==="PageUp"||m.key==="PageDown"?(m.preventDefault(),R=Math.max(o,Math.min(a,t+(m.key==="PageUp"?z:-z)))):(m.key==="Home"||m.key==="End")&&(m.preventDefault(),R=m.key==="Home"?o:a),R!==t&&i?.(R)},[t,i,o,a,s,J,B]),E=(x||"{value}").replace("{value}",String(t)),N=$t(K,w,d,j);return e.jsxs("div",{className:`nice-field nice-knob-field nice-knob-field--err-${F||"bottom"} nice-field--${typeof I=="string"?I:"md"} ${T?"nice-field--loading":""} ${oe||""}`,style:{...ce,...k!=null&&{"--nice-field-label-width":typeof k=="number"?`${k}px`:k},...l!=null&&{"--nice-field-control-width":typeof l=="number"?`${l}px`:l}},"aria-busy":T||void 0,...A,children:[e.jsxs("div",{className:`nice-knob-field__inner nice-knob-field--${Z} ${Y?"nice-knob-field--label-centered":""}`,children:[$&&e.jsx("label",{htmlFor:b,className:`nice-field__label ${W?"nice-field__label--required":""}`,children:$}),e.jsx("div",{className:"nice-field__control",children:e.jsxs("div",{ref:m=>{f.current=m,typeof _=="function"?_(m):_&&(_.current=m)},className:`nice-knob nice-knob--${I} ${J?"nice-knob--disabled":""} ${M?"nice-knob--error":""}`,role:"slider",id:b,tabIndex:J?-1:0,"aria-valuenow":t,"aria-valuemin":o,"aria-valuemax":a,"aria-disabled":J,"aria-invalid":!!M,onPointerDown:m=>{J||B||(C.current=!0,c(m))},onKeyDown:p,children:[e.jsxs("svg",{width:S,height:S,viewBox:`0 0 ${S} ${S}`,children:[e.jsx("path",{d:Ot(K,w,d,dt,rn),fill:"none",stroke:"var(--nice-border-color, #d1d5db)",strokeWidth:gt,strokeLinecap:"round"}),D>0&&e.jsx("path",{d:Ot(K,w,d,dt,j),fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:gt,strokeLinecap:"round"}),e.jsx("circle",{cx:N.x,cy:N.y,r:gt,fill:"var(--nice-primary, #3b82f6)"})]}),g&&e.jsx("span",{className:"nice-knob__value",children:E}),q&&e.jsx("input",{type:"hidden",name:q,value:t}),T&&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"}),On=({options:t,value:i,defaultValue:o,onChange:a,searchable:s=!0,clearable:g,loading:x,placeholder:$,label:P,error:M,helperText:W,required:J,disabled:B,readOnly:I,size:q="md",id:se,className:oe,style:ce,data:Z,columns:F,valueField:k="id",displayField:l,dropdownWidth:T,menuGap:Y,labelPlacement:A,errorPlacement:_,labelWidth:b,controlWidth:C})=>{const f=B||I||x,S=r.useControlId(se),{t:K}=r.useNiceTranslation(),[w,d]=r.useControllableState({value:i,defaultValue:o,fallbackValue:"",onChange:a,componentName:"NiceLookup"}),[D,j]=n.useState(!1),[h,c]=n.useState(""),p=n.useRef(null),E=n.useRef(null),{popupRef:N,coords:m,ready:R,themeClass:z,portalTarget:ie}=Fe.useAnchoredPopup(D,E,()=>j(!1)),v=!!(Z&&F&&F.length>0),ee=l??(F&&F[0]?.key),U=n.useMemo(()=>!v||!Z?[]:Z.map(re=>({value:String(re[k]??""),label:ee?String(re[ee]??""):""})),[v,Z,k,ee]),me=n.useMemo(()=>v?U:t??[],[v,U,t]),pe=me.find(re=>String(re.value)===w),ye=n.useMemo(()=>{if(!v||!Z)return[];if(!h)return Z;const re=h.toLowerCase();return Z.filter(fe=>F.some(H=>String(fe[H.key]??"").toLowerCase().includes(re)))},[v,Z,F,h]),ue=n.useMemo(()=>{if(v||!h)return me;const re=h.toLowerCase();return me.filter(fe=>fe.label.toLowerCase().includes(re))},[me,h,v]),he=v?ye:ue,{activeIndex:de,setActiveIndex:ge,handleKeyDown:ae}=pt.useListKeyboardNav(he,{open:D,onSelect:re=>{const fe=String(v?re[k]??"":re.value);d(fe),j(!1),c("")},onClose:()=>j(!1),onOpen:()=>!f&&j(!0),intentRef:N}),_e=`${n.useId()}-listbox`,te=re=>`${_e}-opt-${re}`,we=D&&he.length>0?te(de):void 0;return n.useLayoutEffect(()=>{we&&document.getElementById(we)?.scrollIntoView?.({block:"nearest"})},[we]),e.jsxs("div",{className:`nice-field nice-field--lookup nice-field--${q} ${M?"nice-field--error":""} ${A==="left"?"nice-field--label-left":""} ${_==="right"&&(M||W)?"nice-field--error-right":""} ${x?"nice-field--loading":""} ${B?"nice-field--disabled":""} ${oe||""}`,style:{...C!=null&&{"--nice-field-control-width":typeof C=="number"?`${C}px`:C},...b!=null&&{"--nice-field-label-width":typeof b=="number"?`${b}px`:b},...Y!=null&&{"--nice-dropdown-gap":`${Y}px`},...ce},"aria-busy":x||void 0,ref:p,children:[P&&e.jsxs("label",{className:"nice-field__label",htmlFor:S,children:[P,J&&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:E,children:[e.jsxs("button",{type:"button",id:S,className:`nice-select__trigger ${B?"nice-select__trigger--disabled":""}`,onClick:()=>!f&&j(!D),onKeyDown:ae,disabled:B,"aria-readonly":I||void 0,role:"combobox","aria-haspopup":"listbox","aria-expanded":D,"aria-controls":D?_e:void 0,"aria-activedescendant":s?void 0:we,children:[e.jsx("span",{children:pe?.label||$||K("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[g&&w&&!B&&!I&&e.jsx("span",{onKeyDown:r.clickOnActivationKey,className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":K("controls.clear","Clear"),onClick:re=>{re.stopPropagation(),d("")},children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("span",{className:`nice-select__arrow${I?" nice-select__arrow--hidden":""}`,children:e.jsx(r.NiceIcon,{name:"chevron-down",size:16})})]})]}),D&&m&&ie&&ot.createPortal(e.jsxs("div",{ref:N,className:`nice-dropdown nice-lookup__dropdown${z?` ${z}`:""}`,"data-theme":z==="nice-dark"?"dark":z==="nice-light"?"light":void 0,style:{position:"fixed",top:m.top,left:m.left,zIndex:1e3,marginTop:"var(--nice-dropdown-gap, 0px)",background:"var(--nice-bg-primary)",border:"1px solid var(--nice-border-color)",borderRadius:"var(--nice-radius-md)",boxShadow:"0 4px 16px var(--nice-overlay-15, rgba(0, 0, 0, 0.15))",minWidth:m.width,width:T!=null?typeof T=="number"?`${T}px`:T:v?"max-content":m.width,opacity:R?1:0,pointerEvents:R?void 0:"none"},children:[s&&e.jsx("div",{className:"nice-dropdown__search",style:{padding:6},children:e.jsx("input",{type:"text",value:h,onChange:re=>{c(re.target.value),ge(0)},onKeyDown:ae,placeholder:K("controls.search","Search..."),"aria-label":K("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:F.map(re=>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:re.width!=null?typeof re.width=="number"?`${re.width}px`:re.width:void 0},children:re.header},re.key))})}),e.jsx("tbody",{children:ye.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:F.length,style:{padding:12,textAlign:"center",color:"var(--nice-text-muted)"},children:K("controls.noResults","No results")})}):ye.map((re,fe)=>{const H=String(re[k]??""),X=H===w,O=fe===de;return e.jsx("tr",{id:te(fe),role:"option","aria-selected":X,onClick:()=>{d(H),j(!1),c("")},style:{cursor:"pointer",background:X||O?"var(--nice-hover-bg)":"transparent"},onMouseEnter:()=>ge(fe),children:F.map(y=>e.jsx("td",{style:{padding:"6px 10px",fontSize:13,borderBottom:"1px solid var(--nice-border-color)"},children:String(re[y.key]??"")},y.key))},H)})})]}):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:ue.length===0?e.jsx("li",{className:"nice-dropdown__empty",style:{padding:8,color:"var(--nice-text-muted)"},children:K("controls.noResults","No results")}):ue.map((re,fe)=>e.jsx("li",{id:te(fe),role:"option",className:`nice-dropdown__option ${String(re.value)===w?"nice-dropdown__option--selected":""} ${fe===de?"nice-dropdown__option--active":""}`,onClick:()=>{d(String(re.value)),j(!1),c("")},onMouseEnter:()=>ge(fe),"aria-selected":String(re.value)===w,children:re.label},String(re.value)))})]}),ie)]}),x&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),_==="right"&&M&&e.jsx("div",{className:"nice-field__error",role:"alert",children:M}),_==="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]}),_!=="right"&&M&&e.jsx("div",{className:"nice-field__error",children:M}),_!=="right"&&!M&&W&&e.jsx("div",{className:"nice-field__hint",children:W})]})},Bn=[];function Bt(t){const i=[],o=a=>{for(const s of a)i.push(s),s.children&&o(s.children)};return o(t),i}function cn(t,i){const o=i.toLowerCase();return t.reduce((a,s)=>{const g=s.children?cn(s.children,i):[];return(s.label.toLowerCase().includes(o)||g.length>0)&&a.push({...s,children:g.length>0?g:s.children}),a},[])}const ln=({node:t,level:i,selectedKeys:o,expandedKeys:a,onToggleExpand:s,onSelect:g,selectableLeafsOnly:x,maxDepth:$})=>{const{t:P}=r.useNiceTranslation(),M=typeof $=="number"?Math.min(10,Math.max(1,$)):1/0,J=!(i+1>=M)&&t.children&&t.children.length>0,B=a.has(t.key),I=o.has(t.key),q=!J,se=!t.disabled&&(!x||q),oe=Math.min(i+1,10),ce={paddingLeft:i*16+14,"--nice-row-bg":`var(--nice-tree-level-${oe}-bg, transparent)`,"--nice-row-text":`var(--nice-tree-level-${oe}-text, inherit)`,"--nice-row-hover-bg":`var(--nice-tree-level-${oe}-hover-bg, var(--nice-bg-secondary, #f3f4f6))`,"--nice-row-active-bg":`var(--nice-tree-level-${oe}-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 ${I?"nice-tree-select__node--selected":""} ${t.disabled?"nice-tree-select__node--disabled":""}`,style:ce,"data-nice-depth":oe,onClick:()=>{t.disabled||(J?s(t.key):se&&g(t.key))},role:"treeitem","aria-level":i+1,"aria-selected":I,"aria-expanded":J?B:void 0,"aria-disabled":t.disabled,"data-key":String(t.key),children:[J?e.jsx("button",{type:"button",className:"nice-tree-select__toggle-btn",tabIndex:-1,onClick:Z=>{Z.stopPropagation(),s(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})]}),J&&B&&t.children.map(Z=>e.jsx(ln,{node:Z,level:i+1,selectedKeys:o,expandedKeys:a,onToggleExpand:s,onSelect:g,selectableLeafsOnly:x,maxDepth:$},Z.key))]})},Hn=Object.assign(n.forwardRef(({nodes:t=Bn,value:i,onChange:o,multiple:a=!1,searchable:s=!1,placeholder:g,selectableLeafsOnly:x=!1,clearable:$=!1,maxDepth:P,label:M,helperText:W,error:J,required:B,disabled:I,readOnly:q,size:se="md",name:oe,id:ce,className:Z,style:F,controlWidth:k,menuGap:l,labelPlacement:T,errorPlacement:Y,labelWidth:A,..._},b)=>{const{t:C}=r.useNiceTranslation(),f=r.useControlId(ce),[S,K]=n.useState(!1),[w,d]=n.useState(""),[D,j]=n.useState(new Set),h=n.useRef(null),{popupRef:c,coords:p,ready:E,themeClass:N,portalTarget:m}=Fe.useAnchoredPopup(S,h,()=>K(!1)),R=n.useMemo(()=>i==null?new Set:new Set(Array.isArray(i)?i:[i]),[i]),z=n.useMemo(()=>w?cn(t,w):t,[t,w]),ie=n.useMemo(()=>{const he=Bt(t);return Array.from(R).map(de=>he.find(ge=>ge.key===de)?.label).filter(Boolean)},[R,t]),v=n.useCallback(he=>{j(de=>{const ge=new Set(de);return ge.has(he)?ge.delete(he):ge.add(he),ge})},[]),ee=n.useCallback(he=>{if(a){const de=new Set(R);de.has(he)?de.delete(he):de.add(he),o?.(Array.from(de))}else o?.(he),K(!1)},[a,R,o]),U=n.useCallback(he=>{he.stopPropagation(),o?.(a?[]:"")},[o,a]),me=n.useRef(null),pe=`${f}-tree`;r.useTreeFocus(me,{onToggle:(he,de)=>{const ge=Bt(z).find(ae=>String(ae.key)===he.dataset.key);ge&&D.has(ge.key)!==de&&v(ge.key)}});const ye=n.useCallback(()=>(me.current?.querySelector('[role="treeitem"][tabindex="0"]')??me.current?.querySelector('[role="treeitem"]'))?.focus(),[]),ue=!!p;return n.useEffect(()=>{S&&ue&&!s&&ye()},[S,ue,s,ye]),e.jsxs("div",{className:`nice-field nice-field--${se}${T?` nice-field--label-${T}`:""}${Y==="right"?" nice-field--error-right":""} ${Z||""}`,style:{width:"fit-content",maxWidth:"100%",...l!=null&&{"--nice-dropdown-gap":`${l}px`},...A!=null&&{"--nice-field-label-width":typeof A=="number"?`${A}px`:A},...F},..._,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:k!=null&&k!==""?typeof k=="number"?`${k}px`:k:"var(--nice-field-control-width, 220px)"},children:[e.jsxs("div",{ref:b,id:f,className:`nice-input nice-input--${se} ${J?"nice-input--error":""} ${I?"nice-input--disabled":""} ${q?"nice-input--readonly":""}`,role:"combobox","aria-expanded":S,"aria-haspopup":"tree","aria-controls":S?pe:void 0,"aria-invalid":!!J,tabIndex:I?-1:0,onClick:()=>!I&&!q&&K(!S),onKeyDown:he=>{(he.key==="Enter"||he.key===" "||he.key==="ArrowDown"||he.key==="ArrowUp")&&!I&&!q&&(he.preventDefault(),S?ye():K(!0))},children:[e.jsx("span",{className:"nice-tree-select__display",children:ie.length>0?ie.join(", "):e.jsx("span",{className:"nice-tree-select__placeholder",children:g??C("controls.select","Select...")})}),$&&R.size>0&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:U,"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:S?"rotate(180deg)":"none",transition:"transform 0.15s"},children:e.jsx(r.NiceIcon,{name:"chevron-down",size:14})})]}),S&&p&&m&&ot.createPortal(e.jsxs("div",{ref:c,className:`nice-tree-select__dropdown${N?` ${N}`:""}`,"data-theme":N==="nice-dark"?"dark":N==="nice-light"?"light":void 0,style:{position:"fixed",left:p.left,top:p.top,width:p.width,minWidth:p.width,zIndex:1e3,opacity:E?1:0,pointerEvents:E?void 0:"none"},children:[s&&e.jsx("div",{className:"nice-select__search",onClick:he=>he.stopPropagation(),role:"presentation",children:e.jsx("input",{type:"text",placeholder:C("controls.search","Search..."),"aria-label":C("controls.search","Search..."),"aria-controls":pe,value:w,onChange:he=>d(he.target.value),onKeyDown:he=>{he.key==="ArrowDown"&&(he.preventDefault(),ye())},autoFocus:!0})}),e.jsx("div",{ref:me,id:pe,className:"nice-tree-select__list",role:"tree","aria-label":M||g||C("controls.select","Select..."),"aria-multiselectable":a||void 0,children:z.length===0?e.jsx("div",{className:"nice-tree-select__empty",children:C("controls.noResults","No results")}):z.map(he=>e.jsx(ln,{node:he,level:0,selectedKeys:R,expandedKeys:D,onToggleExpand:v,onSelect:ee,selectableLeafsOnly:x,maxDepth:P},he.key))})]}),m)]}),oe&&e.jsx("input",{type:"hidden",name:oe,value:Array.isArray(i)?i.join(","):i??""}),J&&e.jsx("div",{id:`${f}-error`,className:"nice-field__error",role:"alert",children:J}),!J&&W&&e.jsx("div",{id:`${f}-helper`,className:"nice-field__helper",children:W})]})}),{displayName:"NiceTreeSelect"}),Fn=({displayValue:t,placeholder:i,clearable:o,children:a,onClear:s,open:g,onOpenChange:x,dropdownWidth:$,searchable:P=!0,onSearch:M,searchPlaceholder:W,label:J,error:B,helperText:I,required:q,disabled:se,size:oe="md",id:ce,className:Z,style:F,accessMode:k,showKeyboardHints:l,displayStyle:T})=>{r.useComponentDisplayStyle("input",T),r.useComponentDisplayClass("input",T);const Y=r.useNiceAccessMode(k,ce),A=Y==="hidden";(Y==="disabled"||Y==="readOnly")&&(se=!0);const _=r.useControlId(ce),{t:b}=r.useNiceTranslation(),[C,f]=n.useState(!1),[S,K]=n.useState(""),w=n.useRef(null),d=n.useRef(null),D=g??C,j=n.useMemo(()=>[{key:"Enter",description:b("shortcuts.openDropdown","Open dropdown")},r.COMMON_SHORTCUTS.cancel],[b]),h=R=>{x?x(R):f(R)},{popupRef:c,coords:p,ready:E,themeClass:N,portalTarget:m}=Fe.useAnchoredPopup(D,d,()=>h(!1));return A?null:e.jsxs("div",{className:`nice-field nice-field--${oe} ${B?"nice-field--error":""} ${Z||""}`,style:F,ref:w,children:[J&&e.jsxs("label",{className:"nice-field__label",htmlFor:_,children:[J,q&&e.jsx("span",{className:"nice-field__required",children:"*"}),l&&e.jsx(r.NiceKeyboardHint,{shortcuts:j,size:"sm"})]}),e.jsxs("div",{className:"nice-field__input-wrap",ref:d,children:[e.jsxs("button",{type:"button",id:_,className:"nice-select__trigger",onClick:()=>!se&&h(!D),disabled:se,children:[e.jsx("span",{children:t||i||b("controls.select","Select...")}),e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4},children:[o&&t&&!se&&e.jsx("span",{className:"nice-input__clear",role:"button",tabIndex:0,"aria-label":b("controls.clear","Clear"),onClick:R=>{R.stopPropagation(),s?.()},onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),R.stopPropagation(),s?.())},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})})]})]}),D&&p&&m&&ot.createPortal(e.jsxs("div",{ref:c,className:`nice-dropdown${N?` ${N}`:""}`,"data-theme":N==="nice-dark"?"dark":N==="nice-light"?"light":void 0,style:{position:"fixed",left:p.left,top:p.top,width:$??p.width,minWidth:$??p.width,zIndex:1e3,maxHeight:320,overflowY:"auto",opacity:E?1:0,pointerEvents:E?void 0:"none"},children:[P&&M&&e.jsx("div",{className:"nice-select__search",children:e.jsx("input",{type:"text",value:S,onChange:R=>{K(R.target.value),M(R.target.value)},placeholder:W??b("controls.search","Search..."),autoFocus:!0})}),a]}),m)]}),B&&e.jsx("div",{className:"nice-field__error",children:B}),I&&!B&&e.jsx("div",{className:"nice-field__hint",children:I})]})},Kn=[],Un=[];function et(t,i){return String(t[i])}const Yn={xxs:10,xs:12,sm:12,md:14,lg:18,xl:22,xxl:26},Xn=Object.assign(n.forwardRef(({source:t=Kn,target:i=Un,onChange:o,keyField:a="id",labelField:s="label",renderItem:g,filterable:x=!1,searchable:$,groupBy:P,sortable:M=!1,bulkActions:W=!0,maxRight:J,sourceHeader:B,targetHeader:I,disabled:q=!1,size:se="md",className:oe,style:ce,id:Z,...F},k)=>{const{t:l}=r.useNiceTranslation(),T=Yn[se]??14,[Y,A]=n.useState(new Set),[_,b]=n.useState(new Set),[C,f]=n.useState(""),[S,K]=n.useState(""),[w,d]=n.useState(null),D=n.useRef(null),j=n.useRef(null),h={orientation:"vertical",typeahead:!0,pageSize:10};r.useRovingFocus(D,h),r.useRovingFocus(j,h);const c=n.useCallback((v,ee,U)=>{ee(me=>{const pe=new Set(me);return pe.has(U)?pe.delete(U):pe.add(U),pe})},[]),p=n.useCallback(()=>{const v=t.filter(pe=>Y.has(et(pe,a))),ee=t.filter(pe=>!Y.has(et(pe,a))),U=typeof J=="number"?v.slice(0,Math.max(0,J-i.length)):v,me=v.slice(U.length);o([...ee,...me],[...i,...U]),A(new Set)},[t,i,Y,a,o,J]),E=n.useCallback(()=>{const v=i.filter(U=>_.has(et(U,a))),ee=i.filter(U=>!_.has(et(U,a)));o([...t,...v],ee),b(new Set)},[t,i,_,a,o]),N=n.useCallback(()=>{if(typeof J=="number"){const v=Math.max(0,J-i.length),ee=t.slice(0,v),U=t.slice(v);o(U,[...i,...ee])}else o([],[...i,...t]);A(new Set)},[t,i,o,J]),m=n.useCallback(()=>{o([...t,...i],[]),b(new Set)},[t,i,o]),R=(v,ee)=>{if(!ee)return v;const U=ee.toLowerCase();return v.filter(me=>String(me[s]).toLowerCase().includes(U))},z=W===!1?{moveAll:!1,removeAll:!1}:W===!0||W===void 0?{moveAll:!0,removeAll:!0}:{moveAll:W.moveAll??!0,removeAll:W.removeAll??!0},ie=(v,ee,U,me,pe,ye,ue,he)=>{let de=R(v,me);M||(de=[...de].sort((re,fe)=>String(re[s]).localeCompare(String(fe[s]),void 0,{numeric:!0,sensitivity:"base"})));const ge=$===!0||x&&$===void 0?"both":$??!1,ae=ge==="both"||ge==="left"&&ue==="left"||ge==="right"&&ue==="right",ve=(()=>{if(!P)return[{label:"",items:de}];const re=new Map;for(const fe of de){const H=String(P(fe));let X=re.get(H);X||(X=[],re.set(H,X)),X.push(fe)}return[...re.entries()].map(([fe,H])=>({label:fe,items:H}))})(),_e=(re,fe)=>{re.dataTransfer.setData("text/plain",fe),re.dataTransfer.effectAllowed="move"},te=(re,fe)=>{if(re.preventDefault(),!M)return;const H=re.currentTarget.getBoundingClientRect(),X=re.clientY<H.top+H.height/2;d(O=>O&&O.side===ue&&O.key===fe&&O.before===X?O:{side:ue,key:fe,before:X})},we=(re,fe)=>{re.preventDefault();const H=w?.before??!1;d(null);const X=re.dataTransfer.getData("text/plain");if(!X||!M)return;const y=[...ue==="right"?i:t],G=y.findIndex(xe=>et(xe,a)===X),ne=y.findIndex(xe=>et(xe,a)===fe);if(G===-1||ne===-1||X===fe)return;let le=H?ne:ne+1;const[be]=y.splice(G,1);G<le&&(le-=1),y.splice(le,0,be),o(ue==="right"?t:y,ue==="right"?y:i)};return e.jsxs("div",{className:"nice-picklist__panel",children:[ye&&e.jsx("div",{className:"nice-picklist__header",children:ye}),ae&&e.jsx("div",{className:"nice-picklist__filter",children:e.jsx("input",{className:"nice-input__native",type:"text",size:1,placeholder:l("controls.search","Search..."),value:me,onChange:re=>pe(re.target.value)})}),e.jsxs("div",{className:"nice-picklist__list",role:"listbox","aria-multiselectable":"true","aria-label":typeof ye=="string"?ye:void 0,ref:he,children:[ve.map(re=>e.jsxs(n.Fragment,{children:[re.label&&e.jsx("div",{className:"nice-picklist__group-header",role:"presentation",children:re.label}),re.items.map(fe=>{const H=et(fe,a),X=ee.has(H),y=w&&w.side===ue&&w.key===H?w.before?"nice-picklist__item--drop-before":"nice-picklist__item--drop-after":"";return e.jsxs("div",{className:`nice-picklist__item ${X?"nice-picklist__item--selected":""} ${y}`,role:"option","aria-selected":X,draggable:M,onDragStart:M?G=>_e(G,H):void 0,onDragOver:M?G=>te(G,H):void 0,onDrop:M?G=>we(G,H):void 0,onDragEnd:M?()=>d(null):void 0,onClick:()=>!q&&c(ee,U,H),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),q||c(ee,U,H))},children:[M&&e.jsx("span",{className:"nice-picklist__drag-handle","aria-hidden":"true",children:e.jsx(r.NiceIcon,{name:"grip",size:T})}),g?g(fe,ue):String(fe[s])]},H)})]},re.label||"__none__")),de.length===0&&e.jsx("div",{className:"nice-picklist__empty",children:l("controls.noItems","No items")})]})]})};return e.jsxs("div",{ref:k,id:Z,className:`nice-picklist nice-picklist--${se} ${q?"nice-picklist--disabled":""} ${oe||""}`,style:ce,...F,children:[ie(t,Y,A,C,f,B??l("picklist.source","Available"),"left",D),e.jsxs("div",{className:"nice-picklist__controls",children:[e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||Y.size===0,onClick:p,"aria-label":l("picklist.moveRight","Move right"),children:e.jsx(r.NiceIcon,{name:"chevron-right",size:T})}),z.moveAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||t.length===0,onClick:N,"aria-label":l("picklist.moveAllRight","Move all right"),children:e.jsx(r.NiceIcon,{name:"chevrons-right",size:T})}),e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||_.size===0,onClick:E,"aria-label":l("picklist.moveLeft","Move left"),children:e.jsx(r.NiceIcon,{name:"chevron-left",size:T})}),z.removeAll&&e.jsx("button",{type:"button",className:`nice-btn nice-btn--outline nice-btn--${se}`,disabled:q||i.length===0,onClick:m,"aria-label":l("picklist.moveAllLeft","Move all left"),children:e.jsx(r.NiceIcon,{name:"chevrons-left",size:T})})]}),ie(i,_,b,S,K,I??l("picklist.target","Selected"),"right",j)]})}),{displayName:"NicePickList"});function Tt(t){return t?.startsWith("datetime")?"datetime":t==="week"?"week":t?.startsWith("month")?"month":"date"}function qn(t){const i=new Date,o=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`,a=Tt(t);return a==="datetime"?`${o}T00:00`:a==="month"?o.slice(0,7):o}function Ht(t,i){if(!t)return t;const o=new Date(t.length<=10?`${t}T00:00`:t);if(Number.isNaN(o.getTime()))return t;o.setDate(o.getDate()+i);const a=`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`;return t.length<=10?a.slice(0,t.length):a+t.slice(10)}function ft(...t){return t.filter(Boolean).sort().pop()}function Ft(t,i,o){if(!t)return"";const a=new Date(t.length<=10?`${t}T00:00`:t);if(Number.isNaN(a.getTime()))return t;const s=Tt(o);return s==="month"?a.toLocaleDateString(i,{year:"numeric",month:"2-digit"}):s==="datetime"?a.toLocaleString(i,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):a.toLocaleDateString(i,{year:"numeric",month:"2-digit",day:"2-digit"})}function Kt(t){let i=0;for(const o of t)i+=/[\p{L}\p{N}]/u.test(o)?1:.5;return i}function Ut(t){const i=/^(\d{4})-(\d{2})(?:-(\d{2}))?(?:T(\d{2}):(\d{2}))?$/.exec(t);if(!i)return!1;const[,o,a,s="01",g="00",x="00"]=i,$=new Date(Number(o),Number(a)-1,Number(s));return $.getMonth()===Number(a)-1&&$.getDate()===Number(s)&&Number(g)<24&&Number(x)<60}const Vn=({startDate:t,endDate:i,defaultStartDate:o,defaultEndDate:a,onStartChange:s,onEndChange:g,min:x,max:$,clearable:P,startPlaceholder:M,endPlaceholder:W,startLabel:J,endLabel:B,layout:I="horizontal",separator:q="–",gap:se=12,fullWidth:oe=!1,dateFormatPreset:ce,locale:Z,timeSelectorType:F,endCondition:k="greater-or-equal",startCondition:l="today-or-greater",singleField:T=!1,label:Y,error:A,helperText:_,required:b,disabled:C,size:f="md",id:S,className:K,style:w,accessMode:d,showKeyboardHints:D,labelPlacement:j,errorPlacement:h,labelWidth:c,controlWidth:p,loading:E,readOnly:N})=>{const m=r.useNiceAccessMode(d,S),R=r.useControlId(S),{t:z}=r.useNiceTranslation(),ie=m==="disabled"||m==="readOnly"||!!C,[v,ee]=r.useControllableState({value:t,defaultValue:o,fallbackValue:"",onChange:s,componentName:"NiceDateRangeBox"}),[U,me]=r.useControllableState({value:i,defaultValue:a,fallbackValue:"",onChange:g,componentName:"NiceDateRangeBox"}),pe=n.useMemo(()=>[{key:"Tab",description:z("shortcuts.switchField","Switch between start/end")},r.COMMON_SHORTCUTS.cancel],[z]),ye=n.useRef(null),ue=n.useRef(null),[he,de]=n.useState(!1),[ge,ae]=n.useState(null),[ve,_e]=n.useState(""),te=n.useContext(r.NiceThemeContext),we=te?.portalTarget??(typeof document<"u"?document.body:null),re=Z||Ue.getDefaultLocale(),fe=n.useMemo(()=>Ue.rangeMaskSpec(ce,re),[ce,re]),[H,X]=n.useState(null);n.useLayoutEffect(()=>{if(!he)return;const L=ye.current?.getBoundingClientRect();L&&(ae({left:L.left,top:L.bottom+6}),_e(te?.portalTarget?"":tt.scopeThemeClass(ye.current)))},[he,te?.portalTarget]),n.useEffect(()=>{if(!he)return;const L=Ce=>{const Pe=Ce.target;ye.current?.contains(Pe)||ue.current?.contains(Pe)||de(!1)},ke=()=>{const Ce=ye.current?.getBoundingClientRect();Ce&&ae({left:Ce.left,top:Ce.bottom+6})};return document.addEventListener("mousedown",L),window.addEventListener("scroll",ke,!0),window.addEventListener("resize",ke),()=>{document.removeEventListener("mousedown",L),window.removeEventListener("scroll",ke,!0),window.removeEventListener("resize",ke)}},[he]),r.useOverlayFocus(ue,{open:he,modal:!1,initialFocus:'.nice-calendar__grid [tabindex="0"]',onClose:()=>de(!1)});const O=qn(ce),y=l==="today-or-greater"?ft(x,O):l==="greater-than-today"?ft(x,Ht(O,1)):x,G=k==="greater-or-equal"?ft(x,v):k==="greater"?ft(x,v?Ht(v,1):void 0):x,ne=n.useMemo(()=>{if(A)return A;if(v&&U){if(k==="greater-or-equal"&&U<v)return z("daterange.endBeforeStart","End date must be on or after the start date");if(k==="greater"&&U<=v)return z("daterange.endAfterStart","End date must be after the start date")}if(v){if(l==="today-or-greater"&&v<O)return z("daterange.startInPast","Start date cannot be in the past");if(l==="greater-than-today"&&v<=O)return z("daterange.startAfterToday","Start date must be after today")}},[A,v,U,l,k,O,z]);if(m==="hidden")return null;const le=L=>{ee(L),L&&U&&L>U&&me(L)},be=I==="horizontal",xe=Tt(ce),Se=re,Te=typeof q=="string"&&q!==""?q:"–",Me=xe!=="week"&&ce!=="time",ze=Ue.dateMaskDigits.slots(fe),qe=L=>L?Me?Ue.dateMaskDigits.render(fe,Ue.dateMaskDigits.fromIso(fe,L)):Ft(L,Se,ce):"",Ve=qe(v),Ge=qe(U),We=Ve||Ge?`${Ve||"…"} ${Te} ${Ge||"…"}`:"",Ee=L=>{const ke=Ue.dateMaskDigits.render(fe,L.slice(0,ze));return L.length<ze?ke:`${ke} ${Te} ${Ue.dateMaskDigits.render(fe,L.slice(ze))}`},Je=`${fe.placeholder} ${Te} ${fe.placeholder}`,$e=(()=>{const L=Me?fe.placeholder:Ft("2026-12-30T22:58",Se,ce),ke=`${L} ${Te} ${L}`;return`${(Math.max(Kt(ke),Kt(We))+1.5).toFixed(1)}ch`})(),Ze=(L,ke)=>xe==="datetime"?ke&&ke.length>10?`${L}${ke.slice(10)}`:`${L}T00:00`:xe==="month"?L.slice(0,7):L,Le=({start:L,end:ke})=>{X(null),ee(L?Ze(L,v):""),me(ke?Ze(ke,U):""),L&&ke&&de(!1)},Ae=()=>{X(null),ee(""),me("")},Oe=L=>{const ke=H!==null?Ee(H):We;let Ce=L.replace(/\D/g,"").slice(0,ze*2);if(L.length<ke.length&&Ce===ke.replace(/\D/g,"")&&(Ce=Ce.slice(0,-1)),Ce.length===0){Ae();return}X(Ce);const Pe=Ce.length>=ze?Ue.dateMaskDigits.toIso(fe,Ce.slice(0,ze)):"";Pe&&Ut(Pe)&&Pe!==v&&ee(Pe);const He=Ce.length===ze*2?Ue.dateMaskDigits.toIso(fe,Ce.slice(ze)):"";He&&Ut(He)&&He!==U&&me(He)},at=()=>{H!==null&&(H.length<ze&&ee(""),H.length<ze*2&&me(""),X(null))},u=()=>{!ie&&!N&&de(L=>!L)},V=L=>L&&L.length>=10?L.slice(0,10):L||void 0;return e.jsxs("div",{className:`nice-field nice-field--${f} nice-daterange nice-daterange--${I} ${j==="left"?"nice-field--label-left":""} ${ne?"nice-field--error":""} ${E?"nice-field--loading":""} ${K||""}`,style:{...w,...c!=null&&{"--nice-field-label-width":typeof c=="number"?`${c}px`:c},...p!=null&&{"--nice-field-control-width":typeof p=="number"?`${p}px`:p}},"aria-busy":E||void 0,children:[Y&&e.jsxs("label",{className:"nice-field__label",htmlFor:R,children:[Y,b&&e.jsx("span",{className:"nice-field__required",children:"*"}),D&&e.jsx(r.NiceKeyboardHint,{shortcuts:pe,size:"sm"})]}),e.jsxs("div",{className:"nice-field__control",children:[T?e.jsxs("div",{ref:ye,className:`nice-input nice-input--date nice-input--${f} nice-daterange__single ${ne?"nice-input--error":""} ${ie?"nice-input--disabled":""} ${N?"nice-input--readonly":""}`,style:{position:"relative",width:oe?"100%":"fit-content"},children:[e.jsx("input",{id:R,className:"nice-input__native",type:"text",readOnly:!Me||N,value:H!==null?Ee(H):We,placeholder:M||(Me?Je:z("controls.startDate","Start date")),disabled:ie||E,autoComplete:"off",spellCheck:!1,inputMode:Me?"numeric":void 0,"aria-invalid":!!ne,"aria-label":Y?void 0:z("controls.startDate","Start date"),"aria-haspopup":"dialog","aria-expanded":he,onClick:Me?void 0:u,onChange:Me?L=>Oe(L.target.value):void 0,onBlur:Me?at:void 0,onKeyDown:L=>{const ke=!!L.nativeEvent.niceSource;(L.key==="Enter"||L.key===" "&&!Me||L.key==="ArrowDown"&&!ke)&&(L.preventDefault(),he||u())},style:{width:oe?"100%":$e,cursor:ie||N?void 0:Me?"text":"pointer"}}),P&&e.jsx("button",{type:"button",className:"nice-input__clear",onClick:Ae,disabled:!v&&!U||ie||N,"aria-label":z("controls.clear","Clear"),tabIndex:(v||U)&&!ie&&!N?0:-1,children:e.jsx(r.NiceIcon,{name:"close",size:14})}),e.jsx("button",{type:"button",className:"nice-input__picker-trigger",onClick:u,"aria-label":z("controls.openPicker","Open picker"),"aria-expanded":he,tabIndex:-1,disabled:ie||N,children:e.jsx(r.NiceIcon,{name:"calendar",size:16})})]}):e.jsxs("div",{className:"nice-daterange__row",style:{display:"flex",flexDirection:be?"row":"column",alignItems:be?j==="left"?"center":"flex-end":"stretch",gap:se,flexWrap:be?"nowrap":"wrap"},children:[e.jsx("div",{style:{flex:oe?"1 1 0":void 0,minWidth:0},children:e.jsx(Ue.NiceDateTimePicker,{id:R,dateFormatPreset:ce,displayLocale:Z,timeSelectorType:F,label:J,value:v,onChange:le,min:y,max:U||$,placeholder:M,disabled:ie,readOnly:N,size:f,clearable:P,labelPlacement:j,labelWidth:c})}),be&&q!==""&&q!=null&&e.jsx("span",{className:"nice-daterange__separator",style:{paddingBottom:8,color:"var(--nice-text-secondary, #666)"},"aria-hidden":"true",children:q}),e.jsx("div",{style:{flex:oe?"1 1 0":void 0,minWidth:0},children:e.jsx(Ue.NiceDateTimePicker,{dateFormatPreset:ce,displayLocale:Z,timeSelectorType:F,label:B,value:U,onChange:L=>me(L),min:G||v||x,max:$,placeholder:W,disabled:ie,readOnly:N,size:f,clearable:P,labelPlacement:j,labelWidth:c})})]}),T&&he&&ge&&we&&ot.createPortal(e.jsxs("div",{ref:ue,className:`nice-datetime-popup${ve?` ${ve}`:""}`,style:{position:"fixed",left:ge.left,top:ge.top,zIndex:1e3},role:"dialog","aria-label":z("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(Ue.NiceCalendar,{selectionMode:"range",rangeStart:V(v),rangeEnd:V(U),onRangeChange:Le,min:V(y),max:V($),size:f})})}),P&&e.jsx("div",{className:"nice-datetime-popup__footer",children:e.jsx("button",{type:"button",className:"nice-datetime-popup__btn",onClick:Ae,disabled:!v&&!U,children:z("controls.clear","Clear")})})]}),we),E&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),h==="right"&&ne&&e.jsx("div",{className:"nice-field__error",role:"alert",children:ne}),h==="right"&&!ne&&_&&e.jsx("div",{className:"nice-field__helper",children:_})]}),h!=="right"&&ne&&e.jsx("div",{className:"nice-field__error",children:ne}),h!=="right"&&!ne&&_&&e.jsx("div",{className:"nice-field__hint",children:_})]})};function Gn(t,i=30){switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-i,180+i];case"analogous":return[0,-i,i];case"analogous-complementary":return[0,-i,i,180];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270];case"shade-chain":return[];case"custom":return[0,60,200];default:return[0]}}function Yt(t,i={}){const o=i.size??16,a="currentColor",s="currentColor";if(i.rectangle||t==="shade-chain"||t==="monochromatic"){const J=Math.max(3,Math.min(7,i.count??5)),B=o*.1,I=o-B*2,q=Math.max(1.2,o/14),se=o/2,oe=Array.from({length:J},(ce,Z)=>{const F=B+I*Z/(J-1),k=.25+.75*Z/(J-1);return e.jsx("circle",{cx:F,cy:se,r:q,fill:s,opacity:k},Z)});return e.jsxs("svg",{width:o,height:o,viewBox:`0 0 ${o} ${o}`,"aria-hidden":!0,children:[e.jsx("rect",{x:1,y:o/2-o/6,width:o-2,height:o/3,rx:o/6,fill:"none",stroke:a,strokeOpacity:.25}),oe]})}const x=i.angles??Gn(t),$=o/2,P=o/2,M=o/2-2,W=Math.max(1.4,o/9);return e.jsxs("svg",{width:o,height:o,viewBox:`0 0 ${o} ${o}`,"aria-hidden":!0,children:[e.jsx("circle",{cx:$,cy:P,r:M,fill:"none",stroke:a,strokeOpacity:.25}),x.map((J,B)=>{const I=(J-90)*Math.PI/180,q=$+M*Math.cos(I),se=P+M*Math.sin(I);return e.jsx("circle",{cx:q,cy:se,r:W,fill:s},B)})]})}function Xt(t,i,o){return Math.max(i,Math.min(o,t))}function dn({h:t,s:i,v:o}){t=(t%360+360)%360;const a=o*i,s=a*(1-Math.abs(t/60%2-1)),g=o-a;let x=0,$=0,P=0;return t<60?(x=a,$=s):t<120?(x=s,$=a):t<180?($=a,P=s):t<240?($=s,P=a):t<300?(x=s,P=a):(x=a,P=s),{r:Math.round((x+g)*255),g:Math.round(($+g)*255),b:Math.round((P+g)*255)}}function Rt({r:t,g:i,b:o}){t/=255,i/=255,o/=255;const a=Math.max(t,i,o),s=Math.min(t,i,o),g=a-s;let x=0;return g!==0&&(a===t?x=(i-o)/g%6:a===i?x=(o-t)/g+2:x=(t-i)/g+4,x=(x*60+360)%360),{h:x,s:a===0?0:g/a,v:a}}function mn({r:t,g:i,b:o}){t/=255,i/=255,o/=255;const a=Math.max(t,i,o),s=Math.min(t,i,o),g=(a+s)/2;if(a===s)return{h:0,s:0,l:g};const x=a-s,$=g>.5?x/(2-a-s):x/(a+s);let P=0;return a===t?P=((i-o)/x+(i<o?6:0))/6:a===i?P=((o-t)/x+2)/6:P=((t-i)/x+4)/6,{h:P*360,s:$,l:g}}function ut(t){const i=t.replace("#",""),o=i.length===3?i[0]+i[0]+i[1]+i[1]+i[2]+i[2]:i,a=parseInt(o,16);return{r:a>>16&255,g:a>>8&255,b:a&255}}function un({r:t,g:i,b:o}){return"#"+[t,i,o].map(a=>a.toString(16).padStart(2,"0")).join("")}function Be(t){return un(dn(t))}function Ye(t){return Rt(ut(t))}function pn(t,i){const o=[];for(let a=0;a<i;a++){const s=i<=1?.5:a/(i-1),g=Xt(t.s*(.3+s*.7),0,1),x=Xt(t.v*(1.2-s*.7),0,1);o.push(Be({h:t.h,s:g,v:x}))}return o}function _t(t,i){if(t==="custom"||t==="shade-chain")return[0];const o=i??30;switch(t){case"monochromatic":return[0];case"complementary":return[0,180];case"split-complementary":return[0,180-o,180+o];case"analogous":return[0,-o,o];case"analogous-complementary":return[0,-o,o,180];case"triadic":return[0,120,240];case"tetradic":return[0,60,180,240];case"square":return[0,90,180,270]}return[0]}function mt(t,i,o){return _t(i,o).map(a=>((t+a)%360+360)%360)}function qt(t,i,o=.12){const a=Math.max(2,i),s=(a-1)/2,g=[];for(let x=0;x<a;x++){const $=(x-s)*o,P=Math.max(.05,Math.min(.98,t.v+$)),M=Math.max(.05,Math.min(1,t.s-Math.abs($)*.25));g.push(Be({h:t.h,s:M,v:P}))}return g}function Vt({r:t,g:i,b:o}){const[a,s,g]=[t,i,o].map(x=>{const $=x/255;return $<=.03928?$/12.92:Math.pow(($+.055)/1.055,2.4)});return .2126*a+.7152*s+.0722*g}function xt(t,i){const o=Vt(ut(t)),a=Vt(ut(i)),s=Math.max(o,a),g=Math.min(o,a);return(s+.05)/(g+.05)}function bt(t){return t>=7?"AAA":t>=4.5?"AA":t>=3?"AA-lg":"Fail"}const hn={"lightest-pastel":{sRange:[.1,.25],vRange:[.92,1]},"bright-pastel":{sRange:[.25,.45],vRange:[.9,1]},shiny:{sRange:[.7,.95],vRange:[.9,1]},pastel:{sRange:[.3,.55],vRange:[.75,.92]},full:{sRange:[.75,1],vRange:[.75,1]},dark:{sRange:[.6,.9],vRange:[.3,.55]},deep:{sRange:[.85,1],vRange:[.45,.65]},muted:{sRange:[.15,.35],vRange:[.5,.7]},earth:{sRange:[.3,.6],vRange:[.4,.65]}};function jt(t,i){const o=hn[i];return t.map(a=>{const s=(o.sRange[0]+o.sRange[1])/2,g=(o.vRange[0]+o.vRange[1])/2;return Be({h:a,s,v:g})})}function Wn(){return Math.floor(Math.random()*360)}function gn(t,i,o){const a=Wn(),s=mt(a,t,o),g=[];for(let x=0;x<i;x++){const $=s[x%s.length],P=.55+Math.random()*.4,M=.5+Math.random()*.45;g.push(Be({h:$+(Math.random()-.5)*8,s:P,v:M}))}return g}const Jn=({hues:t,colors:i,baseHue:o,onBaseHueChange:a,mode:s,distance:g,disabled:x})=>{const{t:$}=r.useNiceTranslation(),P=240,M=P/2,W=P/2,J=110,B=55,I=l=>{if(x)return;const T=l.shiftKey?15:1,Y=l.key==="ArrowLeft"||l.key==="ArrowDown"?-T:l.key==="ArrowRight"||l.key==="ArrowUp"?T:l.key==="PageDown"?-15:l.key==="PageUp"?15:null;Y!==null?(l.preventDefault(),a(((o+Y)%360+360)%360)):(l.key==="Home"||l.key==="End")&&(l.preventDefault(),a(l.key==="Home"?0:359))},q=n.useRef(null),se=n.useCallback((l,T)=>{const Y=q.current;if(!Y)return;const A=Y.getBoundingClientRect(),_=(l-A.left)/A.width*P-M,b=(T-A.top)/A.height*P-W,C=(Math.atan2(b,_)*180/Math.PI+360)%360;a(Math.round(C))},[M,W,P,a]),oe=n.useCallback(l=>{if(x)return;l.preventDefault(),se(l.clientX,l.clientY);const T=A=>se(A.clientX,A.clientY),Y=()=>{document.removeEventListener("pointermove",T),document.removeEventListener("pointerup",Y)};document.addEventListener("pointermove",T),document.addEventListener("pointerup",Y)},[x,se]),ce=[];for(let l=0;l<360;l+=2){const T=(l-1)*Math.PI/180,Y=(l+1)*Math.PI/180,A=Be({h:l,s:1,v:1});ce.push(e.jsx("path",{d:`M${M+B*Math.cos(T)},${W+B*Math.sin(T)} L${M+J*Math.cos(T)},${W+J*Math.sin(T)} A${J},${J} 0 0,1 ${M+J*Math.cos(Y)},${W+J*Math.sin(Y)} L${M+B*Math.cos(Y)},${W+B*Math.sin(Y)} A${B},${B} 0 0,0 ${M+B*Math.cos(T)},${W+B*Math.sin(T)} Z`,fill:A},l))}const Z=`wheel-center-${s}`,F=t.map((l,T)=>{const Y=(J+B)/2,A=l*Math.PI/180;return e.jsx("circle",{cx:M+Y*Math.cos(A),cy:W+Y*Math.sin(A),r:T===0?8:6,fill:i?.[T]??Be({h:l,s:.85,v:.9}),stroke:T===0?"var(--nice-bg-primary, #fff)":"var(--nice-border-color, #ccc)",strokeWidth:T===0?3:2},T)});let k=null;if(s==="analogous"||s==="split-complementary"||s==="analogous-complementary"){const l=(J+B)/2,Y=_t(s,g).slice(1).map((A,_)=>{const b=(o+A)*Math.PI/180;return e.jsx("line",{x1:M,y1:W,x2:M+l*Math.cos(b),y2:W+l*Math.sin(b),stroke:"var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3))",strokeWidth:1,strokeDasharray:"3,3"},`dline-${_}`)});k=e.jsx(e.Fragment,{children:Y})}return e.jsxs("svg",{ref:q,className:"nice-palette__wheel",viewBox:`0 0 ${P} ${P}`,width:P,height:P,onPointerDown:oe,onKeyDown:I,role:"slider",tabIndex:x?-1:0,"aria-label":$("colorPalette.baseHue","Base hue"),"aria-valuemin":0,"aria-valuemax":359,"aria-valuenow":Math.round(o),"aria-valuetext":`${Math.round(o)}°`,style:{cursor:x?"default":"crosshair",touchAction:"none"},children:[e.jsx("defs",{children:e.jsxs("radialGradient",{id:Z,children:[e.jsx("stop",{offset:"0%",stopColor:"var(--nice-bg, #fff)"}),e.jsx("stop",{offset:"100%",stopColor:"transparent"})]})}),ce,e.jsx("circle",{cx:M,cy:W,r:B-2,fill:Be({h:o,s:.6,v:.85})}),e.jsx("circle",{cx:M,cy:W,r:B-2,fill:`url(#${Z})`,opacity:.4}),k,F]})},Zn=({colors:t})=>{const{t:i}=r.useNiceTranslation();if(t.length<2)return null;const o=[];for(let a=0;a<t.length;a++){const s=xt(t[a],"var(--nice-bg-primary, #ffffff)"),g=xt(t[a],"var(--nice-text-primary, #000000)");o.push({a:t[a],b:"var(--nice-bg-primary, #ffffff)",ratio:s,level:bt(s)}),o.push({a:t[a],b:"var(--nice-text-primary, #000000)",ratio:g,level:bt(g)});for(let x=a+1;x<t.length;x++){const $=xt(t[a],t[x]);o.push({a:t[a],b:t[x],ratio:$,level:bt($)})}}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:o.map((a,s)=>e.jsxs("div",{className:"nice-palette__contrast-pair",children:[e.jsxs("div",{className:"nice-palette__contrast-swatches",children:[e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:a.a}}),e.jsx("span",{className:"nice-palette__contrast-vs",children:i("colorPalette.vs","vs")}),e.jsx("span",{className:"nice-palette__contrast-dot",style:{background:a.b}})]}),e.jsxs("span",{className:"nice-palette__contrast-ratio",children:[a.ratio.toFixed(1),":1"]}),e.jsx("span",{className:`nice-palette__contrast-level nice-palette__contrast-level--${a.level.toLowerCase().replace("-","")}`,children:a.level})]},s))})]})},Qn=({hex:t})=>{const i=ut(t),o=mn(i),a=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(o.h),"°, ",Math.round(o.s*100),"%,"," ",Math.round(o.l*100),"%"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"HSV"})," ",Math.round(a.h),"°, ",Math.round(a.s*100),"%,"," ",Math.round(a.v*100),"%"]})]})},ei={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"},ti={"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"},ni=["monochromatic","shade-chain","complementary","split-complementary","analogous","analogous-complementary","triadic","tetradic","square","custom"],fn=["lightest-pastel","bright-pastel","shiny","pastel","full","dark","deep","muted","earth"],yn="nice-palette-custom-schemes";function ii(){if(typeof window>"u")return[];try{const t=window.localStorage.getItem(yn);if(!t)return[];const i=JSON.parse(t);if(Array.isArray(i))return i}catch{}return[]}function oi(t){if(!(typeof window>"u"))try{window.localStorage.setItem(yn,JSON.stringify(t))}catch{}}const ai=Object.assign(n.forwardRef(({id:t,className:i,style:o,accessMode:a,value:s,onChange:g,minColors:x=1,maxColors:$=8,harmonyMode:P,onHarmonyModeChange:M,distance:W,onDistanceChange:J,preset:B,onPresetChange:I,showWheel:q=!0,showContrast:se=!0,showInfo:oe=!0,showPresets:ce=!0,presets:Z=[],showVariations:F=!0,showRandom:k=!0,variationCount:l=5,label:T,labelPlacement:Y="top",disabled:A,readOnly:_,loading:b,error:C,colorCount:f,shadeStep:S,onShadeStepChange:K,customSchemes:w,onCustomSchemesChange:d,persistCustomSchemes:D=!0,"data-testid":j},h)=>{const c=r.useNiceAccessMode(a,t),p=c==="hidden";c==="disabled"&&(A=!0);const E=_||c==="readOnly",N=r.useControlId(t),{t:m}=r.useNiceTranslation(),R=tt.useNiceDialogs(),[z,ie]=n.useState("analogous-complementary"),[v,ee]=n.useState(30),[U,me]=n.useState(""),[pe,ye]=n.useState(0),[ue,he]=n.useState(.12),[de,ge]=n.useState(null),[ae,ve]=n.useState(()=>w??(D?ii():[])),[_e,te]=n.useState(null),[we,re]=n.useState(!1),[fe,H]=n.useState(null),[X,O]=n.useState(""),G=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),ne=n.useRef(null),le=n.useRef(null),be=P??z,xe=W??v,Se=B??U,Te=S??ue,Me=w??ae;n.useEffect(()=>{!w&&D&&oi(ae)},[ae,w,D]);const ze=n.useCallback(Q=>{ve(Q),d?.(Q)},[d]),qe=n.useCallback(Q=>{ie(Q),M?.(Q)},[M]),Ve=n.useCallback(Q=>{ee(Q),J?.(Q)},[J]),Ge=n.useCallback(Q=>{me(Q),Q&&I?.(Q)},[I]),We=n.useMemo(()=>["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)"],[]),Ee=s&&s.length>0?s:We,Je=Ee[0],$e=n.useMemo(()=>Ye(Je),[Je]),Ze=n.useMemo(()=>mt($e.h,be,xe),[$e.h,be,xe]),Le=n.useCallback((Q,je,Ne,Re,Xe)=>{const ht=f??Xe??de??Ee.length,nt=ht!==void 0?Math.max(x,Math.min($,ht)):void 0;if(je==="shade-chain"){const Ke=nt??Math.max(x,5),Qe=qt({h:Q,s:$e.s||.7,v:$e.v||.6},Ke,Te);g?.(Qe);return}let it;const rt=je==="custom"&&_e?Me.find(Ke=>Ke.id===_e):null;rt&&rt.angles.length>0?it=rt.angles.map(Ke=>((Q+Ke)%360+360)%360):it=mt(Q,je,Ne);let De;if(Re&&hn[Re]?De=jt(it,Re):De=it.map(Ke=>Be({h:Ke,s:$e.s||.7,v:$e.v||.85})),rt?.lightnessOffsets?.length&&(De=De.map((Ke,Qe)=>{const Lt=rt.lightnessOffsets?.[Qe];if(Lt==null)return Ke;const Nt=Ye(Ke);return Be({h:Nt.h,s:Nt.s,v:Math.max(.05,Math.min(.98,Nt.v+Lt))})})),nt!==void 0){for(;De.length<nt;){const Ke=De[De.length-1]||"#888888",Qe=Ye(Ke);De.push(Be({h:(Qe.h+18)%360,s:Qe.s,v:Qe.v}))}De=De.slice(0,nt)}else{for(;De.length<x;)De.push(De[De.length-1]||"var(--nice-text-secondary, #888888)");De.length>$&&(De=De.slice(0,$))}g?.(De)},[$e.s,$e.v,x,$,g,f,de,Ee.length,Te,_e,Me]),Ae=n.useCallback(Q=>{if(!A){if(be==="custom"){const je=Be({h:Q,s:$e.s||.7,v:$e.v||.85}),Ne=[...Ee];Ne[pe]=je,g?.(Ne);return}Le(Q,be,xe,Se)}},[A,be,xe,Se,Le,$e.s,$e.v,Ee,pe,g]),Oe=n.useCallback(Q=>{if(A||(qe(Q),Q==="custom"))return;const je=_t(Q).length,Ne=je<=1;if(f==null&&!Ne){const Re=Math.max(x,Math.min($,je));ge(Re),Le($e.h,Q,xe,Se,Re)}else Le($e.h,Q,xe,Se)},[A,$e.h,xe,Se,qe,Le,f,x,$]),at=n.useCallback(Q=>{A||(Ve(Q),Le($e.h,be,Q,Se))},[A,$e.h,be,Se,Ve,Le]),u=n.useCallback(Q=>{if(A)return;Ge(Q);const je=mt($e.h,be,xe),Ne=jt(je,Q);g?.(Ne.slice(0,$))},[A,$e.h,be,xe,$,Ge,g]),V=n.useCallback((Q,je)=>{if(A)return;const Ne=[...Ee];Ne[Q]=je,g?.(Ne)},[A,Ee,g]),L=n.useCallback(()=>{if(A||Ee.length>=$)return;const Q=Ye(Ee[Ee.length-1]),je=Be({h:(Q.h+30)%360,s:Q.s,v:Q.v});g?.([...Ee,je])},[A,Ee,$,g]),ke=n.useCallback(Q=>{if(A||Ee.length<=x)return;const je=Ee.filter((Ne,Re)=>Re!==Q);g?.(je),pe>=je.length&&ye(Math.max(0,je.length-1))},[A,Ee,x,g,pe]),Ce=n.useCallback(()=>{if(A)return;const Q=Math.max(x,Math.min($,_t(be).length)),je=gn(be,Q,xe);g?.(je)},[A,x,$,be,xe,g]),Pe=n.useMemo(()=>{if(!F)return[];const Q=Ee[pe]||Ee[0];return pn(Ye(Q),l)},[F,Ee,pe,l]),He=Ee[pe]||Ee[0],wt=n.useMemo(()=>{const Q=Ye(He);return Be({h:(Q.h+180)%360,s:Q.s,v:Q.v})},[He]);n.useLayoutEffect(()=>{if(!we||!ne.current)return;O(tt.scopeThemeClass(ne.current));const Q=()=>{const je=ne.current?.getBoundingClientRect();if(!je)return;const Ne=600;let Re=je.left;Re+Ne>window.innerWidth-8&&(Re=Math.max(8,window.innerWidth-Ne-8));let Xe=je.bottom+6;Xe>window.innerHeight*.5&&(Xe=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,540)-8)),H({left:Re,top:Xe})};return Q(),window.addEventListener("scroll",Q,!0),window.addEventListener("resize",Q),()=>{window.removeEventListener("scroll",Q,!0),window.removeEventListener("resize",Q)}},[we]),n.useEffect(()=>{if(!we)return;const Q=je=>{const Ne=je.target;ne.current?.contains(Ne)||le.current?.contains(Ne)||(Ne instanceof Element?Ne:Ne?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"], [aria-modal="true"]')||re(!1)};return document.addEventListener("mousedown",Q),()=>{document.removeEventListener("mousedown",Q)}},[we]),r.useOverlayFocus(le,{open:we,modal:!1,onClose:()=>re(!1)});const Dt=n.useRef(null);if(r.useRovingFocus(Dt,{orientation:"horizontal",itemSelector:".nice-palette__variation-chip"}),p)return null;const zt=Z.length>0?Z:fn,$n=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(Fe.NiceSelect,{label:m("colorPalette.harmony","Harmony"),labelPlacement:"left",size:"sm",disabled:A,value:be==="custom"&&_e?`custom:${_e}`:be,onChange:Q=>{const je=Array.isArray(Q)?Q[0]:Q;if(typeof je=="string")if(je.startsWith("custom:")){const Ne=je.slice(7);te(Ne),Oe("custom")}else te(null),Oe(je)},options:[...ni.map(Q=>({value:Q,label:ei[Q]})),...Me.map(Q=>({value:`custom:${Q.id}`,label:Q.name}))],renderOption:(Q,je)=>{const Ne=String(Q.value),Re=Ne.startsWith("custom:"),Xe=Re?Me.find(it=>it.id===Ne.slice(7)):null,ht=Xe?Xe.angles:void 0,nt=Re?"custom":Ne;return e.jsxs("span",{style:{display:"inline-flex",gap:8,alignItems:"center"},children:[e.jsx("span",{style:{width:16,height:16,display:"inline-flex",color:"currentColor"},children:Yt(nt,{angles:ht,size:16,count:f})}),e.jsx("span",{style:{fontWeight:je?600:400},children:Q.label})]})}}),be==="shade-chain"&&e.jsx(Fe.NiceNumberInput,{label:m("colorPalette.step","Step"),labelPlacement:"left",size:"sm",min:.02,max:.5,step:.02,precision:2,value:Te,onChange:Q=>{const je=typeof Q=="number"?Q:Number(Q);Number.isNaN(je)||(he(je),K?.(je),Le($e.h,be,xe,Se))},showStepper:!0,disabled:A}),e.jsx(Fe.NiceNumberInput,{label:m("colorPalette.colors","Colors"),labelPlacement:"left",size:"sm",min:Math.max(2,x),max:Math.min(12,$),step:1,precision:0,value:f??de??Ee.length,onChange:Q=>{const je=typeof Q=="number"?Q:Number(Q);if(!Number.isFinite(je))return;const Ne=Math.max(Math.max(2,x),Math.min(Math.min(12,$),Math.round(je)));ge(Ne),be==="shade-chain"?g?.(qt({h:$e.h,s:$e.s||.7,v:$e.v||.6},Ne,Te)):setTimeout(()=>Le($e.h,be,xe,Se),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:[Ee.map((Q,je)=>e.jsxs("div",{role:"presentation",className:`nice-palette__swatch-wrapper ${pe===je?"nice-palette__swatch-wrapper--selected":""}`,onClick:()=>ye(je),onFocus:()=>ye(je),children:[e.jsx("span",{className:"nice-palette__swatch",style:{background:Q}}),e.jsx("input",{type:"text",className:"nice-palette__hex-input",value:Q.toUpperCase(),maxLength:7,disabled:A,onClick:Ne=>Ne.stopPropagation(),onChange:Ne=>V(je,Ne.target.value),"aria-label":m("colorPalette.colorN","Color {n}").replace("{n}",String(je+1))}),Ee.length>x&&e.jsx("button",{type:"button",className:"nice-palette__swatch-remove",onClick:Ne=>{Ne.stopPropagation(),ke(je)},disabled:A,"aria-label":m("colorPalette.removeColor","Remove color"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},je)),Ee.length<$&&e.jsxs("button",{type:"button",className:"nice-palette__add-btn",onClick:L,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:wt},title:wt.toUpperCase()}),e.jsx("span",{className:"nice-palette__hex-label",children:wt.toUpperCase()})]}),k&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-palette__random-btn",onClick:Ce,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")]})]})})]}),In=e.jsx("div",{className:"nice-palette__tab",children:Pe.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:Dt,className:"nice-palette__variation-strip",role:"group","aria-label":m("colorPalette.tintsShades","Tints & Shades"),children:Pe.map((Q,je)=>e.jsx("div",{className:"nice-palette__variation-chip",style:{background:Q},title:Q.toUpperCase(),onClick:()=>{A||V(pe,Q)},onKeyDown:Ne=>{!A&&(Ne.key==="Enter"||Ne.key===" ")&&(Ne.preventDefault(),V(pe,Q))},role:"button","aria-label":Q.toUpperCase()},je))})]}):e.jsx("div",{className:"nice-palette__empty",children:m("colorPalette.noVariationsAvailable","No variations available.")})}),Mn=e.jsx("div",{className:"nice-palette__tab",children:e.jsx("div",{className:"nice-palette__preset-grid",children:zt.map(Q=>{const je=jt(Ze,Q);return e.jsxs("button",{type:"button",className:`nice-palette__preset-card ${Se===Q?"nice-palette__preset-card--active":""}`,onClick:()=>u(Q),disabled:A,children:[e.jsx("div",{className:"nice-palette__preset-strip",children:je.map((Ne,Re)=>e.jsx("span",{className:"nice-palette__preset-dot",style:{background:Ne}},Re))}),e.jsx("span",{className:"nice-palette__preset-label",children:ti[Q]})]},Q)})})}),Tn=e.jsxs("div",{className:"nice-palette__tab",children:[oe&&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(Qn,{hex:He})]}),se&&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(Zn,{colors:Ee})]})]}),Rn=e.jsx("div",{className:"nice-palette__tab nice-palette__custom-schemes",children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[Me.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.")}),Me.map(Q=>e.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center",fontSize:12},children:[e.jsx("span",{style:{width:16,height:16,display:"inline-flex"},children:Yt("custom",{angles:Q.angles,size:16})}),e.jsx("span",{style:{flex:1},children:Q.name}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>{te(Q.id),Oe("custom")},disabled:A,children:m("colorPalette.use","Use")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--xs",onClick:()=>ze(Me.filter(je=>je.id!==Q.id)),disabled:A,"aria-label":m("colorPalette.delete","Delete {name}").replace("{name}",String(Q.name)),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},Q.id)),e.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A,onClick:()=>{const Q=Ye(Ee[0]).h,je=Ee.map(Ne=>(Ye(Ne).h-Q+540)%360-180);R.prompt({title:m("colorPalette.schemeNamePrompt","Scheme name"),defaultValue:`Scheme ${Me.length+1}`}).then(Ne=>{if(!Ne)return;const Re={id:`cs-${Date.now()}`,name:Ne,angles:je};ze([...Me,Re])})},children:m("colorPalette.saveCurrentAsScheme","+ Save current as scheme")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",disabled:A||Me.length===0,onClick:()=>{typeof navigator>"u"||navigator.clipboard?.writeText(JSON.stringify(Me,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:()=>{R.prompt({title:m("colorPalette.pasteSchemesPrompt","Paste the schemes JSON")}).then(Q=>{if(Q)try{const je=JSON.parse(Q);Array.isArray(je)&&ze(je)}catch{}})},children:m("colorPalette.importJson","Import JSON")})]})]})}),st=[{id:"colors",label:m("colorPalette.colors","Colors"),content:$n}];ce&&zt.length>0&&st.push({id:"presets",label:m("colorPalette.presets","Presets"),content:Mn}),F&&st.push({id:"variations",label:m("colorPalette.variations","Variations"),content:In}),(oe||se)&&st.push({id:"info",label:m("colorPalette.info","Info"),content:Tn}),st.push({id:"schemes",label:m("colorPalette.schemes","Schemes"),content:Rn});const An=e.jsxs("div",{className:"nice-palette__popup-header",children:[q&&e.jsxs("div",{className:"nice-palette__wheel-container",children:[e.jsx(Jn,{hues:Ze,colors:Ee,baseHue:$e.h,onBaseHueChange:Ae,mode:be,distance:xe,disabled:A}),(be==="analogous"||be==="split-complementary"||be==="analogous-complementary")&&e.jsxs("div",{className:"nice-palette__distance",children:[e.jsx("label",{children:m("colorPalette.distance","Distance: {dist}°").replace("{dist}",String(xe))}),e.jsx("input",{type:"range",min:10,max:90,value:xe,onChange:Q=>at(Number(Q.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:()=>re(!1),"aria-label":m("controls.confirm","Confirm"),title:m("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),Dn=e.jsxs("div",{className:"nice-palette nice-palette--studio",children:[An,e.jsx(pt.NiceTabs,{tabs:st,variant:"enclosed",size:"sm"})]});return e.jsxs("div",{ref:h,id:N,className:`nice-field nice-palette-field ${A?"nice-palette--disabled":""} ${Y==="left"?"nice-field--label-left":""} ${b?"nice-field--loading":""} ${C?"nice-field--error":""} ${i||""}`,style:o,"data-testid":j,children:[R.element,T&&e.jsx("label",{htmlFor:N,className:"nice-field__label",children:T}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("div",{ref:ne,className:"nice-palette__field-swatches",role:"button",tabIndex:A||E?-1:0,"aria-haspopup":"dialog","aria-expanded":we,"aria-readonly":E||void 0,"aria-label":m("colorPalette.openStudio","Open palette studio"),onClick:()=>{!A&&!E&&re(Q=>!Q)},onKeyDown:Q=>{!A&&!E&&(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),re(je=>!je))},children:Ee.map((Q,je)=>e.jsx("span",{role:"presentation",className:"nice-palette__field-swatch",style:{background:Q},title:Q.toUpperCase(),onClick:Ne=>{Ne.stopPropagation(),!A&&!E&&(ye(je),re(!0))}},je))}),b&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),we&&fe&&G&&ot.createPortal(e.jsx("div",{ref:le,className:`nice-palette__popup${X?` ${X}`:""}`,"data-theme":X==="nice-dark"?"dark":X==="nice-light"?"light":void 0,role:"dialog","aria-label":m("colorPalette.studio","Palette studio"),style:{position:"fixed",left:fe.left,top:fe.top,zIndex:1e3},children:Dn}),G)]}),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((a,s)=>a.position-s.position).map(a=>`${a.color} ${a.position}%`).join(", "),o=t.repeating?"repeating-":"";switch(t.type){case"linear":return`${o}linear-gradient(${t.angle}deg, ${i})`;case"radial":{const a=t.shape||"ellipse",s=t.size||"farthest-corner",g=t.positionX??50,x=t.positionY??50;return`${o}radial-gradient(${a} ${s} at ${g}% ${x}%, ${i})`}case"conic":{const a=t.angle??0,s=t.positionX??50,g=t.positionY??50;return`${o}conic-gradient(from ${a}deg at ${s}% ${g}%, ${i})`}}}function xn(t){const i=t.trim(),o=i.startsWith("repeating-");if(i.includes("linear-gradient")){const a=i.match(/linear-gradient\((.+)\)/)?.[1];if(!a)return null;const s=a.split(",").map(M=>M.trim());let g=90,x=0;const $=s[0].match(/^(\d+)deg$/);$&&(g=parseInt($[1]),x=1);const P=Ct(s.slice(x));return{type:"linear",angle:g,repeating:o,stops:P}}if(i.includes("radial-gradient")){const a=i.match(/radial-gradient\((.+)\)/)?.[1];if(!a)return null;const s=a.split(",").map(x=>x.trim()),g=Ct(s.filter(x=>x.includes("#")||x.includes("rgb")));return{type:"radial",angle:0,repeating:o,stops:g.length>=2?g:It().stops}}if(i.includes("conic-gradient")){const a=i.match(/conic-gradient\((.+)\)/)?.[1];if(!a)return null;const s=a.split(",").map(x=>x.trim()),g=Ct(s.filter(x=>x.includes("#")||x.includes("rgb")));return{type:"conic",angle:0,repeating:o,stops:g.length>=2?g:It().stops}}return null}function Ct(t){return t.map((i,o,a)=>{const s=i.match(/^(#[0-9a-fA-F]{3,8}|rgba?\([^)]+\))\s*(\d+%?)?$/);if(s){const g=s[2]?parseFloat(s[2]):o/Math.max(1,a.length-1)*100;return{color:s[1],position:g}}return{color:i,position:o/Math.max(1,a.length-1)*100}})}function si(){return"#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0")}function ri(t=2){const i=["linear","radial","conic"],o=i[Math.floor(Math.random()*i.length)],a=[];for(let s=0;s<t;s++)a.push({color:si(),position:Math.round(s/(t-1)*100)});return{type:o,angle:Math.floor(Math.random()*360),stops:a,shape:o==="radial"?Math.random()>.5?"circle":"ellipse":void 0,positionX:o!=="linear"?Math.round(Math.random()*100):void 0,positionY:o!=="linear"?Math.round(Math.random()*100):void 0}}const bn=[{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}}],ci=Object.assign(n.forwardRef(({id:t,className:i,style:o,accessMode:a,value:s,onChange:g,showCssOutput:x=!0,showPresets:$=!0,showEditor:P=!0,showRandom:M=!0,maxStops:W=10,label:J,labelPlacement:B="top",disabled:I,readOnly:q,loading:se,error:oe,errorPlacement:ce="bottom",width:Z,"data-testid":F},k)=>{const l=r.useNiceAccessMode(a,t),T=l==="hidden";l==="disabled"&&(I=!0);const Y=q||l==="readOnly",A=r.useControlId(t),{t:_}=r.useNiceTranslation(),b=s??It(),C=n.useMemo(()=>Mt(b),[b]),[f,S]=n.useState(0),[K,w]=n.useState(""),d=n.useRef(null),[D,j]=n.useState(!1),[h,c]=n.useState(null),[p,E]=n.useState(""),m=n.useContext(r.NiceThemeContext)?.portalTarget??(typeof document<"u"?document.body:null),R=n.useRef(null),z=n.useRef(null),ie=typeof Z=="number"?Z:340;n.useLayoutEffect(()=>{if(!D||!R.current)return;E(tt.scopeThemeClass(R.current));const y=()=>{const G=R.current?.getBoundingClientRect();if(!G)return;let ne=G.left;ne+ie>window.innerWidth-8&&(ne=Math.max(8,window.innerWidth-ie-8));let le=G.bottom+6;le>window.innerHeight*.5&&(le=Math.max(8,window.innerHeight-Math.min(window.innerHeight-16,520)-8)),c({left:ne,top:le})};return y(),window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[D,ie]),n.useEffect(()=>{if(!D)return;const y=G=>{const ne=G.target;R.current?.contains(ne)||z.current?.contains(ne)||(ne instanceof Element?ne:ne?.parentElement??null)?.closest('.nice-select__dropdown, [role="listbox"], [role="option"]')||j(!1)};return document.addEventListener("mousedown",y),()=>{document.removeEventListener("mousedown",y)}},[D]),r.useOverlayFocus(z,{open:D,modal:!1,onClose:()=>j(!1)});const v=n.useCallback(y=>{g?.(y)},[g]),ee=n.useCallback(y=>{I||v({...b,type:y})},[I,b,v]),U=n.useCallback(y=>{I||v({...b,angle:y})},[I,b,v]),me=n.useCallback(y=>{I||v({...b,repeating:y})},[I,b,v]),pe=n.useCallback(y=>{I||v({...b,shape:y})},[I,b,v]),ye=n.useCallback((y,G)=>{if(I)return;const ne=b.stops.map((le,be)=>be===y?{...le,...G}:le);v({...b,stops:ne})},[I,b,v]),ue=n.useRef(!1),he=n.useCallback((y,G)=>{if(I||!d.current)return;y.stopPropagation(),y.preventDefault(),S(G),ue.current=!1;const ne=be=>{if(!d.current)return;ue.current=!0;const xe=d.current.getBoundingClientRect(),Se=Math.round(Math.max(0,Math.min(100,(be.clientX-xe.left)/xe.width*100)));ye(G,{position:Se})},le=()=>{document.removeEventListener("pointermove",ne),document.removeEventListener("pointerup",le),document.removeEventListener("pointercancel",le)};document.addEventListener("pointermove",ne),document.addEventListener("pointerup",le),document.addEventListener("pointercancel",le)},[I,ye]),de=n.useCallback(()=>{if(I||b.stops.length>=W)return;const y=b.stops.slice().sort((xe,Se)=>xe.position-Se.position);let G=0,ne=y[0];for(let xe=0;xe<y.length-1;xe++){const Se=y[xe+1].position-y[xe].position;Se>G&&(G=Se,ne=y[xe])}const le=Math.round(ne.position+G/2),be="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0");v({...b,stops:[...b.stops,{color:be,position:le}]})},[I,b,W,v]),ge=n.useCallback(y=>{if(I||b.stops.length<=2)return;const G=b.stops.filter((ne,le)=>le!==y);v({...b,stops:G}),f>=G.length&&S(G.length-1)},[I,b,f,v]),ae=(y,G)=>{const ne=b.stops[G];if(I||!ne)return;const le=y.shiftKey?10:1,be=y.key==="ArrowLeft"||y.key==="ArrowDown"?ne.position-le:y.key==="ArrowRight"||y.key==="ArrowUp"?ne.position+le:y.key==="PageDown"?ne.position-10:y.key==="PageUp"?ne.position+10:y.key==="Home"?0:y.key==="End"?100:null;be!==null?(y.preventDefault(),ye(G,{position:Math.max(0,Math.min(100,be))})):(y.key==="Delete"||y.key==="Backspace")&&b.stops.length>2&&(y.preventDefault(),ge(G))},ve=n.useCallback(()=>{if(I)return;const y=2+Math.floor(Math.random()*3);v(ri(y))},[I,v]),_e=n.useCallback(()=>{if(I||!K.trim())return;const y=xn(K);y&&v(y)},[I,K,v]),te=n.useCallback(y=>{if(I||!d.current||b.stops.length>=W)return;const G=y.target;if(ue.current||G.closest(".nice-gradient__stop-marker")){ue.current=!1;return}const ne=d.current.getBoundingClientRect(),le=Math.round((y.clientX-ne.left)/ne.width*100),be="#"+Math.floor(Math.random()*16777215).toString(16).padStart(6,"0"),xe=[...b.stops,{color:be,position:le}];v({...b,stops:xe}),S(xe.length-1)},[I,b,W,v]),we=n.useMemo(()=>b.stops.slice().sort((y,G)=>y.position-G.position),[b.stops]),re=n.useMemo(()=>`linear-gradient(90deg, ${we.map(y=>`${y.color} ${y.position}%`).join(", ")})`,[we]);if(T)return null;const fe=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(y=>e.jsx("button",{type:"button",className:`nice-gradient__type-btn ${b.type===y?"nice-gradient__type-btn--active":""}`,onClick:()=>ee(y),disabled:I,"aria-pressed":b.type===y,children:y.charAt(0).toUpperCase()+y.slice(1)},y)),e.jsxs("label",{className:"nice-gradient__repeat-label",children:[e.jsx("input",{type:"checkbox",checked:b.repeating??!1,onChange:y=>me(y.target.checked),disabled:I}),_("controls.repeating","Repeating")]})]}),e.jsxs("div",{className:"nice-gradient__controls",children:[b.type==="linear"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.angle","Angle: {angle}°").replace("{angle}",String(b.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:b.angle,onChange:y=>U(Number(y.target.value)),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.angle","Angle")}),e.jsx("div",{className:"nice-gradient__angle-presets",children:[0,45,90,135,180,225,270,315].map(y=>e.jsx("button",{type:"button",className:`nice-gradient__angle-btn ${b.angle===y?"nice-gradient__angle-btn--active":""}`,onClick:()=>U(y),disabled:I,title:`${y}°`,"aria-label":`${y}°`,"aria-pressed":b.angle===y,children:e.jsx("span",{style:{transform:`rotate(${y}deg)`,display:"inline-flex"},children:e.jsx(r.NiceIcon,{name:"arrow-right",size:14})})},y))})]}),b.type==="radial"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.shape","Shape:")}),e.jsx("div",{className:"nice-gradient__shape-btns",children:["circle","ellipse"].map(y=>e.jsx("button",{type:"button",className:`nice-gradient__shape-btn ${(b.shape||"ellipse")===y?"nice-gradient__shape-btn--active":""}`,onClick:()=>pe(y),disabled:I,"aria-pressed":(b.shape||"ellipse")===y,children:y},y))})]}),(b.type==="radial"||b.type==="conic")&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.center","Center: {positionX}%, {positionY}%").replace("{positionX}",String(b.positionX??50)).replace("{positionY}",String(b.positionY??50))}),e.jsxs("div",{className:"nice-gradient__center-inputs",children:[e.jsx("input",{type:"range",min:0,max:100,value:b.positionX??50,onChange:y=>v({...b,positionX:Number(y.target.value)}),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.centerX","Horizontal center")}),e.jsx("input",{type:"range",min:0,max:100,value:b.positionY??50,onChange:y=>v({...b,positionY:Number(y.target.value)}),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.centerY","Vertical center")})]})]}),b.type==="conic"&&e.jsxs("div",{className:"nice-gradient__control-group",children:[e.jsx("label",{children:_("controls.startAngle","Start angle: {angle}°").replace("{angle}",String(b.angle))}),e.jsx("input",{type:"range",min:0,max:360,value:b.angle,onChange:y=>U(Number(y.target.value)),disabled:I,className:"nice-gradient__slider","aria-label":_("gradient.startAngle","Start angle")})]})]}),e.jsxs("div",{className:"nice-gradient__bar-container",children:[e.jsx("div",{role:"presentation",ref:d,className:"nice-gradient__bar",style:{background:re},onClick:te,children:b.stops.map((y,G)=>e.jsx("div",{className:`nice-gradient__stop-marker ${f===G?"nice-gradient__stop-marker--active":""}`,style:{left:`${y.position}%`},onPointerDown:ne=>he(ne,G),onClick:ne=>{ne.stopPropagation(),S(G),ue.current=!1},onFocus:()=>S(G),onKeyDown:ne=>ae(ne,G),role:"slider",tabIndex:I?-1:0,"aria-label":_("gradient.stop","Stop {n}").replace("{n}",String(G+1)),"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":y.position,"aria-valuetext":`${y.color} ${y.position}%`,title:`${y.color} @ ${y.position}%`,children:e.jsx("div",{className:"nice-gradient__stop-dot",style:{background:y.color}})},G))}),e.jsx("button",{type:"button",className:"nice-gradient__add-stop",onClick:de,disabled:I||b.stops.length>=W,title:_("controls.addStop","Add stop"),"aria-label":_("controls.addStop","Add stop"),children:e.jsx(r.NiceIcon,{name:"plus",size:14})})]}),e.jsx("div",{className:"nice-gradient__stop-editor",children:e.jsx("div",{className:"nice-gradient__stop-list",children:we.map((y,G)=>{const ne=b.stops.indexOf(y);return e.jsxs("div",{role:"presentation",className:`nice-gradient__stop-row ${f===ne?"nice-gradient__stop-row--active":""}`,onClick:()=>S(ne),onFocus:()=>S(ne),children:[e.jsx("input",{type:"color",value:y.color,onChange:le=>ye(ne,{color:le.target.value}),disabled:I,className:"nice-gradient__stop-color","aria-label":_("gradient.stopColor","Stop color")}),e.jsx("input",{type:"text",value:y.color.toUpperCase(),maxLength:7,onChange:le=>ye(ne,{color:le.target.value}),disabled:I,className:"nice-gradient__stop-hex","aria-label":_("gradient.stopHex","Stop color (hex)")}),e.jsx("input",{type:"number",min:0,max:100,value:y.position,onChange:le=>ye(ne,{position:Number(le.target.value)}),disabled:I,className:"nice-gradient__stop-pos","aria-label":_("gradient.stopPosition","Stop position")}),e.jsx("span",{className:"nice-gradient__stop-pct",children:"%"}),b.stops.length>2&&e.jsx("button",{type:"button",className:"nice-gradient__stop-del",onClick:()=>ge(ne),disabled:I,"aria-label":_("controls.removeStop","Remove stop"),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]},ne)})})})]}),M&&e.jsxs("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm nice-gradient__random-btn",onClick:ve,disabled:I,title:_("controls.randomGradient","Random gradient"),"aria-label":_("controls.randomGradient","Random gradient"),children:[e.jsx(r.NiceIcon,{name:"shuffle",size:14})," ",_("controls.randomGradient2","Random Gradient")]})]}),H=e.jsx("div",{className:"nice-gradient__tab",children:e.jsx("div",{className:"nice-gradient__preset-grid",children:bn.map((y,G)=>e.jsxs("button",{type:"button",className:"nice-gradient__preset-card",onClick:()=>{I||v(y.value)},disabled:I,title:y.name,children:[e.jsx("div",{className:"nice-gradient__preset-preview",style:{background:Mt(y.value)}}),e.jsx("span",{className:"nice-gradient__preset-name",children:y.name})]},G))})}),X=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:_("controls.copyCss","Copy CSS"),"aria-label":_("controls.copyCss","Copy CSS"),children:e.jsx(r.NiceIcon,{name:"clipboard",size:16})})]}),e.jsxs("div",{className:"nice-gradient__css-import",children:[e.jsx("input",{type:"text",className:"nice-gradient__css-input",placeholder:_("controls.pasteCssGradientToImport","Paste CSS gradient to import..."),value:K,onChange:y=>w(y.target.value),disabled:I,"aria-label":_("gradient.importCss","CSS gradient to import")}),e.jsx("button",{type:"button",className:"nice-btn nice-btn--outline nice-btn--sm",onClick:_e,disabled:I,children:_("controls.import","Import")})]})]}),O=[{id:"editor",label:_("controls.editor","Editor"),content:fe}];return $&&O.push({id:"presets",label:_("controls.presets","Presets"),content:H}),x&&O.push({id:"css",label:"CSS",content:X}),e.jsxs("div",{ref:k,id:A,className:`nice-field nice-gradient-field ${I?"nice-gradient--disabled":""} ${B==="left"?"nice-field--label-left":""} ${se?"nice-field--loading":""} ${oe?"nice-field--error":""} ${ce==="right"?"nice-field--error-right":""} ${i||""}`,style:o,"data-testid":F,children:[J&&e.jsx("label",{htmlFor:A,className:"nice-field__label",children:J}),e.jsxs("div",{className:"nice-field__control",children:[e.jsx("button",{ref:R,type:"button",className:"nice-gradient__swatch",style:{background:C},"aria-haspopup":"dialog","aria-expanded":D,"aria-readonly":Y||void 0,"aria-label":_("controls.openGradientEditor","Open gradient editor"),disabled:I,onClick:()=>{!I&&!Y&&j(y=>!y)}}),se&&e.jsx("span",{className:"nice-field__spinner",children:e.jsx("span",{className:"nice-spinner nice-spinner--sm"})}),ce==="right"&&typeof oe=="string"&&oe&&e.jsx("div",{className:"nice-field__error",role:"alert",children:oe}),D&&h&&m&&ot.createPortal(e.jsx("div",{ref:z,className:`nice-gradient__popup${p?` ${p}`:""}`,"data-theme":p==="nice-dark"?"dark":p==="nice-light"?"light":void 0,role:"dialog","aria-label":_("controls.gradientEditor","Gradient editor"),style:{position:"fixed",left:h.left,top:h.top,width:Z!=null?typeof Z=="number"?`${Z}px`:Z: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:()=>j(!1),"aria-label":_("controls.confirm","Confirm"),title:_("controls.confirm","Confirm"),children:e.jsx(r.NiceIcon,{name:"check",size:18})})]}),e.jsx(pt.NiceTabs,{tabs:O,variant:"enclosed",size:"sm"})]})}),m)]}),ce!=="right"&&typeof oe=="string"&&oe&&e.jsx("div",{className:"nice-field__error",role:"alert",children:oe})]})}),{displayName:"NiceGradientPicker"}),li=[{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"}],di=[{style:"professional",label:"Professional"},{style:"casual",label:"Casual"},{style:"formal",label:"Formal"},{style:"concise",label:"Concise"}],mi=n.forwardRef(function(i,o){const{enableAI:a=!0,aiModel:s,enableImprove:g=!0,enableTranslate:x=!0,enableGenerate:$=!0,toolbar:P,languages:M=li,textStyles:W=di,onImprove:J,onTranslate:B,onGenerate:I,showAIToolbar:q=!0,value:se,onChange:oe,...ce}=i,Z=n.useRef(null),[F,k]=n.useState(!1),[l,T]=n.useState(!1),[Y,A]=n.useState(!1),[_,b]=n.useState(""),[C,f]=n.useState(""),[S,K]=n.useState("professional"),[w,d]=n.useState(""),[D,j]=n.useState(M[0]?.code||"en"),[h,c]=n.useState(""),[p,E]=n.useState(""),{t:N}=an.useNiceTranslation(),m=r.useNiceAI(),{improveText:R,translate:z,generateHtml:ie,isLoading:v}=r.useTextImprovement(),ee=a&&m.isConfigured,U=n.useCallback(()=>{const ae=window.getSelection();return ae&&ae.toString().trim()?ae.toString():""},[]),me=n.useCallback(ae=>{const ve=window.getSelection();if(ve&&ve.rangeCount>0){const _e=ve.getRangeAt(0);_e.deleteContents();const te=document.createElement("div");te.innerHTML=ae;const we=document.createDocumentFragment();for(;te.firstChild;)we.appendChild(te.firstChild);if(_e.insertNode(we),Z.current){const re=Z.current.innerHTML;oe?.(re)}}},[oe]),pe=n.useCallback(async(ae="professional")=>{if(!ee||!g)return"";const ve=U();if(!ve)return"";b(ve),K(ae),k(!0),f("");try{const _e=await R(ve,ae);return f(_e),J?.(ve,_e,ae),_e}catch{return f(N("htmlEditorAI.improveFailed","Failed to improve text")),""}},[ee,g,U,R,J,N]),ye=n.useCallback(async ae=>{if(!ee||!x)return"";const ve=U();if(!ve)return"";b(ve),j(ae),T(!0),d("");try{const _e=M.find(we=>we.code===ae)?.label||ae,te=await z(ve,_e);return d(te),B?.(ve,te,ae),te}catch{return d(N("htmlEditorAI.translateFailed","Failed to translate text")),""}},[ee,x,U,z,M,B,N]),ue=n.useCallback(async ae=>{if(!ee||!$||!ae.trim())return"";c(ae),E("");try{const ve=await ie(ae);return E(ve),I?.(ae,ve),ve}catch{return E(N("htmlEditorAI.generateFailed","Failed to generate HTML")),""}},[ee,$,ie,I,N]),he=n.useCallback(()=>{C&&me(C),k(!1),f("")},[C,me]),de=n.useCallback(()=>{w&&me(w),T(!1),d("")},[w,me]),ge=n.useCallback(()=>{if(p&&Z.current){document.execCommand("insertHTML",!1,p);const ae=Z.current.innerHTML;oe?.(ae)}A(!1),E(""),c("")},[p,oe]);return n.useImperativeHandle(o,()=>({getEditor:()=>Z.current,focus:()=>Z.current?.focus(),getValue:()=>Z.current?.innerHTML||"",setValue:ae=>{Z.current&&(Z.current.innerHTML=ae,oe?.(ae))},getSelection:U,insertHtml:ae=>{document.execCommand("insertHTML",!1,ae),Z.current&&oe?.(Z.current.innerHTML)},improveSelection:pe,translateSelection:ye,generateHtml:ue})),n.useCallback(ae=>{Z.current=ae},[]),e.jsxs("div",{className:"nice-html-editor-ai","data-testid":i["data-testid"],children:[q&&ee&&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:N("htmlEditorAI.ai","AI")}),v&&e.jsx("span",{className:"nice-html-editor-ai__loading",children:N("htmlEditorAI.processing","Processing...")})]}),e.jsxs("div",{className:"nice-html-editor-ai__toolbar-right",children:[g&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>pe(),disabled:v,title:N("htmlEditorAI.improveText","Improve selected text"),children:[e.jsx(r.NiceIcon,{name:"star",size:14})," ",N("htmlEditorAI.improve","Improve")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu",children:W.map(({style:ae,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>pe(ae),children:ve},ae))})]}),x&&e.jsxs("div",{className:"nice-html-editor-ai__dropdown",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",disabled:v,title:N("htmlEditorAI.translateText","Translate selected text"),children:[e.jsx(r.NiceIcon,{name:"globe",size:14})," ",N("htmlEditorAI.translate","Translate")]}),e.jsx("div",{className:"nice-html-editor-ai__dropdown-menu nice-html-editor-ai__dropdown-menu--languages",children:M.map(({code:ae,label:ve})=>e.jsx("button",{type:"button",className:"nice-html-editor-ai__dropdown-item",onClick:()=>ye(ae),children:ve},ae))})]}),$&&e.jsxs("button",{type:"button",className:"nice-html-editor-ai__btn",onClick:()=>A(!0),disabled:v,title:N("htmlEditorAI.generateHtml","Generate HTML from description"),children:[e.jsx(r.NiceIcon,{name:"zap",size:14})," ",N("htmlEditorAI.generate","Generate")]})]})]}),e.jsx("div",{className:"nice-html-editor-ai__editor-wrapper",children:e.jsx(sn.NiceHtmlEditor,{value:se,onChange:oe,toolbar:P,...ce})}),F&&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})," ",N("htmlEditorAI.improveText","Improve Text")]}),e.jsx("div",{className:"nice-html-editor-ai__style-selector",children:W.map(({style:ae,label:ve})=>e.jsx("button",{type:"button",className:`nice-html-editor-ai__style-btn ${S===ae?"nice-html-editor-ai__style-btn--active":""}`,onClick:()=>{K(ae),pe(ae)},children:ve},ae))}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":N("htmlEditorAI.close","Close"),onClick:()=>k(!1),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:v?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:N("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:N("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:_})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--improved",children:[e.jsx("h5",{children:N("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:he,disabled:!C||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",N("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{k(!1),f("")},children:N("htmlEditorAI.cancel","Cancel")})]})]}),l&&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})," ",N("htmlEditorAI.translateText","Translate Text")]}),e.jsx("div",{className:"nice-html-editor-ai__language-selector",children:e.jsx("select",{value:D,onChange:ae=>{j(ae.target.value),ye(ae.target.value)},className:"nice-html-editor-ai__language-select",children:M.map(({code:ae,label:ve})=>e.jsx("option",{value:ae,children:ve},ae))})}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":N("htmlEditorAI.close","Close"),onClick:()=>T(!1),children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsx("div",{className:"nice-html-editor-ai__panel-body",children:v?e.jsx("div",{className:"nice-html-editor-ai__loading-panel",children:N("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:N("htmlEditorAI.original","Original")}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:_})]}),e.jsxs("div",{className:"nice-html-editor-ai__text-block nice-html-editor-ai__text-block--translated",children:[e.jsx("h5",{children:M.find(ae=>ae.code===D)?.label||D}),e.jsx("div",{className:"nice-html-editor-ai__text-content",children:w})]})]})}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:de,disabled:!w||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",N("htmlEditorAI.apply","Apply")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{T(!1),d("")},children:N("htmlEditorAI.cancel","Cancel")})]})]}),Y&&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})," ",N("htmlEditorAI.generateHtml","Generate HTML")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__close","aria-label":N("htmlEditorAI.close","Close"),onClick:()=>{A(!1),E(""),c("")},children:e.jsx(r.NiceIcon,{name:"close",size:14})})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-body",children:[e.jsxs("div",{className:"nice-html-editor-ai__generate-input",children:[e.jsx("textarea",{placeholder:N("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:ae=>c(ae.target.value),className:"nice-html-editor-ai__generate-textarea",rows:3}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__generate-btn",onClick:()=>ue(h),disabled:v||!h.trim(),children:v?N("htmlEditorAI.generating","Generating..."):N("htmlEditorAI.generate","Generate")})]}),p&&e.jsxs("div",{className:"nice-html-editor-ai__generate-result",children:[e.jsx("h5",{children:N("htmlEditorAI.preview","Preview")}),e.jsx("div",{className:"nice-html-editor-ai__preview",dangerouslySetInnerHTML:{__html:p}}),e.jsx("h5",{children:N("htmlEditorAI.htmlCode","HTML Code")}),e.jsx("pre",{className:"nice-html-editor-ai__code",children:p})]})]}),e.jsxs("div",{className:"nice-html-editor-ai__panel-footer",children:[e.jsxs("button",{type:"button",className:"nice-html-editor-ai__apply",onClick:ge,disabled:!p||v,children:[e.jsx(r.NiceIcon,{name:"check",size:14})," ",N("htmlEditorAI.insert","Insert")]}),e.jsx("button",{type:"button",className:"nice-html-editor-ai__cancel",onClick:()=>{A(!1),E(""),c("")},children:N("htmlEditorAI.cancel","Cancel")})]})]})]})}),ui=[{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 jn(t){let i=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");return i=i.replace(/```(\w*)\n([\s\S]*?)```/g,(o,a,s)=>`<pre><code class="language-${a}">${s.trim()}</code></pre>`),i=i.replace(/^(\|.+\|)\n(\|[-| :]+\|)\n((?:\|.+\|\n?)+)/gm,(o,a,s,g)=>{const x=a.split("|").filter(P=>P.trim()).map(P=>`<th>${P.trim()}</th>`).join(""),$=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>${x}</tr></thead><tbody>${$}</tbody></table>`}),i=i.replace(/^#### (.+)$/gm,"<h4>$1</h4>"),i=i.replace(/^### (.+)$/gm,"<h3>$1</h3>"),i=i.replace(/^## (.+)$/gm,"<h2>$1</h2>"),i=i.replace(/^# (.+)$/gm,"<h1>$1</h1>"),i=i.replace(/^&gt; (.+)$/gm,"<blockquote>$1</blockquote>"),i=i.replace(/^---$/gm,"<hr/>"),i=i.replace(/^- \[x\] (.+)$/gm,'<li class="task done"><input type="checkbox" checked disabled> $1</li>'),i=i.replace(/^- \[ \] (.+)$/gm,'<li class="task"><input type="checkbox" disabled> $1</li>'),i=i.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),i=i.replace(/\*(.+?)\*/g,"<em>$1</em>"),i=i.replace(/~~(.+?)~~/g,"<del>$1</del>"),i=i.replace(/`(.+?)`/g,"<code>$1</code>"),i=i.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,'<img src="$2" alt="$1" style="max-width:100%"/>'),i=i.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2">$1</a>'),i=i.replace(/^- (.+)$/gm,"<li>$1</li>"),i=i.replace(/^\d+\. (.+)$/gm,"<li>$1</li>"),i=i.replace(/\n/g,"<br/>"),i}const pi=[{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:"![](url)",tip:"Image",group:"insert"},{key:"table",icon:"table",md:`| H1 | H2 | H3 |
4
4
  | --- | --- | --- |