import styled, { css } from 'styled-components';

import StyledTextArea from '../Input/StyledTextArea';

const Avatar = styled.div`
  margin: 0;
  padding: 0;
  margin-right: ${({ theme }) => theme.space.comment.avatarMarginRight};

  img {
    width: ${({ theme }) => theme.sizes.comment.avatarSize};
    height: ${({ theme }) => theme.sizes.comment.avatarSize};
    border-radius: 50%;
    margin: 0;
    padding: 0;
  }
`;

const AuthorWrapper = styled.div`
  margin: 0;
  padding: 0;
`;

const Author = styled.div`
  display: flex;
  align-items: center;
  font-weight: ${({ theme }) => theme.fontWeights.comment.author};
  font-size: ${({ theme }) => theme.fontSizes.comment.author};
  line-height: ${({ theme }) => theme.lineHeights.comment.author};
  color: ${({ theme }) => theme.colors.comment.author};
  margin: 0;
  padding: 0;
`;

const AuthorDetails = styled.div`
  margin: 0;
  padding: 0;
  font-weight: ${({ theme }) => theme.fontWeights.comment.authorDetails};
  font-size: ${({ theme }) => theme.fontSizes.comment.authorDetails};
  line-height: ${({ theme }) => theme.lineHeights.comment.authorDetails};
  color: ${({ theme }) => theme.colors.comment.authorDetails};
`;

const TimeWrapper = styled.div`
  white-space: nowrap;
  font-weight: ${({ theme }) => theme.fontWeights.comment.time};
  font-size: ${({ theme }) => theme.fontSizes.comment.time};
  line-height: ${({ theme }) => theme.lineHeights.comment.time};
  color: ${({ theme }) => theme.colors.comment.time};
  margin: 0;
  padding: 0;
`;

const TimeSeparator = styled.span`
  margin: 0;
  padding: ${({ theme }) => theme.space.comment.timeSeparatorPadding};
`;

const ContentWrapper = styled.div`
  position: relative;
  margin: 0;
  padding: 0;
  font-weight: ${({ theme }) => theme.fontWeights.comment.content};
  font-size: ${({ theme }) => theme.fontSizes.comment.content};
  line-height: ${({ theme }) => theme.lineHeights.comment.content};
  flex-grow: 1;
  color: ${({ theme }) => theme.colors.comment.content};
`;

const ContentDetail = styled.div`
  white-space: pre-wrap;
  margin: 0;
  padding: 0;
  margin-top: ${({ theme }) => theme.space.comment.contentMarginTop};
`;

const ActionsWrapper = styled.div<{ themeShown: boolean }>`
  position: absolute;
  top: 0;
  right: 0;
  margin: 0;
  padding: 0;

  ${({ themeShown }) => {
    switch (themeShown) {
      case true:
        return css`
          display: block;
        `;
      case false:
        return css`
          display: none;
        `;
    }
  }};
`;

const ReactionsWrapper = styled.div`
  margin: 0;
  padding: 0;
  margin-top: ${({ theme }) => theme.space.comment.reactionMarginTop};
`;

const CommentWrapper = styled.div`
  margin: 0;
  padding: 0;

  &:not(:last-child) {
    margin-bottom: ${({ theme }) => theme.space.comment.marginBottom};
  }
`;

const CommentInner = styled.div`
  display: flex;
  padding: ${({ theme }) => theme.space.comment.padding};
  border-radius: ${({ theme }) => theme.radii.comment.container};
  margin: 0;
  &:hover {
    background-color: ${({ theme }) => theme.colors.comment.highlight};
  }
`;

const NestedCommentWrapper = styled.div`
  margin: ${({ theme }) => theme.space.comment.nestedMargin};
  padding: 0;
`;

const EditorContainer = styled.div`
  display: flex;
  margin: 0;
  padding: 0;

  ${Avatar} {
    margin-left: ${({ theme }) => theme.space.comment.avatarMarginLeft};
  }
`;

const EditorWrapper = styled.div`
  margin: 0;
  padding: 0;
  border: ${({ theme }) => theme.borderWidths.input.default} solid
    ${({ theme }) => theme.colors.input.border};
  border-radius: ${({ theme }) => theme.radii.input.default};
  width: 0;
  flex-grow: 1;
  flex-shrink: 1;
  color: ${({ theme }) => theme.colors.comment.content};

  &:hover {
    border-color: ${({ theme }) => theme.colors.input.focusBorder};
  }

  &:focus-within {
    outline: none;
    border-color: ${({ theme }) => theme.colors.input.focusBorder};
    box-shadow: ${({ theme }) => theme.shadows.input.focus};
  }

  ${StyledTextArea} {
    border: none;
    box-shadow: none;
  }
`;

const EditorActionsWrapper = styled.div`
  margin: 0;
  padding: ${({ theme }) => theme.space.comment.editorActionsPadding};
  display: flex;
  flex-direction: row-reverse;
  align-items: flex-end;
  justify-content: space-between;
`;

export {
  Avatar,
  AuthorWrapper,
  Author,
  AuthorDetails,
  TimeWrapper,
  TimeSeparator,
  ContentWrapper,
  ContentDetail,
  ActionsWrapper,
  ReactionsWrapper,
  CommentWrapper,
  CommentInner,
  NestedCommentWrapper,
  EditorContainer,
  EditorWrapper,
  EditorActionsWrapper,
};
