import { useQuery } from '@tanstack/react-query';
import { getUser } from 'api/user/query';
import styled from 'styled-components';
import { Flex } from 'ui/grid';
import { min } from 'ui/mq';

const UserText = styled.span`
  margin: 0;
  padding: 0;
  text-transform: uppercase;
  color: #fff;
  font-size: 0.5rem;
  font-family: 'Montserrat';
  font-weight: 500;

  ${min('laptop')} {
    font-size: 0.75rem;
  }
`;

function User() {
  const { data: user } = useQuery(['user'], () => getUser(), {
    enabled: false,
  });

  return <UserText>{user?.displayName}</UserText>;
}

const Logout = styled.a`
  margin: 0;
  padding: 0;
  text-transform: uppercase;
  color: #fff;
  font-size: 0.45rem;
  font-family: 'Montserrat';
  font-weight: 500;

  ${min('laptop')} {
    font-size: 0.55rem;
  }
`;

function Auth() {
  return (
    <Flex
      flexDirection="column"
      alignItems="flex-end"
      alignSelf={['flex-start']}
      justifyContent="space-between"
      height="100%"
    >
      <User />
      <Logout href="/logout">Выход</Logout>
    </Flex>
  );
}

export default Auth;
