import { useBuilderPrefix } from "./useBuilderPrefix";

export type BuilderRoutes = {
  dashboard: () => string;
  resourceIndex: (slug: string) => string;
  resourceCreate: (slug: string) => string;
  resourceEdit: (slug: string, id: number | string) => string;
  resourceShow: (slug: string, id: number | string) => string;
  resourceDestroy: (slug: string, id: number | string) => string;
  resourceBulk: (slug: string) => string;
  upload: () => string;
  account: () => string;
  accountPassword: () => string;
  accountSecurity: () => string;
  settings: (key: string) => string;
  resourceRevisions: (slug: string, id: number | string) => string;
};

export function useBuilderRoutes(): BuilderRoutes {
  const prefix = useBuilderPrefix();

  return {
    dashboard: () => `/${prefix}`,
    resourceIndex: (slug: string) => `/${prefix}/${slug}`,
    resourceCreate: (slug: string) => `/${prefix}/${slug}/create`,
    resourceEdit: (slug: string, id: number | string) =>
      `/${prefix}/${slug}/${id}/edit`,
    resourceShow: (slug: string, id: number | string) =>
      `/${prefix}/${slug}/${id}`,
    resourceDestroy: (slug: string, id: number | string) =>
      `/${prefix}/${slug}/${id}`,
    resourceBulk: (slug: string) => `/${prefix}/${slug}/bulk`,
    upload: () => `/${prefix}/upload`,
    account: () => `/${prefix}/account`,
    accountPassword: () => `/${prefix}/account/password`,
    accountSecurity: () => `/${prefix}/account/security`,
    settings: (key: string) => `/${prefix}/settings/${key}`,
    resourceRevisions: (slug: string, id: number | string) =>
      `/${prefix}/${slug}/${id}/revisions`,
  };
}
