import asyncio
from typing import Any, cast

import imagetext_py
import PIL.Image

from konabot.common.path import ASSETS_PATH

from .base.fonts import HARMONYOS_SANS_SC_BLACK

geimao_image = PIL.Image.open(ASSETS_PATH / "img" / "meme" / "geimao.jpg").convert("RGBA")


def _draw_geimao(saying: str):
    img = geimao_image.copy()
    with imagetext_py.Writer(img) as iw:
        iw.draw_text_wrapped(
            saying, 960, 50, 00.5, 0, 1920, 240, HARMONYOS_SANS_SC_BLACK,
            imagetext_py.Paint.Color(imagetext_py.Color.from_hex("000000FF")),
            0.8,
            imagetext_py.TextAlign.Center,
            cast(Any, 30.0),
            imagetext_py.Paint.Color(imagetext_py.Color.from_hex("FFFFFFFF")),
            draw_emojis=True,
        )
    return img
    

async def draw_geimao(saying: str):
    return await asyncio.to_thread(_draw_geimao, saying)