__id__ = "sdk_tap_count"
__name__ = "Счётчик нажатий"
__version__ = "1.0"
__host__ = "NimarkoGram"
__sdk_version__ = ">=1.0"
__author__ = "NimarkoGram"

from base_plugin import BasePlugin, MenuItemData, MenuItemType
from client_utils import get_user_config
from ui.bulletin import BulletinHelper


class TapCounter(BasePlugin):
    def on_plugin_load(self):
        self.add_menu_item(MenuItemData(
            menu_type=MenuItemType.CHAT_ACTION_MENU,
            text=__name__,
            on_click=self.count_taps,
        ))

    def count_taps(self, context):
        account = context.get("account")
        if account is None:
            return
        user_id = get_user_config(account).getClientUserId()
        if not user_id:
            return
        key = f"taps_{user_id}"
        count = self.get_setting(key, 0) + 1
        self.set_setting(key, count)
        BulletinHelper.show_info(str(count))
