import { z } from "zod"

import { getMembershipCardsSchema } from "@/server/routers/user/output"

import { User } from "@/types/user"

enum scandicMemberships {
  guestpr = "guestpr",
  scandicfriends = "scandicfriend's",
}

export function getMembership(memberships: User["memberships"]) {
  return memberships?.find(
    (membership) =>
      membership.membershipType.toLowerCase() === scandicMemberships.guestpr
  )
}

export function getMembershipCards(
  memberships: z.infer<typeof getMembershipCardsSchema>
) {
  return memberships.filter(function (membership) {
    return (
      membership.membershipType.toLowerCase() !== scandicMemberships.guestpr &&
      membership.membershipType.toLowerCase() !==
        scandicMemberships.scandicfriends
    )
  })
}

export function getInitials(
  firstName: User["firstName"],
  lastName: User["lastName"]
) {
  if (!firstName || !lastName) return null
  const firstInitial = firstName.charAt(0).toUpperCase()
  const lastInitial = lastName.charAt(0).toUpperCase()
  return `${firstInitial}${lastInitial}`
}
