import { Col, ListGroupItem, Row } from "reactstrap";
import { useTo } from "taehui-ts/fe-utility";
import { getDatetime } from "taehui-ts/date";

import AvatarTitle from "src/taehui/AvatarTitle";
import { LatestCommentAPIComment } from "src/wwwAPI";

const CommentTitleView = ({
  forumID,
  essayID,
  comment: { avatarID, avatarName, date, text },
}: {
  forumID: string;
  essayID: number;
  comment: LatestCommentAPIComment;
}) => {
  const to = useTo();

  return (
    <ListGroupItem
      key={essayID}
      className="route"
      onClick={() => {
        to(`/forum/${forumID}/${essayID}`);
      }}
    >
      <Row className="g-0">
        <AvatarTitle avatarID={avatarID} avatarName={avatarName}>
          <span className="title">{text}</span>
        </AvatarTitle>
        <Col className="m-1" xs="auto">
          <span>{getDatetime(date)}</span>
        </Col>
      </Row>
    </ListGroupItem>
  );
};

export default CommentTitleView;
