# -*- coding: utf-8 -*-
import sysactions
from systools import sys_log_exception

from actions.void.do_void_remote_order import void_remote_order
from custom_sysactions import user_authorized_to_execute_action


@sysactions.action
@user_authorized_to_execute_action
def do_ask_void_remote_order(
    pos_id,              # type: str
    remote_id,           # type: str
):
    # type: (...) -> bool

    try:
        message = "$CONFIRM_VOID_ORDER"
        confirmation = sysactions.show_messagebox(
            posid=pos_id,
            message=message,
            title="$TABLE_INFO",
            timeout=720000,
            buttons="$OK|$CANCEL",
        )

        if confirmation == 1:
            return False

        return void_remote_order(
            pos_id=pos_id,
            remote_id=remote_id,
        )
    except Exception as ex:
        sys_log_exception("Error voiding delivery order")
        sysactions.show_messagebox(pos_id, "$ERROR_VOIDING_REMOTE_ORDER|{}".format(ex))
