const DASHBOARD_BASE_PATH = '/dashboard'

export function toDashboardAppPath(path?: string | null): string {
  const value = (path ?? '').trim()
  if (!value || value === '/') return '/'

  let normalized = value.startsWith('/') ? value : `/${value}`

  while (normalized === DASHBOARD_BASE_PATH || normalized.startsWith(`${DASHBOARD_BASE_PATH}/`)) {
    normalized = normalized.slice(DASHBOARD_BASE_PATH.length) || '/'
  }

  return normalized
}

export function toPublicDashboardPath(path?: string | null): string {
  const appPath = toDashboardAppPath(path)
  return appPath === '/' ? DASHBOARD_BASE_PATH : `${DASHBOARD_BASE_PATH}${appPath}`
}
