import { useLayoutEffect, useRef, useState } from "react"; import { MessageIcon } from "@chopin/icons"; import { ChopinMark } from "./agent-mark"; export function ModeSwitch( { effectiveMode, disabled, onToggle }: { effectiveMode: boolean; disabled: boolean; onToggle: () => void; }, ) { let button = useRef(null); let label = useRef(null); let [width, setWidth] = useState(); useLayoutEffect(() => { let element = label.current; let control = button.current; if (!element || !control) return; function measure() { let text = getComputedStyle(element!); let style = getComputedStyle(control!); let symbol = control!.querySelector(".composer-mode-symbol")!; setWidth( parseFloat(text.width) + symbol.offsetWidth + parseFloat(style.columnGap) + parseFloat(style.paddingLeft) + parseFloat(style.paddingRight), ); } measure(); let observer = new ResizeObserver(measure); observer.observe(element); return () => observer.disconnect(); }, [effectiveMode]); return ( ); }