// Fusion Accounting - Attachment View Move Line
// Copyright (C) 2026 Nexa Systems Inc.

import { AttachmentView } from "@mail/core/common/attachment_view";
import { onMounted } from "@odoo/owl";
import { useBus } from "@web/core/utils/hooks";

/**
 * AttachmentViewMoveLine - Extended attachment viewer for journal entries.
 * Provides PDF preview with page navigation tied to move line selection.
 */
export class AttachmentViewMoveLine extends AttachmentView {
    static props = [...AttachmentView.props, "openInPopout"];
    static components = { AttachmentView };

    setup() {
        super.setup();
        if (this.props.openInPopout) {
            onMounted(this.onClickPopout);
        }
        // In the mail_popout_service.js the function pollClosedWindow will trigger a resize event on the main window
        // when the external window is closed. It allow us to know when to hide the preview for small screens.
        useBus(this.uiService.bus, "resize", () => this.env.setPopout(false));
    }
}
