class BaseModal {
    _modal;
    _options;
    _openOptions;
    _events = [];
    _id;
    _ui;

    constructor(id, options = {}) {
        if (!id) {
            throw new Error('Base modal - missing modal id');
        }
        this._id = id;
        this._ui = jQuery(`#${this._id}`);
        this._options = {
            backdrop: true, focus: true, keyboard: true, ...options
        };
        this._modal = new bootstrap.Modal(document.getElementById(`${id}`));
    }

    open(openOptions) {
        this._openOptions = openOptions;
        this._modal.show();
    }

    registerEvent(eventName, callback) {
        this._events.push({eventName, callback});
    }

    getTitle() {
        return this._ui.find('.modal-title').html();
    }

    setTitle(newTitle) {
        this._ui.find('.modal-title').html(newTitle);
    }
}

export default BaseModal;