BuyTicket.cshtml 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. @model LotteryWebApp.Models.HomeIndex_ViewModel
  2. @{
  3. ViewData["Title"] = "Millions - Buy Ticket";
  4. Layout = "~/Areas/Millions/Views/Shared/_Layout.cshtml";
  5. var currentTerm = Model.listTerm?.FirstOrDefault();
  6. }
  7. @using LotteryWebApp.Languages;
  8. @using LotteryWebApp.Common;
  9. @section Styles {
  10. <link rel="stylesheet" href="/Millions/css/buy-ticket.css" asp-append-version="true" />
  11. <style>
  12. /* BuyTicket has its own bottom bar; avoid global navbar padding gap */
  13. body.millions-bg { padding-bottom: 0 !important; }
  14. body.millions-bg .main-container { padding-bottom: 0 !important; }
  15. </style>
  16. }
  17. @if (Model.termType == Constants.PIC10_BIGSMALL_CODE || Model.termType == Constants.PIC10_ODDEVEN_CODE)
  18. {
  19. var isBigSmall = Model.termType == Constants.PIC10_BIGSMALL_CODE;
  20. var themeColor = isBigSmall ? "#0A9800" : "#AA3DC8";
  21. var gameTitle = isBigSmall ? Lang.millions_big_small : Lang.millions_odd_even;
  22. var prizeAmount = isBigSmall ? "100.000" : "200.000";
  23. <!-- ==================== CARD SELECTION GAME UI (BIG/SMALL or ODD/EVEN) ==================== -->
  24. <div class="millions-buy-ticket-page main-container animate__animated animate__fadeIn overflow-hidden">
  25. <!-- Header -->
  26. <div class="header">
  27. <button onclick="location.href='@Url.Action("GameHome", "Home")'" class="back-btn" type="button">
  28. <i class="fa-solid fa-arrow-left"></i>
  29. </button>
  30. <div class="header-title">@gameTitle</div>
  31. </div>
  32. <div class="content-card">
  33. <!-- Sticky Term Info sub-header -->
  34. <div class="ticket-subheader">
  35. <div class="flex items-center justify-between">
  36. <div class="flex items-center gap-2 border border-[#E5E7EB] rounded-lg px-3 py-1.5 bg-gray-50">
  37. <i class="fa-regular fa-calendar text-[[@themeColor]] text-sm" style="color: @themeColor"></i>
  38. <span class="text-[12px] font-bold text-gray-700">@DateTime.Now.ToString("dddd, MMM dd, yyyy", new System.Globalization.CultureInfo("en-US"))</span>
  39. </div>
  40. <div class="flex items-center gap-1 ml-4 flex-1 justify-end">
  41. <span class="text-[12px] font-bold text-gray-400">@Lang.millions_round</span>
  42. <span class="text-[18px] font-black text-brown-main">#@(currentTerm?.id ?? "123")</span>
  43. </div>
  44. </div>
  45. </div>
  46. <!-- Scrollable Content Area -->
  47. <div class="ticket-scroll-area bg-white pb-40" id="bsContent">
  48. <!-- Results for the last 5 days -->
  49. <div class="px-5 pt-4 pb-2">
  50. <h3 class="text-[17px] font-bold text-black text-center mb-3">Results for the last 5 days</h3>
  51. <div id="last5Results" class="flex justify-between gap-1.5 px-1">
  52. @{
  53. var pastTerms = ViewBag.PastTerms as List<LotteryWebApp.Service.Term> ?? new List<LotteryWebApp.Service.Term>();
  54. foreach (var term in pastTerms) {
  55. var rawResult = (term.result ?? "").Trim().ToUpper();
  56. var dateStr = "--";
  57. DateTime dt;
  58. if (DateTime.TryParse(term.date_random, out dt)) {
  59. dateStr = dt.ToString("MMM dd", new System.Globalization.CultureInfo("en-US"));
  60. }
  61. var resKey = rawResult;
  62. var resTitle = rawResult;
  63. if (isBigSmall) {
  64. if (rawResult == "S") { resKey = "Small"; resTitle = Lang.Small; }
  65. else if (rawResult == "B") { resKey = "Big"; resTitle = Lang.Big; }
  66. } else {
  67. if (rawResult == "O") { resKey = "Odd"; resTitle = Lang.Odd; }
  68. else if (rawResult == "E") { resKey = "Even"; resTitle = Lang.Even; }
  69. }
  70. var resColor = "";
  71. var bgStyle = "background: linear-gradient(136deg, #FFFAE6 0%, #FFE588 100%);";
  72. var textStyle = "-webkit-text-stroke: 0.5px #000;";
  73. if (resKey == "NA" || string.IsNullOrEmpty(rawResult)) {
  74. bgStyle = "background: #EAEAEA;";
  75. resTitle = "";
  76. textStyle = "";
  77. } else {
  78. if (isBigSmall) {
  79. resColor = resKey == "Big" ? "#A2FF00" : "#FF4157";
  80. } else {
  81. resColor = resKey == "Odd" ? "#FFC700" : "#B33BD0";
  82. }
  83. textStyle += $" color: {resColor};";
  84. }
  85. <div class="flex flex-col items-center justify-center min-h-[64px] flex-1 rounded-lg py-1.5 border border-gray-200" style="@bgStyle">
  86. <span class="text-[11px] font-bold text-black whitespace-nowrap opacity-70">@dateStr</span>
  87. <span class="text-[22px] font-black leading-tight" style="@textStyle">@resTitle</span>
  88. </div>
  89. }
  90. for(int r = pastTerms.Count; r < 5; r++) {
  91. <div class="flex flex-col items-center justify-center min-h-[64px] flex-1 rounded-lg py-1.5 border border-gray-200" style="background: #EAEAEA; opacity: 0.7;">
  92. <span class="text-[11px] font-bold text-black whitespace-nowrap opacity-70">--</span>
  93. <span class="text-[22px] font-black leading-tight" style="color: transparent;"></span>
  94. </div>
  95. }
  96. }
  97. </div>
  98. </div>
  99. <!-- Selection Cards -->
  100. <!-- Selection Cards -->
  101. <div class="px-5 pt-4 flex gap-3 h-[245px]">
  102. <!-- Card 1 (Big or Odd) -->
  103. <div id="cardBig" onclick="selectBigSmall('big')" class="bigsmall-card flex-1 rounded-2xl relative cursor-pointer transition-all duration-300 active:scale-[0.97] border-2 border-transparent overflow-hidden flex flex-col" style="background: linear-gradient(180deg, #FFF7DB 0%, #FFEEB3 100%);">
  104. <img src="/Millions/img/bigsmall/light_effect_1.png" class="absolute top-0 left-0 w-full opacity-60 pointer-events-none" alt="" />
  105. <img src="/Millions/img/bigsmall/light_effect_2.png" class="absolute bottom-12 left-0 w-full opacity-60 pointer-events-none" alt="" />
  106. <div class="flex flex-col items-center pt-4 pb-3 px-3 relative z-10 h-full justify-between">
  107. <div class="flex flex-col items-center w-full">
  108. <div class="h-[34px] flex items-center justify-center">
  109. <div class="text-[40px] font-[800] leading-none" style="-webkit-text-stroke: 1px #000; text-shadow: 1px 2px 2px rgba(0,0,0,0.15); color: @(isBigSmall ? "#A2FF00" : "#FFC700");">@(isBigSmall ? "Big" : "Odd")</div>
  110. </div>
  111. <div class="text-[11px] font-medium text-gray-500 mt-1 h-[28px] text-center leading-tight">
  112. @(isBigSmall ? "13 number from" : "Odd numbers") <br/> <b>@(isBigSmall ? "41-80" : "1, 3, 5, 7, 9")</b>
  113. </div>
  114. </div>
  115. <div class="flex items-center justify-center -space-x-2 my-2">
  116. @if (isBigSmall) {
  117. <img src="/Millions/img/bigsmall/ball_42_dark.png" class="w-12 h-12 relative z-[1]" alt="42" />
  118. <img src="/Millions/img/bigsmall/ball_88_big.png" class="w-16 h-16 relative z-[2]" alt="88" />
  119. <img src="/Millions/img/bigsmall/ball_54_dark.png" class="w-12 h-12 relative z-[1]" alt="54" />
  120. } else {
  121. <img src="/Millions/img/oddeven/ball_3.png" class="w-12 h-12 relative z-[1]" alt="3" />
  122. <img src="/Millions/img/oddeven/ball_1.png" class="w-16 h-16 relative z-[2]" alt="1" />
  123. <img src="/Millions/img/oddeven/ball_19.png" class="w-12 h-12 relative z-[1]" alt="19" />
  124. }
  125. </div>
  126. <button class="bigsmall-btn w-full py-2.5 rounded-xl font-black text-[15px] transition-all shadow-md" style="background: @themeColor; color: white;">@Lang.millions_select</button>
  127. </div>
  128. </div>
  129. <!-- Card 2 (Small or Even) -->
  130. <div id="cardSmall" onclick="selectBigSmall('small')" class="bigsmall-card flex-1 rounded-2xl relative cursor-pointer transition-all duration-300 active:scale-[0.97] border-2 border-transparent overflow-hidden flex flex-col" style="background: linear-gradient(180deg, #FFF7DB 0%, #FFEEB3 100%);">
  131. <img src="/Millions/img/bigsmall/light_effect_1.png" class="absolute top-0 left-0 w-full opacity-60 pointer-events-none" alt="" />
  132. <img src="/Millions/img/bigsmall/light_effect_2.png" class="absolute bottom-12 left-0 w-full opacity-60 pointer-events-none" alt="" />
  133. <div class="flex flex-col items-center pt-4 pb-3 px-3 relative z-10 h-full justify-between">
  134. <div class="flex flex-col items-center w-full">
  135. <div class="h-[34px] flex items-center justify-center">
  136. <div class="text-[40px] font-[800] leading-none italic" style="-webkit-text-stroke: 1px #000; text-shadow: 1px 2px 2px rgba(0,0,0,0.15); color: @(isBigSmall ? "#FF4157" : "#B33BD0");">@(isBigSmall ? "Small" : "Even")</div>
  137. </div>
  138. <div class="text-[11px] font-medium text-gray-500 mt-1 h-[28px] text-center leading-tight">
  139. @(isBigSmall ? "13 number from" : "Even numbers") <br/> <b>@(isBigSmall ? "01-40" : "0, 2, 4, 6, 8")</b>
  140. </div>
  141. </div>
  142. <div class="flex items-center justify-center -space-x-2 my-2">
  143. @if (isBigSmall) {
  144. <img src="/Millions/img/bigsmall/ball_5_blue.png" class="w-12 h-12 relative z-[1]" alt="5" />
  145. <img src="/Millions/img/bigsmall/ball_1_big.png" class="w-16 h-16 relative z-[2]" alt="1" />
  146. <img src="/Millions/img/bigsmall/ball_8_pink.png" class="w-12 h-12 relative z-[1]" alt="8" />
  147. } else {
  148. <img src="/Millions/img/oddeven/ball_66.png" class="w-12 h-12 relative z-[1]" alt="66" />
  149. <img src="/Millions/img/oddeven/ball_68.png" class="w-16 h-16 relative z-[2]" alt="68" />
  150. <img src="/Millions/img/oddeven/ball_88.png" class="w-12 h-12 relative z-[1]" alt="88" />
  151. }
  152. </div>
  153. <button class="bigsmall-btn w-full py-2.5 rounded-xl font-black text-[15px] transition-all shadow-md"
  154. style="background: @themeColor; color: white;">@Lang.millions_select</button>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- You Choose + Prize Section -->
  159. <div class="px-5 pt-6 flex flex-col items-center gap-4">
  160. <div class="flex flex-col items-center">
  161. <span class="text-[15px] font-medium text-black">@Lang.millions_you_choose</span>
  162. <span id="choiceDisplay" class="text-[42px] font-[800] leading-tight" style="-webkit-text-stroke: 1px #000;">—</span>
  163. </div>
  164. <div class="flex flex-col items-center">
  165. <span class="text-[18px] font-medium text-black">@Lang.millions_prize_if_win</span>
  166. <div class="flex items-baseline gap-1">
  167. <span class="text-[28px] font-black text-black">@prizeAmount</span>
  168. <span class="text-[14px] font-black text-[#E56B23]">HTG</span>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. <!-- Bottom Action Bar -->
  174. <div class="p-4 bg-white border-t border-gray-200 z-[70] shadow-[0px_-4px_10px_rgba(0,0,0,0.03)] absolute bottom-0 w-full left-0">
  175. <div class="flex items-center justify-between">
  176. <div class="flex flex-col">
  177. <div class="flex items-center gap-1.5 mb-0.5">
  178. <span class="text-[11px] text-black font-black uppercase">@Lang.total_ticket:</span>
  179. <span id="bsTotalTicketCount" class="text-[12px] font-black text-black">0</span>
  180. </div>
  181. <span class="text-[11px] text-black font-black uppercase">@Lang.millions_estimated_ticket_price</span>
  182. <div class="flex items-baseline gap-1">
  183. <span id="bsTotalPrice" class="text-[28px] font-black text-black">0</span>
  184. <span class="text-[13px] font-black" style="color: @themeColor">HTG</span>
  185. </div>
  186. </div>
  187. <button id="bsPaymentBtn" onclick="bsShowPayment()" class="text-white text-[20px] font-black px-10 py-3.5 rounded-xl shadow-lg active:scale-95 transition-all" style="background: @themeColor;">
  188. @Lang.millions_payment
  189. </button>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. }
  195. else
  196. {
  197. <!-- ==================== Basic Pick 10 / Odd-Even GAME UI ==================== -->
  198. <div class="millions-buy-ticket-page main-container animate__animated animate__fadeIn overflow-hidden">
  199. <!-- Header -->
  200. <div class="header">
  201. <button onclick="location.href='@Url.Action("GameHome", "Home")'" class="back-btn" type="button">
  202. <i class="fa-solid fa-arrow-left"></i>
  203. </button>
  204. <div class="header-title">
  205. @if (Model.termType == Constants.PIC10_BASIC_CODE) { <text>Basic Pick 10</text> }
  206. else if (Model.termType == Constants.Millions_CODE) { <text>Millions</text> }
  207. else { @Lang.millions_odd_even }
  208. </div>
  209. </div>
  210. <div class="content-card">
  211. <!-- Sticky Term Info sub-header -->
  212. <div class="ticket-subheader">
  213. <div class="flex items-center justify-between">
  214. <div class="flex items-center gap-2 border border-[#E5E7EB] rounded-lg px-3 py-1.5 bg-gray-50">
  215. <i class="fa-regular fa-calendar text-[#0062FF] text-sm"></i>
  216. <span class="text-[12px] font-bold text-gray-700">@DateTime.Now.ToString("dddd, MMM dd, yyyy", new System.Globalization.CultureInfo("en-US"))</span>
  217. </div>
  218. <div class="flex items-center gap-1 ml-4 flex-1 justify-end">
  219. <span class="text-[12px] font-bold text-gray-400">@Lang.millions_round</span>
  220. <span class="text-[18px] font-black text-brown-main">#@(currentTerm?.id ?? "12459")</span>
  221. </div>
  222. </div>
  223. </div>
  224. <!-- Ticket Scrollable List Area -->
  225. <div id="ticketContainer" class="ticket-scroll-area p-4 flex flex-col gap-6 bg-[#F5F5F5] pb-6">
  226. @for (int i = 1; i <= 2; i++)
  227. {
  228. <div class="ticket-card relative group active:bg-gray-50 transition-colors cursor-pointer animate__animated animate__fadeIn">
  229. <button onclick="removeEntry(this)" class="absolute -right-2 top-2 w-7 h-7 bg-[#FF0000] text-white rounded-full flex items-center justify-center text-[11px] shadow-sm z-[10] hover:bg-red-700 transition-all border-2 border-red-600">
  230. <i class="fa-solid fa-xmark"></i>
  231. </button>
  232. <div class="absolute left-2 top-4 w-9 h-9 rounded-full border-[3px] border-white flex items-center justify-center text-white font-black text-sm shadow-md ticket-index">@i</div>
  233. <div class="flex flex-col gap-1 pl-8">
  234. <span class="text-[16px] font-extrabold text-[#333]">@Lang.millions_select_10_lucky_numbers</span>
  235. <div class="flex items-center gap-4">
  236. <div class="grid grid-cols-6 gap-y-2 gap-x-1 flex-1">
  237. @for (int j = 0; j < (Model.termType == Constants.PIC10_BASIC_CODE ? 10 : (Model.termType == Constants.Millions_CODE ? 6 : 15)); j++)
  238. {
  239. var isMbBall = Model.termType == Constants.Millions_CODE && j == 5;
  240. <div class="relative w-fit">
  241. <div class="ball-circle ball-empty@(isMbBall ? " ball-mb-circle" : "")"></div>
  242. @if (isMbBall)
  243. {
  244. <div class="absolute -bottom-[6px] -right-[4px] bg-[#FFD700] text-black text-[8.5px] font-black px-[2.5px] py-[1.5px] rounded-[3px] shadow-sm leading-none z-10 border border-[#EAA800]">MB</div>
  245. }
  246. </div>
  247. }
  248. </div>
  249. <div class="w-[90px] action-area flex flex-col gap-2">
  250. <button onclick="randomizeTicket(this)" class="rand-btn w-full bg-[#2B83F2] text-white flex items-center justify-center gap-1.5 py-1.5 rounded-xl font-extrabold text-[11px] shadow-sm active:scale-95 transition-all">
  251. <i class="fa-solid fa-arrows-rotate text-[10px]"></i> @Lang.Random
  252. </button>
  253. <div class="edit-delete-group hidden flex flex-col gap-2">
  254. <button onclick="editFullTicket(this)" class="w-full bg-[#16A34A] text-white flex items-center justify-center gap-1.5 py-1.5 rounded-xl font-black text-[12px] shadow-sm active:scale-95 transition-all">
  255. <img src="/Millions/img/icons/icon_edit.png" onerror="this.style.display='none'" class="w-[16px] h-[16px] object-contain"> @Lang.millions_edit
  256. </button>
  257. <button onclick="clearTicket(this)" class="w-full bg-[#A855F7] text-white flex items-center justify-center gap-1.5 py-1.5 rounded-xl font-black text-[12px] shadow-sm active:scale-95 transition-all">
  258. <img src="/Millions/img/icons/icon_delete.png" onerror="this.style.display='none'" class="w-[16px] h-[16px] object-contain"> @Lang.millions_delete
  259. </button>
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. }
  266. <div class="w-full pt-2" id="addButtonWrapper">
  267. <button onclick="addNewTicket()" class="w-fit min-w-[220px] mx-auto bg-[#2B83F2] text-white font-black text-md py-2.5 px-6 rounded-xl shadow-md border-b-[4px] border-[#1F66D6] active:translate-y-[1px] active:border-b-[1px] transition-all flex items-center justify-center gap-2">
  268. @Lang.millions_add_more_ticket
  269. </button>
  270. </div>
  271. <div class="h-4"></div>
  272. </div>
  273. <!-- Bottom Action Bar -->
  274. <div class="ticket-bottom-bar p-4 bg-white border-t border-gray-200 z-[70] shadow-[0px_-4px_10px_rgba(0,0,0,0.03)]">
  275. <div class="flex items-center justify-between">
  276. <div class="flex flex-col">
  277. <div class="flex items-center gap-1.5 mb-0.5">
  278. <span class="text-[11px] text-black font-black uppercase">@Lang.total_ticket:</span>
  279. <span id="totalTicketCount" class="text-[12px] font-black text-black">0</span>
  280. </div>
  281. <span class="text-[11px] text-black font-black uppercase">@Lang.millions_estimated_ticket_price</span>
  282. <div class="flex items-baseline gap-1">
  283. <span id="totalPrice" class="text-[28px] font-black text-black">0</span>
  284. <span class="text-[13px] font-black text-[#0062FF]">HTG</span>
  285. </div>
  286. </div>
  287. <button onclick="preparePayment()" class="bg-[#0062FF] text-white text-[20px] font-black px-10 py-3.5 rounded-xl shadow-[0px_6px_15px_rgba(238,0,51,0.25)] active:scale-95 transition-all">
  288. @Lang.millions_payment
  289. </button>
  290. </div>
  291. </div>
  292. </div>
  293. </div>
  294. }
  295. <!-- Payment channel selection -->
  296. <div id="paymentChannelModal" class="hidden fixed inset-0 z-[140] bg-black/70 backdrop-blur-[3px] items-center justify-center p-4 font-bricolage">
  297. <div class="relative w-full max-w-[370px] overflow-hidden rounded-[32px] bg-[#F8F9FC] shadow-[0_28px_70px_rgba(0,0,0,0.35)] animate__animated animate__zoomIn animate__faster">
  298. <div class="relative overflow-hidden bg-gradient-to-br from-[#0062FF] to-[#003FA8] px-6 pb-7 pt-6 text-white">
  299. <div class="absolute -right-8 -top-10 h-32 w-32 rounded-full bg-white/10"></div><div class="absolute -bottom-12 -left-8 h-28 w-28 rounded-full bg-black/10"></div>
  300. <button type="button" onclick="hidePaymentChannelModal()" class="absolute right-4 top-4 z-10 flex h-9 w-9 items-center justify-center rounded-full bg-white/15 text-white transition hover:bg-white/25 active:scale-90" aria-label="Close"><i class="fa-solid fa-xmark"></i></button>
  301. <div class="relative z-[1] flex items-center gap-4"><div class="flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-white text-[25px] text-[#0062FF] shadow-lg"><i class="fa-solid fa-wallet"></i></div><div><h2 class="text-[21px] font-black leading-tight">@Lang.payment_method_title</h2><p class="mt-1 text-[13px] font-semibold text-white/80">@Lang.payment_method_subtitle</p></div></div>
  302. </div>
  303. <div class="space-y-3 p-5">
  304. <button type="button" onclick="selectPaymentChannel('@Constants.BASIC_WALLET_TICKET')" class="group flex w-full items-center gap-4 rounded-[20px] border-2 border-transparent bg-white p-4 text-left shadow-[0_5px_18px_rgba(31,41,55,0.07)] transition hover:-translate-y-0.5 hover:border-[#0062FF] active:scale-[0.98]">
  305. <span class="flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[#E7F0FF] text-[21px] text-[#0062FF]"><i class="fa-solid fa-mobile-screen-button"></i></span><span class="min-w-0 flex-1"><span class="block text-[16px] font-black text-[#171A24]">@Lang.payment_main_account</span><span class="mt-0.5 block text-[12px] font-semibold text-gray-500">@Lang.payment_main_account_desc</span></span><span class="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 text-gray-400 transition group-hover:bg-[#0062FF] group-hover:text-white"><i class="fa-solid fa-chevron-right text-[12px]"></i></span>
  306. </button>
  307. <button type="button" onclick="selectPaymentChannel('@Constants.NATCASH_WALLET_TICKET')" class="group flex w-full items-center gap-4 rounded-[20px] border-2 border-transparent bg-white p-4 text-left shadow-[0_5px_18px_rgba(31,41,55,0.07)] transition hover:-translate-y-0.5 hover:border-[#0A9800] active:scale-[0.98]">
  308. <span class="flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-[#E7F8E6] text-[21px] text-[#0A9800]"><i class="fa-solid fa-wallet"></i></span><span class="min-w-0 flex-1"><span class="flex items-center gap-2 text-[16px] font-black text-[#171A24]">@Lang.payment_wallet <span class="rounded-full bg-[#E7F8E6] px-2 py-0.5 text-[9px] font-black text-[#0A9800]">PIN</span></span><span class="mt-0.5 block text-[12px] font-semibold text-gray-500">@Lang.payment_wallet_desc</span></span><span class="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 text-gray-400 transition group-hover:bg-[#0A9800] group-hover:text-white"><i class="fa-solid fa-chevron-right text-[12px]"></i></span>
  309. </button>
  310. <p class="pt-1 text-center text-[11px] font-semibold text-gray-400"><i class="fa-solid fa-shield-halved mr-1 text-[#0A9800]"></i>@Lang.payment_security_message</p>
  311. </div>
  312. </div>
  313. </div>
  314. <!-- Order Summary Screen (from Figma) -->
  315. <div id="orderSummaryModal" class="hidden fixed inset-0 z-[150] bg-black/60 flex items-center justify-center p-0 font-bricolage backdrop-blur-[2px]">
  316. <div class="w-full h-full bg-white flex flex-col animate__animated animate__fadeInRight animate__faster shadow-2xl relative lg:max-w-[414px]">
  317. <!-- Header đồng bộ tuyệt đối -->
  318. <div class="buy-ticket-modal-header sticky top-0 z-[60]">
  319. <button onclick="hideOrderSummary()" class="back-btn" type="button">
  320. <i class="fa-solid fa-arrow-left"></i>
  321. </button>
  322. <div class="header-title">
  323. @if (Model.termType == Constants.PIC10_BASIC_CODE) { <text>Basic Pick 10</text> }
  324. else if (Model.termType == Constants.Millions_CODE) { <text>Millions</text> }
  325. else if (Model.termType == Constants.PIC10_BIGSMALL_CODE) { @Lang.millions_big_small }
  326. else { @Lang.millions_odd_even }
  327. </div>
  328. </div>
  329. <!-- Content Area: Split into scrollable list and static summary -->
  330. <div class="flex-1 flex flex-col min-h-0 bg-gray-50">
  331. <!-- Scrollable Ticket List -->
  332. <div class="flex-1 overflow-y-auto p-5 pb-2">
  333. <div class="flex justify-between items-center px-1 mb-3">
  334. <span class="text-[14px] font-bold text-gray-800">Selected Tickets</span>
  335. <span class="text-[14px] font-bold text-gray-800">@Lang.price</span>
  336. </div>
  337. <!-- Ticket List -->
  338. <div id="summaryTicketList" class="flex flex-col gap-4">
  339. <!-- Populated dynamically via JS -->
  340. </div>
  341. </div>
  342. <!-- Static Summary Info (Dates & Totals) -->
  343. <div class="shrink-0 bg-white p-5 space-y-4 border-t border-gray-100 shadow-[0px_-10px_20px_rgba(0,0,0,0.03)]">
  344. <!-- Dates Section -->
  345. <div class="grid grid-cols-2 gap-4">
  346. <div class="space-y-1">
  347. <span class="text-[11px] font-black text-[#0062FF] block text-center uppercase tracking-tight">@Lang.date_purchase</span>
  348. <div class="bg-white border border-gray-100 rounded-xl py-2.5 px-2 text-center font-black text-[11px] text-gray-700 shadow-sm">
  349. @DateTime.Now.ToString("dddd MMM dd, yyyy", new System.Globalization.CultureInfo("en-US"))
  350. </div>
  351. </div>
  352. <div class="space-y-1">
  353. <span class="text-[11px] font-black text-[#0062FF] block text-center uppercase tracking-tight">@Lang.draw_date</span>
  354. <div class="bg-white border border-gray-100 rounded-xl py-2.5 px-2 text-center font-black text-[11px] text-gray-700 shadow-sm" id="summaryResultDate">
  355. @{
  356. DateTime drawDate;
  357. bool isValidDate = DateTime.TryParse(currentTerm?.date_end, out drawDate);
  358. if (isValidDate) {
  359. @drawDate.ToString("dddd MMM dd, yyyy", new System.Globalization.CultureInfo("en-US"))
  360. } else {
  361. @:N/A
  362. }
  363. }
  364. </div>
  365. </div>
  366. </div>
  367. <!-- Totals Section -->
  368. <div class="space-y-1 px-1">
  369. <div class="flex justify-between items-center">
  370. <span class="text-[14px] font-bold text-black">@Lang.total_ticket</span>
  371. <span id="summaryTotalCount" class="text-[16px] font-black text-black">0</span>
  372. </div>
  373. <div class="flex justify-between items-center">
  374. <span class="text-[14px] font-bold text-black">@Lang.total_money</span>
  375. <div class="flex items-baseline gap-1">
  376. <span id="summaryTotalAmount" class="text-[32px] font-black text-black">0</span>
  377. <span class="text-[16px] font-black text-[#0062FF]">HTG</span>
  378. </div>
  379. </div>
  380. </div>
  381. </div>
  382. </div>
  383. <div class="shrink-0 p-4 bg-white border-t border-gray-100 grid grid-cols-2 gap-4 pb-8 shadow-[0px_-4px_20px_rgba(0,0,0,0.05)]">
  384. <button onclick="hideOrderSummary()" class="bg-[#FFB000] text-white py-2.5 rounded-2xl font-black text-[18px] shadow-lg shadow-orange-200 active:scale-95 transition-all uppercase tracking-wide">
  385. @Lang.reorder
  386. </button>
  387. <button id="finalPaymentBtn" onclick="confirmCheckout(this)" class="bg-[#0062FF] text-white py-2.5 rounded-2xl font-black text-[18px] shadow-lg shadow-red-200 active:scale-95 transition-all uppercase tracking-wide">
  388. @Lang.millions_payment
  389. </button>
  390. </div>
  391. </div>
  392. </div>
  393. <!-- OTP Verification Modal (V2 Design Overhaul - Matching Figma) -->
  394. <div id="otpModal" class="fixed inset-0 bg-black/80 backdrop-blur-sm z-[200] hidden items-center justify-center p-4">
  395. <!-- Outer container to hold the modal + external overflowing elements (like stars/glitter) -->
  396. <div class="relative w-full max-w-[360px] mt-6 animate__animated animate__zoomIn animate__faster">
  397. <!-- Glitter effect (external to the white box) -->
  398. <div class="absolute -top-[100px] -left-[10px] w-[380px] h-[160px] mix-blend-screen pointer-events-none z-0 overflow-visible opacity-90" style="background: url('/Millions/img/modal/otp_glitter.png') no-repeat center center; background-size: contain;"></div>
  399. <!-- The White Box -->
  400. <div class="bg-white rounded-[32px] w-full relative z-10 shadow-[0px_0px_30px_rgba(255,255,255,0.15)] pb-5 border border-yellow-500/20">
  401. <!-- Floating Coins from Figma -->
  402. <div class="absolute -top-[40px] -right-[10px] z-[80] w-[120px] pointer-events-none drop-shadow-2xl">
  403. <img src="/Millions/img/modal/otp_coins.png" class="w-full object-contain" />
  404. </div>
  405. <!-- Red Header Section -->
  406. <div class="relative w-full pt-4 pb-4 bg-[#0062FF] rounded-t-[32px] flex flex-col items-center justify-center z-20" style="border-bottom-left-radius: 50% 20px; border-bottom-right-radius: 50% 20px;">
  407. <h2 class="text-white text-[17px] sm:text-[20px] font-[900] uppercase tracking-wide relative z-10 font-bricolage drop-shadow-md text-center px-4 leading-tight w-[80%] mr-auto">@Lang.millions_confirm_purchase</h2>
  408. </div>
  409. <!-- Modal Body Content -->
  410. <div class="relative px-6 pt-3 flex flex-col items-center gap-3 z-10">
  411. <!-- Shield Icon: mix-blend-mode multiply to remove the white square background -->
  412. <div class="relative w-full flex justify-center mb-0 mt-1">
  413. <img src="/Millions/img/modal/otp_shield.png" alt="Success" class="w-[90px] object-contain">
  414. </div>
  415. <!-- Info Rows (Aligned exactly like screenshot) -->
  416. <div class="w-full flex flex-col gap-2 items-center mt-0">
  417. <!-- Ticket Info -->
  418. <div class="grid grid-cols-[90px_auto] items-center gap-3 w-full justify-center">
  419. <span class="text-[15px] font-bold text-[#555] text-right font-bricolage">@Lang.millions_ticket</span>
  420. <div id="otpTicketTypeContainer" class="flex justify-start">
  421. <img id="otpTicketTypeImg" src="/Millions/img/even_text.png" class="h-6 object-contain drop-shadow-sm" />
  422. </div>
  423. </div>
  424. <!-- Amount Info -->
  425. <div class="grid grid-cols-[90px_auto] items-center gap-3 w-full justify-center">
  426. <span class="text-[15px] font-bold text-[#555] text-right font-bricolage">@Lang.millions_amount</span>
  427. <div class="flex items-baseline gap-1.5 justify-start">
  428. <span id="otpTotalAmount" class="text-[22px] font-[900] text-black leading-none tracking-tight">1.000</span>
  429. <span class="text-[15px] font-[900] text-[#F37021] font-bricolage">HTG</span>
  430. </div>
  431. </div>
  432. </div>
  433. <p id="paymentCodeInstruction" class="text-[14px] font-bold text-[#555] text-center px-4 leading-snug mt-0 font-bricolage">@Lang.millions_otp_instruction</p>
  434. <!-- 6-Slots OTP Grid (Large Gray Blocks) -->
  435. <div class="flex items-center justify-center gap-2 w-full mt-1 px-2" id="otpInputs">
  436. @for (int i = 1; i <= 6; i++)
  437. {
  438. <input type="tel" maxlength="1" id="otp@(i)"
  439. oninput="moveToNext(this, '@(i < 6 ? "otp" + (i + 1) : "")')"
  440. class="w-[42px] h-[48px] bg-[#757575] rounded-[10px] text-white text-[26px] font-bold text-center appearance-none focus:bg-[#555] focus:scale-[1.03] focus:ring-2 focus:ring-[#0062FF]/50 transition-all outline-none shadow-inner otp-slot"
  441. placeholder="-">
  442. }
  443. </div>
  444. <!-- OTP Error Message -->
  445. <p id="otpError" class="text-[#0062FF] font-bold text-[14px] text-center mb-1 hidden animate__animated animate__shakeX"></p>
  446. <!-- Timer & Resend -->
  447. <div class="flex flex-col items-center gap-1 mt-0">
  448. <span id="otpTimer" class="text-[15px] font-black text-[#0062FF] font-bricolage">60s</span>
  449. <button id="resendOtpBtn" onclick="sendOtpRequest()" class="hidden text-[14px] font-black text-[#0A9800] underline decoration-solid underline-offset-[3px] transition-all hover:text-[#087a00] disabled:opacity-40 disabled:no-underline font-bricolage">@Lang.millions_request_new_otp</button>
  450. </div>
  451. <!-- Action Buttons: Cancel / Confirm -->
  452. <div class="grid grid-cols-2 gap-3 w-full mt-2">
  453. <button onclick="hideOtpModal()" class="bg-[#FF0000] text-white py-[12px] rounded-[16px] font-[900] text-[17px] shadow-[0_8px_15px_rgba(255,0,0,0.2)] active:scale-95 transition-all tracking-wide">@Lang.millions_cancel</button>
  454. <button id="otpConfirmBtn" disabled onclick="finalizePurchase(this)" class="bg-[#0A9800] text-white py-[12px] rounded-[16px] font-[900] text-[17px] shadow-[0_8px_15px_rgba(10,152,0,0.2)] active:scale-95 transition-all tracking-wide disabled:opacity-50 disabled:grayscale disabled:cursor-not-allowed">@Lang.millions_confirm</button>
  455. </div>
  456. </div>
  457. </div>
  458. </div>
  459. </div>
  460. @section Scripts {
  461. <script>
  462. const maxBalls = @(Model.termType == Constants.PIC10_BASIC_CODE ? 10 : (Model.termType == Constants.Millions_CODE ? 6 : (Model.termType == Constants.PIC10_BIGSMALL_CODE ? 13 : 15)));
  463. function reindexTickets() {
  464. $(".ticket-card").each(function(index) {
  465. $(this).find(".ticket-index").text(index + 1);
  466. });
  467. }
  468. function removeEntry(btn) {
  469. var card = $(btn).closest('.ticket-card');
  470. card.addClass('animate__animated animate__fadeOutRight animate__faster');
  471. setTimeout(function() {
  472. card.remove();
  473. reindexTickets();
  474. updateTotalPrice();
  475. }, 300);
  476. }
  477. function randomizeTicket(btn) {
  478. var icon = $(btn).find('i');
  479. icon.addClass('fa-spin');
  480. var card = $(btn).closest('.ticket-card');
  481. var balls = card.find('.ball-circle');
  482. // Generate unique random numbers
  483. var numbers = [];
  484. if ("@Model.termType" === "@Constants.Millions_CODE") {
  485. // First 5 standard balls (1-70)
  486. while(numbers.length < 5){
  487. var r = Math.floor(Math.random() * 70) + 1;
  488. if(numbers.indexOf(r) === -1) numbers.push(r);
  489. }
  490. numbers.sort((a, b) => a - b);
  491. // 6th Mega Ball (1-24)
  492. var mb = Math.floor(Math.random() * 24) + 1;
  493. numbers.push(mb);
  494. } else {
  495. while(numbers.length < maxBalls){
  496. var r = Math.floor(Math.random() * 80) + 1;
  497. if(numbers.indexOf(r) === -1) numbers.push(r);
  498. }
  499. numbers.sort((a, b) => a - b);
  500. }
  501. // Update balls with staggered animation
  502. balls.each(function(index) {
  503. var ball = $(this);
  504. setTimeout(function() {
  505. var formattedNum = numbers[index].toString().padStart(2, '0');
  506. ball.removeClass('ball-empty').addClass('ball-filled').text(formattedNum);
  507. ball.addClass('animate__animated animate__flipInY');
  508. if(index === maxBalls - 1) {
  509. setTimeout(() => {
  510. icon.removeClass('fa-spin');
  511. // Replace button with Edit/Delete group
  512. $(btn).hide();
  513. card.find('.edit-delete-group').removeClass('hidden').addClass('animate__animated animate__fadeInRight animate__faster');
  514. updateTotalPrice();
  515. }, 300);
  516. }
  517. }, index * 40);
  518. });
  519. }
  520. function clearTicket(btn) {
  521. var card = $(btn).closest('.ticket-card');
  522. var balls = card.find('.ball-circle');
  523. balls.removeClass('ball-filled animate__animated animate__flipInY shadow-inner').addClass('ball-empty').text('');
  524. // Hide Edit/Delete group and show Rand button
  525. card.find('.edit-delete-group').addClass('hidden');
  526. card.find('.rand-btn').show().addClass('animate__animated animate__fadeInLeft animate__faster');
  527. updateTotalPrice();
  528. }
  529. // Open Number Picker Modal
  530. var activeBall = null;
  531. var activeTicketCard = null;
  532. var selectedNumbers = []; // For Edit mode, this will be an array of fixed size with nulls
  533. var isMultiMode = false;
  534. function editFullTicket(btn) {
  535. isMultiMode = true;
  536. activeTicketCard = $(btn).closest('.ticket-card');
  537. activeBall = null;
  538. // Initialize fixed slots for slot-based editing
  539. selectedNumbers = new Array(maxBalls).fill(null);
  540. let existing = [];
  541. activeTicketCard.find('.ball-filled').each(function() {
  542. var num = $(this).text().trim();
  543. if(num) existing.push(num);
  544. });
  545. // Initial fill from left to right
  546. existing.forEach((num, idx) => {
  547. if(idx < maxBalls) selectedNumbers[idx] = num;
  548. });
  549. openNumberPicker(true);
  550. }
  551. function openNumberPicker(isMulti) {
  552. var modal = $("#numberPickerModal");
  553. var grid = $("#numberGrid");
  554. var title = $("#modalTitle");
  555. var countArea = $(".selection-count-area");
  556. var confirmBtn = $("#confirmBtn");
  557. grid.empty();
  558. if (isMulti) {
  559. title.text("Edit Ticket");
  560. countArea.removeClass('hidden');
  561. confirmBtn.removeClass('hidden').text("@Lang.confirm");
  562. } else {
  563. title.text("Pick Number");
  564. countArea.addClass('hidden');
  565. confirmBtn.removeClass('hidden').text("@Lang.confirm");
  566. }
  567. updateSelectionCount();
  568. liveUpdateTicket();
  569. // Focus card: append a tall spacer so even the last ticket can scroll up
  570. // above the number-picker sheet (a flex column container does not honor
  571. // padding-bottom as scrollable space), then bring the card to the top.
  572. if (activeTicketCard && activeTicketCard.length) {
  573. var container = $("#ticketContainer");
  574. $("#editScrollSpacer").remove();
  575. container.append('<div id="editScrollSpacer" aria-hidden="true" style="height:100vh;flex-shrink:0;"></div>');
  576. var scrollPos = activeTicketCard.offset().top - container.offset().top + container.scrollTop();
  577. container.stop().animate({ scrollTop: scrollPos - 15 }, 500);
  578. }
  579. var isMillions = "@Model.termType" === "@Constants.Millions_CODE";
  580. if (isMillions) {
  581. // Millions Split UI: 1-70 (cols-7) | Divider | 1-24 (cols-3)
  582. var splitHtml = `
  583. <div class="flex gap-3 h-full">
  584. <!-- Left: Standard (1-70) -->
  585. <div class="flex-1 flex flex-col h-full min-w-0">
  586. <span class="text-[10px] font-black text-blue-600 mb-1 uppercase tracking-wider shrink-0">Standard (1-70)</span>
  587. <div class="flex-1 overflow-y-auto grid grid-cols-7 gap-1 pr-1 pb-2" id="standardGrid" style="scrollbar-width: thin; scrollbar-color: #0062FF transparent;"></div>
  588. </div>
  589. <!-- Divider -->
  590. <div class="w-[1px] bg-gray-300 self-stretch my-1 shrink-0"></div>
  591. <!-- Right: Mega Ball (1-24) -->
  592. <div class="w-[105px] flex flex-col h-full shrink-0">
  593. <span class="text-[10px] font-black text-red-600 mb-1 uppercase tracking-wider shrink-0 text-center">Mega (1-24)</span>
  594. <div class="flex-1 overflow-y-auto grid grid-cols-3 gap-1 pl-1 pb-2" id="megaGrid" style="scrollbar-width: thin; scrollbar-color: #E3132D transparent;"></div>
  595. </div>
  596. </div>
  597. `;
  598. grid.append(splitHtml);
  599. var standardContainer = $("#standardGrid");
  600. var megaContainer = $("#megaGrid");
  601. // Populate Standard (1-70)
  602. for (var i = 1; i <= 70; i++) {
  603. var formatted = i.toString().padStart(2, '0');
  604. var isSelected = selectedNumbers.slice(0, 5).includes(formatted);
  605. var btnClass = isSelected
  606. ? 'bg-[#0062FF] text-white shadow-sm'
  607. : 'bg-white text-gray-700 hover:bg-gray-100 border border-gray-100';
  608. standardContainer.append(`<button type="button" class="std-num-btn w-[26px] h-[26px] rounded-full font-black text-[9.5px] transition-all flex items-center justify-center ${btnClass}">${formatted}</button>`);
  609. }
  610. // Populate Mega (1-24)
  611. for (var i = 1; i <= 24; i++) {
  612. var formatted = i.toString().padStart(2, '0');
  613. var isSelected = selectedNumbers[5] === formatted;
  614. var btnClass = isSelected
  615. ? 'bg-[#E3132D] text-white shadow-sm'
  616. : 'bg-white text-gray-700 hover:bg-gray-100 border border-gray-100';
  617. megaContainer.append(`<button type="button" class="mega-num-btn w-[26px] h-[26px] rounded-full font-black text-[9.5px] transition-all flex items-center justify-center ${btnClass}">${formatted}</button>`);
  618. }
  619. // Standard Grid Click Handler
  620. standardContainer.on('click', '.std-num-btn', function(e) {
  621. e.preventDefault();
  622. var $btn = $(this);
  623. var picked = $btn.text().trim();
  624. if (isMultiMode) {
  625. var stdSelected = selectedNumbers.slice(0, 5);
  626. if (stdSelected.includes(picked)) {
  627. // Deselect
  628. let idx = selectedNumbers.indexOf(picked);
  629. if (idx !== -1 && idx < 5) selectedNumbers[idx] = null;
  630. $btn.removeClass('bg-[#0062FF] text-white shadow-sm').addClass('bg-white text-gray-700 border border-gray-100');
  631. } else {
  632. // Select standard ball (first empty slot in 0-4)
  633. let emptyIdx = -1;
  634. for (var k = 0; k < 5; k++) {
  635. if (selectedNumbers[k] === null) {
  636. emptyIdx = k;
  637. break;
  638. }
  639. }
  640. if (emptyIdx !== -1) {
  641. selectedNumbers[emptyIdx] = picked;
  642. $btn.addClass('bg-[#0062FF] text-white shadow-sm').removeClass('bg-white text-gray-700 border border-gray-100');
  643. }
  644. }
  645. liveUpdateTicket();
  646. }
  647. updateSelectionCount();
  648. });
  649. // Mega Grid Click Handler
  650. megaContainer.on('click', '.mega-num-btn', function(e) {
  651. e.preventDefault();
  652. var $btn = $(this);
  653. var picked = $btn.text().trim();
  654. if (isMultiMode) {
  655. if (selectedNumbers[5] === picked) {
  656. // Deselect Mega Ball
  657. selectedNumbers[5] = null;
  658. $btn.removeClass('bg-[#E3132D] text-white shadow-sm').addClass('bg-white text-gray-700 border border-gray-100');
  659. } else {
  660. // Overwrite Mega Ball
  661. selectedNumbers[5] = picked;
  662. megaContainer.find('.mega-num-btn').removeClass('bg-[#E3132D] text-white shadow-sm').addClass('bg-white text-gray-700 border border-gray-100');
  663. $btn.addClass('bg-[#E3132D] text-white shadow-sm').removeClass('bg-white text-gray-700 border border-gray-100');
  664. }
  665. liveUpdateTicket();
  666. }
  667. updateSelectionCount();
  668. });
  669. } else {
  670. // Default Pick 10 UI: 1-80 Grid
  671. var normalHtml = `<div class="grid grid-cols-10 gap-1.5 w-full pb-2 h-full overflow-y-auto" id="normalGrid"></div>`;
  672. grid.append(normalHtml);
  673. var normalContainer = $("#normalGrid");
  674. for (var i = 1; i <= 80; i++) {
  675. var formatted = i.toString().padStart(2, '0');
  676. var isSelected = selectedNumbers.includes(formatted);
  677. var btnClass = isSelected
  678. ? 'bg-[#0062FF] text-white shadow-md scale-105 active-num'
  679. : 'bg-white text-gray-700 hover:bg-gray-100 border border-gray-100';
  680. normalContainer.append(`<button type="button" class="num-btn w-8 h-8 rounded-full font-black text-[11px] transition-all focus:outline-none flex items-center justify-center ${btnClass}">${formatted}</button>`);
  681. }
  682. normalContainer.on('click', '.num-btn', function(e) {
  683. e.preventDefault();
  684. var $btn = $(this);
  685. var picked = $btn.text().trim();
  686. if (isMultiMode) {
  687. if (selectedNumbers.includes(picked)) {
  688. let idx = selectedNumbers.indexOf(picked);
  689. if (idx !== -1) selectedNumbers[idx] = null;
  690. $btn.removeClass('bg-[#0062FF] text-white shadow-md scale-105 active-num').addClass('bg-white text-gray-700 border border-gray-100');
  691. } else {
  692. let firstEmpty = selectedNumbers.indexOf(null);
  693. if (firstEmpty !== -1) {
  694. selectedNumbers[firstEmpty] = picked;
  695. $btn.addClass('bg-[#0062FF] text-white shadow-md scale-105 active-num').removeClass('bg-white text-gray-700 border border-gray-100');
  696. }
  697. }
  698. liveUpdateTicket();
  699. }
  700. updateSelectionCount();
  701. });
  702. }
  703. modal.removeClass('hidden').addClass('flex');
  704. modal.find('.modal-content').removeClass('animate__zoomOut').addClass('animate__zoomIn');
  705. }
  706. function updateSelectionCount() {
  707. var count = selectedNumbers.filter(n => n !== null && n !== "").length;
  708. $("#selectionCount").text(count);
  709. $("#maxSelectionCount").text(maxBalls);
  710. var isValid = isMultiMode ? (count === maxBalls) : (count === 1);
  711. if (isValid) {
  712. $("#confirmBtn").prop('disabled', false).removeClass('opacity-50 cursor-not-allowed').addClass('cursor-pointer');
  713. } else {
  714. $("#confirmBtn").prop('disabled', true).addClass('opacity-50 cursor-not-allowed').removeClass('cursor-pointer');
  715. }
  716. }
  717. function liveUpdateTicket() {
  718. if (!activeTicketCard) return;
  719. var balls = activeTicketCard.find('.ball-circle');
  720. if (isMultiMode) {
  721. // Update Ticket Card balls
  722. for(var i=0; i < maxBalls; i++){
  723. var val = selectedNumbers[i];
  724. if (i < balls.length) {
  725. var tBall = $(balls[i]);
  726. if (val) {
  727. tBall.removeClass('ball-empty').addClass('ball-filled').text(val);
  728. } else {
  729. tBall.removeClass('ball-filled').addClass('ball-empty').text('');
  730. }
  731. }
  732. }
  733. // Toggle Rand/Edit button visibility
  734. if (selectedNumbers.filter(n => n !== null && n !== "").length > 0) {
  735. activeTicketCard.find('.rand-btn').hide();
  736. activeTicketCard.find('.edit-delete-group').removeClass('hidden').show();
  737. } else {
  738. activeTicketCard.find('.rand-btn').show();
  739. activeTicketCard.find('.edit-delete-group').addClass('hidden');
  740. }
  741. updateTotalPrice();
  742. }
  743. }
  744. // All immediate jQuery event bindings must wait for DOM + jQuery to be ready
  745. document.addEventListener("DOMContentLoaded", function() {
  746. // Click on a ball (filled or empty) to edit the full ticket
  747. $(document).on('click', '.ball-filled, .ball-empty', function() {
  748. editFullTicket(this);
  749. });
  750. updateTotalPrice();
  751. // Confirm button handler
  752. $(document).off('click', '#confirmBtn').on('click', '#confirmBtn', function(e) {
  753. e.preventDefault();
  754. // Check non-null count
  755. var count = selectedNumbers.filter(n => n !== null && n !== "").length;
  756. if (count === 0) return;
  757. if (isMultiMode && activeTicketCard && activeTicketCard.length > 0) {
  758. // Double check validation for Mega Ball before confirming
  759. if ("@Model.termType" === "@Constants.Millions_CODE") {
  760. var mbVal = selectedNumbers[5];
  761. if (mbVal) {
  762. var mbValInt = parseInt(mbVal);
  763. if (mbValInt < 1 || mbValInt > 24) {
  764. showNotification("🎱 @Lang.millions_megaball_invalid_title\n@Lang.millions_megaball_invalid_desc", "warning");
  765. return;
  766. }
  767. }
  768. }
  769. // Keep exact selected order, do not sort!
  770. var finalSorted = [];
  771. if ("@Model.termType" === "@Constants.Millions_CODE") {
  772. var first5 = selectedNumbers.slice(0, 5).filter(n => n !== null && n !== "");
  773. var mb = selectedNumbers[5];
  774. finalSorted = first5;
  775. if (mb) finalSorted.push(mb);
  776. } else {
  777. finalSorted = selectedNumbers.filter(n => n !== null && n !== "");
  778. }
  779. var balls = activeTicketCard.find('.ball-circle');
  780. balls.removeClass('ball-filled').addClass('ball-empty').text('');
  781. finalSorted.forEach((num, index) => {
  782. if (index < balls.length) {
  783. $(balls[index]).removeClass('ball-empty').addClass('ball-filled').text(num);
  784. $(balls[index]).addClass('animate__animated animate__pulse');
  785. setTimeout(() => $(balls[index]).removeClass('animate__animated animate__pulse'), 500);
  786. }
  787. });
  788. activeTicketCard.find('.rand-btn').hide();
  789. activeTicketCard.find('.edit-delete-group').removeClass('hidden').show();
  790. updateTotalPrice();
  791. } else if (!isMultiMode && activeBall && activeBall.length > 0) {
  792. // Single mode: Update only the active ball
  793. activeBall.text(selectedNumbers[0]).removeClass('ball-empty').addClass('ball-filled');
  794. activeBall.addClass('animate__animated animate__pulse');
  795. setTimeout(() => activeBall.removeClass('animate__animated animate__pulse'), 500);
  796. var card = activeBall.closest('.ticket-card');
  797. var filledBalls = card.find('.ball-filled').length;
  798. if (filledBalls > 0) {
  799. card.find('.rand-btn').hide();
  800. card.find('.edit-delete-group').removeClass('hidden').show();
  801. } else {
  802. card.find('.rand-btn').show();
  803. card.find('.edit-delete-group').addClass('hidden');
  804. }
  805. updateTotalPrice();
  806. }
  807. closeNumberPicker();
  808. });
  809. });
  810. function closeNumberPicker() {
  811. var modal = $("#numberPickerModal");
  812. modal.find('.modal-content').removeClass('animate__zoomIn').addClass('animate__zoomOut');
  813. setTimeout(() => {
  814. modal.removeClass('flex').addClass('hidden');
  815. // Remove the temporary scroll spacer
  816. $("#editScrollSpacer").remove();
  817. // Reset state
  818. activeBall = null;
  819. activeTicketCard = null;
  820. }, 200);
  821. }
  822. function updateTotalPrice() {
  823. var filledTickets = 0;
  824. $(".ticket-card").each(function() {
  825. if ($(this).find(".ball-filled").length === maxBalls) {
  826. filledTickets++;
  827. }
  828. });
  829. const pricePerTicket = @(Model.termType == Constants.PIC10_BASIC_CODE ? "10" : (Model.termType == Constants.Millions_CODE ? "20" : "50"));
  830. $("#totalPrice").text(formatMoneyV2(filledTickets * pricePerTicket));
  831. $("#totalTicketCount").text(filledTickets);
  832. }
  833. function addNewTicket() {
  834. var container = $("#ticketContainer");
  835. var wrapper = $("#addButtonWrapper");
  836. var currentIndex = $(".ticket-card").length + 1;
  837. var ballsHtml = '';
  838. var isMillions = @(Model.termType == Constants.Millions_CODE ? "true" : "false");
  839. for (var i = 0; i < maxBalls; i++) {
  840. var isMbBall = isMillions && i === 5;
  841. var mbIndicator = isMbBall ? '<div class="absolute -bottom-[6px] -right-[4px] bg-[#FFD700] text-black text-[8.5px] font-black px-[2.5px] py-[1.5px] rounded-[3px] shadow-sm leading-none z-10 border border-[#EAA800]">MB</div>' : '';
  842. ballsHtml += '<div class="relative w-fit"><div class="ball-circle ball-empty' + (isMbBall ? ' ball-mb-circle' : '') + '"></div>' + mbIndicator + '</div>';
  843. }
  844. var ticketHtml = `
  845. <div class="ticket-card relative group active:bg-gray-50 transition-colors cursor-pointer animate__animated animate__fadeInUp animate__faster">
  846. <button onclick="removeEntry(this)" class="absolute -right-2 top-1 w-7 h-7 bg-[#FF0000] text-white rounded-full flex items-center justify-center text-[11px] shadow-sm z-[10] hover:bg-red-700 transition-all border-2 border-red-600">
  847. <i class="fa-solid fa-xmark"></i>
  848. </button>
  849. <div class="absolute left-2 top-4 w-9 h-9 rounded-full border-[3px] border-white flex items-center justify-center text-white font-black text-sm shadow-md ticket-index">${currentIndex}</div>
  850. <div class="flex flex-col gap-1 pl-8">
  851. <span class="text-[16px] font-extrabold text-[#333]">@Lang.millions_select_10_lucky_numbers</span>
  852. <div class="flex items-center gap-4">
  853. <div class="grid grid-cols-6 gap-y-2 gap-x-1 flex-1">
  854. ${ballsHtml}
  855. </div>
  856. <div class="w-[90px] action-area flex flex-col gap-2">
  857. <button onclick="randomizeTicket(this)" class="rand-btn w-full bg-[#2B83F2] text-white flex items-center justify-center gap-1.5 py-1.5 rounded-xl font-extrabold text-[11px] shadow-sm active:scale-95 transition-all">
  858. <i class="fa-solid fa-arrows-rotate text-[10px]"></i> @Lang.Random
  859. </button>
  860. <div class="edit-delete-group hidden flex flex-col gap-2">
  861. <button onclick="editFullTicket(this)" class="w-full bg-[#16A34A] text-white flex items-center justify-center gap-1.5 py-1.5 rounded-xl font-black text-[12px] shadow-sm active:scale-95 transition-all">
  862. <img src="/Millions/img/icons/icon_edit.png" onerror="this.style.display='none'" class="w-[16px] h-[16px] object-contain"> @Lang.millions_edit
  863. </button>
  864. <button onclick="clearTicket(this)" class="w-full bg-[#A855F7] text-white flex items-center justify-center gap-1.5 py-1.5 rounded-xl font-black text-[12px] shadow-sm active:scale-95 transition-all">
  865. <img src="/Millions/img/icons/icon_delete.png" onerror="this.style.display='none'" class="w-[16px] h-[16px] object-contain"> @Lang.millions_delete
  866. </button>
  867. </div>
  868. </div>
  869. </div>
  870. </div>
  871. </div>
  872. `;
  873. $(ticketHtml).insertBefore(wrapper);
  874. container.animate({ scrollTop: container.prop("scrollHeight") }, 300);
  875. }
  876. // --- Order Summary Modal Logic ---
  877. // --- Payment Preparation & Order Summary Logic ---
  878. let pendingTickets = [];
  879. let currentChannelPayment = '@Constants.BASIC_WALLET_TICKET';
  880. function preparePayment(event) {
  881. const isBSMode = @(Model.termType == Constants.PIC10_BIGSMALL_CODE || Model.termType == Constants.PIC10_ODDEVEN_CODE ? "true" : "false");
  882. const tickets = [];
  883. if (isBSMode) {
  884. if (!bsChoice) {
  885. showNotification("Please select a choice first.", "warning");
  886. return;
  887. }
  888. let bsCode = "";
  889. if ('@Model.termType' === '@Constants.PIC10_BIGSMALL_CODE') {
  890. bsCode = (bsChoice === 'big') ? "B" : "S";
  891. } else {
  892. bsCode = (bsChoice === 'big') ? "O" : "E"; // Odd = O, Even = E
  893. }
  894. tickets.push({
  895. code: bsCode,
  896. money: "50"
  897. });
  898. } else {
  899. $(".ticket-card").each(function() {
  900. const balls = $(this).find(".ball-filled");
  901. if (balls.length === maxBalls) {
  902. const selectedNumbers = [];
  903. balls.each(function() { selectedNumbers.push($(this).text().trim()); });
  904. const itemPrice = "@(Model.termType == Constants.PIC10_BASIC_CODE ? "10" : (Model.termType == Constants.Millions_CODE ? "20" : "50"))";
  905. tickets.push({
  906. code: selectedNumbers.join(','),
  907. money: itemPrice
  908. });
  909. }
  910. });
  911. if (tickets.length === 0) {
  912. showNotification("@Lang.millions_ticket_not_valid", "warning");
  913. return;
  914. }
  915. }
  916. pendingTickets = tickets;
  917. $("#paymentChannelModal").removeClass("hidden").addClass("flex");
  918. }
  919. function hidePaymentChannelModal() {
  920. $("#paymentChannelModal").removeClass("flex").addClass("hidden");
  921. }
  922. function selectPaymentChannel(channelPayment) {
  923. currentChannelPayment = channelPayment;
  924. hidePaymentChannelModal();
  925. const requestData = {
  926. gameId: "@Model.termType",
  927. ticket: pendingTickets,
  928. channelPayment: channelPayment
  929. };
  930. $.ajax({
  931. url: subDomain + '@Url.Action("ConfirmTicketData", "Home")',
  932. type: 'POST',
  933. contentType: 'application/json',
  934. data: JSON.stringify(requestData),
  935. success: function(data) {
  936. if (data.responseCode === "0" || data.responseCode === "0000") {
  937. showOrderSummary(data, pendingTickets);
  938. } else {
  939. showNotification(data.responseMessage || "Confirmation failed", data.responseCode);
  940. }
  941. },
  942. error: function(err) {
  943. showNotification("Network error occurred.", "warning");
  944. }
  945. });
  946. }
  947. let currentTransId = null;
  948. function showOrderSummary(apiData, localTickets) {
  949. currentTransId = apiData.transId;
  950. const summaryModal = $("#orderSummaryModal");
  951. const summaryList = $("#summaryTicketList");
  952. summaryList.empty();
  953. const displayTickets = (apiData && apiData.ticket) ? apiData.ticket : (localTickets || []);
  954. if (!displayTickets || !Array.isArray(displayTickets)) {
  955. console.warn("No tickets found to display in summary.");
  956. return;
  957. }
  958. displayTickets.forEach((t, index) => {
  959. const numbers = t.code.split(',');
  960. let contentHtml = '';
  961. if (numbers.length > 1) {
  962. const isMillionsGame = "@Model.termType" === "@Constants.Millions_CODE";
  963. let numbersBalls = '';
  964. numbers.forEach((n, ni) => {
  965. var isMbBall = isMillionsGame && ni === numbers.length - 1;
  966. var ballBg = isMbBall
  967. ? 'background: radial-gradient(circle at 50% 50%, #0062ff 0%, #0062ff 60%, #0149f0 75%, #0231e0 85%, #0218d1 92%, #0300c2 100%); box-shadow: inset 0 0 6px 2px rgba(0,24,209,0.5), 0 4px 10px rgba(2,24,209,0.3);'
  968. : 'background: linear-gradient(135deg, #FF3D63 0%, #E3132D 60%, #BA0F21 100%); box-shadow: 0 4px 10px rgba(186,15,33,0.3);';
  969. numbersBalls += `<div class="w-7 h-7 rounded-full flex items-center justify-center text-white text-[11px] font-black" style="${ballBg} border: 1px solid rgba(255, 255, 255, 0.3); text-shadow: 0px 1px 2px rgba(0,0,0,0.1); transition: transform 0.2s;">${n.trim()}</div>`;
  970. });
  971. var summaryGridCols = isMillionsGame ? 'grid-cols-6' : 'grid-cols-5';
  972. contentHtml = `<div class="grid ${summaryGridCols} gap-y-2 gap-x-1 relative z-10 px-1 justify-items-center">${numbersBalls}</div>`;
  973. } else {
  974. const isBS = @(Model.termType == Constants.PIC10_BIGSMALL_CODE ? "true" : "false");
  975. const isFirstChoice = (numbers[0] === 'B' || numbers[0] === 'O');
  976. const label = isFirstChoice ? (isBS ? "Big" : "Odd") : (isBS ? "Small" : "Even");
  977. const color = isFirstChoice ? (isBS ? "#A2FF00" : "#FFC700") : (isBS ? "#FF4157" : "#B33BD0");
  978. contentHtml = `<div class="w-full flex justify-center"><span class="text-[28px] font-black italic uppercase" style="-webkit-text-stroke: 1px #000; color: ${color};">${label}</span></div>`;
  979. }
  980. const itemHtml = `
  981. <div class="flex items-center gap-3">
  982. <div class="flex-1 rounded-2xl p-3 relative overflow-hidden flex flex-col gap-2 min-h-[80px] justify-center shadow-sm"
  983. style="background: white; border: 1.5px solid #0062FF;">
  984. ${contentHtml}
  985. </div>
  986. <div class="w-24 shrink-0 bg-white border border-gray-200 rounded-2xl p-2.5 flex items-center justify-center shadow-sm">
  987. <div class="flex items-baseline gap-0.5">
  988. <span class="text-[20px] font-black text-black">${formatMoneyV2(t.money)}</span>
  989. <span class="text-[12px] font-black text-[#0062FF]">HTG</span>
  990. </div>
  991. </div>
  992. </div>
  993. `;
  994. summaryList.append(itemHtml);
  995. });
  996. $("#summaryTotalCount").text(displayTickets.length);
  997. const totalMoney = apiData.totalMoneyPayment || apiData.totalMoney || "0";
  998. $("#summaryTotalAmount").text(formatMoneyV2(totalMoney));
  999. summaryModal.removeClass("hidden").addClass("flex");
  1000. }
  1001. function hideOrderSummary() {
  1002. $("#orderSummaryModal").removeClass("flex").addClass("hidden");
  1003. }
  1004. function confirmCheckout(btn) {
  1005. if (currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET') {
  1006. showOtpModal(true);
  1007. return;
  1008. }
  1009. const originalText = $(btn).html();
  1010. $(btn).prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin mr-2"></i>Processing...');
  1011. // Trigger SendOTP API
  1012. $.ajax({
  1013. url: subDomain + '@Url.Action("SendOTP", "Home")',
  1014. type: 'POST',
  1015. success: function(data) {
  1016. $(btn).prop('disabled', false).html(originalText);
  1017. if (data.responseCode === "0") {
  1018. showOtpModal(false);
  1019. } else {
  1020. showNotification(data.responseMessage || "Failed to send OTP", data.responseCode);
  1021. }
  1022. },
  1023. error: function() {
  1024. $(btn).prop('disabled', false).html(originalText);
  1025. showNotification("Network error occurred.", "warning");
  1026. }
  1027. });
  1028. }
  1029. let otpInterval;
  1030. function showOtpModal(isWalletPin) {
  1031. hideOrderSummary();
  1032. $("#otpModal").removeClass("hidden").addClass("flex");
  1033. $("#otpInputs input").val("");
  1034. $("#otpConfirmBtn").prop('disabled', true);
  1035. $("#otpError").addClass("hidden").text("");
  1036. $("#otp1").focus();
  1037. // Map game type to readable name & image
  1038. let gameTypeStr = "@Model.termType";
  1039. let displayName = gameTypeStr === "@Constants.Millions_CODE" ? "@Lang.millions" : "Basic Pick 10";
  1040. let imgSrc = "";
  1041. if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE") {
  1042. // Get the specific choice from summary
  1043. let firstTicketText = $("#summaryTicketList").find("span.font-black").first().text().trim();
  1044. if (firstTicketText) {
  1045. displayName = firstTicketText.charAt(0).toUpperCase() + firstTicketText.slice(1).toLowerCase(); // Normalize to "Big" or "Small"
  1046. } else {
  1047. displayName = "Big / Small";
  1048. }
  1049. } else if (gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") {
  1050. let firstTicketText = $("#summaryTicketList").find("span.font-black").first().text().trim();
  1051. if (firstTicketText) {
  1052. displayName = firstTicketText.charAt(0).toUpperCase() + firstTicketText.slice(1).toLowerCase(); // Normalize to "Odd" or "Even"
  1053. } else {
  1054. displayName = "Odd / Even";
  1055. }
  1056. }
  1057. // Determine color based on game type
  1058. let typeColorClass = "text-purple-700"; // default
  1059. if (gameTypeStr === "@Constants.PIC10_BASIC_CODE") typeColorClass = "text-[#0062FF]";
  1060. else if (gameTypeStr === "@Constants.Millions_CODE") typeColorClass = "text-[#0062FF]";
  1061. else if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE") typeColorClass = "text-[#0A9800]";
  1062. else if (gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") typeColorClass = "text-[#9333ea]";
  1063. // Hide image for now and use the beautiful text style as requested
  1064. $("#otpTicketTypeImg").hide();
  1065. $("#otpTicketTypeContainer").find("span").remove();
  1066. $("#otpTicketTypeContainer").append(`<span class='text-[17px] font-[900] ${typeColorClass} italic'>${displayName}</span>`);
  1067. $("#otpTotalAmount").text($("#summaryTotalAmount").text());
  1068. if (isWalletPin) {
  1069. $("#paymentCodeInstruction").text('@Html.Raw(Lang.payment_wallet_pin_instruction.Replace("'", "\\'"))');
  1070. $("#otpTimer, #resendOtpBtn").addClass("hidden");
  1071. clearInterval(otpInterval);
  1072. } else {
  1073. $("#paymentCodeInstruction").text('@Html.Raw(Lang.millions_otp_instruction.Replace("'", "\\'"))');
  1074. startOtpTimer(60);
  1075. }
  1076. }
  1077. // Add backspace support for OTP inputs
  1078. $("#otpInputs input").on("keyup", function() {
  1079. let otp = "";
  1080. $("#otpInputs input").each(function() { otp += $(this).val(); });
  1081. $("#otpConfirmBtn").prop('disabled', otp.length < 6);
  1082. });
  1083. $("#otpInputs input").on("keydown", function(e) {
  1084. if (e.key === "Backspace" && this.value.length === 0) {
  1085. $(this).prev('input').focus();
  1086. }
  1087. });
  1088. function hideOtpModal() {
  1089. $("#otpModal").removeClass("flex").addClass("hidden");
  1090. clearInterval(otpInterval);
  1091. }
  1092. function startOtpTimer(seconds) {
  1093. let timeLeft = seconds;
  1094. $("#resendOtpBtn").addClass("hidden");
  1095. $("#otpTimer").removeClass("hidden").text(timeLeft + "s");
  1096. clearInterval(otpInterval);
  1097. otpInterval = setInterval(() => {
  1098. timeLeft--;
  1099. $("#otpTimer").text(timeLeft + "s");
  1100. if (timeLeft <= 0) {
  1101. clearInterval(otpInterval);
  1102. $("#otpTimer").addClass("hidden");
  1103. $("#resendOtpBtn").removeClass("hidden");
  1104. }
  1105. }, 1000);
  1106. }
  1107. function moveToNext(el, nextId) {
  1108. if (el.value.length >= 1) {
  1109. if (nextId) document.getElementById(nextId).focus();
  1110. }
  1111. let otp = "";
  1112. $("#otpInputs input").each(function() { otp += $(this).val(); });
  1113. $("#otpConfirmBtn").prop('disabled', otp.length < 6);
  1114. // Clear error when typing
  1115. $("#otpError").addClass("hidden").text("");
  1116. }
  1117. function sendOtpRequest() {
  1118. // Re-trigger SendOTP
  1119. $.ajax({
  1120. url: subDomain + '@Url.Action("SendOTP", "Home")',
  1121. type: 'POST',
  1122. success: function(data) {
  1123. if (data.responseCode === "0") {
  1124. startOtpTimer(60);
  1125. showNotification("OTP has been resent.", "success");
  1126. } else {
  1127. showNotification(data.responseMessage || "Failed to resend OTP", data.responseCode);
  1128. }
  1129. }
  1130. });
  1131. }
  1132. function showReceiptSuccess(transId, amount, phone, totalTickets, drawDate) {
  1133. // Setup data dynamically
  1134. $("#receiptAmount").text(formatMoneyV2(amount) + " HTG");
  1135. if(phone) $("#receiptPhone").text(phone);
  1136. if(totalTickets) $("#receiptTotalTickets").text(totalTickets);
  1137. if(drawDate) $("#receiptDrawDate").text(drawDate);
  1138. let gameTypeStr = "@Model.termType";
  1139. let displayName = "Basic Pick 10";
  1140. if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE") displayName = "@Lang.millions_big_small";
  1141. else if (gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") displayName = "@Lang.millions_odd_even";
  1142. else if (gameTypeStr === "@Constants.Millions_CODE") displayName = "Millions";
  1143. $("#receiptGameType").text("@Lang.buy " + displayName);
  1144. $("#receiptTicketCode").text("#" + transId);
  1145. let choiceText = "-";
  1146. if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE" || gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") {
  1147. choiceText = $("#summaryTicketList .flex.items-center span.font-black").first().text().trim();
  1148. } else {
  1149. choiceText = gameTypeStr === "@Constants.Millions_CODE" ? "Millions" : "PICK 10";
  1150. }
  1151. $("#receiptChoice").text(choiceText);
  1152. // Format current date "dd/MM/yyyy - HH:mm:ss"
  1153. let now = new Date();
  1154. let ds = now.getDate().toString().padStart(2, '0') + '/' + (now.getMonth() + 1).toString().padStart(2, '0') + '/' + now.getFullYear() + ' - ' + now.getHours().toString().padStart(2, '0') + ':' + now.getMinutes().toString().padStart(2, '0') + ':' + now.getSeconds().toString().padStart(2, '0');
  1155. $("#receiptTime").text(ds);
  1156. hideOtpModal();
  1157. $("#receiptSuccessModal").removeClass("hidden").addClass("flex");
  1158. }
  1159. function finalizePurchase(btn) {
  1160. let otpCode = "";
  1161. $("#otpInputs input").each(function() {
  1162. otpCode += $(this).val();
  1163. });
  1164. if (otpCode.length < 6) {
  1165. showNotification(currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET' ? "Please enter full 6-digit PIN" : "Please enter full 6-digit OTP", "warning");
  1166. return;
  1167. }
  1168. const originalText = $(btn).html();
  1169. $(btn).prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin mr-2"></i> ...');
  1170. const finalData = {
  1171. transIdByTicket: currentTransId,
  1172. paymentCode: currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET' ? null : otpCode,
  1173. walletPin: currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET' ? otpCode : null,
  1174. channelPayment: currentChannelPayment
  1175. };
  1176. // Call the unified backend action that verifies OTP and then buys the ticket
  1177. $.ajax({
  1178. url: subDomain + '@Url.Action("ConfirmBuyingTicketV2", "Home")',
  1179. type: 'POST',
  1180. contentType: 'application/json',
  1181. data: JSON.stringify(finalData),
  1182. success: function(res) {
  1183. $(btn).prop('disabled', false).html(originalText);
  1184. if (res.responseCode === "0" || res.responseCode === "0000") {
  1185. // Success: Show receipt Modal
  1186. showReceiptSuccess(res.orderId || currentTransId, $("#summaryTotalAmount").text(), "@(Model.userStatus?.msisdn ?? "-")", $("#summaryTotalCount").text(), "@(currentTerm?.date_random ?? "-")");
  1187. } else {
  1188. if (res.responseCode === "-2" || (res.responseMessage && res.responseMessage.includes("System is upgrading"))) {
  1189. hideOtpModal();
  1190. showNotification(res.responseMessage || "System is upgrading", res.responseCode);
  1191. } else {
  1192. $("#otpError").text(res.responseMessage || "Invalid OTP").removeClass("hidden");
  1193. $("#otpInputs input").val("");
  1194. $("#otp1").focus();
  1195. }
  1196. }
  1197. },
  1198. error: function() {
  1199. $(btn).prop('disabled', false).html(originalText);
  1200. showNotification("Network error occurred during payment completion.", "warning");
  1201. }
  1202. });
  1203. }
  1204. var systemUpgrading = false;
  1205. function showNotification(message, code) {
  1206. const msgEl = $("#notificationMessage");
  1207. const iconEl = $("#notificationModal img");
  1208. const btnEl = $("#notificationModal button");
  1209. if (message && message.includes("\n")) {
  1210. msgEl.html(message.replace(/\n/g, '<br/>'));
  1211. } else {
  1212. msgEl.text(message);
  1213. }
  1214. if (code === "-2" || (message && message.includes("System is upgrading"))) {
  1215. systemUpgrading = true;
  1216. btnEl.text("@Lang.login");
  1217. } else {
  1218. systemUpgrading = false;
  1219. btnEl.text("OK");
  1220. }
  1221. // Toggle icon based on type (warning or success)
  1222. const warningIcon = '/Millions/img/modal/warning_icon.png';
  1223. const successIcon = '/Millions/img/modal/success_icon_v2.png';
  1224. const fallbackWarning = 'https://cdn-icons-png.flaticon.com/512/564/564619.png';
  1225. const fallbackSuccess = 'https://cdn-icons-png.flaticon.com/512/190/190411.png';
  1226. if (code === "-2" || code === "warning" || code === "error") {
  1227. iconEl.attr('src', warningIcon);
  1228. iconEl.attr('onerror', `this.src='${fallbackWarning}'`);
  1229. } else {
  1230. iconEl.attr('src', successIcon);
  1231. iconEl.attr('onerror', `this.src='${fallbackSuccess}'`);
  1232. }
  1233. $("#notificationModal").removeClass("hidden").addClass("flex");
  1234. }
  1235. function closeNotificationModal() {
  1236. $("#notificationModal").addClass("hidden").removeClass("flex");
  1237. if (systemUpgrading) {
  1238. window.location.href = subDomain + "/Account/Login";
  1239. }
  1240. }
  1241. // ==================== CARD SELECTION GAME LOGIC (BIG/SMALL / ODD/EVEN) ====================
  1242. var bsChoice = null; // 'big' or 'small' (reused as 'odd' or 'even')
  1243. const isBigSmall = @(Model.termType == Constants.PIC10_BIGSMALL_CODE ? "true" : "false");
  1244. const themeColor = isBigSmall ? "#0A9800" : "#AA3DC8";
  1245. const labelBig = isBigSmall ? "Big" : "Odd";
  1246. const labelSmall = isBigSmall ? "Small" : "Even";
  1247. const colorBig = isBigSmall ? "#A2FF00" : "#FFC700";
  1248. const colorSmall = isBigSmall ? "#FF4157" : "#B33BD0";
  1249. // Loclized text from resources
  1250. const langSelect = "@Lang.millions_select";
  1251. const langSelected = "@Lang.millions_selected";
  1252. function selectBigSmall(choice) {
  1253. bsChoice = choice;
  1254. var cardBig = document.getElementById('cardBig');
  1255. var cardSmall = document.getElementById('cardSmall');
  1256. var choiceDisplay = document.getElementById('choiceDisplay');
  1257. if (!cardBig || !cardSmall) return;
  1258. if (choice === 'big') {
  1259. // Highlight Big/Odd card with theme glow
  1260. cardBig.style.border = '2px solid ' + themeColor;
  1261. cardBig.style.boxShadow = '0px 0px 12px 0px ' + (isBigSmall ? 'rgba(162, 255, 0, 1)' : 'rgba(179, 59, 208, 0.6)');
  1262. cardBig.querySelector('.bigsmall-btn').textContent = langSelected;
  1263. cardBig.querySelector('.bigsmall-btn').style.background = '#333';
  1264. // Reset Small/Even card
  1265. cardSmall.style.border = '2px solid transparent';
  1266. cardSmall.style.boxShadow = 'none';
  1267. cardSmall.querySelector('.bigsmall-btn').textContent = langSelect;
  1268. cardSmall.querySelector('.bigsmall-btn').style.background = themeColor;
  1269. // Update display
  1270. if (choiceDisplay) {
  1271. choiceDisplay.textContent = labelBig;
  1272. choiceDisplay.style.color = colorBig;
  1273. choiceDisplay.style.webkitTextStroke = '1px #000';
  1274. }
  1275. } else {
  1276. // Highlight Small/Even card with theme glow
  1277. cardSmall.style.border = '2px solid ' + themeColor;
  1278. cardSmall.style.boxShadow = '0px 0px 12px 0px ' + (isBigSmall ? 'rgba(162, 255, 0, 1)' : 'rgba(179, 59, 208, 0.6)');
  1279. cardSmall.querySelector('.bigsmall-btn').textContent = langSelected;
  1280. cardSmall.querySelector('.bigsmall-btn').style.background = '#333';
  1281. // Reset Big/Odd card
  1282. cardBig.style.border = '2px solid transparent';
  1283. cardBig.style.boxShadow = 'none';
  1284. cardBig.querySelector('.bigsmall-btn').textContent = langSelect;
  1285. cardBig.querySelector('.bigsmall-btn').style.background = themeColor;
  1286. // Update display
  1287. if (choiceDisplay) {
  1288. choiceDisplay.textContent = labelSmall;
  1289. choiceDisplay.style.color = colorSmall;
  1290. choiceDisplay.style.webkitTextStroke = '1px #000';
  1291. }
  1292. }
  1293. $("#bsTotalTicketCount").text(1);
  1294. $("#bsTotalPrice").text(formatMoneyV2(50));
  1295. }
  1296. function bsShowPayment(e) {
  1297. preparePayment(e);
  1298. }
  1299. </script>
  1300. <!-- Number Picker Modal (Refined Bottom Sheet) -->
  1301. <div id="numberPickerModal" class="fixed inset-0 bg-black/10 z-[200] hidden items-end justify-center p-0 transition-all">
  1302. <div class="modal-content bg-white w-full md:max-w-[414px] mx-auto shadow-2xl animate__animated animate__slideInUp animate__faster rounded-t-[20px] overflow-hidden">
  1303. <div class="px-4 py-1.5 bg-[#0062FF] text-white flex justify-between items-center relative">
  1304. <div class="flex flex-col">
  1305. <h3 class="font-black text-[15px] uppercase tracking-wide" id="modalTitle">@Lang.Pick_Number</h3>
  1306. <div class="selection-count-area">
  1307. <span class="text-[10px] font-bold text-white/80 uppercase">Selected: <span id="selectionCount" class="text-white">0</span>/<span id="maxSelectionCount">10</span></span>
  1308. </div>
  1309. </div>
  1310. <button onclick="closeNumberPicker()" class="w-8 h-8 flex items-center justify-center rounded-full bg-white/10 hover:bg-white/20 transition-all">
  1311. <i class="fa-solid fa-xmark text-lg"></i>
  1312. </button>
  1313. </div>
  1314. <style>
  1315. #numberGrid::-webkit-scrollbar { width: 3px; }
  1316. #numberGrid::-webkit-scrollbar-track { background: transparent; }
  1317. #numberGrid::-webkit-scrollbar-thumb { background: #FFD700; border-radius: 10px; }
  1318. #numberGrid { scrollbar-width: thin; scrollbar-color: #FFD700 transparent; }
  1319. </style>
  1320. <div class="p-2 h-[220px] overflow-hidden bg-gray-50 border-b" id="numberGrid">
  1321. <!-- Populated via JS -->
  1322. </div>
  1323. <div class="p-3 bg-white border-t flex gap-3">
  1324. <button onclick="closeNumberPicker()" class="flex-1 py-1 bg-gray-100 text-gray-600 rounded-lg font-black text-[12px] active:bg-gray-200 transition-all uppercase">
  1325. @Lang.millions_back
  1326. </button>
  1327. <button id="confirmBtn" class="hidden flex-[2] py-2 bg-[#0062FF] text-white rounded-lg font-black text-[13px] active:bg-[#CC002D] transition-all uppercase shadow-md">
  1328. @Lang.confirm
  1329. </button>
  1330. </div>
  1331. </div>
  1332. </div>
  1333. <div id="notificationModal" class="fixed inset-0 z-[300] bg-black/60 flex items-center justify-center hidden px-4 font-bricolage backdrop-blur-sm">
  1334. <div class="w-full max-w-[360px] bg-white rounded-[32px] overflow-hidden flex flex-col items-center px-6 pt-5 pb-6 animate__animated animate__zoomIn animate__faster shadow-2xl relative border border-white/50">
  1335. <!-- Alert Icon -->
  1336. <div class="w-full flex justify-center mb-2 mt-0">
  1337. <img src="/Millions/img/modal/success_icon_v2.png" class="w-full max-w-[240px] h-auto object-contain" alt="Notificaton icon" onerror="this.src='https://cdn-icons-png.flaticon.com/512/190/190411.png'" />
  1338. </div>
  1339. <!-- Message Area -->
  1340. <div class="px-2 text-center mb-5">
  1341. <p id="notificationMessage" class="text-black font-[800] text-[17px] leading-snug">
  1342. <!-- Message content -->
  1343. </p>
  1344. </div>
  1345. <!-- Action Button -->
  1346. <div class="w-full">
  1347. <button onclick="closeNotificationModal()" class="w-full bg-[#0062FF] text-white font-[900] text-[18px] py-[13px] rounded-[18px] shadow-[0_8px_20px_rgba(238,0,51,0.25)] active:scale-95 transition-all uppercase tracking-wide">
  1348. OK
  1349. </button>
  1350. </div>
  1351. </div>
  1352. </div>
  1353. <!-- Beautiful Success Receipt Modal (Matches Figma 161:3722) -->
  1354. <div id="receiptSuccessModal" class="fixed inset-0 z-[300] bg-black/80 hidden items-center justify-center px-4 font-bricolage backdrop-blur-md">
  1355. <div class="w-full max-w-[360px] bg-[#F9F9F9] rounded-[32px] overflow-hidden flex flex-col items-center px-6 pt-4 pb-5 shadow-2xl relative animate__animated animate__zoomIn animate__faster border border-white/50">
  1356. <!-- Confetti/Celebration background effect (Subtle removed) -->
  1357. <h2 class="text-[#534A4A] font-[800] text-[19px] tracking-tight relative z-10 w-full text-center mt-1">@Lang.millions_payment_successfully</h2>
  1358. <!-- Ticket / Success Graphic -->
  1359. <div class="relative w-full flex justify-center mt-2 mb-0 z-10 px-4">
  1360. <img src="/Millions/img/modal/success_icon_v2.png" alt="Success" class="w-full h-auto object-contain">
  1361. </div>
  1362. <h3 class="text-[#0A9800] font-[900] text-[20px] uppercase tracking-wide relative z-10">@Lang.success</h3>
  1363. <div class="w-full h-px border-t-[2px] border-dashed border-gray-300 my-3 relative z-10"></div>
  1364. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1365. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.phone_number</span>
  1366. <span class="font-black text-[14px] text-gray-800" id="receiptPhone">-</span>
  1367. </div>
  1368. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1369. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.millions_your_choice</span>
  1370. <span class="text-[#0062FF] font-[900] text-[15px] uppercase" id="receiptChoice">-</span>
  1371. </div>
  1372. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1373. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.ticket_code</span>
  1374. <span class="font-black text-[13px] text-gray-800" id="receiptTicketCode">#</span>
  1375. </div>
  1376. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1377. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.total_ticket</span>
  1378. <span class="font-black text-[14px] text-gray-800" id="receiptTotalTickets">-</span>
  1379. </div>
  1380. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1381. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.millions_draw_date</span>
  1382. <span class="font-black text-[14px] text-gray-800" id="receiptDrawDate">-</span>
  1383. </div>
  1384. <div class="w-full flex justify-between items-center mb-1 relative z-10 px-1">
  1385. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.total_payment</span>
  1386. <span class="text-[#0062FF] font-[900] text-[15px]" id="receiptAmount">0 HTG</span>
  1387. </div>
  1388. <div class="w-full h-px border-t-[2px] border-dashed border-gray-300 my-3 relative z-10"></div>
  1389. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1390. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.time</span>
  1391. <span class="font-bold text-[13px] text-gray-600" id="receiptTime">00:00:00</span>
  1392. </div>
  1393. <div class="w-full flex justify-start items-center relative z-10 px-1 mt-1">
  1394. <span class="text-[#534A4A] font-bold text-[13px] italic text-gray-500" id="receiptGameType">@Lang.millions_buy_ticket_label</span>
  1395. </div>
  1396. <div class="text-[#534A4A] font-[900] text-[18px] relative z-10 text-center mt-3">@Lang.thank_you <span class="text-[#0062FF]">♥️</span></div>
  1397. <div class="w-full flex gap-2.5 mt-4 relative z-10">
  1398. <button type="button" onclick="window.location.href = subDomain + '@Url.Action("BuyTicket", "Home", new { termType = Model.termType })';" class="flex-1 min-w-0 border-2 border-[#0062FF] bg-white text-[#0062FF] font-[900] text-[15px] py-3 rounded-[18px] active:scale-95 transition-all uppercase tracking-wide shadow-sm">
  1399. @Lang.millions_continue
  1400. </button>
  1401. <button type="button" onclick="window.location.href = subDomain + '@Url.Action("GameHome", "Home", new { termType = Model.termType })';" class="flex-1 min-w-0 bg-[#0062FF] text-white font-[900] text-[15px] py-3 rounded-[18px] shadow-[0_8px_20px_rgba(0,98,255,0.25)] active:scale-95 transition-all uppercase tracking-wide">
  1402. @Lang.close
  1403. </button>
  1404. </div>
  1405. </div>
  1406. </div>
  1407. }