import os
import logging
import logging.config

# Get logging configurations
logging.getLogger().setLevel(logging.ERROR)
logging.getLogger("pyrogram").setLevel(logging.WARNING)

from .commands import start, BATCH
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from config import *

@Client.on_callback_query(filters.regex('^help$'))
async def help_cb(c, m):
    await m.answer()

    # help text
    help_text = """**You need Help?? ğŸ§�**

â˜… Just send me the files i will store file and give you share able link


**You can use me in channel too ğŸ˜‰**

â˜… Make me admin in your channel with edit permission. Thats enough now continue uploading files in channel i will edit all posts and add share able link url buttons

**How to enable uploader details in caption**

â˜… Use /mode command to change and also you can use `/mode channel_id` to control caption for channel msg."""

    # creating buttons
    buttons = [
        [
            InlineKeyboardButton('Home ğŸ�•', callback_data='home'),
            InlineKeyboardButton('About ğŸ“•', callback_data='about')
        ],
        [
            InlineKeyboardButton('Close ğŸ”�', callback_data='close')
        ]
    ]

    # editing as help message
    await m.message.edit(
        text=help_text,
        reply_markup=InlineKeyboardMarkup(buttons)
    )


@Client.on_callback_query(filters.regex('^close$'))
async def close_cb(c, m):
    await m.message.delete()
    await m.message.reply_to_message.delete()


@Client.on_callback_query(filters.regex('^about$'))
async def about_cb(c, m):
    await m.answer()
    owner = await c.get_users(int(OWNER_ID))
    bot = await c.get_me()

    # about text
    about_text = f"""--**My Details:**--

ğŸ¤– ğ��Œğ��² ğ���ğ��šğ��¦ğ���: {bot.mention(style='md')}
    
ğŸ“� ğ��‹ğ��šğ��§ğ�� ğ��®ğ��šğ�� ğ���: [Python 3](https://www.python.org/)

ğŸ§° ğ��…ğ��«ğ��šğ��¦ğ���ğ��°ğ��¨ğ��«ğ��¤: [Pyrogram](https://github.com/pyrogram/pyrogram)

ğŸ‘¨â€�ğŸ’» ğ��ƒğ���ğ��¯ğ���ğ��¥ğ��¨ğ��©ğ���ğ��«: {owner.mention(style='md')}

ğŸ“¢ ğ��‚ğ��¡ğ��šğ��§ğ��§ğ���ğ��¥: [NS BOT UPDATES](https://t.me/Ns_bot_updates)

ğŸ‘¥ ğ��†ğ��«ğ��¨ğ��®ğ��©: [Ns BOT SUPPORT](https://t.me/Ns_Bot_supporters)

ğŸŒ�ğ��’ğ��¨ğ��®ğ��«ğ��œğ��� ğ��‚ğ��¨ğ���ğ���: [Press Me ğŸ¥°](https://github.com/Ns-Bots/TG-File-Store)
"""

    # creating buttons
    buttons = [
        [
            InlineKeyboardButton('Home ğŸ�•', callback_data='home'),
            InlineKeyboardButton('Help ğŸ’¡', callback_data='help')
        ],
        [
            InlineKeyboardButton('Close ğŸ”�', callback_data='close')
        ]
    ]

    # editing message
    await m.message.edit(
        text=about_text,
        reply_markup=InlineKeyboardMarkup(buttons),
        disable_web_page_preview=True
    )


@Client.on_callback_query(filters.regex('^home$'))
async def home_cb(c, m):
    await m.answer()
    await start(c, m, cb=True)


@Client.on_callback_query(filters.regex('^done$'))
async def done_cb(c, m):
    BATCH.remove(m.from_user.id)
    c.cancel_listener(m.from_user.id)
    await m.message.delete()


@Client.on_callback_query(filters.regex('^delete'))
async def delete_cb(c, m):
    await m.answer()
    cmd, msg_id = m.data.split("+")
    chat_id = m.from_user.id if not DB_CHANNEL_ID else int(DB_CHANNEL_ID)
    message = await c.get_messages(chat_id, int(msg_id))
    await message.delete()
    await m.message.edit("Deleted files successfully ğŸ‘¨â€�âœˆï¸�")
