# -*- coding: utf-8 -*-

from sysactions import (
    action,
    show_messagebox
)
from bustoken import TK_POS_UPDATER_PERFORM_CHROME_UPDATE
from msgbus import (
    TK_SYS_NAK,
    FM_PARAM
)

from .. import mb_context


@action
def update_chrome(
    pos_id   # type: str
):
    # type: (...) -> None

    resp = show_messagebox(
        posid=pos_id,
        message="$UPDATE_CHROME_MESSAGE_QUESTION",
        buttons="$OK|$CANCEL"
    )
    if resp == 1:
        return

    timeout = 60000000 * 20
    msg = mb_context.MB_EasySendMessage(
        dest_name="PosUpdater",
        token=TK_POS_UPDATER_PERFORM_CHROME_UPDATE,
        format=FM_PARAM,
        data="noValidation",
        timeout=timeout
    )
    if msg.token == TK_SYS_NAK  or msg.data:
        show_messagebox(
            posid=pos_id,
            message="$UPDATE_CHROME_" + msg.data.upper(),
            buttons="OK"
        )
        return

    show_messagebox(
        posid=pos_id,
        message="$UPDATE_CHROME_MESSAGE",
        buttons="OK"
    )
