/** @odoo-module **/

import { registerMessageAction } from "@mail/core/common/message_actions";
import { useService } from "@web/core/utils/hooks";
import { _t } from "@web/core/l10n/translation";

/**
 * Register "Move to Mailbox" action in the message action menu.
 * Pункт 2: пользователь может вручную перенести сообщение в ящик.
 */
registerMessageAction("tier-move-to-mailbox", {
    condition: ({ message }) => Boolean(message?.id && Number.isInteger(message.id)),
    icon: "fa fa-inbox",
    name: _t("Переместить в ящик"),
    setup: ({ owner }) => {
        owner.tierActionService = useService("action");
    },
    onSelected: async ({ message, owner }) => {
        await owner.tierActionService.doAction({
            type: "ir.actions.act_window",
            name: _t("Переместить в ящик"),
            res_model: "tier.move.to.mailbox.wizard",
            view_mode: "form",
            views: [[false, "form"]],
            target: "new",
            context: {
                default_message_id: message.id,
            },
        });
    },
    sequence: 90,
});
