import pygame as pg
from modules import DB


def get_frogs_img(name):
    frogs_img = {
        "Квакуша": "1.jpg",
        "Квакша": "2.jpg",
        "Квак": "3.jpg",
        "Ква": "4.jpg",
        "Кваква": "5.jpg",
        "Джабба-хатт": "6.jpg",
        "Квендальф": "7.jpg",
        "Лягуша": "8.jpg",
        "Жаба": "9.jpg",
        "Абажаю": "10.jpg",
        "Пучеглазый": "11.jpg",
        "Вафля": "12.jpg",
        "13": "13.jpg",
        "14": "14.jpg",
        "15": "15.jpg",
        "16": "16.jpg",
        "17": "17.jpg",
        "18": "18.jpg",
        "19": "19.jpg",
        "20": "20.jpg",
        "21": "21.jpg",
        "22": "22.jpg",
        "23": "23.jpg"
    }
    frogs_img_prepare = frogs_img[name]
    frogs_img_str = f"styles/frogs/{frogs_img_prepare}"
    return frogs_img_str


class Book:  # Окно с необходимой информацией
    @staticmethod
    def info(screen, event):
        db = DB.UseDB("game")
        response = db.find_document(
            {}
        )[0]
        pg.draw.rect(screen, (38, 33, 55), (85, 0, 520, 500))
        pg.draw.rect(screen, (255, 255, 255), (100, 90, 495, 280), 1)
        texts = [f'День {response["day"]}', 'Сегодня произошло следующее:',
                 f"{event['name']}", f"{event['description']}"]
        sizes = [60, 30, 30, 30]
        coords = [(260, 30), (110, 100), (110, 150), (110, 190)]
        for i in range(len(texts)):
            font = pg.font.Font(None, sizes[i])
            text = font.render(texts[i], True, (255, 255, 255))
            screen.blit(text, coords[i])
        frogs = []
        for i in response["frogs"]:
            frogs.append((i["name"], [i["hp"], i["hunger"]]))

        font = pg.font.Font(None, 15)  # Здесь будет указана информация о некоторых лягушках
        for col in range((len(frogs) - 1) % 4 + 1):
            for row in range((len(frogs) - 1) // 4 + 1):
                if col == 0:
                    i = row
                elif col == 1:
                    i = row + 3
                elif col == 2:
                    i = row + 6
                else:
                    i = row + 9
                myimage = pg.image.load(get_frogs_img(frogs[i][0]))
                scaled_image = pg.transform.smoothscale(myimage, (34, 34))
                screen.blit(scaled_image, (100 + 120 * col + 1, 375 + 40 * row + 1))
                pg.draw.rect(screen, (0, 0, 0), (100 + 120 * col, 375 + 40 * row, 35, 35),
                             3)  # Рамка с портретом лягушки
                text = font.render(f'{frogs[i][0]} - ', True, (255, 255, 255))
                screen.blit(text, (140 + 120 * col, 375 + 40 * row))
                text = font.render(f'{frogs[i][-1][0]}% зд.,', True, (255, 255, 255))
                screen.blit(text, (140 + 120 * col, 385 + 40 * row))
                text = font.render(f'{frogs[i][-1][1]}% голода', True, (255, 255, 255))
                screen.blit(text, (140 + 120 * col, 395 + 40 * row))
