"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");
const lodash_1 = tslib_1.__importDefault(require("lodash"));
class CommentsApiImpl extends ApiBase_1.ApiBase {
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new CommentsInternalApi_1.CommentsInternalApi(_adaptable);
    }
    getCommentThread(address) {
        return CommentRedux.GetCellCommentSelector(this.getAdaptableState().Comment, address);
    }
    getGridComments() {
        var _a;
        return (_a = this.getAdaptableState().Comment.CommentThreads) !== null && _a !== void 0 ? _a : [];
        lodash_1.default;
    }
    editComment(comment, address) {
        this.dispatchAction(CommentRedux.CommentsEdit({ comment, cellAddress: address }));
    }
    deleteComment(comment, address) {
        this.dispatchAction(CommentRedux.CommentsDelete({ commentUuid: comment.Uuid, cellAddress: address }));
    }
    addComment(commentText, address) {
        this.dispatchAction(CommentRedux.CommentsAdd({
            comment: commentText
                ? ObjectFactory_1.default.CreateAdaptableComment(commentText, this.getAdaptableApi())
                : null,
            cellAddress: address,
        }));
    }
    addCommentThread(commentThread) {
        if (!commentThread.Uuid) {
            AdaptableHelper_1.default.addUuidAndSource(commentThread);
        }
        this.dispatchAction(CommentRedux.CommentsCellAdd({ commentThread: commentThread }));
    }
    deleteCommentThread(cellAddress) {
        this.dispatchAction(CommentRedux.CommentsCellDelete({ cellAddress }));
    }
    setGridComments(cellComments) {
        this.dispatchAction(CommentRedux.CommentsSet({ commentThread: cellComments }));
    }
    clearGridComments() {
        this.setGridComments([]);
    }
    hideCommentsPopup() {
        this.getAdaptableInternalApi().getCellPopupService().hidePopup();
    }
}
exports.CommentsApiImpl = CommentsApiImpl;
