import { Route } from 'react-router-dom'
import { objectModels } from '../database/ObjectModels'
import { getModelRoutePath } from '../utils/modelActions'
import ModelPage from '../components/Dashboard/common/ModelPage'

const ModelRoutes = objectModels
  .filter((model) => model.pages?.length > 0)
  .flatMap((model) =>
    model.pages.map((page) => (
      <Route
        key={`${model.name}-${page.name}`}
        path={`${getModelRoutePath(model)}/${page.name}`}
        element={
          <ModelPage modelName={model.name} pageName={page.name} />
        }
      />
    ))
  )

export default ModelRoutes
