import { h } from 'preact';
import type { Widget } from '../lib/types';

interface Props { widget: Widget; onContextMenu?: (e: MouseEvent) => void; }

export default function TextLabel({ widget, onContextMenu }: Props) {
  const text = widget.options['label'] ?? widget.options['text'] ?? '';
  const fontSize = widget.options['fontSize'] ?? '1rem';
  const color = widget.options['color'] ?? '#e2e8f0';
  const align = widget.options['align'] ?? 'left';

  return (
    <div
      class="textlabel"
      style={`left:${widget.x}px;top:${widget.y}px;width:${widget.w}px;height:${widget.h}px;font-size:${fontSize};color:${color};text-align:${align};`}
      onContextMenu={onContextMenu}
    >
      {text}
    </div>
  );
}
