/**
 * ServicePortalOperations — سکشن‌های ERP خدمات میدانی داخل پورتال مستقل
 */
import ApiClient from '../../core/ApiClient.js';
import ServiceView from '../../modules/service/ServiceView.js';
import SimpleEventBus from './SimpleEventBus.js';

export default class ServicePortalOperations {
    constructor({ root, apiBase }) {
        this.root = root;
        this.apiBase = apiBase;
        this.eventBus = new SimpleEventBus();
        this.view = null;
    }

    async init() {
        if (!this.root) return;
        this.root.innerHTML = '<div class="svc-ops-mount" data-ref="mount"></div>';
        const mount = this.root.querySelector('[data-ref="mount"]');

        const api = new ApiClient({
            config: { apiUrl: this.apiBase },
            eventBus: this.eventBus,
        });

        this.view = new ServiceView({
            api,
            eventBus: this.eventBus,
            store: null,
            tab: { title: 'خدمات میدانی', fixed: true },
        });

        await this.view.render(mount);
    }

    destroy() {
        this.view?.destroy?.();
        this.view = null;
    }
}
