/**
 * Wizard state management — field update dispatch and default values.
 *
 * Extracted from ProjectWizard.svelte to keep it under 300 lines.
 */

export type SourceType = 'local' | 'git-clone' | 'github' | 'template' | 'remote';
export type AuthMethod = 'password' | 'key' | 'agent' | 'config';
export type PathState = 'idle' | 'checking' | 'valid' | 'invalid' | 'not-dir';
export type ProbeState = 'idle' | 'probing' | 'ok' | 'error';

export interface WizardState {
  step: number;
  sourceType: SourceType;
  localPath: string;
  repoUrl: string;
  cloneTarget: string;
  githubRepo: string;
  selectedTemplate: string;
  templateTargetDir: string;
  templateOriginDir: string;
  remoteHost: string;
  remoteUser: string;
  remotePath: string;
  remoteAuthMethod: AuthMethod;
  remotePassword: string;
  remoteKeyPath: string;
  remoteSshfs: boolean;
  remoteSshfsMountpoint: string;
  pathValid: PathState;
  isGitRepo: boolean;
  gitBranch: string;
  gitProbeStatus: ProbeState;
  gitProbeBranches: string[];
  githubInfo: { stars: number; description: string; defaultBranch: string } | null;
  githubProbeStatus: ProbeState;
  githubLoading: boolean;
  cloning: boolean;
  projectName: string;
  nameError: string;
  selectedBranch: string;
  branches: string[];
  useWorktrees: boolean;
  selectedGroupId: string;
  projectIcon: string;
  projectColor: string;
  shellChoice: string;
  provider: string;
  model: string;
  permissionMode: string;
  systemPrompt: string;
  autoStart: boolean;
  providerModels: Array<{ id: string; name: string; provider: string }>;
  modelsLoading: boolean;
}

export function getDefaults(groupId: string): WizardState {
  return {
    step: 1, sourceType: 'local', localPath: '', repoUrl: '', cloneTarget: '',
    githubRepo: '', selectedTemplate: '', templateTargetDir: '~/projects',
    templateOriginDir: '',
    remoteHost: '', remoteUser: '', remotePath: '',
    remoteAuthMethod: 'agent', remotePassword: '', remoteKeyPath: '~/.ssh/id_ed25519',
    remoteSshfs: false, remoteSshfsMountpoint: '',
    pathValid: 'idle', isGitRepo: false, gitBranch: '',
    gitProbeStatus: 'idle', gitProbeBranches: [], githubInfo: null,
    githubProbeStatus: 'idle', githubLoading: false,
    cloning: false, projectName: '', nameError: '', selectedBranch: '',
    branches: [], useWorktrees: false, selectedGroupId: groupId,
    projectIcon: 'Terminal', projectColor: 'var(--ctp-blue)', shellChoice: 'bash',
    provider: 'claude', model: '', permissionMode: 'default',
    systemPrompt: '', autoStart: false, providerModels: [], modelsLoading: false,
  };
}
