import{d as e,f as t,l as n,s as r,t as i}from"./hooks.module-BrXTvcfS.js";import{H as a,L as o,R as s}from"./content_renderer-DOj8g78V.js";import{a as c,k as l}from"./i18n-BaLR3UdQ.js";import{t as u}from"./jsxRuntime.module-Cao1NCKs.js";import{it as d}from"./hooks-ClTXKdUl.js";e();var f=class{debounceInterval;callback;lastValue;timeoutId=null;constructor(e,t){this.debounceInterval=e,this.callback=t}updateValue(e){this.lastValue=e,this.timeoutId!==null&&clearTimeout(this.timeoutId),this.timeoutId=setTimeout(this.reportUpdate.bind(this),this.debounceInterval)}destroy(){this.timeoutId!==null&&(this.reportUpdate(),clearTimeout(this.timeoutId))}reportUpdate(){this.lastValue!==void 0&&this.callback(this.lastValue)}},p=[`#e64d4d`,`#e6994d`,`#e5e64d`,`#99e64d`,`#4de64d`,`#4de699`,`#4de5e6`,`#4d99e6`,`#4d4de6`,`#994de6`,`#e64db3`];function m(e){if(!e.note)return null;let[i,o]=r(null),[s,l]=r(null),[f,m]=r(!1);n(()=>{typeof e.note==`string`?(async e=>{let t=await a.getNote(e,!0);t&&o(t)})(e.note):o(e.note)},[]),n(()=>{let e=i?.getLabel(`color`)?.value??null;if(e){let t=v(e);t&&l(t.hex().toLowerCase())}},[i]),n(()=>{m(s!==null&&p.indexOf(s)===-1)},[s]);let _=t(e=>{i&&(e===null?d.removeOwnedLabelByName(i,`color`):d.setLabel(i.noteId,`color`,e),l(e))},[i,s]);return u(`div`,{className:`note-color-picker`,children:[u(h,{className:`color-cell-reset`,tooltip:c(`note-color.clear-color`),color:null,isSelected:s===null,isDisabled:i===null,onSelect:_,children:u(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,children:u(`path`,{d:`M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z`})})}),p.map(e=>u(h,{tooltip:c(`note-color.set-color`),color:e,isSelected:e===s,isDisabled:i===null,onSelect:_},e)),u(g,{tooltip:c(`note-color.set-custom-color`),color:s,isSelected:f,isDisabled:i===null,onSelect:_})]})}function h(e){return u(`div`,{className:s(e.className,{"color-cell":!0,selected:e.isSelected,"disabled-color-cell":e.isDisabled}),style:`${e.color===null?``:`--color: ${e.color}`}`,title:e.tooltip,onClick:()=>e.onSelect?.(e.color),children:e.children})}function g(e){let[a,o]=r(null),c=i(null),d=i(null),p=i(e.onSelect);n(()=>(d.current=new f(250,e=>{p.current?.(e),o(e)}),()=>{d.current?.destroy()}),[]),n(()=>{e.isSelected&&a===null&&o(e.color)},[e.isSelected]),n(()=>{p.current=e.onSelect},[e.onSelect]);let m=t(()=>{a!==null&&p.current?.(a),c.current?.click()},[a]);return u(`div`,{style:`--foreground: ${_(e.color)};`,onClick:l()?e=>{e.stopPropagation()}:void 0,children:u(h,{...e,color:a,className:s(`custom-color-cell`,{"custom-color-cell-empty":a===null}),onSelect:m,children:u(`input`,{ref:c,type:`color`,value:a??e.color??`#40bfbf`,onChange:()=>{d.current?.updateValue(c.current?.value??null)},style:`width: 0; height: 0; opacity: 0`})})})}function _(e){if(e===null)return`inherit`;let t=v(e)?.hsl();if(t){let e=t.lightness();return t.saturationl(0).lightness(e>=50?0:100).hex()}else return`inherit`}function v(e){try{return new o(e)}catch(e){console.error(e)}return null}export{m as t};