File size: 3,760 Bytes
c453128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import type React from "react";
import type { ReasoningEffort } from "../types";

interface Props {
  value: ReasoningEffort;
  options: { value: ReasoningEffort; label: string }[];
  disabled?: boolean;
  disabledHint?: string;
  compact?: boolean;
  header?: boolean;
  vertical?: boolean;
  readOnly?: boolean;
  onChange: (v: ReasoningEffort) => void;
}

export function ReasoningEffortControl({
  value, options, disabled = false, disabledHint, compact = false, header = false, vertical = false, readOnly = false, onChange,
}: Props) {
  const labelStyle: React.CSSProperties = {
    fontSize: header ? 12 : compact ? 9 : 10,
    color: disabled ? "#5a6478" : "var(--text-dim)",
    flexShrink: 0,
    userSelect: "none",
    ...(vertical ? { width: 52 } : {}),
  };
  const btnPad = header ? "6px 14px" : compact ? "3px 7px" : "4px 9px";
  const btnFont = header ? 12 : compact ? 9 : 10;
  const displayOptions = disabled ? [{ value: "none" as ReasoningEffort, label: "n/a" }] : options;
  const activeLabel = displayOptions.find((o) => o.value === (disabled ? "none" : value))?.label ?? value;

  if (readOnly) {
    return (
      <div
        style={{
          display: "flex",
          alignItems: "center",
          gap: vertical ? 8 : header ? 8 : compact ? 4 : 6,
          minWidth: 0,
          width: vertical ? "100%" : undefined,
        }}
        title={disabled ? (disabledHint ?? "Reasoning not available for this backend") : "Reasoningchange it from the desk'ssettings"}
      >
        <span style={labelStyle}>Reasoning</span>
        <span style={{
          fontSize: header ? 13 : compact ? 10 : 12,
          fontWeight: 600,
          color: disabled ? "#5a6478" : "var(--text)",
          textTransform: "capitalize",
        }}>
          {activeLabel}
        </span>
      </div>
    );
  }

  return (
    <div
      style={{
        display: "flex",
        alignItems: "center",
        gap: vertical ? 8 : header ? 8 : compact ? 4 : 6,
        minWidth: 0,
        width: vertical ? "100%" : undefined,
      }}
      title={disabled ? (disabledHint ?? "Reasoning not available for this backend") : undefined}
    >
      <span style={labelStyle}>Reasoning</span>
      <div style={{
        display: "flex",
        alignItems: "center",
        flex: vertical ? 1 : undefined,
        minWidth: 0,
        background: disabled ? "#0e121c" : "#121828",
        border: `1px solid ${disabled ? "#1e2436" : "#2a3558"}`,
        borderRadius: 6,
        overflow: "hidden",
        opacity: disabled ? 0.55 : 1,
      }}>
        {(disabled ? [{ value: "none" as ReasoningEffort, label: "n/a" }] : options).map(({ value: v, label }, i, arr) => {
          const effort = disabled ? "none" : v;
          const active = !disabled && value === effort;
          return (
            <button
              key={effort}
              type="button"
              disabled={disabled}
              onClick={() => { if (!disabled) onChange(effort); }}
              title={disabled ? disabledHint : `Reasoning: ${label}`}
              style={{
                padding: btnPad,
                fontSize: btnFont,
                fontWeight: 500,
                cursor: disabled ? "not-allowed" : "pointer",
                border: "none",
                borderRight: i < arr.length - 1 ? "1px solid #2a3558" : undefined,
                background: active ? "var(--accent2)" : "transparent",
                color: active ? "white" : disabled ? "#5a6478" : "var(--text-dim)",
                transition: "background 0.15s, color 0.15s",
                flex: vertical ? 1 : undefined,
              }}
            >
              {label}
            </button>
          );
        })}
      </div>
    </div>
  );
}