import React from 'react';
import type { StrategyDto } from '../../utils/backendApi';
import type { VirtualSessionConfig } from '../../utils/virtualTradingStorage';

interface Props {
  session: Pick<VirtualSessionConfig, 'globalStrategyId' | 'executionType' | 'positionMode' | 'running'>;
  strategies: StrategyDto[];
  onStrategyChange: (strategyId: number | null) => void;
  onExecutionTypeChange: (type: VirtualSessionConfig['executionType']) => void;
  onPositionModeChange: (mode: VirtualSessionConfig['positionMode']) => void;
  onStart: () => void;
  onStop: () => void;
}

/** 레거시 — VirtualSessionHeaderControls 와 동일 드롭다운 레이아웃 */
const VirtualSessionToolbar: React.FC<Props> = ({
  session,
  strategies,
  onStrategyChange,
  onExecutionTypeChange,
  onPositionModeChange,
  onStart,
  onStop,
}) => (
  <div className="vtd-session-toolbar vtd-header-session--compact">
    <select
      className="vtd-header-select vtd-header-select--strategy"
      aria-label="투자전략"
      value={session.globalStrategyId ?? ''}
      onChange={e => {
        const v = e.target.value;
        onStrategyChange(v ? Number(v) : null);
      }}
    >
      <option value="">전략 선택</option>
      {strategies.map(s => (
        <option key={s.id} value={s.id}>{s.name}</option>
      ))}
    </select>

    <select
      className="vtd-header-select vtd-header-select--narrow"
      aria-label="실행방식"
      value={session.executionType}
      onChange={e => onExecutionTypeChange(e.target.value as VirtualSessionConfig['executionType'])}
    >
      <option value="CANDLE_CLOSE">봉 마감 직후</option>
      <option value="REALTIME_TICK">실시간 틱</option>
    </select>

    <select
      className="vtd-header-select vtd-header-select--narrow"
      aria-label="시그널 모드"
      value={session.positionMode}
      onChange={e => onPositionModeChange(e.target.value as VirtualSessionConfig['positionMode'])}
    >
      <option value="LONG_ONLY">보유 자산 기준</option>
      <option value="SIGNAL_ONLY">순수 지표 기준</option>
    </select>

    <div className="vtd-session-actions vtd-session-actions--compact">
      <button
        type="button"
        className="bps-btn vtd-session-btn vtd-session-btn--start"
        disabled={session.running}
        onClick={onStart}
      >
        시작
      </button>
      <button
        type="button"
        className="bps-btn bps-btn--danger vtd-session-btn"
        disabled={!session.running}
        onClick={onStop}
      >
        종료
      </button>
    </div>
  </div>
);

export default VirtualSessionToolbar;
