/**
 * CommissionView.js — کمیسیون ماده ۱۰۰
 */

import BaseView from "../../core/BaseView.js";
import { viewRegistry } from "../../core/registries.js";
import CommissionViewerSection from "./sections/CommissionViewerSection.js";

const SECTIONS = [
    { key:"viewer", icon:"🔨", title:"بررسی پرونده‌های کد نوسازی", desc:"همه پرونده‌ها / رأی‌ها / تخلفات", Class: CommissionViewerSection },
];

export default class CommissionView extends BaseView {

    static title = "کمیسیون ماده ۱۰۰";
    useContextBadge = true;

    constructor(props = {}) {
        super(props);
        this.api = props.api;
        this._active = "viewer";
        this._sections = {};
        this._initialCode = props.tab?.params?.code
                          ?? sessionStorage.getItem('acc_commission_pending_code')
                          ?? null;
        if (this._initialCode) sessionStorage.removeItem('acc_commission_pending_code');
    }

    async template() {
        return `<div data-ref="root"></div>`;
    }

    async afterRender() {
        const root = this.ref("root");
        const def = SECTIONS[0];
        const sec = new def.Class({
            eventBus: this.eventBus, store: this.store, tab: this.tab, api: this.api,
            initialCode: this._initialCode,
        });
        await sec.render(root);
        this._sections.viewer = sec;
    }

    destroy() {
        Object.values(this._sections).forEach(s => s?.destroy?.());
        super.destroy();
    }
}

viewRegistry.register("commission", CommissionView);
