Created At: 2026-11-19T04:44:38Z Completed At: 2026-11-19T04:44:40Z Command exited with code 0. Command output: /root/telegram-saas/modules/billing/coupon_service.py:6:from modules.billing.models import Coupon, CouponRedemption, Referral /root/telegram-saas/modules/billing/coupon_service.py:10:class CouponService: /root/telegram-saas/modules/billing/coupon_service.py:11: """Manages discount coupons and referral rewards.""" /root/telegram-saas/modules/billing/coupon_service.py:17: async def validate_coupon( /root/telegram-saas/modules/billing/coupon_service.py:22: ) -> tuple[bool, Optional[Coupon], int, str]: /root/telegram-saas/modules/billing/coupon_service.py:24: Validates coupon against plan, order value, expiry date, and redemption limits. /root/telegram-saas/modules/billing/coupon_service.py:25: Returns: (is_valid, coupon, discount_amount, message) /root/telegram-saas/modules/billing/coupon_service.py:27: coupon = await self.repo.get_coupon_by_code(code) /root/telegram-saas/modules/billing/coupon_service.py:28: if not coupon: /root/telegram-saas/modules/billing/coupon_service.py:29: return False, None, 0, f"Coupon code '{code}' does not exist" /root/telegram-saas/modules/billing/coupon_service.py:31: if not coupon.is_active: /root/telegram-saas/modules/billing/coupon_service.py:32: return False, coupon, 0, f"Coupon '{code}' is no longer active" /root/telegram-saas/modules/billing/coupon_service.py:35: if coupon.expires_at and now > coupon.expires_at: /root/telegram-saas/modules/billing/coupon_service.py:36: return False, coupon, 0, f"Coupon '{code}' has expired" /root/telegram-saas/modules/billing/coupon_service.py:38: if coupon.max_redemptions and coupon.times_redeemed >= coupon.max_redemptions: /root/telegram-saas/modules/billing/coupon_service.py:39: return False, coupon, 0, f"Coupon '{code}' has reached its maximum redemptions limit" /root/telegram-saas/modules/billing/coupon_service.py:41: if coupon.applicable_plans and plan_id not in coupon.applicable_plans: /root/telegram-saas/modules/billing/coupon_service.py:42: return False, coupon, 0, f"Coupon '{code}' is not applicable to the '{plan_id}' plan" /root/telegram-saas/modules/billing/coupon_service.py:44: if order_amount < coupon.min_order_amount: /root/telegram-saas/modules/billing/coupon_service.py:45: return False, coupon, 0, f"Minimum order amount of {coupon.min_order_amount / 100:.2f} required for coupon" /root/telegram-saas/modules/billing/coupon_service.py:48: if coupon.discount_type == "percentage": /root/telegram-saas/modules/billing/coupon_service.py:49: discount = int(order_amount * (coupon.discount_value / 100)) /root/telegram-saas/modules/billing/coupon_service.py:51: discount = min(coupon.discount_value, order_amount) /root/telegram-saas/modules/billing/coupon_service.py:53: if coupon.max_discount_amount: /root/telegram-saas/modules/billing/coupon_service.py:54: discount = min(discount, coupon.max_discount_amount) /root/telegram-saas/modules/billing/coupon_service.py:56: return True, coupon, discount, "Coupon applied successfully" /root/telegram-saas/modules/billing/coupon_service.py:61: coupon_id: uuid.UUID, /root/telegram-saas/modules/billing/coupon_service.py:64: ) -> CouponRedemption: /root/telegram-saas/modules/billing/coupon_service.py:65: return await self.repo.record_coupon_redemption( /root/telegram-saas/modules/billing/coupon_service.py:67: coupon_id=coupon_id, /root/telegram-saas/modules/billing/service.py:20:from modules.billing.coupon_service import CouponService /root/telegram-saas/modules/billing/service.py:56: self.coupons = CouponService(db) /root/telegram-saas/modules/billing/service.py:216: coupon_id = None /root/telegram-saas/modules/billing/service.py:218: if req.coupon_code: /root/telegram-saas/modules/billing/service.py:219: is_valid, coupon, discount, _ = await self.coupons.validate_coupon( /root/telegram-saas/modules/billing/service.py:220: req.coupon_code, plan.id, plan.price_amount /root/telegram-saas/modules/billing/service.py:222: if is_valid and coupon: /root/telegram-saas/modules/billing/service.py:225: coupon_id = str(coupon.id) /root/telegram-saas/modules/billing/service.py:263: "coupon_id": coupon_id, /root/telegram-saas/modules/billing/service.py:399: # Record Coupon Redemption if applied /root/telegram-saas/modules/billing/service.py:400: coupon_id_str = (order.metadata_json or {}).get("coupon_id") /root/telegram-saas/modules/billing/service.py:401: if coupon_id_str and discount > 0: /root/telegram-saas/modules/billing/service.py:402: await self.coupons.record_redemption( /root/telegram-saas/modules/billing/service.py:404: coupon_id=uuid.UUID(coupon_id_str), /root/telegram-saas/modules/billing/service.py:438: coupon_code: Optional[str] = None, /root/telegram-saas/modules/billing/service.py:447: coupon_id = None /root/telegram-saas/modules/billing/service.py:448: if coupon_code: /root/telegram-saas/modules/billing/service.py:449: is_valid, coupon, discount, _ = await self.coupons.validate_coupon( /root/telegram-saas/modules/billing/service.py:450: coupon_code, plan.id, plan.price_amount /root/telegram-saas/modules/billing/service.py:452: if is_valid and coupon: /root/telegram-saas/modules/billing/service.py:455: coupon_id = str(coupon.id) /root/telegram-saas/modules/billing/service.py:552: coupon_code: Optional[str] = None, /root/telegram-saas/modules/billing/service.py:575: # Apply coupon if given /root/telegram-saas/modules/billing/service.py:577: if coupon_code: /root/telegram-saas/modules/billing/service.py:578: is_valid, coupon, d_amt, _ = await self.coupons.validate_coupon(coupon_code, new_plan.id, net_amount) /root/telegram-saas/modules/billing/service.py:587: coupon_code=coupon_code, grep: /root/telegram-saas/modules/billing/__pycache__/models.cpython-312.pyc: binary file matches grep: /root/telegram-saas/modules/billing/__pycache__/schemas.cpython-312.pyc: binary file matches grep: /root/telegram-saas/modules/billing/__pycache__/__init__.cpython-312.pyc: binary file matches grep: /root/telegram-saas/modules/billing/__pycache__/service.cpython-312.pyc: binary file matches grep: /root/telegram-saas/modules/billing/__pycache__/coupon_service.cpython-312.pyc: binary file matches grep: /root/telegram-saas/modules/billing/__pycache__/repository.cpython-312.pyc: binary file matches /root/telegram-saas/modules/billing/models.py:215:class Coupon(Base, UUIDPrimaryKeyMixin, TimestampMixin): /root/telegram-saas/modules/billing/models.py:216: """Promotional discount coupons with usage restrictions and limits.""" /root/telegram-saas/modules/billing/models.py:217: __tablename__ = "coupons" /root/telegram-saas/modules/billing/models.py:226: times_redeemed: Mapped[int] = mapped_column(Integer, default=0, nullable=False) /root/telegram-saas/modules/billing/models.py:231: redemptions: Mapped[list["CouponRedemption"]] = relationship("CouponRedemption", back_populates="coupon") /root/telegram-saas/modules/billing/models.py:234:class CouponRedemption(Base, UUIDPrimaryKeyMixin, TenantMixin, TimestampMixin): /root/telegram-saas/modules/billing/models.py:235: """Audit of applied coupons.""" /root/telegram-saas/modules/billing/models.py:236: __tablename__ = "coupon_redemptions" /root/telegram-saas/modules/billing/models.py:238: coupon_id: Mapped[uuid.UUID] = mapped_column( /root/telegram-saas/modules/billing/models.py:240: ForeignKey("coupons.id", ondelete="CASCADE"), /root/telegram-saas/modules/billing/models.py:252: coupon: Mapped["Coupon"] = relationship("Coupon", back_populates="redemptions") /root/telegram-saas/modules/billing/schemas.py:50: coupon_code: Optional[str] = None /root/telegram-saas/modules/billing/schemas.py:86: coupon_code: Optional[str] = None /root/telegram-saas/modules/billing/schemas.py:164: coupon_code: Optional[str] = None /root/telegram-saas/modules/billing/schemas.py:167:class ValidateCouponRequest(BaseModel): /root/telegram-saas/modules/billing/schemas.py:172:class CouponValidationResponse(BaseModel): /root/telegram-saas/modules/billing/__init__.py:10: Coupon, /root/telegram-saas/modules/billing/__init__.py:11: CouponRedemption, /root/telegram-saas/modules/billing/__init__.py:25: "Coupon", /root/telegram-saas/modules/billing/__init__.py:26: "CouponRedemption", /root/telegram-saas/modules/billing/repository.py:16: Coupon, /root/telegram-saas/modules/billing/repository.py:17: CouponRedemption, /root/telegram-saas/modules/billing/repository.py:328: # --- Coupons --- /root/telegram-saas/modules/billing/repository.py:329: async def get_coupon_by_code(self, code: str) -> Optional[Coupon]: /root/telegram-saas/modules/billing/repository.py:330: res = await self.db.execute(select(Coupon).where(Coupon.code == code.upper())) /root/telegram-saas/modules/billing/repository.py:333: async def create_coupon(self, coupon: Coupon) -> Coupon: /root/telegram-saas/modules/billing/repository.py:334: self.db.add(coupon) /root/telegram-saas/modules/billing/repository.py:336: await self.db.refresh(coupon) /root/telegram-saas/modules/billing/repository.py:337: return coupon /root/telegram-saas/modules/billing/repository.py:339: async def record_coupon_redemption( /root/telegram-saas/modules/billing/repository.py:342: coupon_id: uuid.UUID, /root/telegram-saas/modules/billing/repository.py:345: ) -> CouponRedemption: /root/telegram-saas/modules/billing/repository.py:346: redemption = CouponRedemption( /root/telegram-saas/modules/billing/repository.py:349: coupon_id=coupon_id, /root/telegram-saas/modules/billing/repository.py:354: # Increment coupon times_redeemed /root/telegram-saas/modules/billing/repository.py:356: update(Coupon) /root/telegram-saas/modules/billing/repository.py:357: .where(Coupon.id == coupon_id) /root/telegram-saas/modules/billing/repository.py:358: .values(times_redeemed=Coupon.times_redeemed + 1) /root/telegram-saas/modules/bots/modular_engine.py:77: "min_payout_points": {"type": "integer", "title": "Redeem Threshold", "default": 50}, grep: /root/telegram-saas/modules/bots/__pycache__/modular_engine.cpython-312.pyc: binary file matches /root/telegram-saas/apps/frontend/src/components/pages/AIAgentsPage.tsx:99: 'Are there any active discount coupons?', /root/telegram-saas/apps/frontend/src/components/pages/BotBuilderPage.tsx:69: 'You are the Digital Store Concierge. Guide shoppers through product tiers, compute discounts with valid coupon codes, and issue secure payment invoices using server-side webhook confirmation.', /root/telegram-saas/apps/frontend/src/components/modules/ModuleConfigModal.tsx:922: Min Redeem Points /root/telegram-saas/apps/frontend/dist/assets/index-JXkSu5zf.js:89:Type your query below or tap an option to proceed:`},ecommerce:{bot_name:"Digital Store & Checkout Bot",headline:"High-converting Telegram storefront with catalog browsing and Razorpay/Stripe checkout.",category:"E-Commerce",matched_blueprint:"bot_ecommerce_concierge",system_prompt:"You are the Digital Store Concierge. Guide shoppers through product tiers, compute discounts with valid coupon codes, and issue secure payment invoices using server-side webhook confirmation.",selected_modules:["welcome_message","payments","subscriptions"],selected_mcp_tools:["payments.checkout","message.send"],preview_text:`๐Ÿ›๏ธ Welcome to Digital Store /root/telegram-saas/apps/frontend/dist/assets/index-JXkSu5zf.js:107:You must join our channel to use this bot.`}),e.jsxs("div",{className:"space-y-1.5 pt-1",children:[e.jsx("div",{className:"w-full py-1.5 text-center text-xs font-mono font-semibold bg-[#2481CC]/20 text-[#2481CC] rounded-lg border border-[#2481CC]/30",children:r.button_text||"๐Ÿ“ข Join Official Channel"}),e.jsx("div",{className:"w-full py-1.5 text-center text-xs font-mono font-semibold bg-space-850 text-pearl-300 rounded-lg border border-white/10",children:r.check_button_text||"๐Ÿ”„ Check Membership"})]})]})]})]}),n.id==="welcome_message"&&e.jsxs("div",{className:"space-y-5 animate-in fade-in",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"Welcome Greeting Text (/start)"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-mono text-pearl-400",children:[e.jsx("span",{children:"Insert:"}),["{first_name}","{username}","{bot_name}"].map(v=>e.jsx("button",{type:"button",onClick:()=>{const R=r.welcome_text||"";C("welcome_text",R+" "+v)},className:"px-1.5 py-0.5 rounded bg-space-850 hover:bg-[#2481CC]/20 hover:text-[#2481CC] border border-white/10 text-pearl-300 transition-colors",children:v},v))]})]}),e.jsx("textarea",{rows:4,value:r.welcome_text||"",onChange:v=>C("welcome_text",v.target.value),placeholder:"๐ŸŒŸ Welcome to {bot_name}! Please select an option below:",className:"w-full p-3.5 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100 focus:border-[#2481CC] focus:outline-none"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-space-950/70 border border-white/10",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-pearl-100",children:"Formatting Mode"}),e.jsx("div",{className:"text-[11px] text-pearl-400",children:"Supports , , and tags"})]}),e.jsx("div",{className:"flex gap-1.5",children:["HTML","MarkdownV2"].map(v=>e.jsx("button",{type:"button",onClick:()=>C("parse_mode",v),className:`px-3 py-1.5 rounded-lg text-xs font-mono font-semibold transition-colors ${(r.parse_mode||"HTML")===v?"bg-[#2481CC] text-white shadow-telegram":"bg-space-900 text-pearl-400 hover:text-pearl-200"}`,children:v},v))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"Inline Action Buttons"}),e.jsxs("button",{type:"button",onClick:()=>{const v=r.buttons||[];C("buttons",[...v,[{text:"โœจ New Action",callback_data:`action_${Date.now()}`}]])},className:"text-xs font-mono text-[#2481CC] hover:underline flex items-center gap-1 font-semibold",children:[e.jsx(se,{className:"w-3.5 h-3.5"})," Add Button Row"]})]}),e.jsx("div",{className:"space-y-2",children:(r.buttons||[]).map((v,R)=>e.jsxs("div",{className:"p-3 rounded-xl bg-space-950/60 border border-white/10 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px] font-mono text-pearl-400",children:[e.jsxs("span",{children:["Row ",R+1]}),e.jsx("button",{type:"button",onClick:()=>{const $=[...r.buttons];$.splice(R,1),C("buttons",$)},className:"text-rose-400 hover:text-rose-300 p-1",children:e.jsx(Xe,{className:"w-3.5 h-3.5"})})]}),v.map(($,S)=>e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[e.jsx("input",{type:"text",value:$.text||"",onChange:D=>{const O=[...r.buttons];O[R][S].text=D.target.value,C("buttons",O)},placeholder:"Button Label",className:"px-3 py-1.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100"}),e.jsx("input",{type:"text",value:$.url||$.callback_data||"",onChange:D=>{const O=[...r.buttons];D.target.value.startsWith("http")?(delete O[R][S].callback_data,O[R][S].url=D.target.value):(delete O[R][S].url,O[R][S].callback_data=D.target.value),C("buttons",O)},placeholder:"URL (https://...) or callback_data",className:"px-3 py-1.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100"})]},S))]},R))})]})]}),n.id==="referrals"&&e.jsxs("div",{className:"space-y-5 animate-in fade-in",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"p-3.5 rounded-xl bg-space-950/80 border border-white/10 space-y-1",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-400 block font-semibold",children:"Points per Referral"}),e.jsx("input",{type:"number",min:1,value:r.points_per_referral??10,onChange:v=>C("points_per_referral",parseInt(v.target.value)||0),className:"w-full px-3 py-2 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 font-bold"})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-space-950/80 border border-white/10 space-y-1",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-400 block font-semibold",children:"Invited User Bonus"}),e.jsx("input",{type:"number",min:0,value:r.welcome_bonus_points??5,onChange:v=>C("welcome_bonus_points",parseInt(v.target.value)||0),className:"w-full px-3 py-2 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 font-bold"})]}),e.jsxs("div",{className:"p-3.5 rounded-xl bg-space-950/80 border border-white/10 space-y-1",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-400 block font-semibold",children:"Min Redeem Points"}),e.jsx("input",{type:"number",min:1,value:r.min_payout_points??50,onChange:v=>C("min_payout_points",parseInt(v.target.value)||0),className:"w-full px-3 py-2 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 font-bold"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"Referral Portal Card Template"}),e.jsx("textarea",{rows:5,value:r.invite_message||"",onChange:v=>C("invite_message",v.target.value),className:"w-full p-3.5 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100 focus:border-[#2481CC] focus:outline-none"}),e.jsxs("div",{className:"flex flex-wrap gap-1.5 text-[10px] font-mono text-pearl-400",children:[e.jsx("span",{children:"Variables:"}),["{bot_username}","{user_id}","{referral_count}","{referral_points}"].map(v=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-space-900 text-pearl-300 border border-white/5",children:v},v))]})]})]}),n.id==="auto_filter"&&e.jsxs("div",{className:"space-y-5 animate-in fade-in",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"Keyword Auto-Reply Rules"}),e.jsxs("button",{type:"button",onClick:()=>{const v=r.rules||[];C("rules",[...v,{trigger:"help",match_type:"contains",response:"How can we assist you today?"}])},className:"text-xs font-mono text-[#2481CC] hover:underline flex items-center gap-1 font-semibold",children:[e.jsx(se,{className:"w-3.5 h-3.5"})," Add Keyword Rule"]})]}),e.jsx("div",{className:"space-y-2.5",children:(r.rules||[]).map((v,R)=>e.jsxs("div",{className:"p-3.5 rounded-xl bg-space-950 border border-white/10 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"Trigger word (e.g. price)",value:v.trigger||"",onChange:$=>{const S=[...r.rules];S[R].trigger=$.target.value,C("rules",S)},className:"flex-1 px-3 py-1.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100"}),e.jsxs("select",{value:v.match_type||"contains",onChange:$=>{const S=[...r.rules];S[R].match_type=$.target.value,C("rules",S)},className:"px-2.5 py-1.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-200",children:[e.jsx("option",{value:"contains",children:"Contains text"}),e.jsx("option",{value:"exact",children:"Exact match"})]}),e.jsx("button",{type:"button",onClick:()=>{const $=[...r.rules];$.splice(R,1),C("rules",$)},className:"text-rose-400 hover:text-rose-300 p-1.5",children:e.jsx(Xe,{className:"w-4 h-4"})})]}),e.jsx("input",{type:"text",placeholder:"Auto-response message sent to user",value:v.response||"",onChange:$=>{const S=[...r.rules];S[R].response=$.target.value,C("rules",S)},className:"w-full px-3 py-1.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-emerald-300"})]},R))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"Prohibited & Spam Words"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",placeholder:"Add blocked word and press enter...",value:T,onChange:v=>B(v.target.value),onKeyDown:v=>{if(v.key==="Enter"&&(v.preventDefault(),T.trim())){const R=r.blocked_words||[];C("blocked_words",[...R,T.trim()]),B("")}},className:"flex-1 px-3 py-2 rounded-lg bg-space-950 border border-white/10 text-xs font-mono text-pearl-100"}),e.jsx("button",{type:"button",onClick:()=>{if(T.trim()){const v=r.blocked_words||[];C("blocked_words",[...v,T.trim()]),B("")}},className:"btn-telegram-secondary px-3 text-xs",children:"Add"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 pt-1",children:(r.blocked_words||[]).map((v,R)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-mono bg-rose-500/10 border border-rose-500/30 text-rose-300",children:[v,e.jsx("button",{type:"button",onClick:()=>{const $=[...r.blocked_words];$.splice(R,1),C("blocked_words",$)},className:"hover:text-rose-100",children:"ร—"})]},R))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-space-950/70 border border-white/10",children:[e.jsx("span",{className:"text-xs font-semibold text-pearl-200",children:"Action when blocked word is detected:"}),e.jsxs("select",{value:r.action_on_blocked||"warn",onChange:v=>C("action_on_blocked",v.target.value),className:"px-3 py-1.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100",children:[e.jsx("option",{value:"warn",children:"โš ๏ธ Warn user in chat"}),e.jsx("option",{value:"delete",children:"๐Ÿ—‘๏ธ Delete message"}),e.jsx("option",{value:"ignore",children:"๐Ÿšซ Silently ignore"})]})]})]}),n.id==="ai_assistant"&&e.jsxs("div",{className:"space-y-5 animate-in fade-in",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:"AI Large Language Model"}),e.jsxs("select",{value:r.model||"gpt-4o-mini",onChange:v=>C("model",v.target.value),className:"w-full px-3 py-2 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100",children:[e.jsx("option",{value:"gpt-4o-mini",children:"OpenAI GPT-4o Mini (Fast & Cheap)"}),e.jsx("option",{value:"gpt-4o",children:"OpenAI GPT-4o (State of the Art)"}),e.jsx("option",{value:"claude-3-5-sonnet",children:"Anthropic Claude 3.5 Sonnet"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:["Temperature (",r.temperature??.5,")"]}),e.jsx("input",{type:"range",min:0,max:1,step:.1,value:r.temperature??.5,onChange:v=>C("temperature",parseFloat(v.target.value)),className:"w-full mt-2 accent-[#2481CC]"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"System Instructions & Bot Persona"}),e.jsx("span",{className:"text-[10px] font-mono text-pearl-400",children:"1-Click Starter Presets:"})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[{label:"๐ŸŽง Support Desk",prompt:"You are the 24/7 Customer Support Concierge for this Telegram bot. Greet users warmly, resolve questions politely, and guide them clearly."},{label:"๐Ÿ’ผ VIP Sales Closer",prompt:"You are an enterprise sales advisor. Highlight the benefits of our VIP subscription tiers and offer assistance with checkout."},{label:"๐Ÿ“š FAQ Specialist",prompt:"You are a concise FAQ specialist. Answer subscriber queries with clear, numbered bullet points and helpful links."},{label:"๐ŸŒ Hindi/Multilingual",prompt:"Aap ek helpful AI assistant hain. User ki bhasha (Hindi, Hinglish, English) detect karein aur usi bhasha me naturally aur politely reply karein."}].map(v=>e.jsx("button",{type:"button",onClick:()=>C("system_prompt",v.prompt),className:"px-2 py-1 rounded-lg text-[11px] font-mono bg-space-900 border border-white/10 hover:border-[#2481CC] text-pearl-300 hover:text-white transition-colors",children:v.label},v.label))}),e.jsx("textarea",{rows:4,value:r.system_prompt||"",onChange:v=>C("system_prompt",v.target.value),placeholder:"You are an intelligent, polite AI Assistant for this Telegram bot...",className:"w-full p-3.5 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100 focus:border-[#2481CC] focus:outline-none"})]}),e.jsxs("div",{className:"flex items-center justify-between p-3.5 rounded-xl bg-space-950/70 border border-white/10",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-pearl-100",children:"Conversational Fallback"}),e.jsx("div",{className:"text-[11px] text-pearl-400",children:"When subscriber sends normal text (not a command), reply using AI"})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.enable_fallback??!1,onChange:v=>C("enable_fallback",v.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-11 h-6 bg-space-800 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-[#2481CC]"})]})]})]}),n.id==="broadcasts"&&e.jsxs("div",{className:"space-y-4 animate-in fade-in",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-space-950 border border-white/10 space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center text-xs font-mono",children:[e.jsx("span",{className:"text-pearl-200",children:"Broadcast Rate Limit:"}),e.jsxs("span",{className:"text-[#2481CC] font-bold",children:[r.rate_limit_per_second??25," msgs/sec"]})]}),e.jsx("input",{type:"range",min:5,max:30,value:r.rate_limit_per_second??25,onChange:v=>C("rate_limit_per_second",parseInt(v.target.value)),className:"w-full accent-[#2481CC]"}),e.jsx("p",{className:"text-[11px] text-pearl-400",children:"Telegram standard limit is 30 msgs/second. We recommend 25 msgs/sec for optimal reliability."})]}),e.jsxs("div",{className:"flex items-center justify-between p-3.5 rounded-xl bg-space-950 border border-white/10",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-pearl-100",children:"Allow Opt-Out Unsubscribe"}),e.jsx("div",{className:"text-[11px] text-pearl-400",children:"Subscribers can type /optout to stop receiving broadcasts"})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.allow_opt_out??!0,onChange:v=>C("allow_opt_out",v.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-11 h-6 bg-space-800 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-[#2481CC]"})]})]})]}),n.id==="payments"&&e.jsx("div",{className:"space-y-4 animate-in fade-in",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:"Default Currency"}),e.jsxs("select",{value:r.currency||"INR",onChange:v=>C("currency",v.target.value),className:"w-full px-3 py-2 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100",children:[e.jsx("option",{value:"INR",children:"INR (โ‚น) - Indian Rupee"}),e.jsx("option",{value:"USD",children:"USD ($) - US Dollar"}),e.jsx("option",{value:"EUR",children:"EUR (โ‚ฌ) - Euro"}),e.jsx("option",{value:"TON",children:"TON (๐Ÿ’Ž) - Telegram Open Network"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:"Active Payment Gateway"}),e.jsxs("select",{value:r.gateway||"razorpay",onChange:v=>C("gateway",v.target.value),className:"w-full px-3 py-2 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100",children:[e.jsx("option",{value:"razorpay",children:"Razorpay Checkout"}),e.jsx("option",{value:"stripe",children:"Stripe Payments"}),e.jsx("option",{value:"telegram_stars",children:"Telegram Stars โญ"})]})]})]})}),n.id==="subscriptions"&&e.jsx("div",{className:"space-y-4 animate-in fade-in",children:e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:"Grace Period Days after Expiry"}),e.jsx("input",{type:"number",min:0,value:r.grace_period_days??3,onChange:v=>C("grace_period_days",parseInt(v.target.value)||0),className:"w-full px-3 py-2 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100 font-bold"})]})}),n.id==="user_management"&&e.jsx("div",{className:"space-y-4 animate-in fade-in",children:e.jsxs("div",{className:"flex items-center justify-between p-3.5 rounded-xl bg-space-950 border border-white/10",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold text-pearl-100",children:"Auto-Detect Subscriber Locale"}),e.jsx("div",{className:"text-[11px] text-pearl-400",children:"Detect language preference from Telegram user profile"})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.auto_detect_locale??!0,onChange:v=>C("auto_detect_locale",v.target.checked),className:"sr-only peer"}),e.jsx("div",{className:"w-11 h-6 bg-space-800 rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-[#2481CC]"})]})]})}),e.jsxs("div",{className:"p-4 rounded-xl bg-space-950/90 border border-white/10 space-y-3",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{className:"w-4 h-4 text-[#2481CC]"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-mono font-bold uppercase tracking-wider text-pearl-100 block",children:"Pre-Flight Module Verification"}),e.jsx("span",{className:"text-[10px] text-pearl-400 font-sans",children:"Automated Telegram Bot admin, topic thread & configuration check"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.id==="logs_tracker"&&r.enable_topics&&e.jsxs("button",{type:"button",disabled:w||m,onClick:()=>E(!0),className:"btn-telegram-secondary py-1.5 px-3 text-[11px] font-mono inline-flex items-center gap-1.5 text-purple-300 hover:text-white border-purple-500/40",children:[w?e.jsx(oe,{className:"w-3.5 h-3.5 animate-spin text-purple-400"}):e.jsx(ce,{className:"w-3.5 h-3.5 text-purple-400"}),e.jsx("span",{children:w?"Testing Topic...":"๐Ÿงช Test Topic Creation"})]}),e.jsxs("button",{type:"button",disabled:m||w,onClick:()=>E(!1),className:"btn-telegram-secondary py-1.5 px-3 text-[11px] font-mono inline-flex items-center gap-1.5 text-[#2481CC] hover:text-white border-[#2481CC]/40",children:[m?e.jsx(oe,{className:"w-3.5 h-3.5 animate-spin text-[#2481CC]"}):e.jsx(Ee,{className:"w-3.5 h-3.5 text-[#2481CC]"}),e.jsx("span",{children:m?"Verifying Module...":"โšก Run Verification Check"})]})]})]}),y?e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:`p-3 rounded-xl border text-xs font-mono flex items-start justify-between gap-3 ${y.ok?"bg-emerald-500/10 border-emerald-500/30 text-emerald-300":y.warning?"bg-amber-500/10 border-amber-500/30 text-amber-300":"bg-rose-500/10 border-rose-500/30 text-rose-300"}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[y.ok?e.jsx(H,{className:"w-4 h-4 text-emerald-400 shrink-0 mt-0.5"}):y.warning?e.jsx($e,{className:"w-4 h-4 text-amber-400 shrink-0 mt-0.5"}):e.jsx(qt,{className:"w-4 h-4 text-rose-400 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-bold",children:y.ok?"Verification Passed: Module Ready for Live Execution":y.warning?`Warning: ${y.warning}`:"Verification Failed: Action Required"}),e.jsx("div",{className:"text-[11px] opacity-90 mt-0.5 font-sans",children:y.message||y.error})]})]}),e.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-bold uppercase tracking-wider shrink-0 ${y.ok?"bg-emerald-500/20 text-emerald-300":"bg-rose-500/20 text-rose-300"}`,children:y.ok?"READY โœ“":"ACTION NEEDED โœ—"})]}),y.checks&&y.checks.length>0&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs font-mono pt-1",children:y.checks.map((v,R)=>e.jsxs("div",{className:`p-2.5 rounded-lg border flex items-center justify-between gap-2 ${v.passed?"bg-emerald-500/5 border-emerald-500/20 text-pearl-200":"bg-rose-500/5 border-rose-500/25 text-rose-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[v.passed?e.jsx(V,{className:"w-3.5 h-3.5 text-emerald-400 shrink-0"}):e.jsx(q,{className:"w-3.5 h-3.5 text-rose-400 shrink-0"}),e.jsx("span",{className:"truncate",children:v.name})]}),e.jsx("span",{className:`text-[10px] truncate shrink-0 max-w-[120px] ${v.passed?"text-emerald-400 font-medium":"text-rose-400 font-bold"}`,children:v.detail})]},R))}),y.topic_test&&e.jsxs("div",{className:`p-2.5 rounded-lg border text-xs font-mono ${y.topic_test.success?"bg-purple-500/10 border-purple-500/30 text-purple-300":"bg-rose-500/10 border-rose-500/30 text-rose-300"}`,children:[e.jsxs("div",{className:"font-bold flex items-center gap-1.5",children:[e.jsx(Y,{className:"w-3.5 h-3.5 text-purple-400"}),e.jsx("span",{children:y.topic_test.success?"Telegram Forum Topic Created Live โœ“":"Topic Creation Test Failed โœ—"})]}),e.jsx("div",{className:"text-[11px] mt-0.5",children:y.topic_test.message||y.topic_test.error})]})]}):e.jsxs("p",{className:"text-[11px] font-sans text-pearl-400 leading-relaxed",children:["Click ",e.jsx("b",{children:"Run Verification Check"})," to validate all module configurations, permissions, and Telegram Bot Administrator rights before activating in production."]})]}),e.jsxs("div",{className:"pt-2 border-t border-white/10",children:[e.jsxs("button",{type:"button",onClick:()=>p(!d),className:"text-[11px] font-mono text-pearl-400 hover:text-[#2481CC] flex items-center gap-1.5 transition-colors",children:[e.jsx(Ds,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:["Advanced Developer Mode: ",d?"Hide Raw JSON":"View Raw JSON"]}),d?e.jsx(Ts,{className:"w-3.5 h-3.5"}):e.jsx(Vt,{className:"w-3.5 h-3.5"})]}),d&&e.jsxs("div",{className:"mt-3 space-y-2 animate-in fade-in",children:[e.jsx("textarea",{rows:6,value:u,onChange:v=>g(v.target.value),className:"w-full p-3 rounded-xl bg-space-950 border border-white/15 text-xs font-mono text-emerald-300 focus:outline-none"}),e.jsx("p",{className:"text-[10px] font-mono text-pearl-400",children:"Direct low-level payload synced with cloud execution engine."})]})]}),e.jsxs("div",{className:"pt-4 border-t border-white/10 flex flex-col sm:flex-row items-stretch sm:items-center justify-end gap-3 sticky bottom-0 bg-space-900/95 py-3",children:[e.jsx("button",{type:"button",onClick:l,className:"btn-telegram-secondary py-2 px-4 justify-center text-xs",children:"CANCEL"}),e.jsxs("button",{type:"submit",disabled:j,className:"btn-telegram-primary py-2 px-6 justify-center inline-flex items-center gap-2 shadow-telegram text-xs font-bold",children:[j?e.jsx(oe,{className:"w-4 h-4 animate-spin"}):e.jsx(ht,{className:"w-4 h-4"}),e.jsx("span",{children:"SAVE MODULE SETTINGS"})]})]})]})]})})})},ni=[{id:"welcome_message",name:"Welcome Message & Onboarding",category:"engagement",icon:Y,version:"1.2.0",description:"Custom greeting message, dynamic placeholders ({first_name}, {bot_name}), parse mode, and inline quick-action buttons on /start.",is_installed:!0,is_enabled:!0,config:{welcome_text:"๐ŸŒŸ Welcome to our VIP Bot! Tap an option below to explore:",buttons_count:4}},{id:"force_join",name:"Force Join Channel Guard",category:"security",icon:K,version:"1.1.0",description:"Enforces mandatory channel/group membership before unlocking bot commands. Verifies status via getChatMember.",is_installed:!0,is_enabled:!0,config:{channel_username:"@astraea_cloud",prompt_text:"โš ๏ธ You must join our official Telegram channel to unlock this bot.",button_text:"๐Ÿ“ข Join Official Channel"}},{id:"referrals",name:"Referral & Viral Growth Engine",category:"growth",icon:pt,version:"1.3.0",description:"Generates subscriber deep-link invite links (/start ref_{userId}), tracks successful signups, awards points, and calculates balances.",is_installed:!0,is_enabled:!0,config:{points_per_referral:10,welcome_bonus_points:5,min_payout_points:50}},{id:"broadcasts",name:"Broadcast & Announcement Pipeline",category:"messaging",icon:he,version:"2.0.0",description:"Token-bucket broadcasts (25 msgs/sec), audience filtering, language targeting, and /optout compliance.",is_installed:!0,is_enabled:!0,config:{rate_limit_per_second:25,allow_opt_out:!0}},{id:"user_management",name:"Audience & Subscriber Directory",category:"management",icon:Ae,version:"1.0.0",description:"Real-time subscriber tracking, interaction count, automatic BCP 47 language preference detection, and block state auditing.",is_installed:!0,is_enabled:!0,config:{auto_detect_locale:!0,track_interactions:!0}},{id:"auto_filter",name:"Auto Filter & Keyword Responder",category:"automation",icon:Gt,version:"1.2.0",description:"Matches subscriber text against trigger keywords and forbidden words. Provides instantaneous auto-replies or warnings.",is_installed:!0,is_enabled:!0,config:{rules_count:3,blocked_words:["scam","free nitro","hack"]}},{id:"payments",name:"In-Chat Payments & Invoicing",category:"monetization",icon:Ge,version:"1.4.0",description:"Seamless Razorpay & Stripe in-chat payment links with cryptographic webhook verification and digital invoice dispatch.",is_installed:!0,is_enabled:!1,config:{currency:"INR",gateway:"razorpay"}},{id:"subscriptions",name:"VIP Subscriptions & Gated Access",category:"monetization",icon:at,version:"1.3.0",description:"Subscription tiers, membership access duration tracking, automated renewal prompts, and grace period protection.",is_installed:!0,is_enabled:!1,config:{tiers_count:2,grace_period_days:3}},{id:"ai_assistant",name:"Autonomous AI Customer Concierge",category:"ai",icon:ge,version:"2.1.0",description:"Multi-turn LLM reasoning using OpenAI (GPT-4o) and Anthropic (Claude 3.5). Responds to /ai or handles conversational fallback.",is_installed:!0,is_enabled:!0,config:{model:"gpt-4o-mini",temperature:.5}},{id:"logs_tracker",name:"Activity Logs & Channel Audit",category:"security",icon:Ie,version:"1.5.0",description:"Real-time event logging to Telegram channel or supergroup. Pro feature: Forum Topics with unique user threads and 2-way admin chat relay.",is_installed:!0,is_enabled:!0,config:{log_channel_id:"-1002345678901",log_channel_type:"supergroup_forum",enable_topics:!0,topic_naming_format:"๐Ÿ‘ค {user_id} - @{username}",relay_chat_replies:!0,log_events:["new_user","command_executed","force_join_attempts","payments","broadcasts","errors"],bot_is_admin_verified:!1}}],li=({botId:t,onNavigate:s})=>{const{slug:n}=sa(),a=xe(),{currentBot:l,selectBot:r}=Z(),o=t||n||(l==null?void 0:l.id)||"astraea-flagship";i.useEffect(()=>{n&&r(n)},[n]);const j=l||{name:"Astraea Concierge Bot",username:"astraea_flagship_bot"},[f,d]=i.useState(ni),[p,u]=i.useState("modules"),[g,b]=i.useState(null),[h,m]=i.useState("{}"),[c,w]=i.useState(!1),[x,N]=i.useState(null);i.useEffect(()=>{async function T(){try{const B=localStorage.getItem("access_token"),C={};B&&(C.Authorization=`Bearer ${B}`);const E=await fetch(`/api/v1/bots/${o}/modules`,{headers:C});if(E.ok){const M=await E.json();if(M.data&&Array.isArray(M.data)){const U={welcome_message:Y,force_join:K,referrals:pt,broadcasts:he,user_management:Ae,auto_filter:Gt,payments:Ge,subscriptions:at,ai_assistant:ge,logs_tracker:Ie},v=M.data.map(R=>({id:R.id,name:R.name,category:R.category,icon:U[R.id]||Ee,version:R.version,description:R.description,is_installed:R.is_installed,is_enabled:R.is_enabled,config:R.config||{}}));d(v)}}}catch{}}T()},[o]);const k=async(T,B)=>{var M,U,v,R,$;const C=!B,E=f.find(S=>S.id===T);if(C){if(T==="logs_tracker"&&!((M=E==null?void 0:E.config)!=null&&M.log_channel_id)){E&&b(E),N("โš ๏ธ Please configure your Log Channel or Supergroup and verify Bot Admin before activating."),setTimeout(()=>N(null),4e3);return}if(T==="force_join"&&!((U=E==null?void 0:E.config)!=null&&U.channel_username)&&!((v=E==null?void 0:E.config)!=null&&v.channel_id)){E&&b(E),N("โš ๏ธ Please configure your Force-Join Channel/Group before activating."),setTimeout(()=>N(null),4e3);return}}d(S=>S.map(D=>D.id===T?{...D,is_enabled:C}:D));try{const S=localStorage.getItem("access_token"),D={"Content-Type":"application/json"};S&&(D.Authorization=`Bearer ${S}`);const O=await fetch(`/api/v1/bots/${o}/modules/${T}/toggle`,{method:"POST",headers:D,body:JSON.stringify({is_enabled:C})});if(O.ok){const X=(R=(await O.json().catch(()=>({}))).data)==null?void 0:R.verification;if(C)if(X&&!X.ok)N(`โš ๏ธ ${(E==null?void 0:E.name)||T} activated, but verification notice: ${X.error||X.message}`);else{const G=($=X==null?void 0:X.details)!=null&&$.topics_supported?" (Forum Topics Active โœ“)":"";N(`โœ… ${(E==null?void 0:E.name)||T} activated & verified!${G}`)}else N(`Module ${(E==null?void 0:E.name)||T} deactivated.`)}else N(`Module ${(E==null?void 0:E.name)||T} state updated.`);setTimeout(()=>N(null),3e3)}catch{N("Module toggle saved."),setTimeout(()=>N(null),2e3)}},y=T=>{b(T)},A=async T=>{if(g){w(!0);try{const B=localStorage.getItem("access_token"),C={"Content-Type":"application/json"};B&&(C.Authorization=`Bearer ${B}`),await fetch(`/api/v1/bots/${o}/modules/${g.id}/config`,{method:"PATCH",headers:C,body:JSON.stringify({config:T})}),d(E=>E.map(M=>M.id===g.id?{...M,config:T}:M)),N(`Configuration for ${g.name} updated successfully!`),b(null),setTimeout(()=>N(null),2500)}catch{d(B=>B.map(C=>C.id===g.id?{...C,config:T}:C)),N(`Configuration for ${g.name} saved!`),b(null),setTimeout(()=>N(null),2500)}finally{w(!1)}}};return e.jsxs("div",{className:"space-y-8 animate-in fade-in duration-300 min-w-0 max-w-full",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-end justify-between gap-4 border-b border-white/10 pb-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 sm:w-14 sm:h-14 rounded-2xl bg-[#2481CC]/10 border border-[#2481CC]/30 flex items-center justify-center text-[#2481CC] shadow-sm shrink-0",children:e.jsx(te,{className:"w-6 h-6 sm:w-8 sm:h-8"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-400"}),e.jsx("span",{className:"text-[11px] font-mono tracking-wider text-emerald-400 uppercase font-semibold",children:"24/7 Managed Cloud Runtime Active"})]}),e.jsx("h1",{className:"text-xl sm:text-2xl md:text-3xl font-bold text-pearl-50 tracking-tight",children:j.name}),e.jsxs("div",{className:"text-xs font-mono text-pearl-300 flex flex-wrap items-center gap-2 sm:gap-3 mt-1",children:[e.jsxs("a",{href:`https://t.me/${j.username}`,target:"_blank",rel:"noopener noreferrer",className:"text-[#2481CC] font-bold hover:underline flex items-center gap-1",children:[e.jsxs("span",{children:["@",j.username]}),e.jsx(je,{className:"w-3 h-3"})]}),e.jsx("span",{className:"hidden sm:inline",children:"ยท"}),e.jsxs("span",{className:"text-pearl-400",children:["ID: ",o]}),e.jsx("span",{className:"hidden sm:inline",children:"ยท"}),e.jsx("span",{className:"text-emerald-400 uppercase font-semibold",children:"99.98% SLA UPTIME"}),e.jsx("span",{className:"hidden sm:inline",children:"ยท"}),e.jsx("span",{className:"text-[#2481CC] font-semibold",children:"VPS FREE CLOUD"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 w-full sm:w-auto",children:[e.jsxs("a",{href:`https://t.me/${j.username}`,target:"_blank",rel:"noopener noreferrer",className:"btn-telegram-primary text-xs py-2 px-3.5 justify-center inline-flex items-center gap-1.5 shadow-telegram font-semibold",children:[e.jsx(je,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"TEST IN TELEGRAM"})]}),e.jsx(I,{to:"/marketplace",className:"btn-telegram-secondary text-xs py-2 px-3 justify-center inline-flex items-center gap-1.5",children:e.jsx("span",{children:"TEMPLATES"})}),e.jsx(I,{to:"/dashboard/studio",className:"btn-telegram-secondary text-xs py-2 px-3 justify-center inline-flex items-center gap-1.5",children:e.jsx("span",{children:"STUDIO"})})]})]}),e.jsx(pa,{bot:l,onOpenTemplates:()=>a("/marketplace"),onOpenConnectModal:()=>a("/dashboard/bots")}),e.jsx("div",{className:"p-3.5 sm:p-4 rounded-xl astraea-card border border-[#2481CC]/30 overflow-x-auto scrollbar-none",children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 min-w-[700px] text-xs font-mono",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-400 font-semibold",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"1. Bot Created"})]}),e.jsx("span",{className:"text-pearl-500",children:"โ†’"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-400 font-semibold",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"2. Template Selected"})]}),e.jsx("span",{className:"text-pearl-500",children:"โ†’"}),e.jsx("div",{className:"flex items-center gap-1.5 text-[#2481CC] font-bold bg-[#2481CC]/10 px-2 py-0.5 rounded-lg border border-[#2481CC]/40",children:e.jsx("span",{children:"3. Modules Installed (9)"})}),e.jsx("span",{className:"text-pearl-500",children:"โ†’"}),e.jsx("div",{className:"flex items-center gap-1.5 text-[#2481CC] font-medium",children:e.jsx("span",{children:"4. Configure"})}),e.jsx("span",{className:"text-pearl-500",children:"โ†’"}),e.jsx("div",{className:"flex items-center gap-1.5 text-[#2481CC] font-medium",children:e.jsx("span",{children:"5. Activate"})}),e.jsx("span",{className:"text-pearl-500",children:"โ†’"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-400 font-semibold",children:[e.jsx(ut,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"6. 24/7 Cloud Running"})]}),e.jsx("span",{className:"text-pearl-500",children:"โ†’"}),e.jsx("div",{className:"flex items-center gap-1.5 text-pearl-300",children:e.jsx("span",{children:"7. Monitoring"})})]})}),x&&e.jsxs("div",{className:"p-3.5 rounded-xl bg-emerald-500/15 border border-emerald-500/40 text-emerald-300 text-xs font-mono flex items-center gap-2 animate-in fade-in",children:[e.jsx(H,{className:"w-4 h-4 text-emerald-400 shrink-0"}),e.jsx("span",{children:x})]}),e.jsxs("div",{className:"flex items-center gap-2 border-b border-white/10 pb-3 overflow-x-auto scrollbar-none",children:[e.jsxs("button",{onClick:()=>u("modules"),className:`px-4 py-2 text-xs font-mono uppercase tracking-wider rounded-xl transition-all flex items-center gap-2 shrink-0 ${p==="modules"?"bg-[#2481CC] text-white font-bold shadow-sm":"text-pearl-400 hover:text-pearl-100 hover:bg-white/5"}`,children:[e.jsx(Pe,{className:"w-3.5 h-3.5"}),e.jsxs("span",{children:["Modular Feature System (",f.filter(T=>T.is_enabled).length," Active)"]})]}),e.jsxs("button",{onClick:()=>u("telemetry"),className:`px-4 py-2 text-xs font-mono uppercase tracking-wider rounded-xl transition-all flex items-center gap-2 shrink-0 ${p==="telemetry"?"bg-[#2481CC] text-white font-bold shadow-sm":"text-pearl-400 hover:text-pearl-100 hover:bg-white/5"}`,children:[e.jsx(Ie,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Cloud Telemetry & Vault"})]}),e.jsxs("button",{onClick:()=>u("commands"),className:`px-4 py-2 text-xs font-mono uppercase tracking-wider rounded-xl transition-all flex items-center gap-2 shrink-0 ${p==="commands"?"bg-[#2481CC] text-white font-bold shadow-sm":"text-pearl-400 hover:text-pearl-100 hover:bg-white/5"}`,children:[e.jsx(ct,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Telegram Commands"})]})]}),p==="modules"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg text-pearl-50 font-bold tracking-tight",children:"Modular Bot Features"}),e.jsx("p",{className:"text-xs text-pearl-400 font-sans mt-0.5",children:"Every bot has independent modular capabilities. Toggles directly control backend webhook execution."})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-400 animate-pulse"}),e.jsx("span",{className:"text-emerald-400 font-semibold",children:"Real-Time Backend Synced"})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:f.map(T=>{const B=T.icon;return e.jsxs("div",{className:`astraea-card rounded-2xl p-5 flex flex-col justify-between transition-all ${T.is_enabled?"border-[#2481CC]/40 bg-space-850/80 shadow-md":"border-white/10 opacity-75 hover:opacity-100"}`,children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#2481CC]/10 border border-[#2481CC]/30 flex items-center justify-center text-[#2481CC] shrink-0",children:e.jsx(B,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-full text-[9px] font-mono uppercase tracking-wider font-semibold ${T.is_enabled?"bg-emerald-500/15 text-emerald-300 border border-emerald-500/30":"bg-space-800 text-pearl-400 border border-white/5"}`,children:T.is_enabled?"ACTIVE":"DEACTIVATED"}),e.jsx("button",{type:"button",onClick:()=>k(T.id,T.is_enabled),className:`w-11 h-6 rounded-full p-1 transition-colors relative ${T.is_enabled?"bg-[#2481CC]":"bg-space-800 border border-white/20"}`,title:`Click to ${T.is_enabled?"deactivate":"activate"}`,children:e.jsx("div",{className:`w-4 h-4 rounded-full bg-white transition-transform ${T.is_enabled?"translate-x-5":"translate-x-0 bg-pearl-400"}`})})]})]}),e.jsx("h4",{className:"text-base text-pearl-50 font-bold tracking-tight",children:T.name}),e.jsx("p",{className:"text-xs font-sans text-pearl-300 mt-1.5 leading-relaxed",children:T.description})]}),e.jsxs("div",{className:"mt-5 pt-3 border-t border-white/10 flex items-center justify-between text-xs font-mono",children:[e.jsxs("span",{className:"text-[10px] text-pearl-400 uppercase",children:["v",T.version," ยท ",T.category]}),e.jsxs("button",{type:"button",onClick:()=>y(T),className:"btn-telegram-secondary py-1 px-3 text-[10px] gap-1",children:[e.jsx(st,{className:"w-3 h-3 text-[#2481CC]"}),e.jsx("span",{children:"CONFIGURE"})]})]})]},T.id)})})]}),p==="telemetry"&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6",children:[e.jsxs("div",{className:"astraea-card rounded-2xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-pearl-200 uppercase font-semibold",children:[e.jsx(Wt,{className:"w-4 h-4 text-[#2481CC]"}),e.jsx("span",{children:"Token Vault Security"})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-mono uppercase bg-emerald-500/10 text-emerald-300 border border-emerald-500/30 font-semibold",children:"AES-256-GCM"})]}),e.jsxs("div",{className:"space-y-3 text-xs font-mono text-pearl-300",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-pearl-400 uppercase mb-1",children:"Storage Status"}),e.jsxs("div",{className:"text-pearl-100 font-semibold flex items-center gap-1.5",children:[e.jsx(K,{className:"w-4 h-4 text-emerald-400"}),e.jsx("span",{children:"Encrypted at Rest with Key Version 1"})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-pearl-400 uppercase mb-1",children:"Masked Hash"}),e.jsx("div",{className:"p-2 rounded-xl bg-space-900 border border-white/5 text-[11px] text-pearl-400 select-all",children:"$aes-gcm$v1$9f8b4a2e...c710d8a1"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-pearl-400 uppercase mb-1",children:"Telegram Verification"}),e.jsx("div",{className:"text-emerald-400 flex items-center gap-1 font-semibold",children:e.jsx("span",{children:"Verified via getMe (ID: 7182910392)"})})]})]})]}),e.jsxs("div",{className:"astraea-card rounded-2xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-pearl-200 uppercase font-semibold",children:[e.jsx(he,{className:"w-4 h-4 text-[#2481CC]"}),e.jsx("span",{children:"Webhook Telemetry"})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-mono uppercase bg-emerald-500/10 text-emerald-300 border border-emerald-500/30 font-semibold",children:"VERIFIED"})]}),e.jsxs("div",{className:"space-y-3 text-xs font-mono text-pearl-300",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-pearl-400 uppercase mb-1",children:"Webhook Endpoint"}),e.jsxs("div",{className:"p-2 rounded-xl bg-space-900 border border-white/5 text-[11px] text-[#2481CC] select-all truncate font-semibold",children:["https://api.yourdomain.com/webhooks/telegram/",o]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] text-pearl-400 uppercase mb-1",children:"Secret Token Hash"}),e.jsx("div",{className:"p-2 rounded-xl bg-space-900 border border-white/5 text-[11px] text-pearl-400 truncate",children:"sha256:d9b4c0e...8f2a17"})]}),e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsx("span",{className:"text-pearl-400",children:"Max Connections:"}),e.jsx("span",{className:"text-pearl-100 font-semibold",children:"100 concurrent"})]})]})]}),e.jsxs("div",{className:"astraea-card rounded-2xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-pearl-200 uppercase font-semibold",children:[e.jsx(ge,{className:"w-4 h-4 text-[#2481CC]"}),e.jsx("span",{children:"Throughput & Latency"})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-mono uppercase bg-emerald-500/10 text-emerald-300 border border-emerald-500/30 font-semibold",children:"38 MS AVG"})]}),e.jsxs("div",{className:"space-y-3 text-xs font-mono text-pearl-300",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-pearl-400",children:"Cloud Runtime:"}),e.jsx("span",{className:"text-emerald-400 font-semibold",children:"24/7 Managed Host"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-pearl-400",children:"Update Deduplication:"}),e.jsx("span",{className:"text-emerald-400",children:"Redis Bloom Active"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-pearl-400",children:"Rate Limit Backoff:"}),e.jsx("span",{className:"text-pearl-100 font-semibold",children:"Exponential Retry"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-pearl-400",children:"Default Locale:"}),e.jsx("span",{className:"text-[#2481CC] font-bold uppercase",children:"en (English)"})]})]})]})]}),p==="commands"&&e.jsxs("div",{className:"astraea-card rounded-2xl p-4 sm:p-6 min-w-0 max-w-full overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between pb-4 border-b border-white/10 mb-4 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ct,{className:"w-5 h-5 text-[#2481CC]"}),e.jsx("h3",{className:"text-lg text-pearl-50 font-bold tracking-tight",children:"Registered Telegram Commands"})]}),e.jsx("span",{className:"text-xs font-mono text-pearl-400",children:"Auto-Synchronized with Telegram setMyCommands"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-4",children:[{cmd:"/start",desc:"Initialize conversation, deep-link attribution & VIP menu",role:"welcome_message"},{cmd:"/referral",desc:"View referral link, point balance & friend invites",role:"referrals"},{cmd:"/plans",desc:"View tiered subscription plans & pricing in-chat",role:"subscriptions"},{cmd:"/pay",desc:"Initiate encrypted Razorpay/Stripe checkout session",role:"payments"},{cmd:"/ai",desc:"Query autonomous LLM customer support concierge",role:"ai_assistant"},{cmd:"/optout",desc:"Manage broadcast delivery & opt-out preferences",role:"broadcasts"},{cmd:"/lang",desc:"Interactive 16-language selector picker",role:"i18n"},{cmd:"/help",desc:"Interactive guidance & support documentation",role:"public"}].map((T,B)=>e.jsxs("div",{className:"p-3.5 rounded-xl bg-space-850/60 border border-white/5 hover:border-[#2481CC]/40 transition-all font-mono text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("span",{className:"text-[#2481CC] font-bold text-sm",children:T.cmd}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] uppercase bg-space-800 text-pearl-400 border border-white/10",children:T.role})]}),e.jsx("p",{className:"text-[11px] text-pearl-300 font-sans leading-relaxed",children:T.desc})]},B))})]}),g&&e.jsx(ri,{botId:o,botUsername:j.username||"mybot",module:g,onSave:A,onClose:()=>b(null)})]})},ii=[{id:"c-001",title:"Spring Flash Sale 2026 โ€” VIP Access",status:"completed",totalRecipients:14280,deliveredCount:14251,failedCount:29,rateLimitPerSec:25,targetLocale:"en",messageSnippet:"๐Ÿ”ฅ Exclusive Offer: Claim 50% discount with code SPRING50!",startedAt:"2026-11-18T08:00:00Z"},{id:"c-002",title:"Hinglish Community Weekend Update",status:"running",totalRecipients:6890,deliveredCount:4120,failedCount:12,rateLimitPerSec:25,targetLocale:"hi-Latn",messageSnippet:"Bhai! Check out the newly added Telegram Premium custom emojis...",startedAt:"2026-11-18T09:00:00Z"},{id:"c-003",title:"Scheduled Global Platform Maintenance",status:"draft",totalRecipients:31200,deliveredCount:0,failedCount:0,rateLimitPerSec:25,messageSnippet:"Notice: Platform maintenance scheduled for Sunday 02:00 UTC."}],oi=()=>{const{currentBot:t}=Z(),[s,n]=i.useState(ii),[a,l]=i.useState(!1),[r,o]=i.useState(""),[j,f]=i.useState(""),[d,p]=i.useState("all"),[u,g]=i.useState(25),[b,h]=i.useState(!1),m=async x=>{if(x.preventDefault(),!(!r.trim()||!j.trim())){h(!0);try{const N={bot_id:t.id,title:r,message_text:j,target_filter:d==="all"?{}:{locale:d},rate_limit_per_second:u,inline_keyboard:[[{text:"Explore Now ๐ŸŒŸ",url:"https://example.com"}]]},k=await fetch("/api/v1/broadcasts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(N)}),y={id:`c-${Date.now()}`,title:r,status:"draft",totalRecipients:t.usersCount||14280,deliveredCount:0,failedCount:0,rateLimitPerSec:u,targetLocale:d==="all"?void 0:d,messageSnippet:j.slice(0,70)};n([y,...s]),l(!1),o(""),f("")}catch{l(!1)}finally{h(!1)}}},c=x=>{n(N=>N.map(k=>k.id===x?{...k,status:"running",startedAt:new Date().toISOString(),deliveredCount:Math.floor(k.totalRecipients*.98)}:k))},w=x=>{n(N=>N.map(k=>k.id!==x?k:{...k,status:k.status==="running"?"paused":"running"}))};return e.jsxs("div",{className:"space-y-6 sm:space-y-8 animate-in fade-in duration-300 min-w-0 max-w-full",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-end justify-between gap-4 border-b border-white/10 pb-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#2481CC]"}),e.jsx("span",{className:"text-[10px] font-mono tracking-wider text-[#2481CC] uppercase font-semibold",children:"High-Throughput Campaign Engine"})]}),e.jsx("h1",{className:"text-2xl sm:text-3xl md:text-4xl text-pearl-50 font-bold tracking-tight",children:"Broadcast Campaigns"}),e.jsx("p",{className:"text-xs text-pearl-400 font-sans mt-1.5 max-w-2xl leading-relaxed",children:"Dispatch rate-limited bulk broadcasts strictly adhering to Telegram's 25โ€“30 msgs/second limit with real-time opt-out filtering, delivery statistics, and error tracking."})]}),e.jsxs("button",{onClick:()=>l(!0),className:"btn-telegram-primary w-full sm:w-auto justify-center py-2.5 px-4 shrink-0 shadow-telegram",children:[e.jsx(se,{className:"w-4 h-4"}),e.jsx("span",{children:"NEW BROADCAST"})]})]}),e.jsxs("div",{className:"bg-[#2481CC]/10 border border-[#2481CC]/30 rounded-xl p-3 sm:p-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#2481CC]/20 border border-[#2481CC]/40 flex items-center justify-center text-xl shrink-0",children:"๐Ÿค–"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-mono uppercase px-1.5 py-0.5 rounded bg-[#2481CC]/20 text-[#2481CC] font-bold",children:"Target Bot"}),e.jsx("span",{className:"text-sm font-bold text-pearl-100",children:t.name}),e.jsxs("span",{className:"text-xs text-[#2481CC]",children:["@",t.username]})]}),e.jsxs("p",{className:"text-xs text-pearl-400 mt-0.5",children:["Broadcasts dispatched here will be delivered from @",t.username," to its ",t.usersCount.toLocaleString()," active subscribers with automatic Telegram rate-limiting."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-pearl-300 bg-white/5 px-3 py-1.5 rounded-lg border border-white/10 shrink-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-400 animate-pulse"}),e.jsxs("span",{children:["Queue Engine: Ready (",t.usersCount.toLocaleString()," targets)"]})]})]}),e.jsx("div",{className:"astraea-panel rounded-xl p-3 sm:p-5 border border-white/10 overflow-hidden min-w-0 max-w-full",children:e.jsx("div",{className:"overflow-x-auto w-full max-w-full",children:e.jsxs("table",{className:"w-full min-w-[650px] text-left text-xs font-mono",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-white/10 text-[10px] text-pearl-400 uppercase tracking-widest",children:[e.jsx("th",{className:"pb-3 pl-2",children:"Campaign Title"}),e.jsx("th",{className:"pb-3",children:"Audience Filter"}),e.jsx("th",{className:"pb-3",children:"Status"}),e.jsx("th",{className:"pb-3",children:"Delivered / Total"}),e.jsx("th",{className:"pb-3",children:"Delivery Rate"}),e.jsx("th",{className:"pb-3 pr-2 text-right",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-white/5",children:s.map(x=>{const N=x.totalRecipients>0?Math.round(x.deliveredCount/x.totalRecipients*100):0;return e.jsxs("tr",{className:"hover:bg-white/[0.02] transition-colors",children:[e.jsxs("td",{className:"py-4 pl-2 font-medium text-pearl-100",children:[e.jsx("div",{className:"text-sm font-bold text-pearl-50",children:x.title}),e.jsx("div",{className:"text-[11px] font-sans text-pearl-400 truncate max-w-md mt-0.5",children:x.messageSnippet})]}),e.jsx("td",{className:"py-4 text-pearl-300",children:x.targetLocale?e.jsxs("span",{className:"px-2 py-0.5 rounded bg-space-850 border border-white/10 text-[10px] uppercase text-[#2481CC] font-semibold",children:["Locale: ",x.targetLocale]}):e.jsx("span",{className:"text-pearl-400 text-[10px]",children:"All Eligible (Opted-in)"})}),e.jsx("td",{className:"py-4",children:e.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] uppercase font-semibold ${x.status==="completed"?"bg-emerald-500/10 text-emerald-300 border border-emerald-500/30":x.status==="running"?"bg-[#2481CC]/15 text-[#2481CC] border border-[#2481CC]/40 animate-pulse":x.status==="paused"?"bg-amber-500/10 text-amber-300 border border-amber-500/30":"bg-space-850 text-pearl-400 border border-white/10"}`,children:x.status})}),e.jsxs("td",{className:"py-4 text-pearl-200",children:[e.jsxs("div",{children:[x.deliveredCount.toLocaleString()," / ",x.totalRecipients.toLocaleString()]}),x.failedCount>0&&e.jsxs("div",{className:"text-[10px] text-rose-400",children:[x.failedCount," failed"]})]}),e.jsxs("td",{className:"py-4",children:[e.jsx("div",{className:"w-32 bg-space-850 rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:"bg-gradient-to-r from-[#2481CC] to-emerald-400 h-1.5 transition-all duration-500",style:{width:`${N}%`}})}),e.jsxs("span",{className:"text-[10px] text-pearl-400 mt-1 block",children:[N,"% complete (",x.rateLimitPerSec," msg/s)"]})]}),e.jsx("td",{className:"py-4 pr-2 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[x.status==="draft"&&e.jsxs("button",{onClick:()=>c(x.id),className:"btn-telegram-primary py-1 px-3 text-[10px] shadow-telegram",children:[e.jsx(Ve,{className:"w-3 h-3"}),e.jsx("span",{children:"DISPATCH"})]}),(x.status==="running"||x.status==="paused")&&e.jsxs("button",{onClick:()=>w(x.id),className:"btn-telegram-secondary py-1 px-2.5 text-[10px]",children:[x.status==="running"?e.jsx(Za,{className:"w-3 h-3 text-amber-400"}):e.jsx(Ve,{className:"w-3 h-3 text-emerald-400"}),e.jsx("span",{children:x.status==="running"?"PAUSE":"RESUME"})]}),x.status==="completed"&&e.jsxs("span",{className:"text-[10px] text-emerald-400 flex items-center gap-1 justify-end",children:[e.jsx(H,{className:"w-3.5 h-3.5"})," Delivered"]})]})})]},x.id)})})]})})}),a&&e.jsx(ne,{children:e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4 bg-black/80 backdrop-blur-md",children:e.jsxs("div",{className:"w-full max-w-xl max-h-[90vh] overflow-y-auto astraea-card rounded-2xl p-4 sm:p-6 border border-white/15 shadow-2xl animate-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between pb-4 border-b border-white/10 mb-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg text-pearl-50 font-bold tracking-tight",children:"Compose Campaign Broadcast"}),e.jsx("p",{className:"text-xs font-mono text-[#2481CC] mt-0.5",children:"Telegram-Compliant Rate-Limited Bulk Messaging"})]}),e.jsx("button",{onClick:()=>l(!1),className:"text-pearl-400 hover:text-pearl-100 p-1",children:e.jsx(q,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:m,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-mono uppercase tracking-widest text-pearl-400 mb-1.5",children:"Campaign Title"}),e.jsx("input",{type:"text",required:!0,value:r,onChange:x=>o(x.target.value),placeholder:"e.g. Black Friday VIP Announcement",className:"w-full px-3.5 py-2.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 focus:outline-none focus:border-[#2481CC]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-mono uppercase tracking-widest text-pearl-400 mb-1.5",children:"Message Content (Telegram HTML Supported)"}),e.jsx("textarea",{rows:4,required:!0,value:j,onChange:x=>f(x.target.value),placeholder:"๐Ÿ”ฅ Exclusive Offer: Get 50% discount using code VIP50!",className:"w-full px-3.5 py-2.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 focus:outline-none focus:border-[#2481CC]"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-mono uppercase tracking-widest text-pearl-400 mb-1.5",children:"Target Audience Locale"}),e.jsxs("select",{value:d,onChange:x=>p(x.target.value),className:"w-full px-3.5 py-2.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 focus:outline-none focus:border-[#2481CC]",children:[e.jsx("option",{value:"all",children:"All Locales (Exclude Opted-out)"}),e.jsx("option",{value:"en",children:"English (en)"}),e.jsx("option",{value:"hi",children:"Hindi (hi)"}),e.jsx("option",{value:"hi-Latn",children:"Hinglish (hi-Latn)"}),e.jsx("option",{value:"es",children:"Spanish (es)"}),e.jsx("option",{value:"ar",children:"Arabic (ar)"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] font-mono uppercase tracking-widest text-pearl-400 mb-1.5",children:"Dispatch Rate Limit"}),e.jsxs("select",{value:u,onChange:x=>g(Number(x.target.value)),className:"w-full px-3.5 py-2.5 rounded-lg bg-space-900 border border-white/10 text-xs font-mono text-pearl-100 focus:outline-none focus:border-[#2481CC]",children:[e.jsx("option",{value:25,children:"25 msgs / sec (Recommended Safe)"}),e.jsx("option",{value:20,children:"20 msgs / sec (Conservative)"}),e.jsx("option",{value:30,children:"30 msgs / sec (Telegram Max)"})]})]})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-space-850 border border-white/5 text-[11px] font-mono text-pearl-300",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[#2481CC] font-semibold mb-1",children:[e.jsx(Y,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Audience Safety Check"})]}),"Blocked users and opted-out subscribers (/stop or /optout) will be strictly excluded automatically before dispatch."]}),e.jsxs("div",{className:"pt-4 border-t border-white/10 flex items-center justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>l(!1),className:"btn-telegram-secondary py-2 px-4",children:"CANCEL"}),e.jsxs("button",{type:"submit",disabled:b,className:"btn-telegram-primary py-2 px-5 shadow-telegram",children:[e.jsx(ce,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"SAVE CAMPAIGN"})]})]})]})]})})})]})},js=[{id:"preset_support",name:"24/7 Support Concierge",emoji:"๐ŸŽง",badge:"Customer Helpdesk",tone:"Polite & Helpful",description:"Resolves subscriber FAQs, guides users with step-by-step instructions, and provides assistance.",model:"gpt-4o-mini",temperature:.5,systemPrompt:"You are the official 24/7 Customer Support Concierge for this Telegram bot. Greet subscribers politely, provide concise and accurate solutions to inquiries, explain bot commands, and guide them calmly.",suggestedQuestions:["What are your operating hours?","How do I upgrade to VIP access?","Can you help me find my referral link?"]},{id:"preset_sales",name:"VIP Sales & Deals Closer",emoji:"๐Ÿ’ผ",badge:"High Conversion",tone:"Persuasive & Professional",description:"Explains premium subscriptions, exclusive perks, and converts free subscribers into paying members.",model:"anthropic/claude-3.5-sonnet",temperature:.7,systemPrompt:"You are an enterprise sales and VIP membership advisor for this Telegram bot. Highlight exclusive premium benefits, explain subscription tiers clearly, offer limited-time promo perks, and encourage users to upgrade.",suggestedQuestions:["What benefits do I get with VIP?","How much do subscription plans cost?","Are there any active discount coupons?"]},{id:"preset_hindi",name:"Hindi & Multilingual Assistant",emoji:"๐ŸŒ",badge:"Hindi / Hinglish / Global",tone:"Natural & Adaptive",description:"Automatically detects the subscriber language (Hindi, Hinglish, English) and chats fluently.",model:"gpt-4o-mini",temperature:.6,systemPrompt:"Aap ek highly intelligent multilingual Telegram bot assistant hain. User ki language (Hindi, Hinglish, English, etc.) ko instantly detect karein aur usi bhasha me naturally, politely aur seedhe tarike se reply karein.",suggestedQuestions:["Aap kaun hain aur kya kar sakte hain?","Bot kaise kaam karta hai?","Mujhe support chahiye"]},{id:"preset_ecommerce",name:"Digital Store & Orders Guide",emoji:"๐Ÿ›๏ธ",badge:"Storefront & Cart",tone:"Friendly & Fast",description:"Guides shoppers through product catalog, explains payment options (UPI, Cards, Crypto), and verifies orders.",model:"gpt-4o-mini",temperature:.5,systemPrompt:"You are the Storefront Concierge. Help shoppers browse available catalog items, explain payment options (UPI, Razorpay, Stripe, Telegram Stars), and assist them in completing checkouts.",suggestedQuestions:["Show me the most popular products","What payment methods do you accept?","How fast is digital product delivery?"]},{id:"preset_knowledge",name:"FAQ & Docs Specialist",emoji:"๐Ÿ“š",badge:"Deep Knowledge",tone:"Detailed & Technical",description:"Provides in-depth technical explanations, rule clarifications, and troubleshooting guidance.",model:"gpt-4o",temperature:.3,systemPrompt:"You are a knowledge base specialist. Provide clear, accurate, step-by-step documentation and troubleshooting steps with formatted bullet points.",suggestedQuestions:["How do I connect my channel to Force Join?","What are the webhook requirements?","How does the referral engine calculate points?"]}],vs=[{id:"agent-1",name:"Customer Concierge & Support",emoji:"๐ŸŽง",provider:"openai",model:"gpt-4o-mini",systemPrompt:"You are a luxury customer concierge for our Telegram bot SaaS platform. Be concise, polite, and helpful.",temperature:.6,maxTokens:800,isActive:!0,isBotDefault:!0,totalTokens:421e3},{id:"agent-2",name:"Autonomous Sales & Onboarding",emoji:"๐Ÿ’ผ",provider:"openrouter",model:"anthropic/claude-3.5-sonnet",systemPrompt:"You are an enterprise sales advisor. Explain subscription tiers, pricing, and bot automation capabilities.",temperature:.7,maxTokens:1200,isActive:!0,isBotDefault:!1,totalTokens:229e3},{id:"agent-3",name:"Hindi & Hinglish Concierge",emoji:"๐ŸŒ",provider:"openai",model:"gpt-4o-mini",systemPrompt:"Aap ek helpful AI assistant hain. User ki bhasha (Hindi, Hinglish, English) detect karein aur usi bhasha me naturally aur politely reply karein.",temperature:.6,maxTokens:800,isActive:!0,isBotDefault:!1,totalTokens:145e3}],ci=()=>{const{currentBot:t}=Z(),[s,n]=i.useState(vs),[a,l]=i.useState(vs[0]),[r,o]=i.useState(null),[j,f]=i.useState(!1),[d,p]=i.useState(null),[u,g]=i.useState(!1),[b,h]=i.useState(""),[m,c]=i.useState("๐Ÿค–"),[w,x]=i.useState("gpt-4o-mini"),[N,k]=i.useState(""),[y,A]=i.useState(.5),[T,B]=i.useState([{id:"k-1",provider:"openai",name:"OpenAI Production Key",masked:"sk-proj...9f21"},{id:"k-2",provider:"openrouter",name:"OpenRouter Claude Key",masked:"sk-or...b401"}]),[C,E]=i.useState(""),[M,U]=i.useState(""),[v,R]=i.useState("openai"),[$,S]=i.useState([{role:"assistant",content:"๐ŸŒŸ Namaste & Welcome! I am your autonomous AI Assistant. How may I assist your Telegram bot subscribers today?",tokens:32,costCents:.001}]),[D,O]=i.useState(""),[ae,X]=i.useState(!1),G=_=>{o(_),setTimeout(()=>o(null),3e3)},J=_=>{_?(p(null),h(_.name),c(_.emoji),x(_.model),k(_.systemPrompt),A(_.temperature)):(p(null),h("New AI Concierge"),c("๐Ÿค–"),x("gpt-4o-mini"),k("You are a polite, helpful AI Assistant for this Telegram bot."),A(.5)),f(!0)},Se=(_,F)=>{F==null||F.stopPropagation(),p(_),h(_.name),c(_.emoji||"๐Ÿค–"),x(_.model),k(_.systemPrompt),A(_.temperature),f(!0)},Re=_=>{if(_.preventDefault(),!!b.trim()){if(d){const F={...d,name:b.trim(),emoji:m,model:w,systemPrompt:N.trim(),temperature:y};n(L=>L.map(W=>W.id===d.id?F:W)),a.id===d.id&&l(F),G(`Agent "${F.name}" updated successfully!`)}else{const F={id:`agent-${Date.now()}`,name:b.trim(),emoji:m,provider:w.includes("claude")?"openrouter":"openai",model:w,systemPrompt:N.trim()||"You are a helpful Telegram bot AI assistant.",temperature:y,maxTokens:1e3,isActive:!0,isBotDefault:!1,totalTokens:0};n(L=>[F,...L]),l(F),G(`New AI Agent "${F.name}" deployed!`)}f(!1)}},ye=(_,F)=>{if(F.stopPropagation(),s.length<=1){alert("You must retain at least one configured AI agent.");return}const L=s.filter(W=>W.id!==_);n(L),a.id===_&&l(L[0]),G("Agent removed.")},Le=_=>{n(F=>F.map(L=>({...L,isBotDefault:L.id===_.id}))),l({..._,isBotDefault:!0}),t!=null&&t.id&&fetch(`/api/v1/bots/${t.id}/modules/ai_assistant/config`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({config:{model:_.model,system_prompt:_.systemPrompt,temperature:_.temperature,enable_fallback:!0}})}).catch(()=>{}),G(`โœ… "${_.name}" is now the active AI Assistant for @${(t==null?void 0:t.username)||"bot"}!`)},Me=async _=>{const F=(_||D).trim();if(!(!F||ae)){O(""),S(L=>[...L,{role:"user",content:F}]),X(!0);try{const L=await fetch(`/api/v1/ai/agents/${a.id}/chat`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:F})});if(L.ok){const W=await L.json();S(de=>{var pe,ue,le;return[...de,{role:"assistant",content:((pe=W.data)==null?void 0:pe.content)||"Completion generated successfully.",tokens:((ue=W.data)==null?void 0:ue.total_tokens)||48,costCents:((le=W.data)==null?void 0:le.cost_cents)||.002}]})}else setTimeout(()=>{let W=`๐Ÿค– [${a.name}]: I have received your query regarding "${F}". All systems operational.`;F.toLowerCase().includes("vip")||F.toLowerCase().includes("cost")?W="๐Ÿ’Ž VIP Membership is available in Monthly (โ‚น999) and Annual (โ‚น9,999) tiers. You get instant access, zero ads, and 24/7 priority execution!":F.toLowerCase().includes("support")||F.toLowerCase().includes("help")?W="๐ŸŽง I am here 24/7 to help! You can ask me any question about our services or type /commands to explore bot tools.":(F.toLowerCase().includes("kaun")||F.toLowerCase().includes("kya"))&&(W=`Namaste! Main @${(t==null?void 0:t.username)||"AstraeaBot"} ka AI Assistant hoon. Main aapke sawalon ka jawab dene aur VIP services samjhane ke liye 24/7 hazir hoon!`),S(de=>[...de,{role:"assistant",content:W,tokens:45,costCents:.0018}])},500)}catch{setTimeout(()=>{S(L=>[...L,{role:"assistant",content:`๐Ÿค– [${a.name}]: Operational response to "${F}".`,tokens:35,costCents:.0015}])},500)}finally{X(!1)}}};return e.jsxs("div",{className:"space-y-8 animate-in fade-in duration-300 min-w-0 max-w-full",children:[r&&e.jsxs("div",{className:"fixed bottom-6 right-6 z-50 p-4 rounded-xl bg-space-900 border border-[#2481CC] shadow-2xl text-pearl-50 text-xs font-mono flex items-center gap-2 animate-in slide-in-from-bottom-5",children:[e.jsx(H,{className:"w-4 h-4 text-emerald-400"}),e.jsx("span",{children:r})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-end justify-between gap-4 border-b border-white/10 pb-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-[#2481CC] animate-pulse"}),e.jsx("span",{className:"text-[11px] font-mono tracking-wide text-[#2481CC] uppercase font-semibold",children:"Telegram AI Studio & Autonomous LLM Agents"})]}),e.jsx("h1",{className:"text-2xl sm:text-3xl font-semibold text-white tracking-tight",children:"AI Assistant & Agents"}),e.jsx("p",{className:"text-xs sm:text-sm text-pearl-400 font-sans mt-1.5 max-w-2xl leading-relaxed",children:"Create and deploy 24/7 conversational AI assistants for your Telegram bot. Use ready-made 1-click persona presets (Support, Sales, Hindi/Hinglish, E-Commerce) with zero setup required."})]}),e.jsxs("div",{className:"flex flex-wrap sm:flex-nowrap items-center gap-2 sm:gap-3 w-full sm:w-auto",children:[e.jsxs("button",{onClick:()=>g(!0),className:"btn-telegram-secondary flex-1 sm:flex-initial justify-center py-2.5 px-3.5 text-xs",children:[e.jsx(ts,{className:"w-3.5 h-3.5 text-[#2481CC]"}),e.jsx("span",{children:"API KEYS VAULT"})]}),e.jsxs("button",{onClick:()=>J(),className:"btn-telegram-primary flex-1 sm:flex-initial justify-center py-2.5 px-4 shadow-telegram text-xs font-bold gap-1.5",children:[e.jsx(se,{className:"w-4 h-4"}),e.jsx("span",{children:"CREATE AGENT"})]})]})]}),e.jsxs("div",{className:"p-4 rounded-2xl bg-gradient-to-r from-[#2481CC]/15 via-purple-900/15 to-space-900 border border-[#2481CC]/30 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-3.5",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#2481CC] text-white flex items-center justify-center text-xl shadow-telegram shrink-0",children:"โšก"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-bold text-pearl-50 uppercase tracking-wide",children:"Managed High-Speed Cloud AI Active"}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[9px] font-mono bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 font-semibold",children:"READY TO USE"})]}),e.jsx("p",{className:"text-xs text-pearl-300 font-sans mt-0.5",children:"Aapko kisi bhi OpenAI ya Claude API key ki jarurat nahi haiโ€”cloud engine out-of-the-box powered hai. (Optional: Enterprise users apna private key API Vault me add kar sakte hain)."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 bg-space-950/60 px-3 py-1.5 rounded-xl border border-white/10 text-xs font-mono text-pearl-200",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-400"}),e.jsxs("span",{children:["Active Bot: ",e.jsxs("b",{className:"text-[#2481CC]",children:["@",(t==null?void 0:t.username)||"bot"]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4 text-[#2481CC]"}),e.jsx("h3",{className:"text-xs font-bold font-mono uppercase tracking-wider text-pearl-200",children:"1-Click AI Persona Presets (Easy Setup)"})]}),e.jsx("span",{className:"text-[11px] font-mono text-pearl-400",children:"Click any preset to create or customize"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-3",children:js.map(_=>e.jsxs("div",{onClick:()=>J(_),className:"p-3.5 rounded-xl astraea-card border border-white/10 hover:border-[#2481CC]/60 cursor-pointer transition-all hover:-translate-y-0.5 group flex flex-col justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-2xl",children:_.emoji}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-mono bg-[#2481CC]/15 text-[#2481CC] border border-[#2481CC]/25 font-semibold",children:_.badge})]}),e.jsx("h4",{className:"text-xs font-bold text-pearl-100 group-hover:text-[#2481CC] transition-colors leading-tight",children:_.name}),e.jsx("p",{className:"text-[11px] text-pearl-400 font-sans mt-1 line-clamp-2 leading-relaxed",children:_.description})]}),e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-white/5 flex items-center justify-between text-[10px] font-mono text-[#2481CC] font-semibold",children:[e.jsx("span",{children:"Use Preset"}),e.jsx("span",{className:"group-hover:translate-x-1 transition-transform",children:"โ†’"})]})]},_.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-6 items-start",children:[e.jsxs("div",{className:"lg:col-span-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs font-semibold text-pearl-100 uppercase tracking-wide",children:[e.jsxs("span",{children:["Your Bot AI Assistants (",s.length,")"]}),e.jsxs("span",{className:"text-[10px] font-mono text-emerald-400",children:[s.filter(_=>_.isActive).length," ACTIVE"]})]}),e.jsx("div",{className:"space-y-3",children:s.map(_=>{const F=_.id===a.id;return e.jsxs("div",{onClick:()=>l(_),className:`p-4 rounded-xl border cursor-pointer transition-all ${F?"bg-space-850 border-[#2481CC] shadow-telegram ring-1 ring-[#2481CC]/50":"bg-space-900/70 border-white/10 hover:border-white/20"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#2481CC]/15 border border-[#2481CC]/30 flex items-center justify-center text-lg shrink-0",children:_.emoji||"๐Ÿค–"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-pearl-50 font-bold leading-tight",children:_.name}),e.jsxs("div",{className:"text-[10px] font-mono text-[#2481CC] mt-0.5",children:[_.model," ยท Temp: ",_.temperature]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[_.isBotDefault&&e.jsxs("span",{className:"px-2 py-0.5 rounded text-[9px] font-mono uppercase bg-[#2481CC]/20 text-[#2481CC] border border-[#2481CC]/40 font-bold flex items-center gap-1",children:[e.jsx($s,{className:"w-2.5 h-2.5 fill-current"})," BOT AI"]}),e.jsx("button",{onClick:L=>Se(_,L),className:"p-1.5 rounded-lg text-pearl-400 hover:text-white hover:bg-white/10 transition-colors",title:"Edit Agent",children:e.jsx(Xa,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:L=>ye(_.id,L),className:"p-1.5 rounded-lg text-pearl-400 hover:text-rose-400 hover:bg-rose-500/10 transition-colors",title:"Delete Agent",children:e.jsx(Xe,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("p",{className:"text-[11px] font-sans text-pearl-400 mt-2 line-clamp-2 leading-relaxed bg-space-950/40 p-2 rounded-lg border border-white/5",children:['"',_.systemPrompt,'"']}),e.jsxs("div",{className:"mt-3 pt-2.5 border-t border-white/5 flex items-center justify-between text-[10px] font-mono",children:[e.jsx("button",{type:"button",onClick:L=>{L.stopPropagation(),Le(_)},className:`px-2 py-1 rounded-md text-[10px] font-mono transition-colors font-semibold ${_.isBotDefault?"bg-emerald-500/15 text-emerald-300 border border-emerald-500/30":"bg-space-800 text-pearl-300 hover:bg-[#2481CC]/20 hover:text-[#2481CC] border border-white/10"}`,children:_.isBotDefault?"โœ“ Assigned to Bot":"โญ Set as Bot AI"}),e.jsxs("span",{className:"text-pearl-400",children:["Tokens: ",_.totalTokens.toLocaleString()]})]})]},_.id)})})]}),e.jsxs("div",{className:"lg:col-span-7 astraea-panel rounded-2xl border border-white/15 flex flex-col h-[520px] sm:h-[580px] min-w-0 max-w-full overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"px-5 py-3.5 border-b border-white/10 flex items-center justify-between bg-space-900/80",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#2481CC]/20 border border-[#2481CC]/40 flex items-center justify-center text-lg",children:a.emoji||"๐Ÿค–"}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xs text-pearl-100 font-bold flex items-center gap-2",children:[e.jsx("span",{children:a.name}),a.isBotDefault&&e.jsx("span",{className:"px-1.5 py-0.2 rounded text-[9px] font-mono bg-emerald-500/20 text-emerald-300",children:"LIVE ON BOT"})]}),e.jsxs("div",{className:"text-[10px] font-mono text-[#2481CC]",children:[a.model," ยท Temp: ",a.temperature]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>S([]),className:"p-1.5 text-pearl-400 hover:text-pearl-100 rounded-lg hover:bg-white/5 transition-colors",title:"Clear Chat History",children:e.jsx(Fs,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-mono text-emerald-400 bg-emerald-500/10 px-2.5 py-1 rounded-full border border-emerald-500/20",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-400 animate-pulse"}),e.jsx("span",{children:"Sandbox Ready"})]})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-5 space-y-4 custom-scrollbar",children:[$.length===0?e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center p-6 text-pearl-400 space-y-2",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-space-850 flex items-center justify-center text-2xl",children:a.emoji||"๐Ÿค–"}),e.jsxs("div",{className:"text-xs font-semibold text-pearl-200",children:["Ready to test ",a.name]}),e.jsx("p",{className:"text-[11px] max-w-xs text-pearl-400",children:"Click a quick test prompt below or type your own question to see how this agent responds to your Telegram subscribers."})]}):$.map((_,F)=>e.jsxs("div",{className:`flex flex-col ${_.role==="user"?"items-end":"items-start"}`,children:[e.jsx("div",{className:`max-w-[85%] rounded-2xl px-4 py-3 text-xs leading-relaxed font-sans ${_.role==="user"?"bg-[#2B5278] border border-[#6AB2F2]/30 text-white rounded-br-sm shadow-md":"bg-[#182533] border border-white/10 text-slate-100 rounded-bl-sm shadow-md"}`,children:_.content}),_.tokens!==void 0&&e.jsxs("span",{className:"text-[9px] font-mono text-pearl-400 mt-1 px-1",children:[_.tokens," tokens ยท $",_.costCents]})]},F)),ae&&e.jsxs("div",{className:"flex items-center gap-2 text-xs font-mono text-[#2481CC] p-2 bg-space-950/60 rounded-xl border border-white/5 w-fit",children:[e.jsx(oe,{className:"w-3.5 h-3.5 animate-spin"}),e.jsxs("span",{children:["Generating completion from ",a.model,"..."]})]})]}),e.jsxs("div",{className:"px-4 py-2 border-t border-white/10 bg-space-950/60 flex items-center gap-1.5 overflow-x-auto no-scrollbar",children:[e.jsxs("span",{className:"text-[10px] font-mono text-pearl-400 uppercase tracking-wider shrink-0 flex items-center gap-1",children:[e.jsx(Ee,{className:"w-3 h-3 text-[#2481CC]"})," Test:"]}),["What services do you offer?","How much is VIP access?","Aap kaun hain?","How can I get support?"].map(_=>e.jsxs("button",{type:"button",onClick:()=>Me(_),className:"px-2.5 py-1 rounded-lg text-[11px] font-mono bg-space-900 border border-white/10 hover:border-[#2481CC] text-pearl-300 hover:text-white shrink-0 transition-colors",children:['"',_,'"']},_))]}),e.jsxs("form",{onSubmit:_=>{_.preventDefault(),Me()},className:"p-3.5 border-t border-white/10 flex items-center gap-2 bg-space-900",children:[e.jsx("input",{type:"text",value:D,onChange:_=>O(_.target.value),placeholder:"Ask anything (e.g. How do I start my bot?)...",className:"flex-1 px-4 py-2.5 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100 focus:outline-none focus:border-[#2481CC]"}),e.jsx("button",{type:"submit",disabled:ae||!D.trim(),className:"btn-telegram-primary py-2.5 px-4 shadow-telegram",children:e.jsx(ce,{className:"w-3.5 h-3.5"})})]})]})]}),j&&e.jsx(ne,{children:e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4 bg-black/75 backdrop-blur-md",children:e.jsxs("div",{className:"w-full max-w-xl max-h-[92vh] flex flex-col astraea-card rounded-2xl border border-[#2481CC]/40 shadow-2xl animate-in zoom-in-95 duration-200 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-white/10 bg-space-900/90 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-[#2481CC]/20 border border-[#2481CC]/40 text-[#2481CC] flex items-center justify-center",children:e.jsx(ge,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base sm:text-lg text-pearl-50 font-bold tracking-tight",children:d?`Edit Agent: ${d.name}`:"Create New AI Agent"}),e.jsx("p",{className:"text-xs text-pearl-400",children:"Configure personality, instructions, and intelligence level."})]})]}),e.jsx("button",{onClick:()=>f(!1),className:"text-pearl-400 hover:text-pearl-100 p-1.5 rounded-lg hover:bg-white/5",children:e.jsx(q,{className:"w-5 h-5"})})]}),e.jsxs("form",{onSubmit:Re,className:"flex-1 overflow-y-auto p-5 sm:p-6 space-y-5 custom-scrollbar",children:[!d&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-400 uppercase font-semibold",children:"Auto-fill from Preset (Optional):"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:js.map(_=>e.jsxs("button",{type:"button",onClick:()=>{h(_.name),c(_.emoji),x(_.model),k(_.systemPrompt),A(_.temperature)},className:"px-2.5 py-1.5 rounded-lg text-xs font-mono bg-space-900 border border-white/10 hover:border-[#2481CC] text-pearl-300 hover:text-white flex items-center gap-1.5 transition-colors",children:[e.jsx("span",{children:_.emoji}),e.jsx("span",{children:_.name})]},_.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:"Emoji Icon"}),e.jsx("input",{type:"text",maxLength:2,value:m,onChange:_=>c(_.target.value),className:"w-full text-center py-2.5 rounded-xl bg-space-950 border border-white/10 text-xl font-bold"})]}),e.jsxs("div",{className:"sm:col-span-3",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 mb-1 block",children:"Agent Name"}),e.jsx("input",{type:"text",required:!0,placeholder:"e.g. VIP Concierge",value:b,onChange:_=>h(_.target.value),className:"w-full px-3.5 py-2.5 rounded-xl bg-space-950 border border-white/10 text-xs font-mono text-pearl-100 focus:border-[#2481CC] focus:outline-none"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-mono font-bold uppercase text-pearl-200",children:"Intelligence & Language Model"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:[{id:"gpt-4o-mini",label:"GPT-4o Mini",desc:"Ultra Fast & Efficient (Recommended)",badge:"โšก FAST"},{id:"gpt-4o",label:"OpenAI GPT-4o",desc:"State of the Art Reasoning",badge:"๐ŸŒŸ SMART"},{id:"anthropic/claude-3.5-sonnet",label:"Claude 3.5 Sonnet",desc:"Superior Writing & Tone",badge:"๐Ÿง  REASONING"}].map(_=>e.jsxs("button",{type:"button",onClick:()=>x(_.id),className:`p-3 rounded-xl border text-left transition-all ${w===_.id?"bg-[#2481CC]/20 border-[#2481CC] text-white shadow-telegram":"bg-space-950/60 border-white/10 text-pearl-400 hover:text-pearl-200 hover:bg-space-900"}`,children:[e.jsxs("div",{className:"flex items-center justify-between text-xs font-bold font-sans",children:[e.jsx("span",{children:_.label}),e.jsx("span",{className:"text-[9px] font-mono px-1 rounded bg-[#2481CC]/20 text-[#2481CC]",children:_.badge})]}),e.jsx("div",{className:"text-[10px] text-pearl-400 mt-1",children:_.desc})]},_.id))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[11px] font-mono text-pearl-300 block",children:"Personality Tone Presets:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:[{label:"๐ŸŽฉ Professional & Polite",addition:"Maintain a professional, polite, and refined tone."},{label:"โšก Direct & Concise",addition:"Be extremely direct, concise, and to-the-point with zero fluff."},{label:"๐Ÿ˜Š Friendly & Casual",addition:"Be warm, friendly, approachable, and engaging."},{label:"๐Ÿ‡ฎ๐Ÿ‡ณ Hindi / Hinglish Friendly",addition:"User ke sath Hindi ya Hinglish me naturally communicate karein."}].map(_=>e.jsx("button",{type:"button",onClick:()=>{N.includes(_.addition)||k(F=>F?`${F} /root/telegram-saas/apps/api/routes/billing.py:13: CouponValidationResponse, /root/telegram-saas/apps/api/routes/billing.py:26: ValidateCouponRequest, /root/telegram-saas/apps/api/routes/billing.py:109: result = await service.pay_with_wallet(tenant.id, req.plan_id, req.coupon_code) /root/telegram-saas/apps/api/routes/billing.py:126: tenant.id, req.new_plan_id, req.provider, req.coupon_code /root/telegram-saas/apps/api/routes/billing.py:264:@router.post("/coupons/validate", response_model=ApiResponse[CouponValidationResponse], status_code=status.HTTP_200_OK) /root/telegram-saas/apps/api/routes/billing.py:265:async def validate_coupon( /root/telegram-saas/apps/api/routes/billing.py:266: req: ValidateCouponRequest, /root/telegram-saas/apps/api/routes/billing.py:270: """Validates coupon code eligibility and calculates discount.""" /root/telegram-saas/apps/api/routes/billing.py:277: is_valid, coupon, discount, message = await service.coupons.validate_coupon( /root/telegram-saas/apps/api/routes/billing.py:284: data=CouponValidationResponse( /root/telegram-saas/apps/api/routes/billing.py:287: discount_type=coupon.discount_type if coupon else "none", /root/telegram-saas/apps/api/routes/billing.py:288: discount_value=coupon.discount_value if coupon else 0, grep: /root/telegram-saas/apps/api/routes/__pycache__/billing.cpython-312.pyc: binary file matches grep: /root/telegram-saas/tests/unit/__pycache__/test_coupons_and_entitlements.cpython-312-pytest-9.2.0.pyc: binary file matches /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:6:from modules.billing.coupon_service import CouponService /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:8:from modules.billing.models import Coupon, Plan /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:14:async def test_coupon_validation_and_discounts(db_session: AsyncSession): /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:18: coupon_service = CouponService(db_session) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:20: # 1. Percentage discount coupon /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:22: pct_coupon = Coupon( /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:31: await coupon_service.repo.create_coupon(pct_coupon) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:33: is_valid, c, discount, msg = await coupon_service.validate_coupon(code_pct, "starter", 99900) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:37: # 2. Fixed amount discount coupon /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:39: fixed_coupon = Coupon( /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:48: await coupon_service.repo.create_coupon(fixed_coupon) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:50: is_valid, c, discount, msg = await coupon_service.validate_coupon(code_fixed, "starter", 99900) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:54: # 3. Expired coupon must fail /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:56: expired_coupon = Coupon( /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:65: await coupon_service.repo.create_coupon(expired_coupon) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:67: is_valid, c, discount, msg = await coupon_service.validate_coupon(code_exp, "starter", 99900) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:73: maxed_coupon = Coupon( /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:80: times_redeemed=1, /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:83: await coupon_service.repo.create_coupon(maxed_coupon) /root/telegram-saas/tests/unit/test_coupons_and_entitlements.py:85: is_valid, c, discount, msg = await coupon_service.validate_coupon(code_max, "starter", 99900) /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:9:from modules.billing.models import Coupon, Plan, Subscription /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:55: # 4. Create coupon for discount verification /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:57: coupon_code = f"LAUNCH_{uuid.uuid4().hex[:4].upper()}" /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:58: coupon = Coupon( /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:60: code=coupon_code, /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:66: await b_service.coupons.repo.create_coupon(coupon) /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:68: # 5. Create checkout order for Starter plan with coupon /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:75: "coupon_code": coupon_code, /root/telegram-saas/tests/integration/test_billing_checkout_and_lifecycle.py:81: # Starter is โ‚น999 - โ‚น500 coupon = โ‚น499 (49900 paise) grep: /root/telegram-saas/tests/integration/__pycache__/test_billing_checkout_and_lifecycle.cpython-312-pytest-9.2.0.pyc: binary file matches