#include "screens/post/PostFooterView.hpp"
#include "screens/components/ReportButton.hpp"
#include "screens/components/VoteView.hpp"
#include "screens/post/ActionIconButton.hpp"
#include "screens/reactions/ReactionsBar.hpp"
#include "spec/PostsSpec.hpp"
#include "ui/Overlays.hpp"
namespace dp {
using namespace ui;
using spec::PostsLayout;
using spec::PostsText;
void presentDeleteConfirmation(const std::string& question, std::function<void()> onDelete) {
Overlays::instance().confirmationDialog(
question, "",
{AlertButton{PostsText::kDelete, AlertButton::Role::Destructive, std::move(onDelete)},
AlertButton{PostsText::kCancel, AlertButton::Role::Cancel, nullptr}});
}
ViewPtr PostFooterView(const PostFooterProps& p) {
std::vector<ViewPtr> actions;
if (p.onReply && !p.isReplying) actions.push_back(ActionIconButton("arrowshape.turn.up.left", PostsText::kReplyToPost, p.onReply));
actions.push_back(ReportButton(TargetType::Post, p.targetId, p.authorId));
if (p.onEdit) actions.push_back(ActionIconButton("pencil", PostsText::kEditPost, p.onEdit));
if (p.onDelete) {
auto onDelete = p.onDelete;
actions.push_back(ActionIconButton("trash", PostsText::kDeletePost,
[onDelete] { presentDeleteConfirmation(PostsText::kDeletePostQuestion, onDelete); }));
}
return HStack({VoteView(TargetType::Post, p.targetId, p.starCount, p.currentVote), ReactionsBar(p.reactions, p.onReact), Spacer(0),
HStack(actions, PostsLayout::kFooterActionSpacing)},
PostsLayout::kFooterSpacing);
}
} // namespace dp