from datetime import datetime
from config import BOT_NAME, USDT_RATE, COMMAND_PREFIX

# --- MINIMALIST UI SYSTEM (STRICTLY NO EMOJIS) ---
DIVIDER = "━━━━━━━━━━━━━━━"
DECOR = "◈"

def get_footer():
    now = datetime.now().strftime("%d-%m-%Y | %I:%M %p")
    return f"{DIVIDER}\n{DECOR} `{now}`\nPᴏᴡᴇʀᴇᴅ Bʏ: **{BOT_NAME.upper()}**"

# --- TEMPLATES ---

def prefix_info_template(prefix):
    return f"""**Sʏsᴛᴇᴍ Pʀᴇғɪx**: `{prefix}`
{get_footer()}"""

def registration_success(fullname, user_id, role, status, currency, group_name):
    return f"""**Rᴇɢɪsᴛʀᴀᴛɪᴏɴ Sᴜᴄᴄᴇssғᴜʟ**
{DIVIDER}
➪ **Nᴀᴍᴇ**: {fullname}
➪ **ID**: `{user_id}`
➪ **Rᴀɴᴋ**: {role.upper()}
{get_footer()}"""

def signup_success(fullname, user_id, role, status, currency, group_name):
    return f"""**Usᴇʀ Sɪɢɴᴇᴅ Uᴘ**
{DIVIDER}
▪ {fullname} (`{user_id}`)
▪ Rᴀɴᴋ: {role.upper()}
{get_footer()}"""

def signout_success(fullname, user_id, role, status, balance, currency):
    return f"""**Usᴇʀ Tᴇʀᴍɪɴᴀᴛɪᴏɴ**
{DIVIDER}
▪ Nᴀᴍᴇ: {fullname}
▪ Bᴀʟ : {balance:.2f} {currency}
{get_footer()}"""

def profile_template(fullname, user_id, role, status):
    return f"""**Usᴇʀ Pʀᴏғɪʟᴇ**
{DIVIDER}
➪ **Nᴀᴍᴇ**: {fullname}
➪ **ID**: `{user_id}`
➪ **Rᴀɴᴋ**: {role.upper()} | {status.upper()}
{get_footer()}"""

def balance_template(name, due, balance, due_limit, currency):
    return f"""**Wᴀʟʟᴇᴛ Sᴜᴍᴍᴀʀʏ**
{DIVIDER}
➪ **Bᴀʟ**: `{balance:.2f} {currency}`
➪ **Dᴜᴇ**: `{due:.2f} {currency}`
➪ **Lɪᴍ**: `{due_limit:.2f} {currency}`
{get_footer()}"""

def due_template(due, currency):
    return f"""**Dᴜᴇ Rᴇᴘᴏʀᴛ**: `{due:.2f} {currency}`
{get_footer()}"""

def limit_info_template(due_limit, current_due, currency):
    available = max(0, due_limit - current_due)
    return f"""**Cʀᴇᴅɪᴛ Lɪᴍɪᴛ**
{DIVIDER}
▪ **Tᴏᴛᴀʟ**: `{due_limit:.2f}`
▪ **Usᴇᴅ**: `{current_due:.2f}`
▪ **Aᴠᴀɪʟ**: `{available:.2f}`
{get_footer()}"""

def product_stock_template(products, usdt_rate, is_admin=False):
    lines = [f"▪ {p['name']} ➜ `{p['stock']} ᴘᴄs`" for p in products]
    body = "\n".join(lines) if lines else "No stock."
    
    if is_admin:
        total = sum(p['rate'] * p['stock'] for p in products)
        return f"""**Sᴛᴏᴄᴋ Rᴇᴘᴏʀᴛ**
{DIVIDER}
{body}
{DIVIDER}
▪ **Wᴏʀᴛʜ**: `{total:,.0f} BDT` | `${total/usdt_rate:.2f}`
{get_footer()}"""
    return f"""**Aᴠᴀɪʟᴀʙʟᴇ Sᴛᴏᴄᴋ**
{DIVIDER}
{body}
{get_footer()}"""

