import { onMount } from "svelte";

/**
 * Bootstrap Modal.
 * @description This class wraps the Bootstrap modal functionality to provide a simple interface for showing and hiding modals.
 * @requires window.bootstrap
 * @example
 * import { Modal } from '$lib/modal';
 * const myModal = new Modal(document.getElementById('myModal'));
 * myModal.show(); // show the modal
 * myModal.hide(); // hide the modal
 */
export class Modal {
    /**
     * Constructor for Bootstrap Modal.
     * @param {HTMLElement} document
     * @param {object?} options
     */
    constructor(document, options = {}) {
        onMount(() => {
            this.modal = new window.bootstrap.Modal(document, {
                keyboard: false,
                ...options,
            });
        });
    }

    show() {
        this.modal.show();
    }

    hide() {
        this.modal.hide();
    }
}
