# দেশি কোর্স — Lovable Credit Selling Site

dpmarket-style design e Bangla digital product (Lovable Credit) selling site. Brand: **দেশি কোর্স** (logo: purple gradient circle, provided). Backend Supabase, order notifications via Telegram bot (configurable from admin dashboard), delivery via email.

## Phase 1 — Setup
- Supabase enable (database, auth)
- Logo → `src/assets/logo.png`
- Database tables:
  - `packages` — id, name, credits, price_bdt, description, is_active, sort_order, created_at
  - `orders` — id, package_id, quantity, total_bdt, customer_email, whatsapp, transaction_id, payment_method, status (pending/verified/delivered/rejected), telegram_message_id, delivered_at, created_at
  - `telegram_settings` — single-row config (bot_token, admin_chat_id, webhook_secret, is_enabled, connected_at)
  - `user_roles` — admin role table + `has_role()` security definer fn
- Seed: 205 Credit package
- RLS: public read active packages, public insert orders, admin-only updates; `telegram_settings` admin-only

## Phase 2 — Public Storefront (dpmarket inspired, দেশি কোর্স brand)
- **Top promo bar**: countdown / flash sale style
- **Header**: দেশি কোর্স logo + nav (Home, Packages, How it works, Contact) + Login
- **Hero**: "Lovable Credit kinun shobcheye shoja upay e" — search-bar style CTA, floating product mockup cards, trust badges
- **Packages grid**:
  - 205 Credits card (primary, highlighted)
  - Quantity selector (1, 2, 3, 4, 5…) — total auto-multiplies live (205 → 410 → 615…)
  - "Order Now" CTA
- **How it works**: 3 steps (Choose → Pay bKash/Nagad → Email e credit pan)
- **FAQ + Footer**

## Phase 3 — Order Flow (no payment gateway yet)
- Order page form:
  - Package + quantity (locked from selection)
  - Email (required, zod validated)
  - WhatsApp (optional)
  - Payment method (bKash / Nagad radio)
  - Transaction ID (optional)
  - Notes
- Submit → public server route `/api/public/orders` (zod validated, rate-limit) inserts order as `pending`
- **Auto-trigger**: order create hoile Telegram bot e sundor formatted message jay (only if Telegram is connected from admin dashboard):
  ```
  🔔 New Order #1234
  📦 205 Credits × 2 = 410 BDT
  📧 customer@email.com
  📱 +880xxx
  💳 bKash — TXN: ABC123
  ⏰ just now
  ```
  Inline buttons: ✅ Verify | 🚫 Reject | 📋 Copy Email | 🔗 Open Dashboard
- Order success page with order ID

## Phase 4 — Admin Dashboard
- Email/password auth (admin only, no public signup)
- Protected `/admin/*` route with sidebar
- **Dashboard home**: stat cards (Total/Pending/Verified/Delivered orders, Revenue, Customers), recent orders, sales chart
- **Packages**: CRUD — admin chaile notun package add korte parbe (different credit sizes ba onno product)
- **Orders**:
  - Filter (status, date, search)
  - Row → detail drawer
  - Action buttons per order:
    - **Verify Payment** → status `verified`
    - **Mark Delivered & Send Email** → opens email composer modal (pre-filled beautiful HTML template with credits info, redeem steps, branding) → admin edit korte parbe → Send → email pathay + status `delivered` + Telegram message update hoy "✅ Delivered"
    - **Reject** → status `rejected`
  - Copy email button on every row
- **Customers**: unique email list, total orders/spend
- **Settings → Telegram Connection** (key feature):
  - Form e Bot Token + Admin Chat ID input
  - "Test Connection" button → bot er getMe + test message pathiye verify
  - "Save & Connect" → saves to `telegram_settings`, auto-registers webhook with Telegram
  - Connected status indicator, Disconnect button
  - Instructions: "BotFather theke bot create korun, token paste korun, /start botke message diye chat ID nin"

## Phase 5 — Telegram Bot ↔ Dashboard Integration
- Server fn `notifyTelegram(orderId)` — reads token from `telegram_settings`, sends formatted message with inline keyboard
- Webhook server route `/api/public/telegram/webhook` (secret-token verified):
  - Handles button callbacks → updates order in DB → edits original Telegram message to reflect new status
  - "Send Email" callback → triggers same delivery email as dashboard button
- Webhook auto-registered when admin connects Telegram from settings page
- **Result**: admin can verify orders + deliver credits + send email — directly from Telegram OR dashboard

## Phase 6 — Email Delivery
- Lovable built-in email (no extra setup)
- **Delivery email template** (React Email): purple gradient header, দেশি কোর্স logo, "Apnar 410 Lovable Credit Ready!", redeem instructions, support contact, footer
- Composer modal in dashboard: subject + HTML body pre-filled, preview, Send
- Idempotent: `idempotencyKey = "order-deliver-${orderId}"`

## Phase 7 — Polish
- Mobile responsive
- Bangla + English mix copy
- Toasts, loading skeletons, empty states
- SEO meta per route

## Out of scope (future)
- Pipra Pay gateway integration
- Customer accounts/order history page
- Auto payment verification

## Design tokens
- Primary: purple gradient (`oklch(0.5 0.22 280)` → `oklch(0.65 0.2 295)`) matching logo
- Background: white + lavender tint sections
- Cards: white, rounded-2xl, soft shadow
- Font: Plus Jakarta Sans / Inter
- Logo: header + footer + email template

## Routes
- `/`, `/packages`, `/order/$packageId`, `/order-success/$orderId`, `/login`
- `/admin`, `/admin/packages`, `/admin/orders`, `/admin/customers`, `/admin/settings`
- `/api/public/orders` (POST), `/api/public/telegram/webhook` (POST)

## Secrets
- None upfront — Telegram bot token admin dashboard theke save hobe (DB te encrypted-at-rest via Supabase)
- Email uses Lovable built-in