def product_rate_template(products, usdt_rate=125.0, curr='BDT'):
    lines = []
    for p in products:
        price = p['rate'] / usdt_rate if curr == 'USDT' else p['rate']
        lines.append(f"▪ {p['name']} ➜ `{price:.2f} {curr}`")
    body = "\n".join(lines) if lines else "No rates."
    return f"""**Pʀɪᴄᴇ Lɪsᴛ**
{DIVIDER}
{body}
{get_footer()}"""

def order_success_template(fullname, prod_name, qty, total_cost, old_balance, codes, is_credit=False, curr='BDT'):
    code_text = "\n".join([f"`{c}`" for c in codes])
    balance_line = f"Dᴜᴇ: {old_balance+total_cost:.2f}" if is_credit else f"Bᴀʟ: {old_balance-total_cost:.2f}"
    return f"""**Dɪɢɪᴛᴀʟ Rᴇᴄᴇɪᴘᴛ**
{DIVIDER}
➪ **Iᴛᴇᴍ**: {prod_name} x{qty}
➪ **Pɪɴs**:
{code_text}
{DIVIDER}
➪ {balance_line} {curr}
{get_footer()}"""

def error_template(msg):
    return f"""**Sʏsᴛᴇᴍ Eʀʀᴏʀ**
{DIVIDER}
! `{msg}`
{get_footer()}"""

def success_template(msg):
    return f"""**Sʏsᴛᴇᴍ Nᴏᴛɪғɪᴄᴀᴛɪᴏɴ**
{DIVIDER}
✓ {msg}
{get_footer()}"""

def balance_added_template(fullname, amount, previous, current, currency):
    return f"""**Bᴀʟᴀɴᴄᴇ Aᴅᴅᴇᴅ**
{DIVIDER}
➪ **Usᴇʀ**: {fullname}
➪ **Aᴍᴛ**: `+{amount:.2f}`
➪ **Nᴇᴡ**: `{current:.2f} {currency}`
{get_footer()}"""

def payment_template(info):
    return f"""**Pᴀʏᴍᴇɴᴛ Mᴇᴛʜᴏᴅs**
{DIVIDER}
{info}
{DIVIDER}
*Usᴇ `{COMMAND_PREFIX}ᴠᴇʀɪғʏ TXNID`*"""

def key_template(key, url):
    return f"""**Lɪᴄᴇɴsᴇ Kᴇʏ**: `{key}`
{get_footer()}"""

def admin_user_info_template(user):
    return f"""**Usᴇʀ Dᴇᴛᴀɪʟs (Aᴅᴍɪɴ)**
{DIVIDER}
➪ **Nᴀᴍᴇ**: {user['fullname']} | `{user['user_id']}`
➪ **Bᴀʟ**: `{user['balance']}` | **Dᴜᴇ**: `{user['due']}`
{get_footer()}"""

def stats_template(stats):
    return f"""**Sʏsᴛᴇᴍ Sᴛᴀᴛs**
{DIVIDER}
▪ **Usᴇʀs**: `{stats['total_users']}`
▪ **Bᴀʟ**: `{stats['total_balance']:.0f}`
▪ **Dᴜᴇ**: `{stats['total_due']:.2f}`
{get_footer()}"""

def uid_info_template(uid, name, server):
    return f"""┏━━━━━━━━━━━━━━┓
      **UID Dᴇᴛᴀɪʟs**
┗━━━━━━━━━━━━━━┛
  ◈ **Usᴇʀɴᴀᴍᴇ**: `{name}`
  ◈ **ID Nᴜᴍʙᴇʀ**: `{uid}`
  ◈ **Rᴇɢɪᴏɴ**: `{server.upper()}`
{get_footer()}"""
