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

type Entity = {
  id: string,
  label: string,
  entity_data: { type: string },
}

export const EntityRoutes = () => {

  return (
    <Routes>
      <Route index element={ <ListEntity /> } />
      <Route path="/edit/:record_id" element={ <EditEntity /> } />
      <Route path="/create" element={ <CreateEntity /> } />
    </Routes>
  );
}

const ListEntity = () => {
  const columns = [
    { field: "entity_data.type", column: { width: 110 }},
    { field: "label", column: { flex: 1 }},
    { field: "updated_at", column: { width: 160 }},
  ];
  return <List<Entity> resource={`entities`} schemaName={"Entity"} columns={columns} />
}

const EditEntity = () => {
  return <Edit<Entity> resource={`entities`} schemaName={"Entity"} />
}

const CreateEntity = () => {
  return <New<Entity> resource={`entities`} schemaName={"Entity"} />
}
