import { Route, Routes } from "react-router";
import React, { useContext } from "react";
import { FirmContext } from "../../contexts/FirmContext";
import List from "./base-page/List";
import Edit from "./base-page/Edit";
import New from "./base-page/New";

type Draft = {
  id: string,
  label: string
}

export const DraftRoutes = () => {
  return (
    <Routes>
      <Route index element={ <ListDraft /> } />
      <Route path="/edit/:record_id" element={ <EditDraft /> } />
      <Route path="/create" element={ <CreateDraft /> } />
    </Routes>
  );
}

const ListDraft = () => {
  const { currentFirm } = useContext(FirmContext);
  const columns = [
    { field: "label", headerName: "Label", flex: 1 },
  ];
  return <List<Draft> resource={`firm/${currentFirm.instance}/${currentFirm.firm}/contracts/drafts`} columns={columns} />
}

const EditDraft = () => {
  const { currentFirm } = useContext(FirmContext);
  return <Edit<Draft> resource={`firm/${currentFirm.instance}/${currentFirm.firm}/contracts/drafts`} schemaName={"ContractDraftUpdate"} />
}

const CreateDraft = () => {
  const { currentFirm } = useContext(FirmContext);
  return <New<Draft> resource={`firm/${currentFirm.instance}/${currentFirm.firm}/contracts/drafts`} schemaName={"ContractDraftCreate"} />
}
