interface UserData {
  email: string;
  userId: string;
  userName?: string; // Optional
  organization: string;
}

export const getUserData = (): UserData => {
  const email = localStorage.getItem("email");
  const userId = localStorage.getItem("userId");
  const userName = localStorage.getItem("userName");

  if (!email || !userId) {
    return {
      email: '',
      userId: '',
      userName: '',
      organization: '',
    };
  }

  const [_, emailDomain] = email.split("@");

  if (!emailDomain) {
    console.error("Invalid email format");
  }

  const [organization] = emailDomain.split(".");

  return {
    email: email,
    userId: userId,
    userName: userName ?? undefined,
    organization,
  };
};
