import { HelpText } from './HelpText';
import { FieldLabel, FieldInput } from './formUtils';
import type { SectionFormProps } from './types';

/**
 * Shared Knowledge Notes injection budget (`notes.inject.*`). Controls how much
 * of a subscribed note is injected into the agent's context per job.
 */
export function NotesForm({ config, onChange }: SectionFormProps) {
  const inject = config.notes?.inject ?? {};

  return (
    <div className="space-y-5">
      <h2 className="text-base font-semibold text-slate-800">Notes Injection</h2>
      <p className="text-[13px] text-slate-500">
        購読済みの共有ナレッジノートを、ジョブ実行時にエージェントの context へ注入する際の予算。
      </p>

      <div>
        <FieldLabel>Per-Note Max (KB)</FieldLabel>
        <FieldInput type="number" value={inject.perNoteMaxKb ?? ''}
          onChange={v => onChange('notes.inject.perNoteMaxKb', v ? Number(v) : undefined)} />
        <HelpText>1 ノートあたり注入する最大サイズ。デフォルト: 8 KB</HelpText>
      </div>

      <div>
        <FieldLabel>Total Max (KB)</FieldLabel>
        <FieldInput type="number" value={inject.totalMaxKb ?? ''}
          onChange={v => onChange('notes.inject.totalMaxKb', v ? Number(v) : undefined)} />
        <HelpText>全ノート合算で注入する最大サイズ。デフォルト: 32 KB</HelpText>
      </div>

      <div>
        <FieldLabel>Over-Budget Strategy</FieldLabel>
        <select
          value={inject.overBudgetStrategy ?? 'skip_remaining'}
          onChange={e => onChange('notes.inject.overBudgetStrategy', e.target.value)}
          className="w-full h-8 px-2 text-[13px] border border-hairline rounded-md bg-canvas focus:ring-2 focus:ring-accent-ring focus:border-accent outline-none transition-shadow"
        >
          <option value="skip_remaining">skip_remaining（予算超過後のノートは注入しない）</option>
          <option value="truncate_last">truncate_last（最後のノートを途中で切り詰める）</option>
          <option value="degrade_to_search">degrade_to_search（注入せず検索ツールに委ねる）</option>
        </select>
        <HelpText>合計予算を超えたときの挙動。デフォルト: skip_remaining</HelpText>
      </div>
    </div>
  );
}
