import handlers
import profiles
import locales
from profiles.ProfileManager import *
from keyboards.basic_kb import inline
import profiles.ProfileStep as ProfileStep
from bot import bot
from handlers.final import final

@bot.callback_query_handler(func=lambda c:c.data.startswith("btn_po_"))
def pocket(call):
    p = get_full_profile_by_tg_id(call.from_user.id)
    p = link_po(p)

    p.print()

    if(not(p.reg) and not(p.ftd) and (p.step == ProfileStep.POCKET_REG)):
        bot.answer_callback_query(
            callback_query_id=call.id,
            text= f"{locales.get(p.language, 'po_not_found_title')}",
            show_alert=False
        )
    elif(not(p.ftd) and (p.step == ProfileStep.POCKET_FTD)):
        bot.answer_callback_query(
            callback_query_id=call.id,
            text= f"{locales.get(p.language, 'po_only_reg_title')}",
            show_alert=False
        )
    else:
        if(p.reg):
            if(p.ftd):
                bot.send_message(group_log, str(p.tg_id) + ' депнул и получил ссылку на приватку')
                final(p)
            else:
                text = (
                    f"{locales.get(p.language, 'po_only_reg_title')}\n\n"
                    f"{locales.get(p.language, 'po_only_reg_subtitle')}"
                )

                reply_markup = inline("btn_po_find_again", p)

                handlers.ui.render(
                    p,
                    call.message.chat.id,
                    text,
                    reply_markup=reply_markup
                )
                p.step = ProfileStep.POCKET_FTD
        else:
            text = (
                f"{locales.get(p.language, 'po_not_found_title')}\n\n"
                f"{locales.get(p.language, 'po_not_found_subtitle')}"
            )

            reply_markup = inline("btn_po_find_again", p)

            handlers.ui.render(
                p,
                call.message.chat.id,
                text,
                reply_markup=reply_markup
            )
            p.step = ProfileStep.POCKET_REG

    update(p)

