BuyTicket.cshtml 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634
  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. <div id="walletPinContainer" class="hidden w-full mt-1 px-2">
  445. <div class="relative">
  446. <i class="fa-solid fa-lock absolute left-4 top-1/2 -translate-y-1/2 text-[#0A9800]"></i>
  447. <input id="walletPinInput" type="password" inputmode="numeric" autocomplete="off"
  448. oninput="this.value = this.value.replace(/[^0-9]/g, ''); updateWalletPinState()"
  449. class="h-[52px] w-full rounded-[14px] border-2 border-gray-200 bg-gray-50 pl-11 pr-12 text-center text-[22px] font-black tracking-[0.3em] text-gray-800 outline-none transition focus:border-[#0A9800] focus:bg-white focus:ring-4 focus:ring-green-100"
  450. placeholder="••••">
  451. <button type="button" onclick="toggleWalletPinVisibility()" class="absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 active:scale-90" aria-label="Show PIN"><i id="walletPinEye" class="fa-solid fa-eye"></i></button>
  452. </div>
  453. </div>
  454. <!-- OTP Error Message -->
  455. <p id="otpError" class="text-[#0062FF] font-bold text-[14px] text-center mb-1 hidden animate__animated animate__shakeX"></p>
  456. <!-- Timer & Resend -->
  457. <div class="flex flex-col items-center gap-1 mt-0">
  458. <span id="otpTimer" class="text-[15px] font-black text-[#0062FF] font-bricolage">60s</span>
  459. <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>
  460. </div>
  461. <!-- Action Buttons: Cancel / Confirm -->
  462. <div class="grid grid-cols-2 gap-3 w-full mt-2">
  463. <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>
  464. <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>
  465. </div>
  466. </div>
  467. </div>
  468. </div>
  469. </div>
  470. @section Scripts {
  471. <script>
  472. const maxBalls = @(Model.termType == Constants.PIC10_BASIC_CODE ? 10 : (Model.termType == Constants.Millions_CODE ? 6 : (Model.termType == Constants.PIC10_BIGSMALL_CODE ? 13 : 15)));
  473. function reindexTickets() {
  474. $(".ticket-card").each(function(index) {
  475. $(this).find(".ticket-index").text(index + 1);
  476. });
  477. }
  478. function removeEntry(btn) {
  479. var card = $(btn).closest('.ticket-card');
  480. card.addClass('animate__animated animate__fadeOutRight animate__faster');
  481. setTimeout(function() {
  482. card.remove();
  483. reindexTickets();
  484. updateTotalPrice();
  485. }, 300);
  486. }
  487. function randomizeTicket(btn) {
  488. var icon = $(btn).find('i');
  489. icon.addClass('fa-spin');
  490. var card = $(btn).closest('.ticket-card');
  491. var balls = card.find('.ball-circle');
  492. // Generate unique random numbers
  493. var numbers = [];
  494. if ("@Model.termType" === "@Constants.Millions_CODE") {
  495. // First 5 standard balls (1-70)
  496. while(numbers.length < 5){
  497. var r = Math.floor(Math.random() * 70) + 1;
  498. if(numbers.indexOf(r) === -1) numbers.push(r);
  499. }
  500. numbers.sort((a, b) => a - b);
  501. // 6th Mega Ball (1-24)
  502. var mb = Math.floor(Math.random() * 24) + 1;
  503. numbers.push(mb);
  504. } else {
  505. while(numbers.length < maxBalls){
  506. var r = Math.floor(Math.random() * 80) + 1;
  507. if(numbers.indexOf(r) === -1) numbers.push(r);
  508. }
  509. numbers.sort((a, b) => a - b);
  510. }
  511. // Update balls with staggered animation
  512. balls.each(function(index) {
  513. var ball = $(this);
  514. setTimeout(function() {
  515. var formattedNum = numbers[index].toString().padStart(2, '0');
  516. ball.removeClass('ball-empty').addClass('ball-filled').text(formattedNum);
  517. ball.addClass('animate__animated animate__flipInY');
  518. if(index === maxBalls - 1) {
  519. setTimeout(() => {
  520. icon.removeClass('fa-spin');
  521. // Replace button with Edit/Delete group
  522. $(btn).hide();
  523. card.find('.edit-delete-group').removeClass('hidden').addClass('animate__animated animate__fadeInRight animate__faster');
  524. updateTotalPrice();
  525. }, 300);
  526. }
  527. }, index * 40);
  528. });
  529. }
  530. function clearTicket(btn) {
  531. var card = $(btn).closest('.ticket-card');
  532. var balls = card.find('.ball-circle');
  533. balls.removeClass('ball-filled animate__animated animate__flipInY shadow-inner').addClass('ball-empty').text('');
  534. // Hide Edit/Delete group and show Rand button
  535. card.find('.edit-delete-group').addClass('hidden');
  536. card.find('.rand-btn').show().addClass('animate__animated animate__fadeInLeft animate__faster');
  537. updateTotalPrice();
  538. }
  539. // Open Number Picker Modal
  540. var activeBall = null;
  541. var activeTicketCard = null;
  542. var selectedNumbers = []; // For Edit mode, this will be an array of fixed size with nulls
  543. var isMultiMode = false;
  544. function editFullTicket(btn) {
  545. isMultiMode = true;
  546. activeTicketCard = $(btn).closest('.ticket-card');
  547. activeBall = null;
  548. // Initialize fixed slots for slot-based editing
  549. selectedNumbers = new Array(maxBalls).fill(null);
  550. let existing = [];
  551. activeTicketCard.find('.ball-filled').each(function() {
  552. var num = $(this).text().trim();
  553. if(num) existing.push(num);
  554. });
  555. // Initial fill from left to right
  556. existing.forEach((num, idx) => {
  557. if(idx < maxBalls) selectedNumbers[idx] = num;
  558. });
  559. openNumberPicker(true);
  560. }
  561. function openNumberPicker(isMulti) {
  562. var modal = $("#numberPickerModal");
  563. var grid = $("#numberGrid");
  564. var title = $("#modalTitle");
  565. var countArea = $(".selection-count-area");
  566. var confirmBtn = $("#confirmBtn");
  567. grid.empty();
  568. if (isMulti) {
  569. title.text("Edit Ticket");
  570. countArea.removeClass('hidden');
  571. confirmBtn.removeClass('hidden').text("@Lang.confirm");
  572. } else {
  573. title.text("Pick Number");
  574. countArea.addClass('hidden');
  575. confirmBtn.removeClass('hidden').text("@Lang.confirm");
  576. }
  577. updateSelectionCount();
  578. liveUpdateTicket();
  579. // Focus card: append a tall spacer so even the last ticket can scroll up
  580. // above the number-picker sheet (a flex column container does not honor
  581. // padding-bottom as scrollable space), then bring the card to the top.
  582. if (activeTicketCard && activeTicketCard.length) {
  583. var container = $("#ticketContainer");
  584. $("#editScrollSpacer").remove();
  585. container.append('<div id="editScrollSpacer" aria-hidden="true" style="height:100vh;flex-shrink:0;"></div>');
  586. var scrollPos = activeTicketCard.offset().top - container.offset().top + container.scrollTop();
  587. container.stop().animate({ scrollTop: scrollPos - 15 }, 500);
  588. }
  589. var isMillions = "@Model.termType" === "@Constants.Millions_CODE";
  590. if (isMillions) {
  591. // Millions Split UI: 1-70 (cols-7) | Divider | 1-24 (cols-3)
  592. var splitHtml = `
  593. <div class="flex gap-3 h-full">
  594. <!-- Left: Standard (1-70) -->
  595. <div class="flex-1 flex flex-col h-full min-w-0">
  596. <span class="text-[10px] font-black text-blue-600 mb-1 uppercase tracking-wider shrink-0">Standard (1-70)</span>
  597. <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>
  598. </div>
  599. <!-- Divider -->
  600. <div class="w-[1px] bg-gray-300 self-stretch my-1 shrink-0"></div>
  601. <!-- Right: Mega Ball (1-24) -->
  602. <div class="w-[105px] flex flex-col h-full shrink-0">
  603. <span class="text-[10px] font-black text-red-600 mb-1 uppercase tracking-wider shrink-0 text-center">Mega (1-24)</span>
  604. <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>
  605. </div>
  606. </div>
  607. `;
  608. grid.append(splitHtml);
  609. var standardContainer = $("#standardGrid");
  610. var megaContainer = $("#megaGrid");
  611. // Populate Standard (1-70)
  612. for (var i = 1; i <= 70; i++) {
  613. var formatted = i.toString().padStart(2, '0');
  614. var isSelected = selectedNumbers.slice(0, 5).includes(formatted);
  615. var btnClass = isSelected
  616. ? 'bg-[#0062FF] text-white shadow-sm'
  617. : 'bg-white text-gray-700 hover:bg-gray-100 border border-gray-100';
  618. 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>`);
  619. }
  620. // Populate Mega (1-24)
  621. for (var i = 1; i <= 24; i++) {
  622. var formatted = i.toString().padStart(2, '0');
  623. var isSelected = selectedNumbers[5] === formatted;
  624. var btnClass = isSelected
  625. ? 'bg-[#E3132D] text-white shadow-sm'
  626. : 'bg-white text-gray-700 hover:bg-gray-100 border border-gray-100';
  627. 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>`);
  628. }
  629. // Standard Grid Click Handler
  630. standardContainer.on('click', '.std-num-btn', function(e) {
  631. e.preventDefault();
  632. var $btn = $(this);
  633. var picked = $btn.text().trim();
  634. if (isMultiMode) {
  635. var stdSelected = selectedNumbers.slice(0, 5);
  636. if (stdSelected.includes(picked)) {
  637. // Deselect
  638. let idx = selectedNumbers.indexOf(picked);
  639. if (idx !== -1 && idx < 5) selectedNumbers[idx] = null;
  640. $btn.removeClass('bg-[#0062FF] text-white shadow-sm').addClass('bg-white text-gray-700 border border-gray-100');
  641. } else {
  642. // Select standard ball (first empty slot in 0-4)
  643. let emptyIdx = -1;
  644. for (var k = 0; k < 5; k++) {
  645. if (selectedNumbers[k] === null) {
  646. emptyIdx = k;
  647. break;
  648. }
  649. }
  650. if (emptyIdx !== -1) {
  651. selectedNumbers[emptyIdx] = picked;
  652. $btn.addClass('bg-[#0062FF] text-white shadow-sm').removeClass('bg-white text-gray-700 border border-gray-100');
  653. }
  654. }
  655. liveUpdateTicket();
  656. }
  657. updateSelectionCount();
  658. });
  659. // Mega Grid Click Handler
  660. megaContainer.on('click', '.mega-num-btn', function(e) {
  661. e.preventDefault();
  662. var $btn = $(this);
  663. var picked = $btn.text().trim();
  664. if (isMultiMode) {
  665. if (selectedNumbers[5] === picked) {
  666. // Deselect Mega Ball
  667. selectedNumbers[5] = null;
  668. $btn.removeClass('bg-[#E3132D] text-white shadow-sm').addClass('bg-white text-gray-700 border border-gray-100');
  669. } else {
  670. // Overwrite Mega Ball
  671. selectedNumbers[5] = picked;
  672. megaContainer.find('.mega-num-btn').removeClass('bg-[#E3132D] text-white shadow-sm').addClass('bg-white text-gray-700 border border-gray-100');
  673. $btn.addClass('bg-[#E3132D] text-white shadow-sm').removeClass('bg-white text-gray-700 border border-gray-100');
  674. }
  675. liveUpdateTicket();
  676. }
  677. updateSelectionCount();
  678. });
  679. } else {
  680. // Default Pick 10 UI: 1-80 Grid
  681. var normalHtml = `<div class="grid grid-cols-10 gap-1.5 w-full pb-2 h-full overflow-y-auto" id="normalGrid"></div>`;
  682. grid.append(normalHtml);
  683. var normalContainer = $("#normalGrid");
  684. for (var i = 1; i <= 80; i++) {
  685. var formatted = i.toString().padStart(2, '0');
  686. var isSelected = selectedNumbers.includes(formatted);
  687. var btnClass = isSelected
  688. ? 'bg-[#0062FF] text-white shadow-md scale-105 active-num'
  689. : 'bg-white text-gray-700 hover:bg-gray-100 border border-gray-100';
  690. 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>`);
  691. }
  692. normalContainer.on('click', '.num-btn', function(e) {
  693. e.preventDefault();
  694. var $btn = $(this);
  695. var picked = $btn.text().trim();
  696. if (isMultiMode) {
  697. if (selectedNumbers.includes(picked)) {
  698. let idx = selectedNumbers.indexOf(picked);
  699. if (idx !== -1) selectedNumbers[idx] = null;
  700. $btn.removeClass('bg-[#0062FF] text-white shadow-md scale-105 active-num').addClass('bg-white text-gray-700 border border-gray-100');
  701. } else {
  702. let firstEmpty = selectedNumbers.indexOf(null);
  703. if (firstEmpty !== -1) {
  704. selectedNumbers[firstEmpty] = picked;
  705. $btn.addClass('bg-[#0062FF] text-white shadow-md scale-105 active-num').removeClass('bg-white text-gray-700 border border-gray-100');
  706. }
  707. }
  708. liveUpdateTicket();
  709. }
  710. updateSelectionCount();
  711. });
  712. }
  713. modal.removeClass('hidden').addClass('flex');
  714. modal.find('.modal-content').removeClass('animate__zoomOut').addClass('animate__zoomIn');
  715. }
  716. function updateSelectionCount() {
  717. var count = selectedNumbers.filter(n => n !== null && n !== "").length;
  718. $("#selectionCount").text(count);
  719. $("#maxSelectionCount").text(maxBalls);
  720. var isValid = isMultiMode ? (count === maxBalls) : (count === 1);
  721. if (isValid) {
  722. $("#confirmBtn").prop('disabled', false).removeClass('opacity-50 cursor-not-allowed').addClass('cursor-pointer');
  723. } else {
  724. $("#confirmBtn").prop('disabled', true).addClass('opacity-50 cursor-not-allowed').removeClass('cursor-pointer');
  725. }
  726. }
  727. function liveUpdateTicket() {
  728. if (!activeTicketCard) return;
  729. var balls = activeTicketCard.find('.ball-circle');
  730. if (isMultiMode) {
  731. // Update Ticket Card balls
  732. for(var i=0; i < maxBalls; i++){
  733. var val = selectedNumbers[i];
  734. if (i < balls.length) {
  735. var tBall = $(balls[i]);
  736. if (val) {
  737. tBall.removeClass('ball-empty').addClass('ball-filled').text(val);
  738. } else {
  739. tBall.removeClass('ball-filled').addClass('ball-empty').text('');
  740. }
  741. }
  742. }
  743. // Toggle Rand/Edit button visibility
  744. if (selectedNumbers.filter(n => n !== null && n !== "").length > 0) {
  745. activeTicketCard.find('.rand-btn').hide();
  746. activeTicketCard.find('.edit-delete-group').removeClass('hidden').show();
  747. } else {
  748. activeTicketCard.find('.rand-btn').show();
  749. activeTicketCard.find('.edit-delete-group').addClass('hidden');
  750. }
  751. updateTotalPrice();
  752. }
  753. }
  754. // All immediate jQuery event bindings must wait for DOM + jQuery to be ready
  755. document.addEventListener("DOMContentLoaded", function() {
  756. // Click on a ball (filled or empty) to edit the full ticket
  757. $(document).on('click', '.ball-filled, .ball-empty', function() {
  758. editFullTicket(this);
  759. });
  760. updateTotalPrice();
  761. // Confirm button handler
  762. $(document).off('click', '#confirmBtn').on('click', '#confirmBtn', function(e) {
  763. e.preventDefault();
  764. // Check non-null count
  765. var count = selectedNumbers.filter(n => n !== null && n !== "").length;
  766. if (count === 0) return;
  767. if (isMultiMode && activeTicketCard && activeTicketCard.length > 0) {
  768. // Double check validation for Mega Ball before confirming
  769. if ("@Model.termType" === "@Constants.Millions_CODE") {
  770. var mbVal = selectedNumbers[5];
  771. if (mbVal) {
  772. var mbValInt = parseInt(mbVal);
  773. if (mbValInt < 1 || mbValInt > 24) {
  774. showNotification("🎱 @Lang.millions_megaball_invalid_title\n@Lang.millions_megaball_invalid_desc", "warning");
  775. return;
  776. }
  777. }
  778. }
  779. // Keep exact selected order, do not sort!
  780. var finalSorted = [];
  781. if ("@Model.termType" === "@Constants.Millions_CODE") {
  782. var first5 = selectedNumbers.slice(0, 5).filter(n => n !== null && n !== "");
  783. var mb = selectedNumbers[5];
  784. finalSorted = first5;
  785. if (mb) finalSorted.push(mb);
  786. } else {
  787. finalSorted = selectedNumbers.filter(n => n !== null && n !== "");
  788. }
  789. var balls = activeTicketCard.find('.ball-circle');
  790. balls.removeClass('ball-filled').addClass('ball-empty').text('');
  791. finalSorted.forEach((num, index) => {
  792. if (index < balls.length) {
  793. $(balls[index]).removeClass('ball-empty').addClass('ball-filled').text(num);
  794. $(balls[index]).addClass('animate__animated animate__pulse');
  795. setTimeout(() => $(balls[index]).removeClass('animate__animated animate__pulse'), 500);
  796. }
  797. });
  798. activeTicketCard.find('.rand-btn').hide();
  799. activeTicketCard.find('.edit-delete-group').removeClass('hidden').show();
  800. updateTotalPrice();
  801. } else if (!isMultiMode && activeBall && activeBall.length > 0) {
  802. // Single mode: Update only the active ball
  803. activeBall.text(selectedNumbers[0]).removeClass('ball-empty').addClass('ball-filled');
  804. activeBall.addClass('animate__animated animate__pulse');
  805. setTimeout(() => activeBall.removeClass('animate__animated animate__pulse'), 500);
  806. var card = activeBall.closest('.ticket-card');
  807. var filledBalls = card.find('.ball-filled').length;
  808. if (filledBalls > 0) {
  809. card.find('.rand-btn').hide();
  810. card.find('.edit-delete-group').removeClass('hidden').show();
  811. } else {
  812. card.find('.rand-btn').show();
  813. card.find('.edit-delete-group').addClass('hidden');
  814. }
  815. updateTotalPrice();
  816. }
  817. closeNumberPicker();
  818. });
  819. });
  820. function closeNumberPicker() {
  821. var modal = $("#numberPickerModal");
  822. modal.find('.modal-content').removeClass('animate__zoomIn').addClass('animate__zoomOut');
  823. setTimeout(() => {
  824. modal.removeClass('flex').addClass('hidden');
  825. // Remove the temporary scroll spacer
  826. $("#editScrollSpacer").remove();
  827. // Reset state
  828. activeBall = null;
  829. activeTicketCard = null;
  830. }, 200);
  831. }
  832. function updateTotalPrice() {
  833. var filledTickets = 0;
  834. $(".ticket-card").each(function() {
  835. if ($(this).find(".ball-filled").length === maxBalls) {
  836. filledTickets++;
  837. }
  838. });
  839. const pricePerTicket = @(Model.termType == Constants.PIC10_BASIC_CODE ? "10" : (Model.termType == Constants.Millions_CODE ? "20" : "50"));
  840. $("#totalPrice").text(formatMoneyV2(filledTickets * pricePerTicket));
  841. $("#totalTicketCount").text(filledTickets);
  842. }
  843. function addNewTicket() {
  844. var container = $("#ticketContainer");
  845. var wrapper = $("#addButtonWrapper");
  846. var currentIndex = $(".ticket-card").length + 1;
  847. var ballsHtml = '';
  848. var isMillions = @(Model.termType == Constants.Millions_CODE ? "true" : "false");
  849. for (var i = 0; i < maxBalls; i++) {
  850. var isMbBall = isMillions && i === 5;
  851. 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>' : '';
  852. ballsHtml += '<div class="relative w-fit"><div class="ball-circle ball-empty' + (isMbBall ? ' ball-mb-circle' : '') + '"></div>' + mbIndicator + '</div>';
  853. }
  854. var ticketHtml = `
  855. <div class="ticket-card relative group active:bg-gray-50 transition-colors cursor-pointer animate__animated animate__fadeInUp animate__faster">
  856. <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">
  857. <i class="fa-solid fa-xmark"></i>
  858. </button>
  859. <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>
  860. <div class="flex flex-col gap-1 pl-8">
  861. <span class="text-[16px] font-extrabold text-[#333]">@Lang.millions_select_10_lucky_numbers</span>
  862. <div class="flex items-center gap-4">
  863. <div class="grid grid-cols-6 gap-y-2 gap-x-1 flex-1">
  864. ${ballsHtml}
  865. </div>
  866. <div class="w-[90px] action-area flex flex-col gap-2">
  867. <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">
  868. <i class="fa-solid fa-arrows-rotate text-[10px]"></i> @Lang.Random
  869. </button>
  870. <div class="edit-delete-group hidden flex flex-col gap-2">
  871. <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">
  872. <img src="/Millions/img/icons/icon_edit.png" onerror="this.style.display='none'" class="w-[16px] h-[16px] object-contain"> @Lang.millions_edit
  873. </button>
  874. <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">
  875. <img src="/Millions/img/icons/icon_delete.png" onerror="this.style.display='none'" class="w-[16px] h-[16px] object-contain"> @Lang.millions_delete
  876. </button>
  877. </div>
  878. </div>
  879. </div>
  880. </div>
  881. </div>
  882. `;
  883. $(ticketHtml).insertBefore(wrapper);
  884. container.animate({ scrollTop: container.prop("scrollHeight") }, 300);
  885. }
  886. // --- Order Summary Modal Logic ---
  887. // --- Payment Preparation & Order Summary Logic ---
  888. let pendingTickets = [];
  889. let currentChannelPayment = '@Constants.BASIC_WALLET_TICKET';
  890. function preparePayment(event) {
  891. const isBSMode = @(Model.termType == Constants.PIC10_BIGSMALL_CODE || Model.termType == Constants.PIC10_ODDEVEN_CODE ? "true" : "false");
  892. const tickets = [];
  893. if (isBSMode) {
  894. if (!bsChoice) {
  895. showNotification("Please select a choice first.", "warning");
  896. return;
  897. }
  898. let bsCode = "";
  899. if ('@Model.termType' === '@Constants.PIC10_BIGSMALL_CODE') {
  900. bsCode = (bsChoice === 'big') ? "B" : "S";
  901. } else {
  902. bsCode = (bsChoice === 'big') ? "O" : "E"; // Odd = O, Even = E
  903. }
  904. tickets.push({
  905. code: bsCode,
  906. money: "50"
  907. });
  908. } else {
  909. $(".ticket-card").each(function() {
  910. const balls = $(this).find(".ball-filled");
  911. if (balls.length === maxBalls) {
  912. const selectedNumbers = [];
  913. balls.each(function() { selectedNumbers.push($(this).text().trim()); });
  914. const itemPrice = "@(Model.termType == Constants.PIC10_BASIC_CODE ? "10" : (Model.termType == Constants.Millions_CODE ? "20" : "50"))";
  915. tickets.push({
  916. code: selectedNumbers.join(','),
  917. money: itemPrice
  918. });
  919. }
  920. });
  921. if (tickets.length === 0) {
  922. showNotification("@Lang.millions_ticket_not_valid", "warning");
  923. return;
  924. }
  925. }
  926. pendingTickets = tickets;
  927. $("#paymentChannelModal").removeClass("hidden").addClass("flex");
  928. }
  929. function hidePaymentChannelModal() {
  930. $("#paymentChannelModal").removeClass("flex").addClass("hidden");
  931. }
  932. function selectPaymentChannel(channelPayment) {
  933. currentChannelPayment = channelPayment;
  934. hidePaymentChannelModal();
  935. const requestData = {
  936. gameId: "@Model.termType",
  937. ticket: pendingTickets,
  938. channelPayment: channelPayment
  939. };
  940. $.ajax({
  941. url: subDomain + '@Url.Action("ConfirmTicketData", "Home")',
  942. type: 'POST',
  943. contentType: 'application/json',
  944. data: JSON.stringify(requestData),
  945. success: function(data) {
  946. if (data.responseCode === "0" || data.responseCode === "0000") {
  947. showOrderSummary(data, pendingTickets);
  948. } else {
  949. showNotification(data.responseMessage || "Confirmation failed", data.responseCode);
  950. }
  951. },
  952. error: function(err) {
  953. showNotification("Network error occurred.", "warning");
  954. }
  955. });
  956. }
  957. let currentTransId = null;
  958. function showOrderSummary(apiData, localTickets) {
  959. currentTransId = apiData.transId;
  960. const summaryModal = $("#orderSummaryModal");
  961. const summaryList = $("#summaryTicketList");
  962. summaryList.empty();
  963. const displayTickets = (apiData && apiData.ticket) ? apiData.ticket : (localTickets || []);
  964. if (!displayTickets || !Array.isArray(displayTickets)) {
  965. console.warn("No tickets found to display in summary.");
  966. return;
  967. }
  968. displayTickets.forEach((t, index) => {
  969. const numbers = t.code.split(',');
  970. let contentHtml = '';
  971. if (numbers.length > 1) {
  972. const isMillionsGame = "@Model.termType" === "@Constants.Millions_CODE";
  973. let numbersBalls = '';
  974. numbers.forEach((n, ni) => {
  975. var isMbBall = isMillionsGame && ni === numbers.length - 1;
  976. var ballBg = isMbBall
  977. ? '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);'
  978. : 'background: linear-gradient(135deg, #FF3D63 0%, #E3132D 60%, #BA0F21 100%); box-shadow: 0 4px 10px rgba(186,15,33,0.3);';
  979. 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>`;
  980. });
  981. var summaryGridCols = isMillionsGame ? 'grid-cols-6' : 'grid-cols-5';
  982. contentHtml = `<div class="grid ${summaryGridCols} gap-y-2 gap-x-1 relative z-10 px-1 justify-items-center">${numbersBalls}</div>`;
  983. } else {
  984. const isBS = @(Model.termType == Constants.PIC10_BIGSMALL_CODE ? "true" : "false");
  985. const isFirstChoice = (numbers[0] === 'B' || numbers[0] === 'O');
  986. const label = isFirstChoice ? (isBS ? "Big" : "Odd") : (isBS ? "Small" : "Even");
  987. const color = isFirstChoice ? (isBS ? "#A2FF00" : "#FFC700") : (isBS ? "#FF4157" : "#B33BD0");
  988. 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>`;
  989. }
  990. const itemHtml = `
  991. <div class="flex items-center gap-3">
  992. <div class="flex-1 rounded-2xl p-3 relative overflow-hidden flex flex-col gap-2 min-h-[80px] justify-center shadow-sm"
  993. style="background: white; border: 1.5px solid #0062FF;">
  994. ${contentHtml}
  995. </div>
  996. <div class="w-24 shrink-0 bg-white border border-gray-200 rounded-2xl p-2.5 flex items-center justify-center shadow-sm">
  997. <div class="flex items-baseline gap-0.5">
  998. <span class="text-[20px] font-black text-black">${formatMoneyV2(t.money)}</span>
  999. <span class="text-[12px] font-black text-[#0062FF]">HTG</span>
  1000. </div>
  1001. </div>
  1002. </div>
  1003. `;
  1004. summaryList.append(itemHtml);
  1005. });
  1006. $("#summaryTotalCount").text(displayTickets.length);
  1007. const totalMoney = apiData.totalMoneyPayment || apiData.totalMoney || "0";
  1008. $("#summaryTotalAmount").text(formatMoneyV2(totalMoney));
  1009. summaryModal.removeClass("hidden").addClass("flex");
  1010. }
  1011. function hideOrderSummary() {
  1012. $("#orderSummaryModal").removeClass("flex").addClass("hidden");
  1013. }
  1014. function confirmCheckout(btn) {
  1015. if (currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET') {
  1016. showOtpModal(true);
  1017. return;
  1018. }
  1019. const originalText = $(btn).html();
  1020. $(btn).prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin mr-2"></i>Processing...');
  1021. // Trigger SendOTP API
  1022. $.ajax({
  1023. url: subDomain + '@Url.Action("SendOTP", "Home")',
  1024. type: 'POST',
  1025. success: function(data) {
  1026. $(btn).prop('disabled', false).html(originalText);
  1027. if (data.responseCode === "0") {
  1028. showOtpModal(false);
  1029. } else {
  1030. showNotification(data.responseMessage || "Failed to send OTP", data.responseCode);
  1031. }
  1032. },
  1033. error: function() {
  1034. $(btn).prop('disabled', false).html(originalText);
  1035. showNotification("Network error occurred.", "warning");
  1036. }
  1037. });
  1038. }
  1039. let otpInterval;
  1040. function showOtpModal(isWalletPin) {
  1041. hideOrderSummary();
  1042. $("#otpModal").removeClass("hidden").addClass("flex");
  1043. $("#otpInputs input").val("");
  1044. $("#walletPinInput").val("").attr("type", "password");
  1045. $("#walletPinEye").attr("class", "fa-solid fa-eye");
  1046. $("#otpConfirmBtn").prop('disabled', true);
  1047. $("#otpError").addClass("hidden").text("");
  1048. // Map game type to readable name & image
  1049. let gameTypeStr = "@Model.termType";
  1050. let displayName = gameTypeStr === "@Constants.Millions_CODE" ? "@Lang.millions" : "Basic Pick 10";
  1051. let imgSrc = "";
  1052. if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE") {
  1053. // Get the specific choice from summary
  1054. let firstTicketText = $("#summaryTicketList").find("span.font-black").first().text().trim();
  1055. if (firstTicketText) {
  1056. displayName = firstTicketText.charAt(0).toUpperCase() + firstTicketText.slice(1).toLowerCase(); // Normalize to "Big" or "Small"
  1057. } else {
  1058. displayName = "Big / Small";
  1059. }
  1060. } else if (gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") {
  1061. let firstTicketText = $("#summaryTicketList").find("span.font-black").first().text().trim();
  1062. if (firstTicketText) {
  1063. displayName = firstTicketText.charAt(0).toUpperCase() + firstTicketText.slice(1).toLowerCase(); // Normalize to "Odd" or "Even"
  1064. } else {
  1065. displayName = "Odd / Even";
  1066. }
  1067. }
  1068. // Determine color based on game type
  1069. let typeColorClass = "text-purple-700"; // default
  1070. if (gameTypeStr === "@Constants.PIC10_BASIC_CODE") typeColorClass = "text-[#0062FF]";
  1071. else if (gameTypeStr === "@Constants.Millions_CODE") typeColorClass = "text-[#0062FF]";
  1072. else if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE") typeColorClass = "text-[#0A9800]";
  1073. else if (gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") typeColorClass = "text-[#9333ea]";
  1074. // Hide image for now and use the beautiful text style as requested
  1075. $("#otpTicketTypeImg").hide();
  1076. $("#otpTicketTypeContainer").find("span").remove();
  1077. $("#otpTicketTypeContainer").append(`<span class='text-[17px] font-[900] ${typeColorClass} italic'>${displayName}</span>`);
  1078. $("#otpTotalAmount").text($("#summaryTotalAmount").text());
  1079. if (isWalletPin) {
  1080. $("#paymentCodeInstruction").text('@Html.Raw(Lang.payment_wallet_pin_instruction.Replace("'", "\\'"))');
  1081. $("#otpInputs").addClass("hidden");
  1082. $("#walletPinContainer").removeClass("hidden");
  1083. $("#otpTimer, #resendOtpBtn").addClass("hidden");
  1084. clearInterval(otpInterval);
  1085. $("#walletPinInput").focus();
  1086. } else {
  1087. $("#paymentCodeInstruction").text('@Html.Raw(Lang.millions_otp_instruction.Replace("'", "\\'"))');
  1088. $("#walletPinContainer").addClass("hidden");
  1089. $("#otpInputs").removeClass("hidden");
  1090. startOtpTimer(60);
  1091. $("#otp1").focus();
  1092. }
  1093. }
  1094. function updateWalletPinState() {
  1095. $("#otpConfirmBtn").prop('disabled', $("#walletPinInput").val().length === 0);
  1096. $("#otpError").addClass("hidden").text("");
  1097. }
  1098. function toggleWalletPinVisibility() {
  1099. const input = $("#walletPinInput");
  1100. const showPin = input.attr("type") === "password";
  1101. input.attr("type", showPin ? "text" : "password");
  1102. $("#walletPinEye").attr("class", showPin ? "fa-solid fa-eye-slash" : "fa-solid fa-eye");
  1103. input.focus();
  1104. }
  1105. // Add backspace support for OTP inputs
  1106. $("#otpInputs input").on("keyup", function() {
  1107. let otp = "";
  1108. $("#otpInputs input").each(function() { otp += $(this).val(); });
  1109. $("#otpConfirmBtn").prop('disabled', otp.length < 6);
  1110. });
  1111. $("#otpInputs input").on("keydown", function(e) {
  1112. if (e.key === "Backspace" && this.value.length === 0) {
  1113. $(this).prev('input').focus();
  1114. }
  1115. });
  1116. function hideOtpModal() {
  1117. $("#otpModal").removeClass("flex").addClass("hidden");
  1118. clearInterval(otpInterval);
  1119. }
  1120. function startOtpTimer(seconds) {
  1121. let timeLeft = seconds;
  1122. $("#resendOtpBtn").addClass("hidden");
  1123. $("#otpTimer").removeClass("hidden").text(timeLeft + "s");
  1124. clearInterval(otpInterval);
  1125. otpInterval = setInterval(() => {
  1126. timeLeft--;
  1127. $("#otpTimer").text(timeLeft + "s");
  1128. if (timeLeft <= 0) {
  1129. clearInterval(otpInterval);
  1130. $("#otpTimer").addClass("hidden");
  1131. $("#resendOtpBtn").removeClass("hidden");
  1132. }
  1133. }, 1000);
  1134. }
  1135. function moveToNext(el, nextId) {
  1136. if (el.value.length >= 1) {
  1137. if (nextId) document.getElementById(nextId).focus();
  1138. }
  1139. let otp = "";
  1140. $("#otpInputs input").each(function() { otp += $(this).val(); });
  1141. $("#otpConfirmBtn").prop('disabled', otp.length < 6);
  1142. // Clear error when typing
  1143. $("#otpError").addClass("hidden").text("");
  1144. }
  1145. function sendOtpRequest() {
  1146. // Re-trigger SendOTP
  1147. $.ajax({
  1148. url: subDomain + '@Url.Action("SendOTP", "Home")',
  1149. type: 'POST',
  1150. success: function(data) {
  1151. if (data.responseCode === "0") {
  1152. startOtpTimer(60);
  1153. showNotification("OTP has been resent.", "success");
  1154. } else {
  1155. showNotification(data.responseMessage || "Failed to resend OTP", data.responseCode);
  1156. }
  1157. }
  1158. });
  1159. }
  1160. function showReceiptSuccess(transId, amount, phone, totalTickets, drawDate) {
  1161. // Setup data dynamically
  1162. $("#receiptAmount").text(formatMoneyV2(amount) + " HTG");
  1163. if(phone) $("#receiptPhone").text(phone);
  1164. if(totalTickets) $("#receiptTotalTickets").text(totalTickets);
  1165. if(drawDate) $("#receiptDrawDate").text(drawDate);
  1166. let gameTypeStr = "@Model.termType";
  1167. let displayName = "Basic Pick 10";
  1168. if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE") displayName = "@Lang.millions_big_small";
  1169. else if (gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") displayName = "@Lang.millions_odd_even";
  1170. else if (gameTypeStr === "@Constants.Millions_CODE") displayName = "Millions";
  1171. $("#receiptGameType").text("@Lang.buy " + displayName);
  1172. $("#receiptTicketCode").text("#" + transId);
  1173. let choiceText = "-";
  1174. if (gameTypeStr === "@Constants.PIC10_BIGSMALL_CODE" || gameTypeStr === "@Constants.PIC10_ODDEVEN_CODE") {
  1175. choiceText = $("#summaryTicketList .flex.items-center span.font-black").first().text().trim();
  1176. } else {
  1177. choiceText = gameTypeStr === "@Constants.Millions_CODE" ? "Millions" : "PICK 10";
  1178. }
  1179. $("#receiptChoice").text(choiceText);
  1180. // Format current date "dd/MM/yyyy - HH:mm:ss"
  1181. let now = new Date();
  1182. 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');
  1183. $("#receiptTime").text(ds);
  1184. hideOtpModal();
  1185. $("#receiptSuccessModal").removeClass("hidden").addClass("flex");
  1186. }
  1187. function finalizePurchase(btn) {
  1188. const isWalletPayment = currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET';
  1189. let otpCode = isWalletPayment ? $("#walletPinInput").val().trim() : "";
  1190. if (!isWalletPayment) {
  1191. $("#otpInputs input").each(function() { otpCode += $(this).val(); });
  1192. }
  1193. if ((isWalletPayment && otpCode.length === 0) || (!isWalletPayment && otpCode.length < 6)) {
  1194. showNotification(isWalletPayment ? '@Html.Raw(Lang.payment_wallet_pin_instruction.Replace("'", "\\'"))' : "Please enter full 6-digit OTP", "warning");
  1195. return;
  1196. }
  1197. const originalText = $(btn).html();
  1198. $(btn).prop('disabled', true).html('<i class="fa-solid fa-spinner fa-spin mr-2"></i> ...');
  1199. const finalData = {
  1200. transIdByTicket: currentTransId,
  1201. paymentCode: currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET' ? null : otpCode,
  1202. walletPin: currentChannelPayment === '@Constants.NATCASH_WALLET_TICKET' ? otpCode : null,
  1203. channelPayment: currentChannelPayment
  1204. };
  1205. // Call the unified backend action that verifies OTP and then buys the ticket
  1206. $.ajax({
  1207. url: subDomain + '@Url.Action("ConfirmBuyingTicketV2", "Home")',
  1208. type: 'POST',
  1209. contentType: 'application/json',
  1210. data: JSON.stringify(finalData),
  1211. success: function(res) {
  1212. $(btn).prop('disabled', false).html(originalText);
  1213. if (res.responseCode === "0" || res.responseCode === "0000") {
  1214. // Success: Show receipt Modal
  1215. showReceiptSuccess(res.orderId || currentTransId, $("#summaryTotalAmount").text(), "@(Model.userStatus?.msisdn ?? "-")", $("#summaryTotalCount").text(), "@(currentTerm?.date_random ?? "-")");
  1216. } else {
  1217. if (res.responseCode === "-2" || (res.responseMessage && res.responseMessage.includes("System is upgrading"))) {
  1218. hideOtpModal();
  1219. showNotification(res.responseMessage || "System is upgrading", res.responseCode);
  1220. } else {
  1221. $("#otpError").text(res.responseMessage || "Invalid OTP").removeClass("hidden");
  1222. if (isWalletPayment) {
  1223. $("#walletPinInput").val("").focus();
  1224. } else {
  1225. $("#otpInputs input").val("");
  1226. $("#otp1").focus();
  1227. }
  1228. }
  1229. }
  1230. },
  1231. error: function() {
  1232. $(btn).prop('disabled', false).html(originalText);
  1233. showNotification("Network error occurred during payment completion.", "warning");
  1234. }
  1235. });
  1236. }
  1237. var systemUpgrading = false;
  1238. function showNotification(message, code) {
  1239. const msgEl = $("#notificationMessage");
  1240. const iconEl = $("#notificationModal img");
  1241. const btnEl = $("#notificationModal button");
  1242. if (message && message.includes("\n")) {
  1243. msgEl.html(message.replace(/\n/g, '<br/>'));
  1244. } else {
  1245. msgEl.text(message);
  1246. }
  1247. if (code === "-2" || (message && message.includes("System is upgrading"))) {
  1248. systemUpgrading = true;
  1249. btnEl.text("@Lang.login");
  1250. } else {
  1251. systemUpgrading = false;
  1252. btnEl.text("OK");
  1253. }
  1254. // Toggle icon based on type (warning or success)
  1255. const warningIcon = '/Millions/img/modal/warning_icon.png';
  1256. const successIcon = '/Millions/img/modal/success_icon_v2.png';
  1257. const fallbackWarning = 'https://cdn-icons-png.flaticon.com/512/564/564619.png';
  1258. const fallbackSuccess = 'https://cdn-icons-png.flaticon.com/512/190/190411.png';
  1259. if (code === "-2" || code === "warning" || code === "error") {
  1260. iconEl.attr('src', warningIcon);
  1261. iconEl.attr('onerror', `this.src='${fallbackWarning}'`);
  1262. } else {
  1263. iconEl.attr('src', successIcon);
  1264. iconEl.attr('onerror', `this.src='${fallbackSuccess}'`);
  1265. }
  1266. $("#notificationModal").removeClass("hidden").addClass("flex");
  1267. }
  1268. function closeNotificationModal() {
  1269. $("#notificationModal").addClass("hidden").removeClass("flex");
  1270. if (systemUpgrading) {
  1271. window.location.href = subDomain + "/Account/Login";
  1272. }
  1273. }
  1274. // ==================== CARD SELECTION GAME LOGIC (BIG/SMALL / ODD/EVEN) ====================
  1275. var bsChoice = null; // 'big' or 'small' (reused as 'odd' or 'even')
  1276. const isBigSmall = @(Model.termType == Constants.PIC10_BIGSMALL_CODE ? "true" : "false");
  1277. const themeColor = isBigSmall ? "#0A9800" : "#AA3DC8";
  1278. const labelBig = isBigSmall ? "Big" : "Odd";
  1279. const labelSmall = isBigSmall ? "Small" : "Even";
  1280. const colorBig = isBigSmall ? "#A2FF00" : "#FFC700";
  1281. const colorSmall = isBigSmall ? "#FF4157" : "#B33BD0";
  1282. // Loclized text from resources
  1283. const langSelect = "@Lang.millions_select";
  1284. const langSelected = "@Lang.millions_selected";
  1285. function selectBigSmall(choice) {
  1286. bsChoice = choice;
  1287. var cardBig = document.getElementById('cardBig');
  1288. var cardSmall = document.getElementById('cardSmall');
  1289. var choiceDisplay = document.getElementById('choiceDisplay');
  1290. if (!cardBig || !cardSmall) return;
  1291. if (choice === 'big') {
  1292. // Highlight Big/Odd card with theme glow
  1293. cardBig.style.border = '2px solid ' + themeColor;
  1294. cardBig.style.boxShadow = '0px 0px 12px 0px ' + (isBigSmall ? 'rgba(162, 255, 0, 1)' : 'rgba(179, 59, 208, 0.6)');
  1295. cardBig.querySelector('.bigsmall-btn').textContent = langSelected;
  1296. cardBig.querySelector('.bigsmall-btn').style.background = '#333';
  1297. // Reset Small/Even card
  1298. cardSmall.style.border = '2px solid transparent';
  1299. cardSmall.style.boxShadow = 'none';
  1300. cardSmall.querySelector('.bigsmall-btn').textContent = langSelect;
  1301. cardSmall.querySelector('.bigsmall-btn').style.background = themeColor;
  1302. // Update display
  1303. if (choiceDisplay) {
  1304. choiceDisplay.textContent = labelBig;
  1305. choiceDisplay.style.color = colorBig;
  1306. choiceDisplay.style.webkitTextStroke = '1px #000';
  1307. }
  1308. } else {
  1309. // Highlight Small/Even card with theme glow
  1310. cardSmall.style.border = '2px solid ' + themeColor;
  1311. cardSmall.style.boxShadow = '0px 0px 12px 0px ' + (isBigSmall ? 'rgba(162, 255, 0, 1)' : 'rgba(179, 59, 208, 0.6)');
  1312. cardSmall.querySelector('.bigsmall-btn').textContent = langSelected;
  1313. cardSmall.querySelector('.bigsmall-btn').style.background = '#333';
  1314. // Reset Big/Odd card
  1315. cardBig.style.border = '2px solid transparent';
  1316. cardBig.style.boxShadow = 'none';
  1317. cardBig.querySelector('.bigsmall-btn').textContent = langSelect;
  1318. cardBig.querySelector('.bigsmall-btn').style.background = themeColor;
  1319. // Update display
  1320. if (choiceDisplay) {
  1321. choiceDisplay.textContent = labelSmall;
  1322. choiceDisplay.style.color = colorSmall;
  1323. choiceDisplay.style.webkitTextStroke = '1px #000';
  1324. }
  1325. }
  1326. $("#bsTotalTicketCount").text(1);
  1327. $("#bsTotalPrice").text(formatMoneyV2(50));
  1328. }
  1329. function bsShowPayment(e) {
  1330. preparePayment(e);
  1331. }
  1332. </script>
  1333. <!-- Number Picker Modal (Refined Bottom Sheet) -->
  1334. <div id="numberPickerModal" class="fixed inset-0 bg-black/10 z-[200] hidden items-end justify-center p-0 transition-all">
  1335. <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">
  1336. <div class="px-4 py-1.5 bg-[#0062FF] text-white flex justify-between items-center relative">
  1337. <div class="flex flex-col">
  1338. <h3 class="font-black text-[15px] uppercase tracking-wide" id="modalTitle">@Lang.Pick_Number</h3>
  1339. <div class="selection-count-area">
  1340. <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>
  1341. </div>
  1342. </div>
  1343. <button onclick="closeNumberPicker()" class="w-8 h-8 flex items-center justify-center rounded-full bg-white/10 hover:bg-white/20 transition-all">
  1344. <i class="fa-solid fa-xmark text-lg"></i>
  1345. </button>
  1346. </div>
  1347. <style>
  1348. #numberGrid::-webkit-scrollbar { width: 3px; }
  1349. #numberGrid::-webkit-scrollbar-track { background: transparent; }
  1350. #numberGrid::-webkit-scrollbar-thumb { background: #FFD700; border-radius: 10px; }
  1351. #numberGrid { scrollbar-width: thin; scrollbar-color: #FFD700 transparent; }
  1352. </style>
  1353. <div class="p-2 h-[220px] overflow-hidden bg-gray-50 border-b" id="numberGrid">
  1354. <!-- Populated via JS -->
  1355. </div>
  1356. <div class="p-3 bg-white border-t flex gap-3">
  1357. <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">
  1358. @Lang.millions_back
  1359. </button>
  1360. <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">
  1361. @Lang.confirm
  1362. </button>
  1363. </div>
  1364. </div>
  1365. </div>
  1366. <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">
  1367. <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">
  1368. <!-- Alert Icon -->
  1369. <div class="w-full flex justify-center mb-2 mt-0">
  1370. <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'" />
  1371. </div>
  1372. <!-- Message Area -->
  1373. <div class="px-2 text-center mb-5">
  1374. <p id="notificationMessage" class="text-black font-[800] text-[17px] leading-snug">
  1375. <!-- Message content -->
  1376. </p>
  1377. </div>
  1378. <!-- Action Button -->
  1379. <div class="w-full">
  1380. <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">
  1381. OK
  1382. </button>
  1383. </div>
  1384. </div>
  1385. </div>
  1386. <!-- Beautiful Success Receipt Modal (Matches Figma 161:3722) -->
  1387. <div id="receiptSuccessModal" class="fixed inset-0 z-[300] bg-black/80 hidden items-center justify-center px-4 font-bricolage backdrop-blur-md">
  1388. <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">
  1389. <!-- Confetti/Celebration background effect (Subtle removed) -->
  1390. <h2 class="text-[#534A4A] font-[800] text-[19px] tracking-tight relative z-10 w-full text-center mt-1">@Lang.millions_payment_successfully</h2>
  1391. <!-- Ticket / Success Graphic -->
  1392. <div class="relative w-full flex justify-center mt-2 mb-0 z-10 px-4">
  1393. <img src="/Millions/img/modal/success_icon_v2.png" alt="Success" class="w-full h-auto object-contain">
  1394. </div>
  1395. <h3 class="text-[#0A9800] font-[900] text-[20px] uppercase tracking-wide relative z-10">@Lang.success</h3>
  1396. <div class="w-full h-px border-t-[2px] border-dashed border-gray-300 my-3 relative z-10"></div>
  1397. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1398. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.phone_number</span>
  1399. <span class="font-black text-[14px] text-gray-800" id="receiptPhone">-</span>
  1400. </div>
  1401. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1402. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.millions_your_choice</span>
  1403. <span class="text-[#0062FF] font-[900] text-[15px] uppercase" id="receiptChoice">-</span>
  1404. </div>
  1405. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1406. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.ticket_code</span>
  1407. <span class="font-black text-[13px] text-gray-800" id="receiptTicketCode">#</span>
  1408. </div>
  1409. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1410. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.total_ticket</span>
  1411. <span class="font-black text-[14px] text-gray-800" id="receiptTotalTickets">-</span>
  1412. </div>
  1413. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1414. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.millions_draw_date</span>
  1415. <span class="font-black text-[14px] text-gray-800" id="receiptDrawDate">-</span>
  1416. </div>
  1417. <div class="w-full flex justify-between items-center mb-1 relative z-10 px-1">
  1418. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.total_payment</span>
  1419. <span class="text-[#0062FF] font-[900] text-[15px]" id="receiptAmount">0 HTG</span>
  1420. </div>
  1421. <div class="w-full h-px border-t-[2px] border-dashed border-gray-300 my-3 relative z-10"></div>
  1422. <div class="w-full flex justify-between items-center mb-2 relative z-10 px-1">
  1423. <span class="text-[#534A4A] font-bold text-[14px]">@Lang.time</span>
  1424. <span class="font-bold text-[13px] text-gray-600" id="receiptTime">00:00:00</span>
  1425. </div>
  1426. <div class="w-full flex justify-start items-center relative z-10 px-1 mt-1">
  1427. <span class="text-[#534A4A] font-bold text-[13px] italic text-gray-500" id="receiptGameType">@Lang.millions_buy_ticket_label</span>
  1428. </div>
  1429. <div class="text-[#534A4A] font-[900] text-[18px] relative z-10 text-center mt-3">@Lang.thank_you <span class="text-[#0062FF]">♥️</span></div>
  1430. <div class="w-full flex gap-2.5 mt-4 relative z-10">
  1431. <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">
  1432. @Lang.millions_continue
  1433. </button>
  1434. <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">
  1435. @Lang.close
  1436. </button>
  1437. </div>
  1438. </div>
  1439. </div>
  1440. }