import { useServiceConnection } from '../../hooks/useServiceConnection';
import { useTransmissionSection } from './useTransmissionSection';
import { TorrentsView } from './TorrentsView';
import { StatsView } from './StatsView';
import { SettingsView } from './SettingsView';
import { ConnectionView } from './ConnectionView';

// Right panel of the /transmission workspace — renders the section named by the URL.
//
// With no daemon configured every other section can only render an error, so the connection form takes over
// until there is one. The URL is left alone: once connected, the section already in it is what appears.

export const TransmissionView = () => {
  const section = useTransmissionSection();
  const { data, isLoading } = useServiceConnection('transmission');

  if (!isLoading && !data?.configured) return <ConnectionView />;

  switch (section) {
    case 'connection':
      return <ConnectionView />;
    case 'stats':
      return <StatsView />;
    case 'settings':
      return <SettingsView />;
    default:
      return <TorrentsView />;
  }
};
