import type { ContentKey } from '../../content/schemas';
import { EditTabs } from './EditTabs';
import { RawJsonEditor } from './RawJsonEditor';
import { ProfileForm } from './forms/ProfileForm';
import { SkillsForm } from './forms/SkillsForm';
import { ExperiencesForm } from './forms/ExperiencesForm';
import { FormationsForm } from './forms/FormationsForm';
import { ProjectsForm } from './forms/ProjectsForm';
import { InterestsForm } from './forms/InterestsForm';
import { SiteForm } from './forms/SiteForm';

type Props = {
  section: ContentKey;
  data: unknown;
};

export function EditPanel({ section, data }: Props) {
  return (
    <EditTabs
      section={section}
      formNode={renderForm(section, data)}
      rawNode={<RawJsonEditor section={section} initial={data} />}
    />
  );
}

function renderForm(section: ContentKey, data: unknown) {
  switch (section) {
    case 'profile':
      return <ProfileForm defaultValues={data as never} />;
    case 'skills':
      return <SkillsForm defaultValues={data as never} />;
    case 'experiences':
      return <ExperiencesForm defaultValues={data as never} />;
    case 'formations':
      return <FormationsForm defaultValues={data as never} />;
    case 'projects':
      return <ProjectsForm defaultValues={data as never} />;
    case 'interests':
      return <InterestsForm defaultValues={data as never} />;
    case 'site':
      return <SiteForm defaultValues={data as never} />;
    default:
      return null;
  }
}
