import * as ModuleConstants from '../Utilities/Constants/ModuleConstants';
import { AdaptableModuleBase } from './AdaptableModuleBase';
export class NoteModule extends AdaptableModuleBase {
    constructor(api) {
        super(ModuleConstants.NoteModuleId, ModuleConstants.NoteFriendlyName, 'note', 'NotePopup', 'Notes', api);
    }
    isModuleEnabled() {
        // Note module doesn't support autogenerated primary keys
        return !this.api.optionsApi.isAutogeneratePrimaryKey();
    }
    getModuleAdaptableObjects() {
        return this.api.noteApi.getAllNotes();
    }
    createContextMenuItems(menuContext) {
        if (!this.isModuleVisible()) {
            return;
        }
        if (!this.api.noteApi.internalApi.areNotesSupported()) {
            return;
        }
        if (menuContext.isRowGroupColumn ||
            menuContext.isGroupedNode ||
            !menuContext.isSingleSelectedCell) {
            return;
        }
        const isReadOnly = this.api.entitlementApi.getEntitlementAccessLevelForModule(this.moduleInfo.ModuleName) ===
            'ReadOnly';
        if (isReadOnly) {
            return undefined;
        }
        const isCellNotable = typeof this.api.optionsApi?.getNoteOptions()?.isCellNotable === 'function'
            ? this.api.optionsApi.getNoteOptions().isCellNotable({
                gridCell: menuContext.gridCell,
                ...this.api.internalApi.buildBaseContext(),
            })
            : true;
        if (!isCellNotable) {
            return;
        }
        const note = this.api.noteApi.getNoteForCell({
            PrimaryKeyValue: menuContext.primaryKeyValue,
            ColumnId: menuContext.adaptableColumn.columnId,
        });
        if (note) {
            return [
                this.createMenuItemClickFunction('note-remove', 'Remove Note', this.moduleInfo.Glyph, () => {
                    this.api.noteApi.deleteNote(note);
                }),
            ];
        }
        else {
            return [
                this.createMenuItemClickFunction('note-add', 'Add Note', this.moduleInfo.Glyph, () => {
                    // add an empty one
                    this.api.noteApi.addNote('', menuContext.primaryKeyValue, menuContext.adaptableColumn.columnId);
                    this.api.internalApi.getAnnotationsService().showPopup({
                        PrimaryKeyValue: menuContext.primaryKeyValue,
                        ColumnId: menuContext.adaptableColumn.columnId,
                    }, true);
                }),
            ];
        }
    }
}
