const $ = require('jquery');
const bootstrap = require('bootstrap');
module.exports = class Modal {
constructor({ title, body, primary_label, primary_action, secondary_label, secondary_action }) {
Object.assign(this, arguments[0]);
this.$modal = $(`
`).appendTo(document.body);
if (this.primary_label) {
this.add_primary(this.primary_label, this.primary_action);
}
if (this.secondary_label) {
this.add_secondary(this.secondary_label, this.secondary_action);
}
this.show();
}
add_primary(label, action) {
this.$primary = $(``)
.appendTo(this.$modal.find('.modal-footer'))
.on('click', () => action(this));
}
add_secondary(label, action) {
this.$primary = $(``)
.appendTo(this.$modal.find('.modal-footer'))
.on('click', () => action(this));
}
show() {
this.$modal.modal('show');
}
hide() {
this.$modal.modal('hide');
}
get_body() {
return this.$modal.find('.modal-body').get(0);
}
}