// ─── Composer.jsx ────────────────────────────────────────────
// Bottom-fixed input. Ivory textarea, gold focus halo, send pill.
// Action row: @-mention, /commands, attach, send.

function Composer({ value, onChange, onSubmit, disabled }) {
  const [v, setV] = React.useState(value || '');
  React.useEffect(() => { setV(value || ''); }, [value]);

  function submit(e) {
    e && e.preventDefault();
    const text = (v || '').trim();
    if (!text || disabled) return;
    onSubmit && onSubmit(text);
    setV('');
  }
  function onKey(e) {
    if (e.key === 'Enter' && !e.shiftKey) submit(e);
  }

  return (
    <div className="le-composer">
      <form className="le-composer-inner" onSubmit={submit}>
        <textarea
          className="le-composer-textarea"
          placeholder="הכנס טענה משפטית, כתב טענות או שאלה…"
          value={v}
          onChange={e => { setV(e.target.value); onChange && onChange(e.target.value); }}
          onKeyDown={onKey}
          rows={2}
          dir="rtl"
        />
        <div className="le-composer-actions">
          <button type="button" className="le-composer-action" title="פקודה (/)">/</button>
          <button type="button" className="le-composer-action" title="@-מקור">@</button>
          <button type="button" className="le-composer-action" title="צרף קובץ"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"><path d="M12.6 6.4 L6.9 12.1 A2.5 2.5 0 0 1 3.4 8.6 L9 3 A1.7 1.7 0 0 1 11.4 5.4 L5.9 11 A0.85 0.85 0 0 1 4.7 9.8 L9.8 4.7"></path></svg></button>
          <button type="button" className="le-composer-action" title="הקלטה"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"><rect x="6" y="2" width="4" height="7.4" rx="2"></rect><path d="M3.8 8 A4.2 4.2 0 0 0 12.2 8"></path><line x1="8" y1="12.2" x2="8" y2="14"></line><line x1="5.8" y1="14" x2="10.2" y2="14"></line></svg></button>
          <button type="submit" className="le-composer-send" disabled={disabled || !v.trim()}>
            נתח ↑
          </button>
        </div>
      </form>
      <div className="le-composer-hint">
        ⏎ to send · ⇧⏎ for newline · ציטוטים מילה במילה · <b>0% הזיות</b>
      </div>
    </div>
  );
}

window.Composer = Composer;
