import{a as e,n as t}from"./preload-helper-DxX6f4wy.js";import{$ as n,O as r,n as i}from"./Fade-Bj1YUcWe.js";import{t as a}from"./Box-BoFhqo9n.js";import{t as o}from"./ButtonBase-dVPwHUcG.js";import{n as s}from"./Menu-DT9JOTRT.js";import{t as c}from"./Slider-DvHcYIbx.js";import{t as l}from"./Stack-sZ5R3ZLo.js";import{t as u}from"./TextField-DaTG2iA-.js";var d=e(t(),1),f=n(),p=[`#ef4444`,`#f97316`,`#f59e0b`,`#84cc16`,`#10b981`,`#06b6d4`,`#0ea5e9`,`#3b82f6`,`#6366f1`,`#8b5cf6`,`#a855f7`,`#d946ef`,`#f472b6`,`#fb7185`,`#78716c`,`#1f2937`];function m(e){let t=e.replace(`#`,``);if(t.length!==6)return{r:0,g:0,b:0};let n=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16);return{r:Number.isNaN(n)?0:n,g:Number.isNaN(r)?0:r,b:Number.isNaN(i)?0:i}}function h(e,t,n){return`#${[e,t,n].map(e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,`0`)).join(``)}`}function g(e){return/^#?[0-9A-Fa-f]{6}$/.test(e)}function _({value:e,onChange:t,disabled:n,label:_}){let[v,y]=(0,d.useState)(null),[b,x]=(0,d.useState)(e),S=!!v,C=m(e),w=t=>{n||(x(e),y(t.currentTarget))},T=()=>{y(null)},E=e=>{let n=e.startsWith(`#`)?e:`#${e}`;g(n)&&t(n.toLowerCase()),x(n.toLowerCase())},D=(e,n)=>{let r={...C,[e]:n};t(h(r.r,r.g,r.b))};return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(o,{onClick:w,disabled:n,sx:{display:`inline-flex`,alignItems:`center`,gap:1,p:1,borderRadius:1,border:`1px solid`,borderColor:`divider`,opacity:n?.5:1,cursor:n?`not-allowed`:`pointer`,minWidth:0,maxWidth:`100%`,verticalAlign:`middle`},children:[(0,f.jsx)(a,{sx:{width:24,height:24,borderRadius:1,backgroundColor:e,border:`1px solid`,borderColor:`divider`,flexShrink:0}}),_&&(0,f.jsx)(i,{variant:`body2`,sx:{color:`text.primary`,fontWeight:500,overflowWrap:`break-word`,minWidth:0},children:_}),(0,f.jsx)(i,{variant:`caption`,sx:{color:`text.secondary`,fontFamily:`monospace`,flexShrink:0},children:e})]}),(0,f.jsx)(s,{open:S,anchorEl:v,onClose:T,anchorOrigin:{vertical:`bottom`,horizontal:`left`},transformOrigin:{vertical:`top`,horizontal:`left`},PaperProps:{sx:{p:{xs:1.5,sm:2},borderRadius:1,width:280,maxWidth:{xs:`calc(100vw - 32px)`,sm:280},boxShadow:e=>e.palette.mode===`light`?`0 8px 32px ${r(e.palette.primary.main,.12)}`:`0 8px 32px ${r(e.palette.common.black,.4)}`}},children:(0,f.jsxs)(l,{spacing:2,children:[(0,f.jsx)(a,{sx:{width:`100%`,height:48,borderRadius:1,backgroundColor:e,border:`1px solid`,borderColor:`divider`}}),(0,f.jsx)(a,{sx:{display:`grid`,gridTemplateColumns:`repeat(8, 1fr)`,gap:.75},children:p.map(n=>(0,f.jsx)(o,{onClick:()=>t(n),sx:{width:24,height:24,borderRadius:1,backgroundColor:n,border:`2px solid`,borderColor:e===n?`text.primary`:`transparent`,"&:hover":{transform:`scale(1.1)`},transition:`transform 0.15s ease`}},n))}),(0,f.jsx)(u,{label:`HEX`,value:b,onChange:e=>E(e.target.value),size:`small`,fullWidth:!0,inputProps:{maxLength:7}}),[`r`,`g`,`b`].map(e=>(0,f.jsxs)(a,{children:[(0,f.jsxs)(a,{sx:{display:`flex`,justifyContent:`space-between`,mb:.5},children:[(0,f.jsx)(i,{variant:`caption`,sx:{textTransform:`uppercase`,fontWeight:600},children:e}),(0,f.jsx)(i,{variant:`caption`,sx:{fontFamily:`monospace`},children:C[e]})]}),(0,f.jsx)(c,{value:C[e],onChange:(t,n)=>D(e,n),min:0,max:255,size:`small`,sx:{color:e===`r`?`#ef4444`:e===`g`?`#10b981`:`#3b82f6`}})]},e))]})})]})}export{_ as t};