(function($, window) {
    function small(url) {
        openModal('small', url);
    }

    function large(url) {
        openModal('large', url);
    }

    function openModal(size, url) {
        const modal = new tingle.modal({
            closeMethods: ['overlay', 'button'],
            closeLabel: "Close",
            cssClass: [`guru-modal-${size}`],
            onClose: function() {
                modal.destroy()
            },
        });
        
        modal.setContent(`<iframe src="${url}"></iframe>`);
        modal.open();
    }

    function closeAll() {
        $('.tingle-modal__close').click();
    }

    function largeContent(content) {
        openModalContent('large', content);
    }

    function openModalContent(size, content) {
        const modal = new tingle.modal({
            closeMethods: ['overlay', 'button'],
            closeLabel: "Close",
            cssClass: ['guru-content-modal', `guru-content-modal-${size}`],
            onClose: function() {
                modal.destroy()
            },
        });
        
        modal.setContent(content);
        modal.open();
    }

    window.guruModal = window.guruModal || {};
    window.guruModal.small = small;
    window.guruModal.large = large;
    window.guruModal.largeContent = largeContent;
    window.guruModal.closeAll = closeAll;
})(jQuery, window);