// ui/src/modules/activityLogs/index.js

export const ACTIVITY_LOGS_ALLOWED_USER_IDS = [5]

function toNumberOrNull (v) {
  const n = Number(v)
  return Number.isFinite(n) ? n : null
}

export function getAuthUserId (authUser) {
  if (!authUser || typeof authUser !== 'object') return null

  // tolerate backend field naming differences
  return (
    toNumberOrNull(authUser.id) ??
    toNumberOrNull(authUser.ID) ??
    toNumberOrNull(authUser.user_id) ??
    toNumberOrNull(authUser.userId) ??
    null
  )
}

export function isActivityLogsAllowedUser (authUser) {
  const id = getAuthUserId(authUser)
  if (id == null) return false
  return ACTIVITY_LOGS_ALLOWED_USER_IDS.includes(id)
}

export const activityLogsRoute = {
  path: 'activity-logs',
  name: 'activity-logs',
  component: () => import('pages/ActivityLogs.vue'),
  meta: {
    permission: 'system:read',
    onlyUserIds: ACTIVITY_LOGS_ALLOWED_USER_IDS
  }
}

export const activityLogsMenuItem = {
  label: 'Loglar',
  to: '/app/activity-logs',
  permission: 'system:read',
  onlyUserIds: ACTIVITY_LOGS_ALLOWED_USER_IDS
}

