import { useQuery, useUserIdentity } from "@saasquatch/component-boilerplate";
import { gql } from "graphql-request";
const GET_USER_NAME = gql `
  query getUserName {
    viewer {
      ... on User {
        firstName
        lastName
      }
    }
  }
`;
export function useUserName(props) {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  const user = useUserIdentity();
  const res = useQuery(GET_USER_NAME, {}, !(user === null || user === void 0 ? void 0 : user.jwt));
  const loading = res.loading;
  const username = ((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.viewer) === null || _b === void 0 ? void 0 : _b.firstName) || ((_d = (_c = res.data) === null || _c === void 0 ? void 0 : _c.viewer) === null || _d === void 0 ? void 0 : _d.lastName)
    ? `${(_f = (_e = res.data) === null || _e === void 0 ? void 0 : _e.viewer) === null || _f === void 0 ? void 0 : _f.firstName} ${(_h = (_g = res.data) === null || _g === void 0 ? void 0 : _g.viewer) === null || _h === void 0 ? void 0 : _h.lastName}`
    : props.fallback;
  return {
    loadingText: props.loadingText,
    loading,
    username,
  };
}
