"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommentsApiImpl = void 0;
const tslib_1 = require("tslib");
const CommentRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/CommentsRedux"));
const ApiBase_1 = require("./ApiBase");
const ObjectFactory_1 = tslib_1.__importDefault(require("../../Utilities/ObjectFactory"));
const AdaptableHelper_1 = tslib_1.__importDefault(require("../../Utilities/Helpers/AdaptableHelper"));
const CommentsInternalApi_1 = require("../Internal/CommentsInternalApi");
class CommentsApiImpl extends ApiBase_1.ApiBase {
    internalApi;
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new CommentsInternalApi_1.CommentsInternalApi(_adaptable);
    }
    getCommentThreadForCell(address) {
        return CommentRedux.GetCellCommentSelector(this.getAdaptableState().Comment, address);
    }
    getAllComments() {
        return this.getAdaptableState().Comment.CommentThreads ?? [];
    }
    editComment(comment, address) {
        this.dispatchAction(CommentRedux.CommentEdit({ comment, cellAddress: address }));
    }
    deleteComment(comment, address) {
        this.dispatchAction(CommentRedux.CommentsDelete({ commentUuid: comment.Uuid, cellAddress: address }));
    }
    addComment(commentText, address) {
        this.dispatchAction(CommentRedux.CommentAdd({
            comment: commentText
                ? ObjectFactory_1.default.CreateAdaptableComment(commentText, this.getAdaptableApi())
                : null,
            cellAddress: address,
        }));
    }
    addCommentThread(commentThread) {
        if (!commentThread.Uuid) {
            AdaptableHelper_1.default.addAdaptableObjectPrimitives(commentThread);
        }
        this.dispatchAction(CommentRedux.CommentThreadAdd({ commentThread: commentThread }));
    }
    deleteCommentThread(cellAddress) {
        this.dispatchAction(CommentRedux.CommentThreadDelete({ cellAddress }));
    }
    setComments(commentThreads) {
        this.dispatchAction(CommentRedux.CommentThreadsLoad({ commentThreads: commentThreads }));
    }
    clearComments() {
        this.setComments([]);
    }
    hideCommentsPopup() {
        this.getAdaptableInternalApi().getAnnotationsService().hidePopup();
    }
}
exports.CommentsApiImpl = CommentsApiImpl;
