import { getRoleLaneFromUser } from './roleLanes'

export const canManageInventoryWorkspace = (currentUser?: any) =>
  getRoleLaneFromUser(currentUser) === 'super_admin'

export const getCurrentOrganizationOption = (currentUser?: any) => {
  const organization = currentUser?.organizations || currentUser?.organization || null
  const id = organization?.id || currentUser?.organizationsId || currentUser?.organizationId || ''
  const name =
    organization?.name ||
    currentUser?.organizationName ||
    currentUser?.organizations?.name ||
    currentUser?.organization?.name ||
    'Current organization'

  if (!id) {
    return null
  }

  return {
    id,
    name,
  }
}

export const getRelationId = (value?: any) => {
  if (!value) {
    return ''
  }

  if (typeof value === 'string') {
    return value
  }

  return value.id || value.value || ''
}
