(function($) {
    'use strict';
    class MMPDBModal {
        constructor() {
            this.init();
        }
        init() {
            this.createModalHTML();
            this.bindEvents();
        }
        createModalHTML() {
            const modalHTML = `
                <div class="mmpdb-modal">
                    <div class="mmpdb-modal__content">
                        <button class="mmpdb-modal__close">&times;</button>
                        <iframe class="mmpdb-modal__iframe" src="" frameborder="0"></iframe>
                    </div>
                </div>
            `;
            
            $('body').append(modalHTML);
        }
        bindEvents() {
            $(document).on('click', '.modal-link', (e) => {
                e.preventDefault();
                this.openModal($(e.currentTarget).attr('href'));
            });
            $('.mmpdb-modal__close').on('click', () => this.closeModal());
            $(document).on('keyup', (e) => {
                if (e.key === 'Escape') this.closeModal();
            });
            // Close on overlay click
            $('.mmpdb-modal').on('click', (e) => {
                if ($(e.target).hasClass('mmpdb-modal')) {
                    this.closeModal();
                }
            });
        }
        openModal(url) {
            $('.mmpdb-modal__iframe').attr('src', url);
            $('.mmpdb-modal').addClass('mmpdb-modal--active');
            $('body').addClass('modal-is-open');
        }
        closeModal() {
            $('.mmpdb-modal').removeClass('mmpdb-modal--active');
            $('body').removeClass('modal-is-open');
            $('.mmpdb-modal__iframe').attr('src', '');
        }
    }
    // Initialize on document ready
    $(document).ready(() => {
        window.mmpdbModal = new MMPDBModal();
    });
})(jQuery); 