#include "screens/post/PostHeaderView.hpp"
#include "screens/components/RelativeTime.hpp"
#include "screens/components/UserViews.hpp"
#include "spec/PostsSpec.hpp"
#include "screens/post/Accessible.hpp"
#include "ui/Palette.hpp"
namespace dp {
using namespace ui;
using spec::PostsLayout;
ViewPtr PostHeaderView(const User& author, Date date, const PostHeaderOptions& options, const PostEnvironment& env) {
ViewPtr avatar = UserAvatarView(author);
if (options.linksToProfile && env.openProfile) {
const std::string username = author.username;
auto open = env.openProfile;
avatar = Button(avatar, [open, username] { open(username); }, ButtonStyles::plain())->id("profile-" + author.id);
}
std::vector<ViewPtr> trailing{RelativeTimeLabel(date)};
if (options.commentCount && *options.commentCount > 0) {
const std::string count = std::to_string(*options.commentCount);
ViewPtr label = HStack({Icon("text.bubble", PostsLayout::kHeaderCountFont), Text(count)}, PostsLayout::kHeaderCountSpacing)
->font(FontSpec::system(PostsLayout::kHeaderCountFont))->foreground(Palette::fg2());
trailing.push_back(Accessible(label, count + spec::PostsText::kCommentCountSuffix));
}
return HStack({avatar, Spacer(), VStack(trailing, PostsLayout::kHeaderCountSpacing, HAlign::Trailing)}, 8, VAlign::Top);
}
} // namespace dp