'use strict';

const BaseComponent = (function () {
    function BaseComponent(container) {
        this.container = container;
    }

    BaseComponent.prototype.render = function () {
        throw new Error('render() must be implemented');
    };

    BaseComponent.prototype.mount = function () {
        const html = this.render();
        const wrapper = document.createElement('div');
        wrapper.innerHTML = html;

        // Append the first element (skip text nodes)
        const element = wrapper.firstElementChild;
        if (element) {
            this.element = element;
            this.container.appendChild(element);
            this.afterMount();
        }
    };

    BaseComponent.prototype.afterMount = function () {
        // Override for event listeners, etc.
    };

    BaseComponent.prototype.destroy = function () {
        if (this.element && this.element.parentNode) {
            this.element.parentNode.removeChild(this.element);
        }
    };

    return BaseComponent;
})();
