import locales
import handlers
from profiles.ProfileManager import *
from bot import bot
from keyboards.language_kb import language_keyboard
import handlers.guide
from handlers.final import final

class StartHandler:
    @staticmethod
    @bot.message_handler(commands=["start"])
    def start(message):

        parts = message.text.split(maxsplit = 1)

        ref_id = 0
        if len(parts) > 1:
            try:
                ref_id = int(parts[1])
            except:
                pass

        p = reg(message.chat.id, message.message_id+1, bot, ref_id)


        if(not(p.step == ProfileStep.FINAL)):
            text = (
                f"{locales.get(p.language, 'language_title')}"
            )

            handlers.ui.render(
                p,
                message.chat.id,
                text,
                reply_markup=language_keyboard(
                    texts=locales.LANGUAGES[p.language]
                )
            )
            p.step = ProfileStep.START
            update(p)
        else:
            final(p)


