student-reward-core.min.js · v4.11.2: ảnh trợ giảng link lh3 + nhớ trong máy; getTroGiangPhoto(code) cho Bảng xếp hạng và danh thiếp (18/11/2026)

/* Reward Core 4.11.2 · 18/11/2026: ảnh trợ giảng dùng link lh3 (tải nhanh), nhớ danh sách ảnh trong máy (ocdTgPhoto) để trang hiện đúng ngay cả khi danh sách công khai chưa tải xong; thêm getTroGiangPhoto(code). — 4.11.1 · 18/11/2026: getProfileAvatar ưu tiên ảnh riêng của trợ giảng ("anh:<id>" trong lựa chọn Trang trí). — 4.11.0 · 17/11/2026: hồ sơ 1 học viên chỉ tải giao dịch của chính học viên đó (PhieuDoi, QuaTangGVCN, SoDuChot lọc theo mã) thay vì sổ của cả lớp; lỗi thì tự tải đầy đủ như cũ. Trang admin (core-v31) và Apps Script vẫn tải đầy đủ. — Bản 3.6.0 · sửa 15/11/2026: chấm điểm lẻ (5,25 / 5,5 / 5,75…) – thưởng bài nộp xếp nhóm theo phần nguyên: 5–dưới 6 như điểm 5, 6–dưới 7 như 6, 7–dưới 8 như 7, 8–dưới 10 như 8–9, đúng 10 = Lục Thạch. Chuỗi điểm cao vẫn tính bài từ 6 điểm. */
(function(){"use strict";if(window.StudentRewardSystem&&window.StudentRewardSystem.version){try{window.dispatchEvent(new CustomEvent("studentRewardCoreReady",{detail:{version:window.StudentRewardSystem.version}}))}catch{}return}const $="3.6.0",S={spreadsheetId:"1-IkcpEkKQtIavl5DIf6Sbwx3p0aAfnSS4HjT6dn1u_E",giftGid:"0",npcGid:"1348051654",formSheetName:"PhieuDoi",teacherGiftSheetName:"QuaTangGVCN",snapshotSheetName:"SoDuChot",formConfirmValue:"T\xF4i x\xE1c nh\u1EADn \u0111\u1ED5i m\xF3n qu\xE0 n\xE0y",studentCsv:"https://docs.google.com/spreadsheets/d/e/2PACX-1vRP5cc8duj1XrCXMrymo6Cj7aqIkWfX6bHxGeW-lXcSewfQXhM8fZ5rzbNIQ9mBeVuB8yYr_o1aBoYA/pub?output=csv",studentRegistryCsv:"https://docs.google.com/spreadsheets/d/e/2PACX-1vRP5cc8duj1XrCXMrymo6Cj7aqIkWfX6bHxGeW-lXcSewfQXhM8fZ5rzbNIQ9mBeVuB8yYr_o1aBoYA/pub?gid=1603096683&single=true&output=csv",studentRegistryStrict:!1,studentRegistryCacheTtl:15e3,timeZone:"Asia/Ho_Chi_Minh",marketCurrency:"hongNgoc",avatarGiftPrefix:"Th\u1EBB \u0111\u1ED5i Avatar",avatarFramePrefix:"Khung ",profileBackgroundPrefix:"N\u1EC1n h\u1ED3 s\u01A1 ",appsScriptUrl:"https://script.google.com/macros/s/AKfycbwtMkodKNVrUgVWhpvhwMndPZKBrdWD4OF0XoR4i5poQsxRkEDLIkm56-MTxuOCVW9JXA/exec",multitaskPotionGiftName:"Thu\u1ED1c \u0111a nhi\u1EC7m",mysteryBoxGiftName:"H\u1ED9p qu\xE0 b\xED \u1EA9n",mysteryRewardColumn:"Qu\xE0 nh\u1EADn \u0111\u01B0\u1EE3c",cacheTtl:15e3},Ze=1440*60*1e3,U={user:String.fromCodePoint(128100),gift:String.fromCodePoint(127873),seed:String.fromCodePoint(127793),medal:String.fromCodePoint(127941),tree:String.fromCodePoint(127795),fire:String.fromCodePoint(128293),star:String.fromCodePoint(11088),target:String.fromCodePoint(127919),rocket:String.fromCodePoint(128640),sparkles:String.fromCodePoint(10024),eagle:String.fromCodePoint(129413),crown:String.fromCodePoint(128081),box:String.fromCodePoint(128230),gem:String.fromCodePoint(128142)},te={hoangNgoc:{key:"hoangNgoc",displayName:"Ho\xE0ng Ng\u1ECDc",className:"gem-hoang",image:"1ELG5w78c1vM2H53NjR__Wif-COFBIa4-"},haiLamNgoc:{key:"haiLamNgoc",displayName:"H\u1EA3i Lam Ng\u1ECDc",className:"gem-hailam",image:"1TMrH31aDPivPaSSTbZts1syEXtvJWc7N"},thachAnhTim:{key:"thachAnhTim",displayName:"Th\u1EA1ch Anh T\xEDm",className:"gem-thachanh",image:"1vhsBzLr3kqCDuK3kAd0ueRGJBEdjuWnd"},lamBaoThach:{key:"lamBaoThach",displayName:"Lam B\u1EA3o Th\u1EA1ch",className:"gem-lambao",image:"1vDrlf7846xVNJ4g8HPdkFNWhOtpTNrGu"},lucThach:{key:"lucThach",displayName:"L\u1EE5c Th\u1EA1ch",className:"gem-luc",image:"19FSdR0HkIbvQIyTejqw7kXlxWEARG5ZB"},hongNgoc:{key:"hongNgoc",displayName:"H\u1ED3ng Ng\u1ECDc",className:"gem-hong",image:"1S4DuNvJypXLIeg1LUV-IpVD5gM8tRK43"}},z=["hoangNgoc","haiLamNgoc","thachAnhTim","lamBaoThach","lucThach","hongNgoc"],re={phoThong:{key:"phoThong",displayName:"Ph\u1ED5 th\xF4ng",gemType:"hoangNgoc",rank:1},trungPham:{key:"trungPham",displayName:"Trung ph\u1EA9m",gemType:"haiLamNgoc",rank:2},trungThuongPham:{key:"trungThuongPham",displayName:"Trung th\u01B0\u1EE3ng ph\u1EA9m",gemType:"thachAnhTim",rank:3},thuongPham:{key:"thuongPham",displayName:"Th\u01B0\u1EE3ng ph\u1EA9m",gemType:"lamBaoThach",rank:4},caoCap:{key:"caoCap",displayName:"Cao c\u1EA5p",gemType:"lucThach",rank:5},cucPham:{key:"cucPham",displayName:"C\u1EF1c ph\u1EA9m",gemType:"hongNgoc",rank:6}},Q=["phoThong","trungPham","trungThuongPham","thuongPham","caoCap","cucPham"],P={hoangNgocToLuc:5,haiLamNgocToLuc:4,thachAnhTimToLuc:3,lamBaoThachToLuc:2,lucThachToHong:3};function x(n){return String(n??"").trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/đ/g,"d").replace(/\s+/g," ")}function X(n){return String(n??"").trim().toUpperCase()}function ue(n){if(n==null||n==="")return 0;let e=String(n).trim().replace(/\s+/g,"");e.includes(",")&&!e.includes(".")&&(e=e.replace(",","."));const t=Number(e);return Number.isFinite(t)?t:0}function ge(n){if(n==null)return null;const e=String(n).trim();if(!e)return null;const t=ue(e);return Number.isFinite(t)?t:null}function Ie(n){const e=Number(n||0);return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function Z(n,e){const t=(n||[]).map(x);for(let o=0;o<e.length;o++){const r=x(e[o]),c=t.indexOf(r);if(c>=0)return c}for(let o=0;o<e.length;o++){const r=x(e[o]),c=t.findIndex(function(l){return l.includes(r)});if(c>=0)return c}return-1}function fe(n){n=String(n||"");const e=[];let t=[],o="",r=!1;for(let c=0;c<n.length;c++){const l=n[c];if(l==='"'){r&&n[c+1]==='"'?(o+='"',c++):r=!r;continue}if(l===","&&!r){t.push(o),o="";continue}if((l===`
`||l==="\r")&&!r){l==="\r"&&n[c+1]===`
`&&c++,t.push(o),e.push(t),t=[],o="";continue}o+=l}return(o.length||t.length)&&(t.push(o),e.push(t)),e.filter(function(c){return c.some(function(l){return String(l||"").trim()!==""})})}async function Y(n,e){const t=e?null:E(n);return t&&!Ne()?j(function(){return pe(t.src,t.name).then(ct)},function(o){return Pe(n,o)},t.name,function(o,r){try{f(t.name,fe(o),fe(r))}catch{}}):(t&&(Te="CSV (Apps Script t\u1EA1m t\u1EAFt, "+le()+")"),Pe(n))}const Me="https://docs.google.com/spreadsheets/d/e/2PACX-1vRP5cc8duj1XrCXMrymo6Cj7aqIkWfX6bHxGeW-lXcSewfQXhM8fZ5rzbNIQ9mBeVuB8yYr_o1aBoYA/pub?",ne="https://docs.google.com/spreadsheets/d/1GJoTRsbq0kZfZrDdh0uCC667PwS3Bgkje2fHQnwnCKs/export?format=csv&gid=";let be=!1;function Ee(n){if(n=String(n||""),be||n.indexOf(Me)!==0)return"";const e=n.match(/[?&]gid=(\d+)/);return ne+(e?e[1]:"1837470623")}function xe(n){const e=String(n||"").slice(0,200).trim().toLowerCase();return!!e&&e.indexOf("<!doctype")!==0&&e.indexOf("<html")!==0}async function Pe(n,e){const t=Ee(n);if(t)try{const o=await qe(t,e);if(xe(o))return o;be=!0}catch(o){if(e&&e.aborted)throw o;be=!0}return qe(n,e)}async function qe(n,e){const t=new AbortController;let o=!1;const r=setTimeout(function(){o=!0,t.abort()},oe),c=function(){t.abort()};e&&(e.aborted?t.abort():e.addEventListener("abort",c,{once:!0}));try{const l=await fetch(n,{cache:"no-store",signal:t.signal});if(!l.ok)throw new Error("Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c d\u1EEF li\u1EC7u CSV.");return await l.text()}catch(l){throw o?new Error("Ngu\u1ED3n d\u1EEF li\u1EC7u kh\xF4ng ph\u1EA3n h\u1ED3i sau 20 gi\xE2y."):l}finally{clearTimeout(r),e&&e.removeEventListener("abort",c)}}let Te="";const Ae={},Be={},De=2500,v=25e3,oe=2e4,Oe=18e4,ie="srcApiPausedUntil_v446";let He=(function(){try{return Number(window.sessionStorage.getItem(ie))||0}catch{return 0}})();function Ne(){return Date.now()<He}function ee(){He=Date.now()+Oe;try{window.sessionStorage.setItem(ie,String(He))}catch{}}let he=!1;try{window.addEventListener("pagehide",function(){he=!0}),window.addEventListener("beforeunload",function(){he=!0}),window.addEventListener("pageshow",function(){he=!1})}catch{}function Re(n){return!n||he?!1:n.apiCap===!0||n.name==="TypeError"}function le(){return new Date().toLocaleTimeString("vi-VN",{timeZone:S.timeZone})}const Ke=8e3;let Ge=0,i=0;function d(n){i=Date.now(),Ge=Math.max(Ge,Date.now()+(Number(n)||6e4))}function y(){return i}const p=3e3;function C(n){const e=Date.now();return n>0&&e-n<p&&n>i&&e>=Ge}function G(){return Date.now()<Ge?Ke:De}const D=45e3;let _=null,m=0,w=null;function a(n){_=typeof n=="function"?n:null}function s(n){if(!Array.isArray(n))return-1;let e=0;for(let t=1;t<n.length;t++){const o=n[t];Array.isArray(o)&&o.some(function(r){return String(r??"").trim()!==""})&&e++}return e}function u(n){if(!Array.isArray(n))return-1;let e=0;for(let t=1;t<n.length;t++){const o=n[t];Array.isArray(o)&&o.forEach(function(r){String(r??"").trim()!==""&&e++})}return e}function f(n,e,t){const o=s(e),r=s(t);if(o<0||r<0)return;const c=u(e),l=u(t);o<=r&&c<=l||(console.info("[Reward Core] CSV ("+n+") kh\xE1c Apps Script: "+o+"/"+r+" d\xF2ng, "+c+"/"+l+" \xF4 c\xF3 d\u1EEF li\u1EC7u. T\u1EF1 c\u1EADp nh\u1EADt l\u1EA1i."),!(w||Date.now()-m<D)&&(w=setTimeout(function(){w=null,m=Date.now(),d(6e4),Ce=null,yt=0,SFc.clear(),Promise.resolve().then(function(){return _?_():wt(!0)}).then(function(){try{window.dispatchEvent(new CustomEvent("ocdRewardSharedChanged",{detail:{reason:"late-api",label:n}}))}catch{}}).catch(function(h){console.warn("[Reward Core] T\u1EF1 c\u1EADp nh\u1EADt l\u1EA1i ch\u01B0a \u0111\u01B0\u1EE3c:",h&&h.message||h)})},800)))}let b=null;function T(n){try{let e=document.getElementById("ocdDataFallbackNotice");if(!n){e&&(e.style.display="none");return}if(!document.body)return;e||(e=document.createElement("div"),e.id="ocdDataFallbackNotice",e.setAttribute("role","status"),e.style.cssText="position:fixed;left:12px;bottom:12px;z-index:99999;max-width:min(320px,calc(100vw - 24px));padding:8px 12px;border-radius:10px;background:rgba(60,45,20,.92);color:#fff;font:13px/1.4 system-ui,sans-serif;box-shadow:0 4px 14px rgba(0,0,0,.25);pointer-events:none",e.textContent="\u0110ang hi\u1EC3n th\u1ECB d\u1EEF li\u1EC7u d\u1EF1 ph\xF2ng, c\xF3 th\u1EC3 ch\u1EADm v\xE0i ph\xFAt. H\u1EC7 th\u1ED1ng s\u1EBD t\u1EF1 c\u1EADp nh\u1EADt.",document.body.appendChild(e)),e.style.display="block",clearTimeout(b),b=setTimeout(function(){e.style.display="none"},12e3)}catch{}}const I=["m\xE3 h\u1ECDc vi\xEAn","ma hoc vien","m\xE3 hv","studentcode","student code"];function F(n){try{const e=typeof n=="string"?fe(n):n;if(!Array.isArray(e)||e.length<2||!Array.isArray(e[0]))return 0;const t=e[0].findIndex(function(r){return I.indexOf(String(r??"").trim().toLowerCase())>=0});if(t<0)return 0;let o=0;for(let r=1;r<e.length;r++){const c=e[r];if(!Array.isArray(c))continue;c.filter(function(h){return String(h??"").trim()!==""}).length>=2&&String(c[t]==null?"":c[t]).trim()===""&&o++}return o}catch{return 0}}function j(n,e,t,o){return new Promise(function(r,c){let l=null,h=null,N=!1,M=!1,H=!1,R=!1,g=null,O=null,L=null;const V=new AbortController;function k(A,B){N||(N=!0,clearTimeout(L),A?r(B):c(B))}function K(){M||N||(M=!0,Promise.resolve().then(function(){return e(V.signal)}).then(function(A){if(R=!0,N)return;const B=F(A);if(B>0){h=A,console.warn("[Reward Core] CSV ("+t+") c\xF3 "+B+" d\xF2ng tr\u1ED1ng m\xE3 h\u1ECDc vi\xEAn, ch\u1EDD Apps Script."),H&&g&&(Te="CSV d\u1EF1 ph\xF2ng ("+le()+")",l=A,T(!0),k(!0,A));return}Te="CSV d\u1EF1 ph\xF2ng ("+le()+")",l=A,T(!0),k(!0,A)},function(A){R=!0,O=A,H&&k(!1,g||A)}))}Promise.resolve().then(n).then(function(A){if(H=!0,N){if(o&&l!==null){T(!1);try{o(A,l)}catch{}}}else{Te="Apps Script ("+le()+")",T(!1);try{V.abort()}catch{}k(!0,A)}},function(A){if(H=!0,g=A,A&&A.locked){k(!1,A);return}if(!N&&!he&&console.warn("[Reward Core] Apps Script l\u1ED7i ("+t+"), d\xF9ng CSV:",A&&A.message||A),Re(A)&&ee(),h!==null){Te="CSV d\u1EF1 ph\xF2ng ("+le()+")",l=h,T(!0),k(!0,h);return}M?R&&k(!1,O||A):K()});const me=G();L=setTimeout(function(){N||M||(console.info("[Reward Core] Apps Script ch\u01B0a tr\u1EA3 l\u1EDDi sau "+me/1e3+"s ("+t+"), t\u1EA3i CSV song song."),K())},me)})}function E(n){if(!S.appsScriptUrl)return null;n=String(n||"");const e="https://docs.google.com/spreadsheets/d/"+encodeURIComponent(S.spreadsheetId)+"/gviz/tq?";if(n.indexOf(e)===0){let r=n.match(/[?&]sheet=([^&]+)/);if(r)return{src:"gift",name:decodeURIComponent(r[1])};r=n.match(/[?&]gid=([^&]+)/);const c={0:"QuaTang"};return c[String(S.npcGid)]="NhanVat",r&&c[decodeURIComponent(r[1])]?{src:"gift",name:c[decodeURIComponent(r[1])]}:null}if(n===S.studentRegistryCsv)return{src:"students",name:"HocVien"};const t="https://docs.google.com/spreadsheets/d/e/2PACX-1vRP5cc8duj1XrCXMrymo6Cj7aqIkWfX6bHxGeW-lXcSewfQXhM8fZ5rzbNIQ9mBeVuB8yYr_o1aBoYA/pub?";if(n.indexOf(t)===0||n.indexOf("https://docs.google.com/spreadsheets/d/1GJoTRsbq0kZfZrDdh0uCC667PwS3Bgkje2fHQnwnCKs/export?")===0){const r=n.match(/[?&]gid=(\d+)/),c=r?r[1]:n.indexOf(t)===0?"1837470623":"",l={1837470623:"Form Responses 1",1326884435:"XepHang",521976322:"XoaBai",1023688821:"TacPhamWeb",1603096683:"HocVien"};if(l[c])return{src:"students",name:l[c]}}return null}const J="ocdApiMulti_v1";let q=null;function ae(){if(q)return q;try{q=JSON.parse(window.sessionStorage.getItem(J)||"{}")||{}}catch{q={}}return q}function de(n,e,t){const o=ae();o[n]={h:e,sheets:t,at:Date.now()};try{Object.keys(o).sort(function(c,l){return(o[l].at||0)-(o[c].at||0)}).slice(6).forEach(function(c){delete o[c]});const r=JSON.stringify(o);r.length<3e6?window.sessionStorage.setItem(J,r):window.sessionStorage.removeItem(J)}catch{}}function pe(n,e,t){t=t?String(t):"";let o=Be[e]?n+":"+e:t&&SFk[e]?"sf":"all",r=Ae[o];r&&t&&r.code&&r.code!==t&&(o+="|"+t,r=Ae[o]),r||(r=Ae[o]={names:new Set,code:""},r.promise=new Promise(function(l,h){setTimeout(async function(){delete Ae[o];const N=new AbortController;let M=!1;const H=setTimeout(function(){M=!0,N.abort()},v),R=Date.now();try{const g=Array.from(r.names).sort(),O=g.join(";")+"|"+(r.code||""),L=ae()[O],V=await fetch(S.appsScriptUrl+"?multi="+encodeURIComponent(g.join(";"))+(r.code?"&code="+encodeURIComponent(r.code):"")+"&v=449"+(L&&L.h&&L.sheets?"&h="+encodeURIComponent(L.h):"")+"&_="+Date.now(),{cache:"no-store",credentials:"omit",signal:N.signal}),k=JSON.parse(await V.text());if(k&&k.ok&&k.same&&L&&L.sheets){console.info("[Reward Core] Apps Script "+(Date.now()-R)+"ms (kh\xF4ng \u0111\u1ED5i):",g.join(" ; ")),L.at=Date.now(),l(L.sheets);return}if(console.info("[Reward Core] Apps Script "+(Date.now()-R)+"ms:",g.join(" ; ")),k&&k.locked){const K=new Error(k.error||"H\u1ED3 s\u01A1 \u0111\xE3 \u0111\u01B0\u1EE3c b\u1EA3o m\u1EADt.");throw K.locked=!0,K.code="STUDENT_PROTECTED",K}if(!k||!k.ok||!k.sheets)throw new Error(k&&k.error||"Apps Script tr\u1EA3 v\u1EC1 l\u1ED7i.");k.h&&de(O,k.h,k.sheets),l(k.sheets)}catch(g){if(M){const O=new Error("Apps Script kh\xF4ng tr\u1EA3 l\u1EDDi sau "+v/1e3+" gi\xE2y.");O.apiCap=!0,h(O)}else h(g)}finally{clearTimeout(H)}},0)})),t&&(r.code=t);const c=n+":"+e+(t?"!":"");return r.names.add(c),r.promise.then(function(l){const h=l[c];if(!Array.isArray(h)||!h.length)throw new Error("Apps Script thi\u1EBFu tab "+e+".");return h})}function $e(n,e){const t=X(e);return!t||!S.appsScriptUrl||Ne()?Promise.reject(new Error("Apps Script t\u1EA1m t\u1EAFt.")):new Promise(function(o,r){const c=setTimeout(function(){r(new Error("Apps Script ch\u1EADm (qu\xE1 5 gi\xE2y)."))},De*2);pe("students",String(n||""),t).then(ct).then(function(l){clearTimeout(c),o(l)},function(l){clearTimeout(c),Re(l)&&ee(),r(l)})})}const _e="srcApiNoKind_v447",mn=36e5;function fn(n){try{const e=JSON.parse(window.localStorage.getItem(_e)||"{}");return Date.now()<Number(e[n]||0)}catch{return!1}}function hn(n){try{const e=JSON.parse(window.localStorage.getItem(_e)||"{}");e[n]=Date.now()+mn,window.localStorage.setItem(_e,JSON.stringify(e))}catch{}}function gn(n){return!!n&&n.ok===!1&&/lo[aạ]i d[uữ] li[eệ]u ghi kh[oô]ng h[oợ]p l[eệ]/i.test(String(n.error||""))}async function pn(n,e){if(!S.appsScriptUrl||fn(n))return"notsent";for(let t=0;t<3;t++){const o=new AbortController,r=setTimeout(function(){o.abort()},2e4),c=Date.now();try{const l=await fetch(S.appsScriptUrl,{method:"POST",body:JSON.stringify({action:"append",items:[{kind:n,row:e}]}),headers:{"Content-Type":"text/plain;charset=utf-8"},credentials:"omit",cache:"no-store",signal:o.signal}),h=JSON.parse(await l.text());if(console.info("[Reward Core] Ghi th\u1EB3ng "+n+" "+(Date.now()-c)+"ms:",h),h&&h.ok){const N=h.written&&h.written[n]||h.dup&&h.dup[n];return N&&d(9e4),N?"sent":"notsent"}if(gn(h))return hn(n),"notsent";if(h&&(h.busy||/đang bận/i.test(String(h.error||"")))&&t<2){await new Promise(function(N){setTimeout(N,1500)});continue}return"notsent"}catch(l){if(console.warn("[Reward Core] Ghi th\u1EB3ng "+n+" l\u1ED7i:",l&&l.message||l),t<1){await new Promise(function(h){setTimeout(h,1200)});continue}return"unknown"}finally{clearTimeout(r)}}return"notsent"}const et=new Map;function ct(n){return n.map(function(e){return e.map(function(t){return t=t==null?"":String(t),/[",\r\n]/.test(t)?'"'+t.replace(/"/g,'""')+'"':t}).join(",")}).join(`
`)}function yn(n,e){const t=X(n);if(!t)return Y(S.studentCsv);const o=et.get(t);if(o&&(o.pending||!e&&Date.now()-o.at<15e3||e&&C(o.startedAt)))return o.p;const r={at:Date.now(),startedAt:Date.now(),pending:!0};return r.p=(function(){return S.appsScriptUrl&&!Ne()?j(function(){return pe("students","Form Responses 1",t).then(ct)},function(c){return Pe(S.studentCsv,c)},"b\xE0i n\u1ED9p"):Y(S.studentCsv,!0)})(),et.set(t,r),r.p.then(function(){r.pending=!1,r.at=Date.now()},function(){et.get(t)===r&&et.delete(t)}),r.p}async function Xe(n,cd){const e=E(n);if(cd&&e&&!Ne()&&SFk[e.name])return pe(e.src,e.name,cd);return e&&!Ne()?j(function(){return pe(e.src,e.name)},function(t){return Pe(n,t).then(fe)},e.name,function(t,o){f(e.name,t,o)}):(e&&(Te="CSV (Apps Script t\u1EA1m t\u1EAFt, "+le()+")"),fe(await Y(n,!0)))}let Ve=null,st=0;function bt(n){const e=x(n).replace(/\s+/g,"-");return{active:"active","hoat-dong":"active","dang-hoat-dong":"active",paused:"paused",pause:"paused","tam-dung":"paused",pending:"pending","cho-kich-hoat":"pending","chua-kich-hoat":"pending",graduated:"graduated","tot-nghiep":"graduated","da-tot-nghiep":"graduated",banned:"banned",blocked:"banned",khoa:"banned","da-khoa":"banned",inactive:"paused"}[e]||e}function ut(n){return n==="paused"?"M\xE3 h\u1ECDc vi\xEAn hi\u1EC7n \u0111ang t\u1EA1m d\u1EEBng.":n==="pending"?"M\xE3 h\u1ECDc vi\xEAn hi\u1EC7n ch\u01B0a \u0111\u01B0\u1EE3c k\xEDch ho\u1EA1t.":n==="graduated"?"M\xE3 h\u1ECDc vi\xEAn \u0111\xE3 chuy\u1EC3n sang tr\u1EA1ng th\xE1i t\u1ED1t nghi\u1EC7p.":n==="banned"?"M\xE3 h\u1ECDc vi\xEAn hi\u1EC7n \u0111\xE3 b\u1ECB kh\xF3a.":n==="not-found"?"Kh\xF4ng t\xECm th\u1EA5y M\xE3 h\u1ECDc vi\xEAn trong danh b\u1EA1.":"M\xE3 h\u1ECDc vi\xEAn hi\u1EC7n kh\xF4ng \u1EDF tr\u1EA1ng th\xE1i ho\u1EA1t \u0111\u1ED9ng."}function Tt(n){const e=n&&n.length?n[0].map(x):[];return{code:Z(e,["m\xE3 h\u1ECDc vi\xEAn","ma hoc vien"]),name:Z(e,["h\u1ECD v\xE0 t\xEAn","ho va ten","h\u1ECD t\xEAn","ho ten"]),group:Z(e,["t\u1ED5","to"]),course:Z(e,["kh\xF3a","kho\xE1","khoa"]),status:Z(e,["tr\u1EA1ng th\xE1i","trang thai","status"]),activatedAt:Z(e,["ng\xE0y k\xEDch ho\u1EA1t","ngay kich hoat"])}}function Nt(n){const e=Tt(n);if(e.code<0)throw new Error("Kh\xF4ng t\xECm th\u1EA5y c\u1ED9t M\xE3 h\u1ECDc vi\xEAn trong HocVien.");const t=[],o=new Map;return(n||[]).slice(1).forEach(function(r,c){const l=X(r[e.code]||"");if(!l)return;const h=e.status>=0?String(r[e.status]||"").trim():"",N=bt(h||"pending")||"pending",M={code:l,name:e.name>=0?String(r[e.name]||"").trim():"",group:e.group>=0?String(r[e.group]||"").trim():"",course:e.course>=0?String(r[e.course]||"").trim():"",status:N,rawStatus:h,activatedAt:e.activatedAt>=0?String(r[e.activatedAt]||"").trim():"",sourceRow:c+2};t.push(M),o.set(l,M)}),{students:t,studentMap:o,columns:e,loadedAt:Date.now()}}let ze=null,St=0;function lt(n){if(ze&&(!n||ze.force||C(ze.at)))return ze.p;if(n&&Ve&&C(St))return Promise.resolve(Ve);const e={force:!!n,at:Date.now()};e.p=wn(n),ze=e;const t=function(){ze===e&&(ze=null)};return e.p.then(function(){St=e.at,t()},t),e.p}async function wn(n){const e=Date.now();if(!n&&Ve&&e-st<S.studentRegistryCacheTtl)return Ve;const t=await Xe(S.studentRegistryCsv);return Ve=Nt(t),st=e,Ve}function dt(n,e,t){if(!!(t&&t.adminBypass))return{code:e,exists:!!n,status:n?n.status:"admin-bypass",canAccess:!0,canSubmit:!0,canDisplayPublicly:!0,adminBypass:!0,student:n||null,message:""};if(!n){const c=S.studentRegistryStrict!==!0;return{code:e,exists:!1,status:"not-found",canAccess:c,canSubmit:c,canDisplayPublicly:c,adminBypass:!1,student:null,message:c?"":ut("not-found")}}const r=n.status==="active";return{code:e,exists:!0,status:n.status,canAccess:r,canSubmit:r,canDisplayPublicly:r,adminBypass:!1,student:n,message:r?"":ut(n.status)}}async function xt(n,e){const t=X(n);if(!t)return dt(null,"",e);const o=await lt(!!(e&&e.forceRefresh));return dt(o.studentMap.get(t)||null,t,e)}async function bn(n,e){const t=await xt(n,e);if(!t.canAccess){const o=new Error(t.message);throw o.code="STUDENT_ACCESS_DENIED",o.studentAccess=t,o}return t}async function Tn(n,e){const t=Array.isArray(n)?n:[],o=await lt(!!(e&&e.forceRefresh)),r=e&&typeof e.getCode=="function"?e.getCode:function(c){return c&&(c.code||c.studentCode||c.maHocVien||c["M\xE3 h\u1ECDc vi\xEAn"]||"")};return t.filter(function(c){const l=X(r(c));return dt(o.studentMap.get(l)||null,l,e).canDisplayPublicly})}function Nn(){Ve=null,st=0}function kt(n,e){const t=e||S.spreadsheetId;return"https://docs.google.com/spreadsheets/d/"+encodeURIComponent(t)+"/gviz/tq?tqx=out:csv&gid="+encodeURIComponent(String(n))}function tt(n,e){const t=e||S.spreadsheetId;return"https://docs.google.com/spreadsheets/d/"+encodeURIComponent(t)+"/gviz/tq?tqx=out:csv&sheet="+encodeURIComponent(n)}function Ct(n){const e=String(n||"").trim();if(!e)return"";if(/^[a-zA-Z0-9_-]{20,}$/.test(e))return e;let t=e.match(/\/d\/([a-zA-Z0-9_-]+)/);return t||(t=e.match(/[?&]id=([a-zA-Z0-9_-]+)/),t)?t[1]:""}function nt(n,e){const t=String(n||"").trim();if(!t)return"";const o=Ct(t);if(!o)return t;const r=Math.max(96,Number(e||500));return"https://drive.google.com/thumbnail?id="+encodeURIComponent(o)+"&sz=w"+Math.round(r)}function ye(n){if(n instanceof Date)return Number.isNaN(n.getTime())?null:n;const e=String(n||"").trim();if(!e)return null;let t=e.match(/^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})(?:\s+(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?/);if(t){const r=new Date(Number(t[3]),Number(t[2])-1,Number(t[1]),Number(t[4]||0),Number(t[5]||0),Number(t[6]||0));return Number.isNaN(r.getTime())?null:r}if(t=e.match(/^(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})(?:[T\s]+(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?/),t){const r=new Date(Number(t[1]),Number(t[2])-1,Number(t[3]),Number(t[4]||0),Number(t[5]||0),Number(t[6]||0));return Number.isNaN(r.getTime())?null:r}const o=new Date(e);return Number.isNaN(o.getTime())?null:o}function vt(n){if(!n)return"";const e=n.getFullYear(),t=String(n.getMonth()+1).padStart(2,"0"),o=String(n.getDate()).padStart(2,"0");return e+"-"+t+"-"+o}function Fe(){return{hoangNgoc:0,haiLamNgoc:0,thachAnhTim:0,lamBaoThach:0,lucThach:0,hongNgoc:0}}function ce(n){const e=Fe();return z.forEach(function(t){e[t]=Math.max(0,Number(n&&n[t]||0))}),e}function ke(n){const e=x(n);if(!e)return null;for(let o=0;o<z.length;o++){const r=z[o];if(x(r)===e||x(te[r].displayName)===e)return r}return{hoang:"hoangNgoc","hoang ngoc":"hoangNgoc","hai lam":"haiLamNgoc","hai lam ngoc":"haiLamNgoc","thach anh":"thachAnhTim","thach anh tim":"thachAnhTim","lam bao":"lamBaoThach","lam bao thach":"lamBaoThach",luc:"lucThach","luc thach":"lucThach",hong:"hongNgoc","hong ngoc":"hongNgoc"}[e]||null}function Le(n){const e=ce(n);function t(r,c){const l=Math.floor(e[r]),h=Math.floor(l/c);h>0&&(e[r]-=h*c,e.lucThach+=h)}t("hoangNgoc",P.hoangNgocToLuc),t("haiLamNgoc",P.haiLamNgocToLuc),t("thachAnhTim",P.thachAnhTimToLuc),t("lamBaoThach",P.lamBaoThachToLuc);const o=Math.floor(e.lucThach/P.lucThachToHong);return o>0&&(e.lucThach-=o*P.lucThachToHong,e.hongNgoc+=o),z.forEach(function(r){e[r]=Math.max(0,Math.floor(Number(e[r]||0)))}),e}function ot(n,e,t){const o=ce(n),r=ke(e),c=Math.floor(Number(t||0));return!r||c<=0||(o[r]+=c),Le(o)}function It(n,e){const t=ke(n),o=Number(e||0);if(!t||o<=0)return 0;switch(t){case"hongNgoc":return o;case"lucThach":return o/3;case"lamBaoThach":return o/6;case"thachAnhTim":return o/9;case"haiLamNgoc":return o/12;case"hoangNgoc":return o/15;default:return 0}}function mt(n){const e=x(n);if(!e)return null;for(let o=0;o<Q.length;o++){const r=Q[o];if(x(r)===e||x(re[r].displayName)===e)return r}return{"pho thong":"phoThong","trung pham":"trungPham","trung thuong pham":"trungThuongPham","thuong pham":"thuongPham","cao cap":"caoCap","cuc pham":"cucPham","hoang ngoc":"phoThong","hai lam ngoc":"trungPham","thach anh tim":"trungThuongPham","lam bao thach":"thuongPham","luc thach":"caoCap","hong ngoc":"cucPham"}[e]||null}function Mt(n){const e=mt(n);return e&&re[e]||null}function Sn(n){const e=Mt(n);return e&&e.gemType&&te[e.gemType]||null}function At(n){const e=String(n||""),t=e.match(/\[\s*GEM\s*:\s*([^:\]]+)\s*:\s*(\d+)\s*\]/i);if(!t)return{isGemReward:!1,gemType:null,amount:0,marker:"",cleanDescription:e.trim()};const o=ke(t[1]),r=Math.max(0,Math.floor(Number(t[2]||0)));return{isGemReward:!!(o&&r>0),gemType:o,amount:r,marker:t[0],cleanDescription:e.replace(t[0],"").replace(/\s{2,}/g," ").trim()}}function Se(n){return!!(n&&n.isGemReward&&n.rewardGemType&&Number(n.rewardGemAmount||0)>0)}function Gt(n){if(!n||!n.length)return[];const e=n[0].map(x);let t=Z(e,["t\xEAn qu\xE0","ten qua"]),o=Z(e,["icon","h\xECnh \u1EA3nh","hinh anh"]),r=Z(e,["m\xF4 t\u1EA3","mo ta"]),c=Z(e,["\u0111i\u1EC3m c\u1EA7n thi\u1EBFt","diem can thiet","gi\xE1","gia"]),l=Z(e,["\u0111\u1ED9 hi\u1EBFm","do hiem","ph\u1EA9m c\u1EA5p","pham cap"]);return t<0&&(t=0),o<0&&(o=1),r<0&&(r=2),c<0&&(c=3),n.slice(1).map(function(h,N){const M=String(h[t]||"").trim(),H=String(h[o]||"").trim(),R=String(h[r]||"").trim(),g=Math.max(0,ue(h[c])),O=l>=0?String(h[l]||"").trim():"",L=mt(O),V=L?re[L]:null,k=At(R);return{index:N+1,name:M,normalizedName:x(M),image:H,rawDescription:R,description:k.cleanDescription,correctPrice:g,cost:g,rawRarity:O,rarity:L,rarityInfo:V,rarityGemType:V?V.gemType:null,gemType:S.marketCurrency,isGemReward:k.isGemReward,rewardGemType:k.gemType,rewardGemAmount:k.amount,gemReward:k.isGemReward?{gemType:k.gemType,amount:k.amount}:null,rewardMarker:k.marker}}).filter(function(h){return!!h.name})}function at(n){const e={};return(n||[]).forEach(function(t){e[x(t.name)]=t}),e}function xn(n,e){const t=Number(e||n&&n.correctPrice||0);if(!Se(n))return{isGemReward:!1,paidHong:t,rewardHongValue:0,difference:0,ratio:0,type:"item"};const o=It(n.rewardGemType,n.rewardGemAmount),r=o-t;let c="break-even";return r>1e-6?c="profit":r<-1e-6&&(c="loss"),{isGemReward:!0,paidHong:t,rewardHongValue:o,difference:r,ratio:t>0?o/t:0,type:c}}function Je(n){const e=x(n),t=x(S.mysteryBoxGiftName);return e===t||e.startsWith(t+" ")}function Qe(n){return String(n||"").trim().replace(/[^a-zA-Z0-9._:-]/g,"").slice(0,120)}function Et(n){const e=Qe(n);return e?"[DEAL:"+e+"]":""}function Pt(n){const e=String(n||""),t=e.match(/\[\s*DEAL\s*:\s*([a-zA-Z0-9._:-]+)\s*\]/i);if(!t)return{hasDeal:!1,dealId:"",marker:"",cleanValue:e.trim()};const o=Qe(t[1]);return{hasDeal:!!o,dealId:o,marker:t[0],cleanValue:e.replace(t[0],"").replace(/\s{2,}/g," ").trim()}}function kn(n){let e=2166136261;const t=String(n||"");for(let o=0;o<t.length;o++)e^=t.charCodeAt(o),e=Math.imul(e,16777619);return e>>>0}function Cn(n,e,t,o){const r=x(e).replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"npc",c=String(n||"")+"|"+r+"|"+String(t||0)+"|"+x(o),l=kn(c).toString(36);return Qe(String(n||"").replace(/[^0-9]/g,"")+"-"+r+"-"+String(t||0)+"-"+l)}function vn(n){const e=new Set;return(n||[]).forEach(function(t){t&&t.dealId&&t.accountingStatus==="valid"&&e.add(Qe(t.dealId))}),e}function In(n,e,t,o){let r="";const c=ke(t);o?r=o:t&&!c&&(r=t);let l=String(n||"").trim()+" - "+Ie(e)+" "+te[S.marketCurrency].displayName;const h=Et(r);return h&&(l+=" "+h),l}function Dt(n,e){const t=String(n||"").trim(),o=Pt(t),r=o.cleanValue,c=e||{};if(!r)return{giftName:"",gift:null,price:0,gemType:null,dealId:o.dealId,hasDeal:o.hasDeal,dealMarker:o.marker,format:"invalid"};const l=" - ",h=r.lastIndexOf(l);if(h>0){const M=r.slice(0,h).trim(),R=r.slice(h+l.length).trim().match(/^([0-9]+(?:[.,][0-9]+)?)\s+(.+)$/);if(R){const g=ue(R[1]),O=ke(R[2]),L=c[x(M)]||null;if(g>0&&O)return{giftName:L?L.name:M,gift:L,price:g,gemType:O,dealId:o.dealId,hasDeal:o.hasDeal,dealMarker:o.marker,format:"priced"}}}const N=c[x(r)]||null;return N?{giftName:N.name,gift:N,price:Number(N.correctPrice||0),gemType:S.marketCurrency,dealId:o.dealId,hasDeal:o.hasDeal,dealMarker:o.marker,format:"legacy"}:{giftName:r,gift:null,price:0,gemType:null,dealId:o.dealId,hasDeal:o.hasDeal,dealMarker:o.marker,format:"invalid"}}function Ot(n){if(!n||!n.length)return{};const e=n[0].map(x);function t(o,r){const c=Z(e,o);return c>=0?c:r}return{timestamp:t(["d\u1EA5u th\u1EDDi gian","dau thoi gian","timestamp"],0),name:t(["h\u1ECD t\xEAn","ho ten","h\u1ECD v\xE0 t\xEAn","ho va ten"],1),code:t(["m\xE3 h\u1ECDc vi\xEAn","ma hoc vien"],2),gift:t(["m\xF3n qu\xE0 mu\u1ED1n \u0111\u1ED5i","mon qua muon doi"],3),confirm:t(["x\xE1c nh\u1EADn","xac nhan"],4),isMystery:t(["l\xE0 h\u1ED9p b\xED \u1EA9n","la hop bi an"],5),mysteryCode:t(["m\xE3 quay","ma quay"],6),mysteryRoll:t(["s\u1ED1 quay","so quay"],7),mysteryReward:t(["qu\xE0 nh\u1EADn \u0111\u01B0\u1EE3c","qua nhan duoc"],8),mysteryStatus:t(["tr\u1EA1ng th\xE1i","trang thai"],9)}}function Ht(n,e){if(!n||n.length<2)return[];const t=at(e),o=Ot(n),r=x(S.formConfirmValue);return n.slice(1).map(function(c,l){const h=String(c[o.gift]||"").trim(),N=Dt(h,t),M=X(c[o.code]),H=String(c[o.confirm]||"").trim(),R=x(H)===r,g=x(c[o.isMystery]||""),O=String(c[o.mysteryReward]||"").trim(),L=Je(N.giftName)||g==="true"||g==="co"||g==="yes",V=O&&t[x(O)]||null;return{index:l+1,rowIndex:l+2,transactionType:"redemption",timestamp:String(c[o.timestamp]||"").trim(),studentName:String(c[o.name]||"").trim(),code:M,confirmation:H,confirmed:R,rawGiftValue:h,giftName:N.giftName,gift:N.gift,price:Number(N.price||0),gemType:N.gemType,format:N.format,dealId:N.dealId||"",hasDeal:!!N.hasDeal,dealMarker:N.dealMarker||"",isGemReward:Se(N.gift),isMysteryBox:L,mysteryRewardName:O,mysteryRewardGift:V,mysteryCode:String(c[o.mysteryCode]||"").trim(),mysteryRoll:String(c[o.mysteryRoll]||"").trim(),mysteryStatus:String(c[o.mysteryStatus]||"").trim()}}).filter(function(c){return c.confirmed&&!!c.code&&!!c.giftName})}function Rt(n){if(!n||!n.length)return{};const e=n[0].map(x);function t(o,r){const c=Z(e,o);return c>=0?c:r}return{timestamp:t(["d\u1EA5u th\u1EDDi gian","dau thoi gian"],0),scope:t(["ph\u1EA1m vi t\u1EB7ng","pham vi tang"],1),code:t(["m\xE3 h\u1ECDc vi\xEAn","ma hoc vien"],2),group:t(["t\u1ED5","to"],3),rewardType:t(["lo\u1EA1i ph\u1EA7n th\u01B0\u1EDFng","loai phan thuong"],4),giftName:t(["t\xEAn v\u1EADt ph\u1EA9m","ten vat pham"],5),gemType:t(["lo\u1EA1i linh th\u1EA1ch","loai linh thach"],6),quantity:t(["s\u1ED1 l\u01B0\u1EE3ng","so luong"],7),reason:t(["l\xFD do t\u1EB7ng","ly do tang"],8),giver:t(["ng\u01B0\u1EDDi t\u1EB7ng","nguoi tang"],9),status:t(["tr\u1EA1ng th\xE1i","trang thai"],10),course:t(["kh\xF3a","khoa"],11)}}function Lt(n){const e=x(n);return e?!["het hieu luc","da huy","huy","khong hieu luc","thu hoi","da thu hoi"].some(function(t){return e.includes(t)}):!0}function Bt(n,e,t,o){const r=x(n),c=Math.max(1,Math.floor(Number(t||1))),l=ke(e);return l&&(r.includes("linh thach")||!r)?{isGemReward:!0,gemType:l,amount:c,source:"teacher-direct-gem"}:o&&Se(o)?{isGemReward:!0,gemType:o.rewardGemType,amount:Math.max(1,Number(o.rewardGemAmount||0))*c,source:"teacher-gem-bag"}:{isGemReward:!1,gemType:null,amount:0,source:""}}function _t(n,e){if(!n||n.length<2)return[];const t=Rt(n),o=at(e);return n.slice(1).map(function(r,c){const l=X(r[t.code]||""),h=String(r[t.giftName]||"").trim(),N=o[x(h)]||null,M=Math.max(1,Math.floor(ue(r[t.quantity]||1))),H=String(r[t.rewardType]||"").trim(),R=String(r[t.gemType]||"").trim(),g=String(r[t.status]||"").trim(),O=Bt(H,R,M,N);return{index:c+1,rowIndex:c+2,transactionType:O.isGemReward?"teacher-gem":"teacher-item",timestamp:String(r[t.timestamp]||"").trim(),code:l,scope:String(r[t.scope]||"").trim(),group:String(r[t.group]||"").trim(),course:String(r[t.course]||"").trim(),rewardType:H,giftName:N?N.name:h,gift:N,quantity:M,teacherGemType:O.gemType,teacherGemAmount:O.amount,teacherGemSource:O.source,isTeacherGemReward:O.isGemReward,reason:String(r[t.reason]||"").trim(),giver:String(r[t.giver]||"").trim(),status:g,active:Lt(g),ownershipSource:O.isGemReward?"teacher-gem":"teacher-gift"}}).filter(function(r){return!!r.code&&r.active&&(r.isTeacherGemReward||!!r.giftName)})}function Vt(n){return(n||[]).filter(function(e){return e.isTeacherGemReward&&e.teacherGemType&&Number(e.teacherGemAmount||0)>0}).map(function(e){return{index:e.index,rowIndex:e.rowIndex,transactionType:"teacher-gem",timestamp:e.timestamp,code:e.code,studentName:"",giftName:e.giftName||"T\u1EB7ng "+te[e.teacherGemType].displayName,gift:e.gift||null,rewardGemType:e.teacherGemType,rewardGemAmount:Number(e.teacherGemAmount),price:0,gemType:null,dealId:"",accountingStatus:"pending",ownershipSource:"teacher-gem",reason:e.reason,giver:e.giver,teacherGiftRow:e}})}function zt(n){const e=[];return(n||[]).forEach(function(t){t.isTeacherGemReward||t.gift&&(Je(t.gift.name)||e.push({index:t.index,rowIndex:t.rowIndex,timestamp:t.timestamp,studentName:"",code:t.code,giftName:t.gift.name,gift:t.gift,image:t.gift.image||"",description:t.gift.description||"",rarity:t.gift.rarity||null,rarityInfo:t.gift.rarityInfo||null,rarityGemType:t.gift.rarityGemType||null,price:0,gemType:null,quantity:Math.max(1,Number(t.quantity||1)),format:"teacher-gift",ownershipSource:"teacher-gift",accountingStatus:"valid",reason:t.reason||"",giver:t.giver||"GVCN",status:t.status||"",group:t.group||"",course:t.course||""}))}),e}function Ft(n){const e=new Map;return zt(n).forEach(function(t){const o=X(t.code);o&&(e.has(o)||e.set(o,[]),e.get(o).push(t))}),e}function Ut(n){const e=new Map;return Vt(n).forEach(function(t){const o=X(t.code);o&&(e.has(o)||e.set(o,[]),e.get(o).push(t))}),e}const we={code:"M\xE3 h\u1ECDc vi\xEAn",cut:"M\u1ED1c ch\u1ED1t",version:"M\xE3 l\u1EA7n ch\u1ED1t",raw:"Linh th\u1EA1ch h\u1ECDc t\u1EADp l\xFAc ch\u1ED1t",items:"V\u1EADt ph\u1EA9m",deals:"Giao d\u1ECBch \u0111\xE3 d\xF9ng",reasons:"Th\u01B0\u1EDFng \u0111\xE3 nh\u1EADn",sold:"\u0110\xE3 b\xE1n Minh H\u1ED3ng",mystery:"H\u1ED9p b\xED \u1EA9n \u0111\xE3 m\u1EDF",tickets:"V\xE9 PLC",status:"Tr\u1EA1ng th\xE1i"};function We(n,e){const t=String(n??"").trim();if(!t)return e;try{return JSON.parse(t)}catch{return e}}function ft(n){const e=Number(String(n??"").replace(",","."));return Number.isFinite(e)?e:0}function jt(n){const e=new Map;if(!n||n.length<2)return e;const t=n[0].map(x),o=function(k){return t.indexOf(x(k))},r=o(we.code),c=o(we.cut),l=o(we.items);if(r<0||c<0||l<0)return e;const h=o(we.version),N=o(we.raw),M=o(we.deals),H=o(we.reasons),R=o(we.sold),g=o(we.mystery),O=o(we.tickets),L=o(we.status),V={};return z.forEach(function(k){V[k]=o(te[k].displayName)}),n.slice(1).forEach(function(k){const K=X(k[r]);if(!K)return;if(L>=0){const ve=x(k[L]);if(ve&&ve!=="dang hieu luc"&&ve!=="active")return}const me=String(k[c]||"").trim(),A=ye(me);if(!A)return;const B=A.getTime(),W=e.get(K);if(W&&W.cutMs>=B)return;const se=Fe();z.forEach(function(ve){V[ve]>=0&&(se[ve]=Math.max(0,Math.floor(ft(k[V[ve]]))))});const je=N>=0?We(k[N],[]):[],ln=Fe();z.forEach(function(ve,Vn){const zn=Array.isArray(je)?je[Vn]:je&&je[ve];ln[ve]=Math.max(0,Math.floor(Number(zn||0)))});const dn=We(k[l],[]);e.set(K,{code:K,cutText:me,cutMs:B,version:h>=0?String(k[h]||"").trim():"",gems:se,raw:ln,items:Array.isArray(dn)?dn:[],deals:M>=0?We(k[M],[])||[]:[],reasons:H>=0?We(k[H],[])||[]:[],sold:R>=0?We(k[R],{})||{}:{},mystery:g>=0?Math.max(0,Math.floor(ft(k[g]))):0,tickets:O>=0?Math.floor(ft(k[O])):0})}),e}function qt(n,e){if(!n)return!0;const t=ye(e);return t?t.getTime()>n.cutMs:!0}function Mn(n){return function(e){return!n||!n.size||!e?!0:qt(n.get(X(e.code)),e.timestamp)}}function An(n){const e=[];if(!n)return e;const t=n.cutText.split(" ")[0]||n.cutText;return z.forEach(function(o){const r=Number(n.gems[o]||0);r<=0||e.push({index:0,rowIndex:0,transactionType:"teacher-gem",timestamp:n.cutText,code:n.code,studentName:"",giftName:"S\u1ED1 d\u01B0 ch\u1ED1t s\u1ED5 "+t+" \u2013 "+te[o].displayName,gift:null,rewardGemType:o,rewardGemAmount:r,price:0,gemType:null,dealId:"",accountingStatus:"pending",ownershipSource:"snapshot",isSnapshot:!0,reason:"CHOT_SO:"+(n.version||t),giver:"Ch\u1ED1t s\u1ED5"})}),e}function Kt(n,e){const t=[];return n&&(n.items||[]).forEach(function(o,r){const c=String(Array.isArray(o)?o[0]:o&&o.name||"").trim();if(!c)return;const l=Math.max(1,Math.floor(Number(Array.isArray(o)?o[1]:o&&o.quantity)||1)),h=String(Array.isArray(o)?o[2]||"":o&&o.timestamp||"")||n.cutText,N=String(Array.isArray(o)?o[3]||"":o&&o.source||"")||"snapshot",M=e&&e[x(c)]||{name:c,image:"",description:""};t.push({index:0,rowIndex:0,timestamp:h,studentName:"",code:n.code,giftName:M.name||c,gift:M,image:M.image||"",description:M.description||"",rarity:M.rarity||null,rarityInfo:M.rarityInfo||null,rarityGemType:M.rarityGemType||null,price:0,gemType:null,quantity:l,format:"snapshot",ownershipSource:N,fromSnapshot:!0,accountingStatus:"valid",reason:"",giver:"Ch\u1ED1t s\u1ED5",status:"",group:"",course:""})}),t}function Xt(n,e){const t=Fe();return z.forEach(function(o){t[o]=Math.max(0,Number(n&&n[o]||0)-Number(e.raw[o]||0))}),Le(t)}function rt(n){return(n||[]).slice().sort(function(e,t){const o=ye(e.timestamp),r=ye(t.timestamp),c=o?o.getTime():0,l=r?r.getTime():0;return c!==l?c-l:Number(e.rowIndex||e.index||0)-Number(t.rowIndex||t.index||0)})}function Qt(n,e,t){const o=ke(e),r=Number(t||0);return!o||r<=0?!1:Number(n&&n[o]||0)>=r}function Ye(n,e,t){const o=Le(n||Fe());let r=ce(o);const c=[],l=[],h=[],N=[],M=new Set(t||[]);rt(e).forEach(function(g){if(g.transactionType==="teacher-gem"){const A=ke(g.rewardGemType),B=Math.max(0,Math.floor(Number(g.rewardGemAmount||0)));if(!A||B<=0){l.push(Object.assign({},g,{accountingStatus:"rejected-invalid-teacher-gem",rejectionReason:"invalid-teacher-gem"}));return}const W=ce(r);r=ot(r,A,B);const se={index:g.index,rowIndex:g.rowIndex,timestamp:g.timestamp,code:g.code,source:"teacher-gift",sourceGiftName:g.giftName,giftName:g.giftName,gemType:A,amount:B,giver:g.giver||"GVCN"};N.push(se),c.push(Object.assign({},g,{accountingStatus:"valid",balanceBefore:W,balanceAfter:ce(r),grantedGemReward:se}));return}const O=Number(g.price||0),L=ke(g.gemType),V=Qe(g.dealId||""),k=ce(r);if(!g.gift||!L||O<=0){l.push(Object.assign({},g,{dealId:V,accountingStatus:"rejected-invalid",rejectionReason:"invalid-transaction",balanceBefore:k,balanceAfter:ce(r)}));return}if(V&&M.has(V)){l.push(Object.assign({},g,{dealId:V,accountingStatus:"rejected-duplicate-deal",rejectionReason:"duplicate-deal",balanceBefore:k,balanceAfter:ce(r)}));return}if(!Qt(r,L,O)){l.push(Object.assign({},g,{dealId:V,accountingStatus:"rejected-insufficient-balance",rejectionReason:"insufficient-balance",balanceBefore:k,balanceAfter:ce(r)}));return}r[L]-=O;let K=null;if(g.isMysteryBox){const A=g.mysteryRewardGift;A&&Se(A)&&(K={index:g.index,timestamp:g.timestamp,code:g.code,dealId:V,source:"mystery-box",sourceGiftName:g.giftName,giftName:A.name,gemType:A.rewardGemType,amount:Number(A.rewardGemAmount||0)},r=ot(r,K.gemType,K.amount),N.push(K))}else Se(g.gift)&&(K={index:g.index,timestamp:g.timestamp,code:g.code,dealId:V,source:"redemption",sourceGiftName:g.giftName,giftName:g.giftName,gemType:g.gift.rewardGemType,amount:Number(g.gift.rewardGemAmount||0)},r=ot(r,K.gemType,K.amount),N.push(K));r=Le(r),V&&M.add(V);const me=Object.assign({},g,{dealId:V,accountingStatus:"valid",balanceBefore:k,balanceAfter:ce(r),grantedGemReward:K});if(c.push(me),g.isMysteryBox){const A=g.mysteryRewardGift;A&&!Je(A.name)&&!Se(A)&&h.push({index:g.index,timestamp:g.timestamp,studentName:g.studentName,code:g.code,dealId:V,giftName:A.name,gift:A,image:A.image||"",description:A.description||"",rarity:A.rarity||null,rarityInfo:A.rarityInfo||null,rarityGemType:A.rarityGemType||null,quantity:1,price:0,gemType:null,format:"mystery-reward",ownershipSource:"mystery-box",accountingStatus:"valid",sourceGiftName:g.giftName})}else Se(g.gift)||h.push(Object.assign({},me,{image:g.gift.image||"",description:g.gift.description||"",rarity:g.gift.rarity||null,rarityInfo:g.gift.rarityInfo||null,rarityGemType:g.gift.rarityGemType||null,quantity:1,ownershipSource:"redemption"}))});const R=Le(r);return{startingGems:ce(o),gems:ce(R),balance:ce(R),validTransactions:c,transactions:c,rejectedTransactions:l,ownedItems:h,redeemedItems:h,gemRewards:N,consumedDealIds:M}}function Gn(n,e){return Ye(n,e).gems}function En(n,e){return Ye(n,e)}function Pn(n,e){return Ye(n,e)}function Zt(n){const e=[];return(n||[]).forEach(function(t){if(!(t&&t.transactionType==="teacher-gem")&&!(!t||!t.gift)){if(t.isMysteryBox){const o=t.mysteryRewardGift;o&&!Se(o)&&!Je(o.name)&&e.push({index:t.index,timestamp:t.timestamp,studentName:t.studentName,code:t.code,dealId:t.dealId||"",giftName:o.name,gift:o,image:o.image||"",description:o.description||"",rarity:o.rarity||null,rarityInfo:o.rarityInfo||null,rarityGemType:o.rarityGemType||null,quantity:1,price:0,gemType:null,ownershipSource:"mystery-box"});return}Se(t.gift)||e.push(Object.assign({},t,{image:t.gift.image||"",description:t.gift.description||"",rarity:t.gift.rarity||null,rarityInfo:t.gift.rarityInfo||null,rarityGemType:t.gift.rarityGemType||null,quantity:Number(t.quantity||1),ownershipSource:t.ownershipSource||"redemption"}))}}),e}function ht(n,e){return[...n||[],...e||[]].sort(function(t,o){const r=ye(t.timestamp),c=ye(o.timestamp),l=r?r.getTime():0,h=c?c.getTime():0;return h!==l?h-l:Number(o.rowIndex||o.index||0)-Number(t.rowIndex||t.index||0)})}function Jt(n,e){const t=X(e);return n&&n.ownedItemMap&&n.ownedItemMap.get(t)||[]}function Dn(n,e){const t=x(e);return(n||[]).some(function(o){return x(o.giftName)===t})}function On(n,e){const t=x(e);return(n||[]).reduce(function(o,r){return x(r.giftName)!==t?o:o+Math.max(1,Number(r.quantity||1))},0)}const Wt=[{days:5,icon:U.seed,name:"M\u1EA7m c\xE2y ch\u0103m ch\u1EC9",hoangNgocValue:1},{days:7,icon:U.medal,name:"Phi\u1EBFu b\xE9 ngoan",hoangNgocValue:2},{days:14,icon:U.tree,name:"C\xE2y nh\u1ECF b\u1EC1n b\u1EC9",hoangNgocValue:4},{days:30,icon:U.fire,name:"Ng\u1ECDn l\u1EEDa kh\xF4ng t\u1EAFt",hoangNgocValue:8}],Yt=[{blockSize:3,requiredBlocks:1,icon:U.star,name:"Ng\xF4i sao \u1ED5n \u0111\u1ECBnh",hoangNgocValue:2},{blockSize:4,requiredBlocks:1,icon:U.target,name:"M\u0169i t\xEAn t\u1EADp trung",hoangNgocValue:3},{blockSize:5,requiredBlocks:1,icon:U.rocket,name:"T\xEAn l\u1EEDa ti\u1EBFn b\u1ED9",hoangNgocValue:4},{blockSize:3,requiredBlocks:2,icon:U.sparkles,name:"Song tinh b\u1EC1n b\u1EC9",hoangNgocValue:4},{blockSize:4,requiredBlocks:2,icon:U.eagle,name:"\u0110\xF4i c\xE1nh v\u1EEFng v\xE0ng",hoangNgocValue:6},{blockSize:5,requiredBlocks:2,icon:U.crown,name:"V\u01B0\u01A1ng mi\u1EC7n \u1ED5n \u0111\u1ECBnh",hoangNgocValue:8}];function $t(n){const e=new Set;(n||[]).forEach(function(c){const l=ye(c.timestamp);l&&e.add(vt(l))});const t=Array.from(e).map(function(c){const l=c.split("-");return new Date(Number(l[0]),Number(l[1])-1,Number(l[2]))}).sort(function(c,l){return c.getTime()-l.getTime()});if(!t.length)return 0;let o=1,r=1;for(let c=1;c<t.length;c++)Math.round((t[c].getTime()-t[c-1].getTime())/Ze)===1?(r++,o=Math.max(o,r)):r=1;return o}function en(n){const e=(n||[]).slice().sort(function(r,c){const l=ye(r.timestamp),h=ye(c.timestamp),N=l?l.getTime():0,M=h?h.getTime():0;return N!==M?N-M:Number(r.originalIndex||0)-Number(c.originalIndex||0)}),t=[];let o=0;return e.forEach(function(r){const c=ge(r.score);if(c!==null){if(c>=6){o++;return}o>0&&(t.push(o),o=0)}}),o>0&&t.push(o),t}function tn(n){const e={score5:0,score6:0,score7:0,score89:0,score10:0};(n||[]).forEach(function(o){const r=ge(o.score);r!==null&&(r===10?e.score10++:r>=8&&r<10?e.score89++:r>=7&&r<8?e.score7++:r>=6&&r<7?e.score6++:r>=5&&r<6&&e.score5++)});const t=Fe();return t.hoangNgoc+=Math.floor(e.score5/2),t.haiLamNgoc+=Math.floor(e.score6/2),t.thachAnhTim+=Math.floor(e.score7/2),t.lamBaoThach+=Math.floor(e.score89/2),t.lucThach+=e.score10,{counts:e,gems:t}}function nn(n){const e=$t(n),t=Wt.filter(function(g){return e>=g.days}),o=t.length?t[t.length-1]:null,r=en(n),c=r.length?Math.max.apply(null,r):0,l={};[3,4,5].forEach(function(g){l[g]=r.reduce(function(O,L){return O+Math.floor(L/g)},0)});const h=Yt.filter(function(g){return Number(l[g.blockSize]||0)>=g.requiredBlocks});let N=null;h.forEach(function(g){(!N||g.hoangNgocValue>=N.hoangNgocValue)&&(N=g)});const M=tn(n),H=ce(M.gems);o&&(H.hoangNgoc+=Number(o.hoangNgocValue||0)),h.forEach(function(g){H.hoangNgoc+=Number(g.hoangNgocValue||0)});const R=Le(H);return{longestStreak:e,streakGift:o,streakUnlocked:t,highScoreRuns:r,bestHighRun:c,highScoreBlocks:l,highScoreGift:N,unlockedHighScoreGifts:h,scoreCounts:M.counts,rawGems:H,gems:R}}function Hn(n){return n=n||{},n.highScoreGift?{icon:n.highScoreGift.icon||U.star,name:n.highScoreGift.name||"H\u1ECDc vi\xEAn"}:n.streakGift?{icon:n.streakGift.icon||U.seed,name:n.streakGift.name||"H\u1ECDc vi\xEAn"}:{icon:U.seed,name:"H\u1ECDc vi\xEAn m\u1EDBi"}}function gt(n){return(n||[]).slice().sort(function(e,t){const o=ye(e.timestamp),r=ye(t.timestamp),c=o?o.getTime():0,l=r?r.getTime():0;return l!==c?l-c:Number(t.rowIndex||t.index||0)-Number(e.rowIndex||e.index||0)})}function it(n,e){const t=x(e);return gt(n).find(function(o){return x(o.giftName).startsWith(t)})||null}function pt(n,e,t,o){try{const r=n||[],c=X(o||r[0]&&(r[0].code||r[0].studentCode)||""),l=window.OCDAuth;if(!c||!l||typeof l.lookCached!="function")return null;const h=l.lookCached(c),N=h&&h[t];if(!N)return null;const M=x(N);return M.startsWith(x(e))&&gt(r).find(function(H){return x(H.giftName)===M})||null}catch{return null}}function tgPh(c){try{c=X(c||"");if(!c)return"";const A0=window.OCDAuth,U=function(i){return"https://lh3.googleusercontent.com/d/"+i+"=w500"};if(A0&&typeof A0.publicInfo=="function"&&!tgPh.p){tgPh.p=Promise.resolve(A0.publicInfo()).then(function(pi){if(!pi||pi.failed)return;const lk=pi.look||{},nm={};for(const k in lk){const a=String(lk[k]&&lk[k].avatar||"");a.indexOf("anh:")===0&&(nm[X(k)]=a.slice(4))}try{localStorage.setItem("ocdTgPhoto",JSON.stringify(nm))}catch{}}).catch(function(){})}const L=A0&&typeof A0.lookCached=="function"?A0.lookCached(c):null;if(L){const a=String(L.avatar||"");return a.indexOf("anh:")===0?U(a.slice(4)):""}let m={};try{m=JSON.parse(localStorage.getItem("ocdTgPhoto")||"{}")||{}}catch{}return m[c]?U(m[c]):""}catch{return""}}function on(n,e){const ph0=tgPh(e||n&&n[0]&&(n[0].code||n[0].studentCode)||"");if(ph0)return ph0;const t=pt(n,S.avatarGiftPrefix,"avatar",e)||it(n,S.avatarGiftPrefix);return t&&t.image?nt(t.image,500):""}function an(n,e){const t=pt(n,S.avatarFramePrefix,"frame",e)||it(n,S.avatarFramePrefix);return t&&t.image?nt(t.image,700):""}function rn(n,e){const t=pt(n,S.profileBackgroundPrefix,"bg",e)||it(n,S.profileBackgroundPrefix);return t&&t.image?nt(t.image,1600):""}function cn(n){const e=x(S.multitaskPotionGiftName);return(n||[]).some(function(t){return x(t.giftName)===e})}function sn(n,e){n&&(n.classList.remove("reward-multitask-wrap","reward-multitask-size-small","reward-multitask-size-medium","reward-multitask-size-large"),n.querySelectorAll(".reward-multitask-star").forEach(function(t){t.remove()})),e&&e.classList.remove("reward-multitask-name")}function Rn(n,e,t){if(!n||!e)return;sn(n,e);const o=t&&t.size?t.size:"medium";n.classList.add("reward-multitask-wrap"),n.classList.add("reward-multitask-size-"+o),e.classList.add("reward-multitask-name");const r=String.fromCodePoint(10022),c=String.fromCodePoint(10023);[["reward-multitask-star-left",r],["reward-multitask-star-right",c],["reward-multitask-star-bottom-left",c],["reward-multitask-star-bottom-right",r]].forEach(function(l){const h=document.createElement("span");h.className="reward-multitask-star "+l[0],h.textContent=l[1],h.setAttribute("aria-hidden","true"),n.appendChild(h)})}let Ce=null,yt=0,Ue=null,un=0;function wt(n){if(Ue&&(!n||Ue.force||C(Ue.at)))return Ue.p;if(n&&Ce&&C(un))return Promise.resolve(Ce);const e={force:!!n,at:Date.now()};e.p=Ln(n),Ue=e;const t=function(){Ue===e&&(Ue=null)};return e.p.then(function(){un=e.at,t()},t),e.p}async function Ln(n,cd){const e=Date.now();if(!cd&&!n&&Ce&&e-yt<S.cacheTtl)return Ce;const t=await Promise.all([Xe(kt(S.giftGid)),Xe(tt(S.formSheetName),cd),Xe(tt(S.teacherGiftSheetName),cd),S.snapshotSheetName?Xe(tt(S.snapshotSheetName),cd).catch(function(B){return console.warn("[Reward Core] Ch\u01B0a \u0111\u1ECDc \u0111\u01B0\u1EE3c "+S.snapshotSheetName+", t\xEDnh nh\u01B0 ch\u01B0a ch\u1ED1t s\u1ED5.",B),[]}):Promise.resolve([])]),o=t[0],r=t[1],c=t[2],l=jt(t[3]),h=Mn(l),N=Gt(o),M=at(N),H=Ht(r,N).filter(h),R=new Map;H.forEach(function(B){R.has(B.code)||R.set(B.code,[]),R.get(B.code).push(B)});const g=_t(c,N).filter(h),O=Ft(g),L=Ut(g);l.forEach(function(B,W){const se=An(B);se.length&&L.set(W,rt(se.concat(L.get(W)||[])));const je=Kt(B,M);je.length&&O.set(W,ht(je,O.get(W)||[]))});const V=new Map,k=new Set;R.forEach(function(B,W){k.add(W)}),L.forEach(function(B,W){k.add(W)}),k.forEach(function(B){V.set(B,rt([...R.get(B)||[],...L.get(B)||[]]))});const K=new Map,me=new Set;V.forEach(function(B,W){me.add(W)}),O.forEach(function(B,W){me.add(W)}),me.forEach(function(B){const W=Zt(V.get(B)||[]),se=O.get(B)||[];K.set(B,ht(W,se))});const A=new Map;return V.forEach(function(B,W){A.set(W,B.filter(function(se){return se.transactionType==="teacher-gem"||se.isGemReward||se.isMysteryBox&&Se(se.mysteryRewardGift)}))}),(function(o){return cd?o:(Ce=o,yt=e,Ce)})({gifts:N,giftMap:M,responses:H,marketRedemptionMap:R,redemptionMap:V,teacherGifts:g,teacherOwnedItemMap:O,teacherGemTransactionMap:L,snapshots:l,ownedItemMap:K,gemRewardMap:A,rawGiftRows:o,rawResponseRows:r,rawTeacherGiftRows:c})};const SFk={PhieuDoi:1,QuaTangGVCN:1,SoDuChot:1},SFc=new Map;let SFm=!1;function SFon(){try{return S.studentFilter!==!1&&typeof location!="undefined"&&/(^|\.)thudao\.com$/i.test(String(location.hostname||""))&&!/core-v31/i.test(String(location.pathname||""))}catch(x){return!1}}function wtc(n,cd){const k=X(cd);if(!k||!SFon())return wt(n);if(SFm||Ue||Ce&&Date.now()-yt<S.cacheTtl)return wt(n);if(SFc.size>=2&&!SFc.has(k))return SFm=!0,wt(n);const c=SFc.get(k);if(c&&(n?C(c.at):Date.now()-c.at<S.cacheTtl))return c.p;const o={at:Date.now()};o.p=Ln(!!n,k).catch(function(x){console.warn("[Reward Core] T\u1ea3i ri\u00eang "+k+" ch\u01b0a \u0111\u01b0\u1ee3c, t\u1ea3i \u0111\u1ea7y \u0111\u1ee7:",(x&&x.message)||x);return wt(n)});SFc.set(k,o),SFc.size>20&&SFc.delete(SFc.keys().next().value);o.p.catch(function(){SFc.get(k)===o&&SFc.delete(k)});return o.p}async function Bn(n,e){const t=X(n),o=await wtc(!1,t);let r=[];if(e){const g=fe(e);if(g.length){const O=g[0].map(x),L=Z(O,["m\xE3 h\u1ECDc vi\xEAn","ma hoc vien"]),V=Z(O,["d\u1EA5u th\u1EDDi gian","dau thoi gian","timestamp"]),k=Z(O,["\u0111i\u1EC3m","diem","\u0111i\u1EC3m s\u1ED1","diem so"]);L>=0&&(r=g.slice(1).map(function(K,me){return{code:X(K[L]),timestamp:V>=0&&K[V]||"",score:k>=0&&K[k]||"",originalIndex:me+1}}).filter(function(K){return K.code===t}))}}const c=nn(r),l=ce(c.gems),h=o.redemptionMap.get(t)||[],N=o.snapshots&&o.snapshots.get(t)||null,M=N?Xt(c.rawGems,N):l,H=Ye(M,h,N?N.deals:null),R=Jt(o,t);return{code:t,rewardData:c,earnedGems:l,ledgerStartGems:M,snapshot:N,gems:H.gems,balance:H.balance,rawTransactions:h,transactions:H.validTransactions,validTransactions:H.validTransactions,rejectedTransactions:H.rejectedTransactions,ownedItems:R,redeemedItems:R,redemptionOwnedItems:H.ownedItems,teacherOwnedItems:o.teacherOwnedItemMap.get(t)||[],teacherGemTransactions:o.teacherGemTransactionMap.get(t)||[],gemRewards:H.gemRewards,consumedDealIds:H.consumedDealIds,avatar:on(R,t),avatarFrame:an(R,t),profileBackground:rn(R,t),hasMultitaskPotion:cn(R),accounting:H}}function _n(){return console.log("[Reward Core] Version:",$),console.log("[Reward Core] CONFIG:",S),Ce&&console.log("[Reward Core] Shared:",Ce),{version:$,config:S,cache:Ce}}window.StudentRewardSystem={version:$,CONFIG:S,ONE_DAY:Ze,ICONS:U,GEM_TYPES:te,GEM_ORDER:z,GEM_CONVERSION:P,RARITY_TYPES:re,RARITY_ORDER:Q,STREAK_RULES:Wt,HIGH_SCORE_RULES:Yt,normalizeText:x,normalizeCode:X,parseNumber:ue,parseScore:ge,formatNumber:Ie,findColumn:Z,parseCSV:fe,fetchCSV:Y,getDataSource:function(){return Te},getStudentSubmissionsCsv:yn,apiAppend:pn,markDataFresh:d,getLastWriteAt:y,isRecentLoad:C,setLateRefreshHook:a,getStudentSheetCsv:$e,fetchRows:Xe,sheetCsvUrl:kt,sheetNameCsvUrl:tt,normalizeStudentStatus:bt,getStudentAccessMessage:ut,detectStudentRegistryColumns:Tt,mapStudentRegistryRows:Nt,loadStudentRegistry:lt,getStudentAccess:xt,assertStudentActive:bn,filterActiveStudents:Tn,clearStudentRegistryCache:Nn,extractDriveFileId:Ct,convertDriveImageUrl:nt,parseVietnameseDate:ye,getCalendarDayKey:vt,createEmptyGems:Fe,cloneGems:ce,normalizeGemType:ke,normalizeGemBalance:Le,addGemReward:ot,getGemValueInHong:It,parseGemRewardMarker:At,isGemRewardGift:Se,analyzeGemOfferEconomy:xn,normalizeRarity:mt,getRarityInfo:Mt,getRarityGem:Sn,mapGiftRows:Gt,createGiftMap:at,isMysteryBoxGiftName:Je,sanitizeDealId:Qe,createDealMarker:Et,parseDealMarker:Pt,createDealId:Cn,getConsumedDealIds:vn,createFormGiftValue:In,parseFormGiftValue:Dt,detectFormColumns:Ot,mapFormResponseRows:Ht,detectTeacherGiftColumns:Rt,isTeacherGiftActive:Lt,resolveTeacherGemReward:Bt,mapTeacherGiftRows:_t,buildTeacherGemTransactions:Vt,buildTeacherOwnedItems:zt,buildTeacherOwnedItemMap:Ft,buildTeacherGemTransactionMap:Ut,sortTransactionsChronologically:rt,canAffordTransaction:Qt,processTransactions:Ye,mapSnapshotRows:jt,isAfterSnapshot:qt,buildSnapshotItems:Kt,snapshotStartGems:Xt,SNAPSHOT_HEADERS:we,applyTransactions:En,calculateGemBalance:Pn,applyRedeemedItems:Gn,buildOwnedItems:Zt,mergeOwnedItems:ht,getOwnedItemsFromShared:Jt,hasOwnedItem:Dn,getOwnedItemQuantity:On,calculateLongestStreak:$t,calculateHighScoreRuns:en,calculateScoreGems:tn,calculateStudentRewardData:nn,getProfileTitle:Hn,sortOwnedItemsNewest:gt,getLatestOwnedItemByPrefix:it,getProfileAvatar:on,getTroGiangPhoto:tgPh,getProfileAvatarFrame:an,getProfileBackground:rn,hasMultitaskPotion:cn,clearMultitaskEffect:sn,applyMultitaskEffect:Rn,loadSharedRewardData:wt,loadStudentRewardData:wtc,getStudentRewardProfile:Bn,debug:_n},console.log("[Reward Core] StudentRewardSystem v3.6.0 \u0111\xE3 s\u1EB5n s\xE0ng.");try{window.dispatchEvent(new CustomEvent("studentRewardCoreReady",{detail:{version:$}}))}catch{}})(),(function(){"use strict";const $="4.11.0",S={minRate:.1,maxRate:.5,maxAmount:20,gemOrder:["hoangNgoc","haiLamNgoc","thachAnhTim","lamBaoThach","lucThach","hongNgoc"],fixedPriceItems:["V\xE9 v\xE0o ph\xF2ng luy\u1EC7n c\xF4ng"],policySheetName:"MinhHongThuMua",transactionSheetName:"MinhHongGiaoDich",confirmValue:"T\xF4i x\xE1c nh\u1EADn b\xE1n v\u1EADt ph\u1EA9m n\xE0y.",formResponseUrl:"https://docs.google.com/forms/d/e/1FAIpQLSdKYU3t5LgVKKY326Arq4TkqeUOe53HR6l8ZzM0-Z50YwvgsQ/formResponse",formEntries:{sellId:"entry.563661764",code:"entry.540081212",giftName:"entry.256766747",quantity:"entry.697793477",price:"entry.1111443255",gemType:"entry.1616135319",confirm:"entry.256416718"},cacheTtl:15e3,pollDelay:2200,pollAttempts:18};let Ze=null,U=null,te=0;const z=new Set,re=new Map;function Q(i){return String(i??"").trim()}function P(i){return new Promise(d=>setTimeout(d,i))}function x(i,d){return Math.max(0,Math.floor(d.parseNumber(i)))}function X(i,d){return Math.max(0,Number(d.parseNumber(i)||0))}function ue(i,d){try{window.dispatchEvent(new CustomEvent(i,{detail:d||{}}))}catch{}}function ge(i,d){if(!i||!i.length)return{};const y=i[0].map(d.normalizeText),p=(C,G)=>{const D=d.findColumn(y,C);return D>=0?D:G};return{giftName:p(["t\xEAn v\u1EADt ph\u1EA9m","ten vat pham"],0),price:p(["gi\xE1 thu mua","gia thu mua"],1),gemType:p(["lo\u1EA1i linh th\u1EA1ch","loai linh thach"],2),status:p(["tr\u1EA1ng th\xE1i","trang thai","status"],3),dailyLimit:p(["gi\u1EDBi h\u1EA1n/ng\xE0y","gioi han/ngay","gi\u1EDBi h\u1EA1n ng\xE0y","gioi han ngay"],4)}}function Ie(i,d){if(!i||!i.length)return{};const y=i[0].map(d.normalizeText),p=(C,G)=>{const D=d.findColumn(y,C);return D>=0?D:G};return{timestamp:p(["d\u1EA5u th\u1EDDi gian","dau thoi gian","timestamp"],0),sellId:p(["sell_id","sell id","m\xE3 giao d\u1ECBch","ma giao dich"],1),code:p(["m\xE3 h\u1ECDc vi\xEAn","ma hoc vien"],2),giftName:p(["t\xEAn v\u1EADt ph\u1EA9m","ten vat pham"],3),quantity:p(["s\u1ED1 l\u01B0\u1EE3ng","so luong"],4),price:p(["gi\xE1 thu mua","gia thu mua"],5),gemType:p(["lo\u1EA1i linh th\u1EA1ch","loai linh thach"],6),confirm:p(["x\xE1c nh\u1EADn","xac nhan"],7),status:d.findColumn(y,["tr\u1EA1ng th\xE1i","trang thai","status"])}}function Z(i,d){return d.normalizeText(i)==="active"}function fe(i,d,y){if(Q(i[d.confirm])!==S.confirmValue)return!1;if(d.status>=0){const C=y.normalizeText(i[d.status]);if(["huy","da huy","h\u1EE7y","\u0111\xE3 h\u1EE7y","thu hoi","da thu hoi","het hieu luc","khong hieu luc"].includes(C)||C&&C!=="deal"&&C!=="active"&&C!=="hoan tat"&&C!=="completed")return!1}return!0}function Y(i,d,g){const y=[];if(!i||i.length<2)return y;const p=ge(i,d),R=d.mapGiftRows&&d.GEM_CONVERSION?d:window.StudentRewardSystem||d,K=new Map;try{(R.mapGiftRows(g||[])||[]).forEach(function(t){t&&t.name&&K.set(d.normalizeText(t.name),t)})}catch(t){}const V=R.GEM_CONVERSION||{},h=Number(V.hoangNgocToLuc)||5,H={hoangNgoc:1,lucThach:h,hongNgoc:h*(Number(V.lucThachToHong)||3),haiLamNgoc:h/(Number(V.haiLamNgocToLuc)||4),thachAnhTim:h/(Number(V.thachAnhTimToLuc)||3),lamBaoThach:h/(Number(V.lamBaoThachToLuc)||2)},W=new Intl.DateTimeFormat("en-CA",{timeZone:R.CONFIG&&R.CONFIG.timeZone||"Asia/Ho_Chi_Minh",year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date),F=S.fixedPriceItems.map(function(t){return d.normalizeText(t)}),O=d.normalizeGemType("Ho\xE0ng Ng\u1ECDc")||"hoangNgoc";for(let C=1;C<i.length;C++){const G=i[C],D=Q(G[p.giftName]),N=d.normalizeText(D);let _=d.normalizeGemType(G[p.gemType]),m=X(G[p.price],d),B=0,P=0;if(D&&F.indexOf(N)<0){const t=K.get(N);m=0;if(t&&!t.isGemReward&&Number(t.cost)>0&&H[t.gemType]){B=Number(t.cost)*H[t.gemType];const c=Math.floor(B*S.maxRate),l=Math.max(1,Math.floor(B*S.minRate));if(c>=1&&c<B){let r=2166136261;const k=W+"|"+N;for(let n=0;n<k.length;n++)r^=k.charCodeAt(n),r=Math.imul(r,16777619);r^=r>>>15,r=Math.imul(r,739982445),r^=r>>>12,m=l>=c?c:l+(r>>>0)%(c-l+1),P=m;let q=2166136261;const z="gem|"+k;for(let n=0;n<z.length;n++)q^=z.charCodeAt(n),q=Math.imul(q,16777619);q^=q>>>15,q=Math.imul(q,739982445),q^=q>>>12;const e=S.gemOrder.filter(function(a){return H[a]&&Math.floor(P/H[a])>=1}),s=e.filter(function(a){return Math.floor(P/H[a])<=S.maxAmount}),o=s.length?s[(q>>>0)%s.length]:e[e.length-1]||"hoangNgoc";_=o==="hoangNgoc"?O:o,m=Math.floor(P/(H[o]||1))}}}!D||!_||m<=0||!Z(G[p.status],d)||y.push({giftName:D,normalizedGiftName:N,price:m,gemType:_,dailyLimit:x(G[p.dailyLimit],d),dailyPrice:B>0,realValueHoang:B,payValueHoang:P,priceDate:W})}return y}function Me(i,d){const y=[];if(!i||i.length<2)return y;const p=Ie(i,d),C=new Set;for(let G=1;G<i.length;G++){const D=i[G];if(!fe(D,p,d))continue;const _=Q(D[p.sellId]),m=d.normalizeCode(D[p.code]),w=Q(D[p.giftName]),a=x(D[p.quantity],d),s=X(D[p.price],d),u=d.normalizeGemType(D[p.gemType]);!_||C.has(_)||!m||!w||a<=0||s<=0||!u||(C.add(_),y.push({transactionType:"minh-hong-sell",transactionId:"MH-"+_,sellId:_,timestamp:Q(D[p.timestamp]),code:m,giftName:w,normalizedGiftName:d.normalizeText(w),quantity:a,unitPrice:s,rewardGemType:u,rewardGemAmount:a*s,rowIndex:G}))}return y.sort((G,D)=>{const _=d.parseVietnameseDate(G.timestamp),m=d.parseVietnameseDate(D.timestamp),w=_?_.getTime():0,a=m?m.getTime():0;return w-a||G.rowIndex-D.rowIndex}),y}let ne=null,be=0;function Ee(i,d){return typeof i.isRecentLoad=="function"&&i.isRecentLoad(d)}function xe(i,d){if(ne&&(!i||ne.force||Ee(d,ne.at)))return ne.p;if(i&&U&&(Date.now()-mhLF<15e3||Ee(d,be)))return Promise.resolve(U);const y={force:!!i,at:Date.now()};y.p=Pe(i,d),ne=y;const p=function(){ne===y&&(ne=null)};return y.p.then(function(){be=y.at,p()},p),y.p}let mhMem=null,mhLF=0,mhGC={rows:null,at:0};function mhPL(){if(!mhMem){mhMem=[];try{const a=JSON.parse(window.localStorage.getItem("ocdMhPendingSales_v1")||"[]");Array.isArray(a)&&(mhMem=a)}catch(a){}}const n=Date.now();return mhMem=mhMem.filter(function(t){return t&&t.sellId&&n-Number(t.ts||0)<9e5}),mhMem}function mhPS(a){mhMem=a;try{window.localStorage.setItem("ocdMhPendingSales_v1",JSON.stringify(a))}catch(n){}}function mhMK(t,d,n){const q=Math.max(0,Number(t.quantity)||0),r=Math.max(0,Number(t.unitPrice)||0);return{transactionType:"minh-hong-sell",transactionId:"MH-"+Q(t.sellId),sellId:Q(t.sellId),timestamp:new Intl.DateTimeFormat("en-GB",{timeZone:d.CONFIG&&d.CONFIG.timeZone||"Asia/Ho_Chi_Minh",day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}).format(new Date(Number(t.ts)||Date.now())).replace(", "," "),code:d.normalizeCode(t.code),giftName:Q(t.giftName),normalizedGiftName:d.normalizeText(t.giftName),quantity:q,unitPrice:r,rewardGemType:t.gemType,rewardGemAmount:q*r,rowIndex:1e9+(n||0),localPending:!0}}function mhMG(C,d){const a=mhPL();if(!a.length)return;const h=new Set(C.map(function(t){return Q(t.sellId)})),k=[];a.forEach(function(t,n){h.has(Q(t.sellId))||(k.push(t),C.push(mhMK(t,d,n)))});k.length!==a.length&&mhPS(k)}function mhPA(m,d){const a=mhPL().filter(function(t){return Q(t.sellId)!==Q(m.sellId)}),t={sellId:Q(m.sellId),code:m.code,giftName:m.giftName,quantity:m.quantity,unitPrice:m.unitPrice,gemType:m.gemType,ts:Date.now()};a.push(t),mhPS(a);if(U){if(!U.sales.some(function(n){return Q(n.sellId)===t.sellId})){const n=mhMK(t,d,a.length);U.sales.push(n),U.salesByCode.has(n.code)||U.salesByCode.set(n.code,[]),U.salesByCode.get(n.code).push(n)}te=Date.now(),mhLF=Date.now()}}function mhLS(a,d){if(U){const n=U.sales.find(function(t){return Q(t.sellId)===a});if(n)return n}const t=mhPL().find(function(n){return Q(n.sellId)===a});return t?mhMK(t,d,0):null}async function Pe(i,d){if(!i&&U&&Date.now()-te<S.cacheTtl)return U;const gR=d.sheetCsvUrl&&d.CONFIG?d:window.StudentRewardSystem||d,y=await Promise.all([d.fetchRows(d.sheetNameCsvUrl(S.policySheetName)),d.fetchRows(d.sheetNameCsvUrl(S.transactionSheetName)),(mhGC.rows&&Date.now()-mhGC.at<3e5?Promise.resolve(mhGC.rows):gR.fetchRows(gR.sheetCsvUrl(gR.CONFIG.giftGid)).then(function(t){return t&&t.length>1&&(mhGC={rows:t,at:Date.now()}),t}).catch(function(){return mhGC.rows||[]}))]),p=Y(y[0],d,y[2]),C=Me(y[1],d),G=new Map;mhMG(C,d);return C.forEach(D=>{G.has(D.code)||G.set(D.code,[]),G.get(D.code).push(D)}),U={policies:p,sales:C,salesByCode:G,policyRows:y[0],saleRows:y[1]},te=Date.now(),U}function qe(i){return(i||[]).map(d=>Object.assign({},d))}function Te(i){return Math.max(1,Math.floor(Number(i&&i.quantity||1)))}function Ae(i,d){let y=d.normalizeText(i||"");return y=y.replace(/^(goi|gói)\s+/i,"").replace(/\s+/g," ").trim(),y}function Be(i){return Q(i&&(i.giftName||i.name||i.gift&&i.gift.name)||"")}function De(i,d,y){const p=qe(i),C=[],G=[];function D(m){return Ae(m,y)}function _(m){const w=D(m);let a=0;return p.forEach(s=>{D(Be(s))===w&&(a+=Math.max(0,Number(s.quantity===void 0?1:s.quantity)))}),a}return(d||[]).forEach(m=>{let w=Math.max(0,Number(m.quantity)||0);if(!w)return;if(_(m.giftName)<w){C.push(Object.assign({reason:"INSUFFICIENT_ITEM"},m));return}const a=D(m.giftName);for(let s=0;s<p.length&&w>0;s++){const u=p[s];if(D(Be(u))!==a)continue;const f=Math.max(0,Number(u.quantity===void 0?1:u.quantity)),b=Math.min(f,w);u.quantity=f-b,w-=b}w===0?G.push(m):C.push(Object.assign({reason:"ITEM_DEDUCTION_INCOMPLETE"},m))}),{items:p.filter(m=>Number(m.quantity===void 0?1:m.quantity)>0),applied:G,rejected:C}}function v(i,d){d=String(d||"").trim().toUpperCase();const y="PLC|"+["PLC-TICKET",i,d].join("|")+"|"+d;let p=2166136261;for(let C=0;C<y.length;C++)p^=y.charCodeAt(C),p=Math.imul(p,16777619);return"PLC-"+d+"-"+(p>>>0).toString(36).toUpperCase()}function oe(i,d,y,p){const C=new Map;(d||[]).forEach(function(m){C.set(m.sellId,m)});const G=new Set,D=[],_=[];return(i||[]).forEach(function(m){const w=/PLC-REFUND\|([^|\s]+)\|([A-Za-z0-9_-]+)/.exec(String(m&&m.reason||""));if(w&&p.normalizeCode(w[2])===y&&Te(m)===1){const a=v(w[1],y),s=C.get(a);if(s&&!G.has(a)&&p.normalizeText(s.giftName)===p.normalizeText(Be(m))){G.add(a),_.push({sellId:a,roomId:w[1],timestamp:m.timestamp||"",refundTimestamp:m.timestamp||"",saleTimestamp:s.timestamp});return}}D.push(m)}),{n:G.size,items:D,sales:(d||[]).filter(function(m){return!G.has(m.sellId)}),cancelled:_}}function Oe(i,d,y,p){const C=(i.rawTransactions||[]).filter(function(f){return!(f&&f.isMinhHongSale)}),G=i.ledgerStartGems||i.earnedGems||y.createEmptyGems(),D=i.snapshot?i.snapshot.deals:null,_=i.teacherOwnedItems||[],m=typeof y.buildOwnedItems=="function"?y.buildOwnedItems.bind(y):null;let w=(d||[]).slice(),a=null,s=null,u=null;for(let f=0;f<4;f++){const b=w.map(function(E,J){return{transactionType:"teacher-gem",isMinhHongSale:!0,index:"MH-"+J,rowIndex:E.rowIndex,timestamp:E.timestamp,code:E.code,giftName:"Minh H\u1ED3ng thu mua "+E.giftName,giver:"Minh H\u1ED3ng",rewardGemType:E.rewardGemType,rewardGemAmount:E.rewardGemAmount,sellId:E.sellId}});a=p.processTransactions(G,C.concat(b),D);const T=m?m(a.validTransactions||[]):i.ownedItems||[],I=p.mergeOwnedItems?p.mergeOwnedItems(T,_):T.concat(_);s=De(I,d||[],y);const F=s.applied.map(function(E){return E.sellId}).join("|"),j=F===w.map(function(E){return E.sellId}).join("|");if(w=s.applied,j||F===u)break;u=F}return{accounting:a,itemResult:s}}function ie(i,d,y){let p=Object.assign({},i||{});return(d||[]).forEach(C=>{p=y.addGemReward(p,C.rewardGemType,C.rewardGemAmount)}),p}function He(i,d,y){const p=y.normalizeCode(i&&i.code||i&&i.studentCode||""),C=i&&i.ownedItems||[],G=new Date,D=new Intl.DateTimeFormat("en-CA",{timeZone:y.CONFIG.timeZone||"Asia/Ho_Chi_Minh",year:"numeric",month:"2-digit",day:"2-digit"}).format(G);return d.policies.map(_=>{const m=y.getOwnedItemQuantity(C,_.giftName);let w=0;(d.salesByCode.get(p)||[]).forEach(u=>{if(u.normalizedGiftName!==_.normalizedGiftName)return;const f=y.parseVietnameseDate(u.timestamp);if(!f)return;new Intl.DateTimeFormat("en-CA",{timeZone:y.CONFIG.timeZone||"Asia/Ho_Chi_Minh",year:"numeric",month:"2-digit",day:"2-digit"}).format(f)===D&&(w+=u.quantity)});const a=_.dailyLimit>0?Math.max(0,_.dailyLimit-w):m,s=Math.max(0,Math.min(m,a));return Object.assign({},_,{ownedQuantity:m,soldToday:w,remainingToday:a,maxQuantity:s,available:s>0})}).filter(_=>_.ownedQuantity>0)}function Ne(i,d){const y=d.normalizeCode(i)||"UNKNOWN";let p="";try{if(window.crypto&&window.crypto.getRandomValues){const G=new Uint32Array(2);window.crypto.getRandomValues(G),p=G[0].toString(36)+G[1].toString(36)}}catch{}return p||(p=Date.now().toString(36)+Math.random().toString(36).slice(2,10)),("MH-"+new Intl.DateTimeFormat("en-CA",{timeZone:d.CONFIG.timeZone||"Asia/Ho_Chi_Minh",year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date).replace(/-/g,"")+"-"+y+"-"+p).replace(/[^a-zA-Z0-9._:-]/g,"").slice(0,120)}function ee(i){return new Promise(function(d){const y=document.createElement("iframe");y.name="mhSellFrame_"+Date.now(),y.style.display="none";const p=document.createElement("form");p.method="POST",p.action=S.formResponseUrl,p.target=y.name,p.style.display="none",Object.keys(i).forEach(C=>{const G=document.createElement("input");G.type="hidden",G.name=C,G.value=i[C],p.appendChild(G)}),document.body.appendChild(y),document.body.appendChild(p),p.submit(),setTimeout(()=>{try{p.remove(),y.remove()}catch{}d(!0)},700)})}function he(i,d){const y=Q(i);if(!y||typeof d!="function")throw new Error("Asset source kh\xF4ng h\u1EE3p l\u1EC7.");return re.set(y,d),!0}function Re(i){return re.delete(Q(i))}function le(){return Array.from(re.keys())}async function Ke(i){if(i.__OCD_UNIFIED_ASSET_V4__)return i;Object.defineProperty(i,"__OCD_UNIFIED_ASSET_V4__",{value:!0,configurable:!1});const d={version:i.version,loadSharedRewardData:i.loadSharedRewardData.bind(i),getStudentRewardProfile:i.getStudentRewardProfile.bind(i),processTransactions:i.processTransactions.bind(i),mergeOwnedItems:i.mergeOwnedItems.bind(i)};i.CONFIG.minhHongBuybackSheetName=S.policySheetName,i.CONFIG.minhHongTransactionSheetName=S.transactionSheetName,i.CONFIG.minhHongConfirmValue=S.confirmValue,i.CONFIG.minhHongFormResponseUrl=S.formResponseUrl,i.CONFIG.minhHongFormEntries=Object.assign({},S.formEntries),i.loadMinhHongData=function(m){return xe(!!m,i)},i.getStudentSnapshot=async function(m,w){const a=await d.loadSharedRewardData(!!w);return a&&a.snapshots&&a.snapshots.get(i.normalizeCode(m))||null},i.loadSharedRewardData=async function(m){const w=await Promise.all([d.loadSharedRewardData(m),xe(!!m,i)]),a=w[0],s=w[1];return a.minhHongPolicies=s.policies,a.minhHongSales=s.sales,a.minhHongSalesByCode=s.salesByCode,a},i.prefetchStudent=function(m){const w=i.normalizeCode(m),a=[w&&i.loadStudentRewardData?i.loadStudentRewardData(!1,w):i.loadSharedRewardData(!1)];return w&&(i.getStudentAccess&&a.push(i.getStudentAccess(w)),i.getStudentSubmissionsCsv&&a.push(i.getStudentSubmissionsCsv(w))),Promise.allSettled(a)};let y=null;typeof i.setLateRefreshHook=="function"&&i.setLateRefreshHook(function(){return y?i.refreshStudentRewardProfile(y[0],y[1],y[2]):i.loadSharedRewardData(!0)});const p=4e3;let C=null;function G(){return typeof i.getLastWriteAt=="function"?i.getLastWriteAt():0}i.getStudentRewardProfile=async function(m,w,a,s){m&&(y=[m,w,s]);const u=i.normalizeCode(m);if(a&&C&&C.code===u&&Date.now()-C.at<p&&C.at>G()&&C.csv===(w||""))return C.profile;const f=Date.now(),b=await D(m,w,a,s);return C={code:u,at:f,csv:w||"",profile:b},b};async function D(m,w,a,s){const u=(i.loadStudentRewardData?i.loadStudentRewardData(!!a,m):d.loadSharedRewardData(!!a)).catch(function(de){console.warn("[StudentRewardSystem v4] Ch\u01B0a l\xE0m m\u1EDBi \u0111\u01B0\u1EE3c d\u1EEF li\u1EC7u chung:",de)}),f=xe(!!a,i);f.catch(function(){}),await i.assertStudentActive(m,s),await u;const b=await Promise.all([d.getStudentRewardProfile(m,w),f]),T=b[0],I=b[1],F=i.normalizeCode(m);let j=(I.salesByCode.get(F)||[]).filter(function(de){return i.isAfterSnapshot(T.snapshot||null,de.timestamp)});const E=oe(T.teacherOwnedItems||[],j,F,i);E.n&&(j=E.sales,T.teacherOwnedItems=E.items,T.cancelledTicketSales=E.cancelled);const J=Oe(T,j,i,d),q=J.itemResult,ae=J.accounting.gems;return T.code=T.code||F,T.gems=ae,T.balance=ae,T.transactions=J.accounting.validTransactions,T.validTransactions=J.accounting.validTransactions,T.rejectedTransactions=J.accounting.rejectedTransactions,T.gemRewards=J.accounting.gemRewards||T.gemRewards,T.consumedDealIds=J.accounting.consumedDealIds||T.consumedDealIds,T.accounting=J.accounting,T.ownedItems=q.items,T.redeemedItems=q.items,T.minhHong={sales:q.applied.slice(),rejectedSales:q.rejected.slice(),offers:[]},T.minhHong.offers=He(T,I,i),T.assets={gems:T.gems,items:T.ownedItems,transactions:q.applied.slice(),rejectedTransactions:q.rejected.slice()},T}i.refreshStudentRewardProfile=async function(m,w,a){U=null,te=0;const s=await i.getStudentRewardProfile(m,w,!0,a);return ue("ocdRewardProfileChanged",{code:i.normalizeCode(m),profile:s,version:$}),s},i.getMinhHongOffers=async function(m,w,a){const s=await i.getStudentRewardProfile(m,w,a);return s.minhHong?s.minhHong.offers:[]},i.createMinhHongSaleRequest=async function(m,w,a,s){const u=await i.getStudentRewardProfile(m,s,!1),f=x(a,i);if(f<=0)throw new Error("S\u1ED1 l\u01B0\u1EE3ng b\xE1n kh\xF4ng h\u1EE3p l\u1EC7.");const b=(u.minhHong.offers||[]).find(T=>T.normalizedGiftName===i.normalizeText(w));if(!b||!b.available)throw new Error("V\u1EADt ph\u1EA9m n\xE0y hi\u1EC7n kh\xF4ng n\u1EB1m trong danh s\xE1ch Minh H\u1ED3ng thu mua.");if(f>b.maxQuantity)throw new Error("S\u1ED1 l\u01B0\u1EE3ng v\u01B0\u1EE3t qu\xE1 s\u1ED1 \u0111ang s\u1EDF h\u1EEFu ho\u1EB7c gi\u1EDBi h\u1EA1n thu mua h\xF4m nay.");return{sellId:Ne(m,i),code:i.normalizeCode(m),giftName:b.giftName,quantity:f,unitPrice:b.price,gemType:b.gemType,rewardAmount:f*b.price,confirm:S.confirmValue}},i.submitMinhHongSaleRequest=async function(m){const w=i.GEM_TYPES[m.gemType]?i.GEM_TYPES[m.gemType].displayName:m.gemType;if(typeof i.apiAppend=="function"){const u=await i.apiAppend("mhSale",["",m.sellId,m.code,m.giftName,String(m.quantity),String(m.unitPrice),w,S.confirmValue]);if(u==="sent")return z.add(Q(m.sellId)),mhPA(m,i),m;if(u==="unknown"){U=null,te=0;try{if(((await xe(!0,i)).sales||[]).some(b=>Q(b.sellId)===Q(m.sellId)))return z.add(Q(m.sellId)),m}catch{}}}const a=S.formEntries,s={};return s[a.sellId]=m.sellId,s[a.code]=m.code,s[a.giftName]=m.giftName,s[a.quantity]=String(m.quantity),s[a.price]=String(m.unitPrice),s[a.gemType]=w,s[a.confirm]=S.confirmValue,await ee(s),m};async function _(m,w){C=null;const a=await i.getStudentRewardProfile(m,w,!1);return ue("ocdRewardProfileChanged",{code:i.normalizeCode(m),profile:a,version:$}),a}return i.waitForMinhHongSale=async function(m,w){const a=Q(m),s=Math.max(1,Number(w||S.pollAttempts));if(z.has(a)){const L=mhLS(a,i);if(L)return L}for(let u=0;u<s;u++){u>0&&await P(z.has(a)?1e3:S.pollDelay),U=null,te=0;try{const b=((await xe(!0,i)).sales||[]).find(T=>Q(T.sellId)===a);if(b)return b}catch(f){console.warn("[MinhHongBuyback] Ch\u01B0a \u0111\u1ECDc \u0111\u01B0\u1EE3c giao d\u1ECBch, s\u1EBD th\u1EED l\u1EA1i.",f)}}return null},i.confirmMinhHongSale=async function(m,w,a,s){const u=await i.waitForMinhHongSale(m,s);if(!u)return null;const f=i.normalizeCode(a||u.code||""),b=f?await _(f,w):null;return{sale:u,profile:b}},i.sellItemToMinhHong=async function(m,w,a,s){const u=await i.createMinhHongSaleRequest(m,w,a,s);await i.submitMinhHongSaleRequest(u);const f=await i.waitForMinhHongSale(u.sellId);if(!f)return ue("ocdMinhHongSalePending",{sellId:u.sellId,code:u.code,giftName:u.giftName,quantity:u.quantity}),{request:u,sale:null,profile:null,pending:!0,confirmed:!1};const b=await _(m,s);return ue("ocdMinhHongSaleConfirmed",{sellId:u.sellId,code:u.code,sale:f,profile:b}),{request:u,sale:f,profile:b,pending:!1,confirmed:!0}},i.registerAssetSource=he,i.unregisterAssetSource=Re,i.getRegisteredAssetSources=le,i.createAssetTransaction=function(m){const w=Object.assign({},m||{});if(w.transactionId=Q(w.transactionId),w.transactionType=Q(w.transactionType||"external"),w.code=i.normalizeCode(w.code),w.effects=Array.isArray(w.effects)?w.effects.map(a=>Object.assign({},a)):[],!w.transactionId)throw new Error("transactionId l\xE0 b\u1EAFt bu\u1ED9c.");return w},i.version=d.version,i.coreVersion=$,i.legacyVersion=d.version,i.MinhHongBuyback={version:"2.2.0-core",config:S,loadData:i.loadMinhHongData,getOffers:i.getMinhHongOffers,createSaleRequest:i.createMinhHongSaleRequest,submitSaleRequest:i.submitMinhHongSaleRequest,waitForSale:i.waitForMinhHongSale,confirmSale:i.confirmMinhHongSale,sell:i.sellItemToMinhHong},ue("studentRewardCoreReady",{version:d.version,coreVersion:$,legacyVersion:d.version,unifiedAssets:!0}),ue("ocdRewardCoreUpgraded",{version:$,compatibilityVersion:d.version}),console.log("[StudentRewardSystem] Core v"+$+" ready. Compatibility API: "+d.version),Ge(i),i}function Ge(i){try{const d=window.localStorage.getItem("ocd_student_session_v1");if(!d)return;const y=JSON.parse(d)||{},p=i.normalizeCode(y.code||"");if(String(y.mode||"")!=="student"||!p)return;setTimeout(function(){Promise.resolve(i.prefetchStudent(p)).catch(function(){})},0)}catch{}}if(!window.StudentRewardSystem){console.error("[StudentRewardSystem v4] Kh\xF4ng t\xECm th\u1EA5y n\u1EC1n Core n\u1ED9i b\u1ED9.");return}window.StudentRewardSystemReady=Ke(window.StudentRewardSystem).catch(function(i){throw console.error("[StudentRewardSystem v4]",i),i})})(),(function(){"use strict";if(window.OCDAuth)return;const $="ocd_auth_v1",S="ocd_auth_public_v1",Ze=60*1e3,U=window.StudentRewardSystem,te=U&&U.CONFIG&&U.CONFIG.appsScriptUrl||"https://script.google.com/macros/s/AKfycbwtMkodKNVrUgVWhpvhwMndPZKBrdWD4OF0XoR4i5poQsxRkEDLIkm56-MTxuOCVW9JXA/exec";function z(a){return String(a??"").trim().toUpperCase().replace(/\s+/g,"")}function re(a,s){try{if(s===void 0)return JSON.parse(localStorage.getItem(a)||"null");s===null?localStorage.removeItem(a):localStorage.setItem(a,JSON.stringify(s))}catch{return null}}function Q(a,s){try{window.dispatchEvent(new CustomEvent(a,{detail:s||{}}))}catch{}}let P=re($);P&&(!P.token||!P.expires||P.expires<Date.now())&&(P=null,re($,null));function x(){return P&&P.expires>Date.now()?P.token:""}function X(){return x()?P.me:null}function ue(){const a=X();return a?[z(a.code),z(a.linked)].filter(Boolean):[]}function ge(a){return a=z(a),!!a&&ue().indexOf(a)>=0}function Ie(a){P={token:a.token,expires:a.expires,me:a.me,checked:Date.now()},re($,P);const s=z(a.me&&(a.me.linked||a.me.code));try{s&&window.OCDStudentSession&&window.OCDStudentSession.confirmStudent&&window.OCDStudentSession.confirmStudent(s,"ocd-auth")}catch{}try{sessionStorage.removeItem(S)}catch{}Q("ocdAuthChanged",{loggedIn:!0,me:a.me})}function Z(a){const s=X();if(P=null,re($,null),a)try{window.OCDStudentSession&&window.OCDStudentSession.clear&&window.OCDStudentSession.clear("ocd-auth-logout")}catch{}Q("ocdAuthChanged",{loggedIn:!1,previous:s})}const fe=window.fetch.bind(window);window.fetch=function(a,s){try{const u=typeof a=="string"?a:a&&a.url||"",f=x();if(f&&u.indexOf(te)===0){s=s?Object.assign({},s):{};const b=String(s.method||typeof a!="string"&&a.method||"GET").toUpperCase();if(b==="GET"&&typeof a=="string"&&!/[?&]token=/.test(a))a=a+(a.indexOf("?")>=0?"&":"?")+"token="+encodeURIComponent(f);else if(b==="POST"&&typeof s.body=="string")try{const T=JSON.parse(s.body);T&&typeof T=="object"&&!T.token&&(T.token=f,s.body=JSON.stringify(T))}catch{}}}catch{}return fe(a,s)};async function Y(a,s){const u=new AbortController,f=setTimeout(function(){u.abort()},25e3);try{const b=Object.assign({action:a,device:navigator.userAgent.slice(0,100)},s||{}),T=await fe(te,{method:"POST",body:JSON.stringify(b),headers:{"Content-Type":"text/plain;charset=utf-8"},credentials:"omit",cache:"no-store",signal:u.signal}),I=JSON.parse(await T.text());return I&&I.expired&&a!=="authMe"&&Z(!1),I||{ok:!1,error:"M\xE1y ch\u1EE7 kh\xF4ng ph\u1EA3n h\u1ED3i."}}catch{return{ok:!1,error:"Kh\xF4ng k\u1EBFt n\u1ED1i \u0111\u01B0\u1EE3c m\xE1y ch\u1EE7. Vui l\xF2ng th\u1EED l\u1EA1i."}}finally{clearTimeout(f)}}let Me=null,ne=null;try{ne=JSON.parse(sessionStorage.getItem(S)||"null")}catch{}function be(a){if(!a){try{const s=JSON.parse(sessionStorage.getItem(S)||"null");if(s&&Date.now()-s.at<Ze)return Promise.resolve(s)}catch{}if(Me)return Me}return Me=(async function(){try{const s=await fe(te+"?action=authPublic&_="+Date.now(),{cache:"no-store",credentials:"omit"}),u=JSON.parse(await s.text());if(!u||!u.ok)throw new Error("authPublic");const f={at:Date.now(),protected:(u.protected||[]).map(z),look:u.look||{}};ne=f;try{sessionStorage.setItem(S,JSON.stringify(f))}catch{}return f}catch{return{at:0,protected:[],look:{},failed:!0}}finally{setTimeout(function(){Me=null},0)}})(),Me}async function Ee(a){return(await be()).protected.indexOf(z(a))>=0}async function xe(a){return a=z(a),!a||ge(a)?!0:!await Ee(a)}async function Pe(a){return ge(a)&&P.me&&P.me.look?P.me.look:(await be()).look[z(a)]||null}function qe(a){return a=z(a),a?ge(a)&&P.me&&P.me.look?P.me.look:ne&&ne.look&&ne.look[a]||null:null}function Te(a){if(x()){P.me=Object.assign({},P.me,{look:Object.assign({},a||{})}),re($,P);try{sessionStorage.removeItem(S)}catch{}if(ne&&ne.look){const s=z(P.me.linked||P.me.code);ne.look[s]=P.me.look}Q("ocdAuthLookChanged",{look:P.me.look})}}async function Ae(){if(!x())return null;if(P.checked&&Date.now()-P.checked<600*1e3)return P.me;const a=await Y("authMe",{token:x()});return a.ok?(P.me=a.me,P.checked=Date.now(),re($,P),a.me):(a.expired&&Z(!1),X())}const Be=`
.oa-back{position:fixed;inset:0;z-index:2147483600;background:rgba(30,22,16,.55);display:flex;align-items:center;justify-content:center;padding:16px;font-family:Arial,sans-serif}
.oa-box{background:#fffaf2;color:#2c241b;border-radius:14px;max-width:400px;width:100%;max-height:92vh;overflow:auto;box-shadow:0 18px 50px rgba(0,0,0,.3);border-top:5px solid #8b3328}
.oa-head{display:flex;align-items:center;justify-content:space-between;padding:16px 18px 6px}
.oa-title{font:bold 17px/1.4 Georgia,"Times New Roman",serif;color:#8b3328;margin:0}
.oa-x{border:0;background:none;font-size:24px;line-height:1;color:#8b7b6a;cursor:pointer;padding:2px 6px}
.oa-body{padding:6px 18px 18px}
.oa-text{font-size:14px;line-height:1.6;margin:0 0 12px;color:#4e4436}
.oa-label{display:block;font-size:13px;font-weight:bold;margin:10px 0 4px;color:#5a4a3a}
.oa-field{position:relative}
.oa-input{box-sizing:border-box;width:100%;padding:11px 12px;border:1px solid #d8ccb8;border-radius:8px;font-size:16px;background:#fff;color:#2c241b}
.oa-input:focus{outline:2px solid #c9a45c;border-color:#c9a45c}
.oa-eye{position:absolute;right:6px;top:50%;transform:translateY(-50%);border:0;background:none;cursor:pointer;font-size:16px;padding:6px;color:#8b7b6a}
.oa-btn{display:block;width:100%;margin-top:16px;padding:12px;border:0;border-radius:8px;background:#8b3328;color:#fffaf0;font:bold 14px Arial,sans-serif;letter-spacing:.5px;cursor:pointer}
.oa-btn[disabled]{opacity:.6;cursor:wait}
.oa-btn.oa-ghost{background:#f1e6d3;color:#8b3328}
.oa-links{display:flex;justify-content:space-between;gap:10px;margin-top:12px;font-size:13px}
.oa-link{border:0;background:none;color:#8b3328;text-decoration:underline;cursor:pointer;padding:0;font-size:13px}
.oa-msg{margin-top:12px;font-size:13px;line-height:1.5;padding:9px 11px;border-radius:7px;display:none}
.oa-msg.err{display:block;background:#fbe9e6;color:#8b2a1f}
.oa-msg.ok{display:block;background:#e9f4e6;color:#2f5d26}
.oa-hint{font-size:12px;color:#8b7b6a;margin-top:6px;line-height:1.5}
.oa-steps{font-size:12px;color:#8b7b6a;margin:0 0 8px;letter-spacing:.5px}
.oa-badge{display:inline-flex;align-items:center;gap:6px;font-size:13px;font-weight:bold;color:#2f5d26}
.oa-card{margin:10px 0;padding:12px 13px;border-radius:10px;background:#f6efe2;border:1px solid #e3d5bd;font-family:Arial,sans-serif}
.oa-card-title{font-weight:bold;font-size:13px;letter-spacing:.5px;color:#8b3328;margin-bottom:6px}
.oa-card-text{font-size:13px;line-height:1.55;color:#4e4436;margin:0 0 8px}
.oa-card .oa-btn{margin-top:6px;padding:10px}
.oa-card-row{display:flex;gap:8px;flex-wrap:wrap}
.oa-card-row .oa-btn{flex:1;min-width:120px}
.oa-toast{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);z-index:2147483500;max-width:min(440px,calc(100% - 32px));background:#2c241b;color:#fffaf0;border-radius:12px;padding:14px 16px;box-shadow:0 10px 30px rgba(0,0,0,.35);font:14px/1.5 Arial,sans-serif}
.oa-toast .oa-btn{margin-top:10px;padding:10px}
.oa-toast-x{position:absolute;right:8px;top:4px;border:0;background:none;color:#d8ccb8;font-size:20px;cursor:pointer}
`;function De(){if(document.getElementById("oa-style"))return;const a=document.createElement("style");a.id="oa-style",a.textContent=Be,(document.head||document.documentElement).appendChild(a)}function v(a,s,u){const f=document.createElement(a);return s&&(f.className=s),u!==void 0&&(f.textContent=u),f}function oe(a,s,u,f){const b=v("div");b.appendChild(v("label","oa-label",a));const T=v("div","oa-field"),I=v("input","oa-input");if(I.type=s||"text",I.value=u||"",f&&(I.placeholder=f),I.autocomplete=s==="password"?"current-password":"off",T.appendChild(I),s==="password"){const F=v("button","oa-eye","\u{1F441}");F.type="button",F.setAttribute("aria-label","Hi\u1EC7n m\u1EADt kh\u1EA9u"),F.onclick=function(){I.type=I.type==="password"?"text":"password"},T.appendChild(F)}return b.appendChild(T),b.input=I,b}let Oe=null;function ie(){Oe&&(Oe.remove(),Oe=null,document.removeEventListener("keydown",He))}function He(a){a.key==="Escape"&&ie()}function Ne(a){De(),ie();const s=v("div","oa-back"),u=v("div","oa-box"),f=v("div","oa-head"),b=v("div","oa-body");u.setAttribute("role","dialog"),u.setAttribute("aria-modal","true"),f.appendChild(v("h3","oa-title",a));const T=v("button","oa-x","\xD7");T.type="button",T.setAttribute("aria-label","\u0110\xF3ng"),T.onclick=ie,f.appendChild(T),u.append(f,b),s.appendChild(u),s.addEventListener("click",function(F){F.target===s&&ie()}),document.body.appendChild(s),Oe=s,document.addEventListener("keydown",He);const I=v("div","oa-msg");return{body:b,msg:I,say:function(F,j){I.className="oa-msg "+(j?"ok":"err"),I.textContent=F},hush:function(){I.className="oa-msg",I.textContent=""}}}function ee(a,s,u){s?(a.dataset.t=a.textContent,a.textContent=u||"\u0110ANG X\u1EEC L\xDD...",a.disabled=!0):(a.textContent=a.dataset.t||a.textContent,a.disabled=!1)}function he(a,s){a.forEach(function(u){u.input.addEventListener("keydown",function(f){f.key==="Enter"&&s()})})}function Re(a,s){return a.length<6?"M\u1EADt kh\u1EA9u c\u1EA7n t\u1ED1i thi\u1EC3u 6 k\xFD t\u1EF1.":a!==s?"Hai l\u1EA7n nh\u1EADp m\u1EADt kh\u1EA9u ch\u01B0a gi\u1ED1ng nhau.":""}function le(a){a=a||{};const s=Ne("\u{1F512} \u0110\u0103ng nh\u1EADp t\xE0i kho\u1EA3n");s.body.appendChild(v("p","oa-text",a.code?"M\xE3 "+z(a.code)+" \u0111\xE3 \u0111\u01B0\u1EE3c b\u1EA3o m\u1EADt. Vui l\xF2ng nh\u1EADp m\u1EADt kh\u1EA9u \u0111\u1EC3 ti\u1EBFp t\u1EE5c.":"\u0110\u0103ng nh\u1EADp b\u1EB1ng m\xE3 h\u1ECDc vi\xEAn, m\xE3 th\xE0nh vi\xEAn ho\u1EB7c email."));const u=oe("M\xE3 h\u1ECDc vi\xEAn / m\xE3 th\xE0nh vi\xEAn / email","text",a.code||""),f=oe("M\u1EADt kh\u1EA9u","password"),b=v("button","oa-btn","\u0110\u0102NG NH\u1EACP");b.type="button";const T=v("div","oa-links"),I=v("button","oa-link","Qu\xEAn m\u1EADt kh\u1EA9u?"),F=v("button","oa-link",a.code?"Nh\u1EADp m\xE3 kh\xE1c":"\u0110\xF3ng");I.type=F.type="button",T.append(I,F),s.body.append(u,f,b,T,s.msg);async function j(){if(s.hush(),!u.input.value.trim()||!f.input.value){s.say("Vui l\xF2ng nh\u1EADp \u0111\u1EE7 m\xE3 (ho\u1EB7c email) v\xE0 m\u1EADt kh\u1EA9u.");return}ee(b,!0,"\u0110ANG \u0110\u0102NG NH\u1EACP...");const E=await Y("authLogin",{id:u.input.value.trim(),password:f.input.value});if(ee(b,!1),!E.ok){s.say(E.error||"\u0110\u0103ng nh\u1EADp ch\u01B0a th\xE0nh c\xF4ng."),f.input.select();return}Ie(E),ie(),a.onSuccess&&a.onSuccess(E.me)}b.onclick=j,he([u,f],j),I.onclick=function(){Ge({id:u.input.value.trim(),onSuccess:a.onSuccess})},F.onclick=function(){ie(),a.onCancel&&a.onCancel()},(a.code?f:u).input.focus()}function Ke(a){a=a||{};const s=z(a.code),u=Ne("\u{1F512} N\xE2ng c\u1EA5p b\u1EA3o m\u1EADt");u.body.appendChild(v("div","oa-steps","B\u01AF\u1EDAC 1/2 \xB7 X\xC1C MINH CH\u1EE6 T\xC0I KHO\u1EA2N")),u.body.appendChild(v("p","oa-text","M\xE3 h\u1ECDc vi\xEAn "+s+". Nh\u1EADp \u0111\xFAng s\u1ED1 \u0111i\u1EC7n tho\u1EA1i v\xE0 email b\u1EA1n \u0111\xE3 d\xF9ng khi \u0111\u0103ng k\xFD kho\xE1 h\u1ECDc."));const f=oe("S\u1ED1 \u0111i\u1EC7n tho\u1EA1i \u0111\xE3 \u0111\u0103ng k\xFD","tel"),b=oe("Email \u0111\xE3 \u0111\u0103ng k\xFD","email"),T=v("button","oa-btn","X\xC1C MINH");T.type="button",u.body.append(f,b,T,u.msg);async function I(){if(u.hush(),!f.input.value.trim()||!b.input.value.trim()){u.say("Vui l\xF2ng nh\u1EADp \u0111\u1EE7 s\u1ED1 \u0111i\u1EC7n tho\u1EA1i v\xE0 email.");return}ee(T,!0,"\u0110ANG X\xC1C MINH...");const E=await Y("authUpgradeStart",{code:s,phone:f.input.value,email:b.input.value});if(ee(T,!1),!E.ok){u.say(E.error||"Ch\u01B0a x\xE1c minh \u0111\u01B0\u1EE3c.");return}F(E.ticket,E.name)}T.onclick=I,he([f,b],I),f.input.focus();function F(E,J){u.body.innerHTML="",u.hush(),u.body.appendChild(v("div","oa-steps","B\u01AF\u1EDAC 2/2 \xB7 \u0110\u1EB6T M\u1EACT KH\u1EA8U")),u.body.appendChild(v("p","oa-text","Xin ch\xE0o "+(J||s)+". H\xE3y \u0111\u1EB7t m\u1EADt kh\u1EA9u cho t\xE0i kho\u1EA3n "+s+"."));const q=oe("M\u1EADt kh\u1EA9u m\u1EDBi","password"),ae=oe("Nh\u1EADp l\u1EA1i m\u1EADt kh\u1EA9u","password");q.input.autocomplete=ae.input.autocomplete="new-password",u.body.append(q,ae,v("div","oa-hint","T\u1ED1i thi\u1EC3u 6 k\xFD t\u1EF1. Kh\xF4ng d\xF9ng m\xE3 h\u1ECDc vi\xEAn hay s\u1ED1 \u0111i\u1EC7n tho\u1EA1i l\xE0m m\u1EADt kh\u1EA9u."));const de=v("button","oa-btn","L\u01AFU M\u1EACT KH\u1EA8U");de.type="button",u.body.append(de,u.msg);async function pe(){u.hush();const $e=Re(q.input.value,ae.input.value);if($e){u.say($e);return}ee(de,!0,"\u0110ANG L\u01AFU...");const _e=await Y("authUpgradeFinish",{ticket:E,password:q.input.value});if(ee(de,!1),!_e.ok){u.say(_e.error||"Ch\u01B0a l\u01B0u \u0111\u01B0\u1EE3c m\u1EADt kh\u1EA9u.");return}Ie(_e),j()}de.onclick=pe,he([q,ae],pe),q.input.focus()}function j(){u.body.innerHTML="",u.body.appendChild(v("p","oa-text","\u2705 T\xE0i kho\u1EA3n "+s+" \u0111\xE3 \u0111\u01B0\u1EE3c b\u1EA3o m\u1EADt. T\u1EEB nay ng\u01B0\u1EDDi kh\xE1c kh\xF4ng th\u1EC3 tra c\u1EE9u h\u1ED3 s\u01A1 c\u1EE7a b\u1EA1n. B\u1EA1n \u0111ang \u0111\u0103ng nh\u1EADp tr\xEAn thi\u1EBFt b\u1ECB n\xE0y (30 ng\xE0y)."));const E=v("button","oa-btn","HO\xC0N T\u1EA4T");E.type="button",E.onclick=function(){ie(),a.onSuccess&&a.onSuccess(X())},u.body.appendChild(E)}}function Ge(a){a=a||{};const s=Ne("Qu\xEAn m\u1EADt kh\u1EA9u");s.body.appendChild(v("p","oa-text","Nh\u1EADp m\xE3 h\u1ECDc vi\xEAn, m\xE3 th\xE0nh vi\xEAn ho\u1EB7c email. Minh H\u1ED3ng s\u1EBD g\u1EEDi m\xE3 x\xE1c nh\u1EADn 6 s\u1ED1 t\u1EDBi email \u0111\xE3 \u0111\u0103ng k\xFD c\u1EE7a t\xE0i kho\u1EA3n."));const u=oe("M\xE3 / email","text",a.id||""),f=v("button","oa-btn","G\u1EECI M\xC3 X\xC1C NH\u1EACN");f.type="button",s.body.append(u,f,s.msg);async function b(){if(s.hush(),!u.input.value.trim()){s.say("Vui l\xF2ng nh\u1EADp m\xE3 ho\u1EB7c email.");return}ee(f,!0,"\u0110ANG G\u1EECI...");const I=await Y("authForgot",{id:u.input.value.trim()});if(ee(f,!1),!I.ok){s.say(I.error||"Ch\u01B0a g\u1EEDi \u0111\u01B0\u1EE3c m\xE3.");return}if(!I.sentTo){s.say("Kh\xF4ng t\xECm th\u1EA5y t\xE0i kho\u1EA3n \u0111\xE3 b\u1EA3o m\u1EADt v\u1EDBi th\xF4ng tin n\xE0y, ho\u1EB7c t\xE0i kho\u1EA3n ch\u01B0a c\xF3 email. Vui l\xF2ng li\xEAn h\u1EC7 gi\xE1o vi\xEAn.");return}T(u.input.value.trim(),I.sentTo)}f.onclick=b,he([u],b),u.input.focus();function T(I,F){s.body.innerHTML="",s.hush(),s.body.appendChild(v("p","oa-text","\u0110\xE3 g\u1EEDi m\xE3 x\xE1c nh\u1EADn t\u1EDBi "+F+" (c\xF3 hi\u1EC7u l\u1EF1c 15 ph\xFAt). Ki\u1EC3m tra c\u1EA3 th\u01B0 m\u1EE5c Spam/Qu\u1EA3ng c\xE1o."));const j=oe("M\xE3 x\xE1c nh\u1EADn 6 s\u1ED1","text","","______"),E=oe("M\u1EADt kh\u1EA9u m\u1EDBi","password"),J=oe("Nh\u1EADp l\u1EA1i m\u1EADt kh\u1EA9u","password");j.input.inputMode="numeric",E.input.autocomplete=J.input.autocomplete="new-password";const q=v("button","oa-btn","\u0110\u1EB6T L\u1EA0I M\u1EACT KH\u1EA8U");q.type="button",s.body.append(j,E,J,q,s.msg);async function ae(){s.hush();const de=Re(E.input.value,J.input.value);if(de){s.say(de);return}ee(q,!0,"\u0110ANG \u0110\u1EB6T L\u1EA0I...");const pe=await Y("authReset",{id:I,otp:j.input.value.trim(),password:E.input.value});if(ee(q,!1),!pe.ok){s.say(pe.error||"Ch\u01B0a \u0111\u1EB7t l\u1EA1i \u0111\u01B0\u1EE3c m\u1EADt kh\u1EA9u.");return}Ie(pe),ie(),a.onSuccess&&a.onSuccess(pe.me)}q.onclick=ae,he([j,E,J],ae),j.input.focus()}}function i(a){a=a||{};const s=X();if(!s){le(a);return}const u=Ne("T\xE0i kho\u1EA3n c\u1EE7a b\u1EA1n");u.body.appendChild(v("div","oa-badge","\u{1F512} "+(s.name||"")+" \xB7 "+(s.linked||s.code))),u.body.appendChild(v("p","oa-hint","Email: "+(s.email||"\u2013")+" \xB7 \u0110\u0103ng nh\u1EADp tr\xEAn thi\u1EBFt b\u1ECB n\xE0y \u0111\u1EBFn "+new Date(P.expires).toLocaleDateString("vi-VN")));const f=v("button","oa-btn oa-ghost","\u0110\u1ED4I M\u1EACT KH\u1EA8U"),b=v("button","oa-btn","\u0110\u0102NG XU\u1EA4T"),T=v("button","oa-btn oa-ghost","\u0110\u0102NG XU\u1EA4T KH\u1ECEI M\u1ECCI THI\u1EBET B\u1ECA");[f,b,T].forEach(function(I){I.type="button"}),u.body.append(f,b,T,u.msg),b.onclick=async function(){ee(b,!0),await Y("authLogout",{token:x()}),Z(!0),ie(),a.onLogout&&a.onLogout()},T.onclick=async function(){confirm("\u0110\u0103ng xu\u1EA5t t\xE0i kho\u1EA3n tr\xEAn t\u1EA5t c\u1EA3 thi\u1EBFt b\u1ECB?")&&(ee(T,!0),await Y("authLogout",{token:x(),all:!0}),Z(!0),ie(),a.onLogout&&a.onLogout())},f.onclick=function(){u.body.innerHTML="",u.hush();const I=oe("M\u1EADt kh\u1EA9u hi\u1EC7n t\u1EA1i","password"),F=oe("M\u1EADt kh\u1EA9u m\u1EDBi","password"),j=oe("Nh\u1EADp l\u1EA1i m\u1EADt kh\u1EA9u m\u1EDBi","password");F.input.autocomplete=j.input.autocomplete="new-password";const E=v("button","oa-btn","L\u01AFU M\u1EACT KH\u1EA8U M\u1EDAI");E.type="button",u.body.append(I,F,j,v("div","oa-hint","Sau khi \u0111\u1ED5i, c\xE1c thi\u1EBFt b\u1ECB kh\xE1c s\u1EBD ph\u1EA3i \u0111\u0103ng nh\u1EADp l\u1EA1i."),E,u.msg),E.onclick=async function(){u.hush();const J=Re(F.input.value,j.input.value);if(J){u.say(J);return}ee(E,!0);const q=await Y("authChangePw",{token:x(),oldPassword:I.input.value,password:F.input.value});if(ee(E,!1),!q.ok){u.say(q.error||"Ch\u01B0a \u0111\u1ED5i \u0111\u01B0\u1EE3c m\u1EADt kh\u1EA9u.");return}P.token=q.token,P.expires=q.expires,re($,P),u.body.innerHTML="",u.body.appendChild(v("p","oa-text","\u2705 \u0110\xE3 \u0111\u1ED5i m\u1EADt kh\u1EA9u."));const ae=v("button","oa-btn","\u0110\xD3NG");ae.type="button",ae.onclick=ie,u.body.appendChild(ae)},I.input.focus()}}let d=null;function y(a,s){De(),d&&d.remove(),d=v("div","oa-toast"),d.setAttribute("role","alert");const u=v("button","oa-toast-x","\xD7");u.type="button",u.onclick=function(){d.remove(),d=null},d.append(u,v("div","","\u{1F512} H\u1ED3 s\u01A1 "+z(a)+" \u0111\xE3 \u0111\u01B0\u1EE3c ch\u1EE7 t\xE0i kho\u1EA3n b\u1EA3o m\u1EADt."));const f=v("button","oa-btn","\u0110\xC2Y L\xC0 T\xD4I \u2013 \u0110\u0102NG NH\u1EACP");f.type="button",f.onclick=function(){d.remove(),d=null,le({code:a,onSuccess:s||function(){location.reload()}})},d.appendChild(f),document.body.appendChild(d)}async function p(a,s){if(a=z(a),!a)return!1;if(ge(a))return!0;let u=null;try{u=await Y("authStatus",{code:a})}catch{}return!u||!u.ok?!await Ee(a):u.protected?(le(Object.assign({},s||{},{code:a})),!1):!0}function C(a,s){De(),a=z(a);const u=v("div","oa-card");u.appendChild(v("div","oa-card-text","\u0110ang ki\u1EC3m tra b\u1EA3o m\u1EADt t\xE0i kho\u1EA3n\u2026"));const f=function(){s&&s()};return(async function(){if(ge(a)){const I=X();u.innerHTML="",u.appendChild(v("div","oa-badge","\u{1F512} "+(I.name||"")+" \xB7 \u0110\xE3 b\u1EA3o m\u1EADt"));const F=v("div","oa-card-row"),j=v("button","oa-btn oa-ghost","T\xC0I KHO\u1EA2N");j.type="button",j.onclick=function(){i({onLogout:f})},F.appendChild(j),u.appendChild(F);return}let b=null;try{b=await Y("authStatus",{code:a})}catch{}if(u.innerHTML="",!b||!b.ok){u.appendChild(v("div","oa-card-text","Ch\u01B0a ki\u1EC3m tra \u0111\u01B0\u1EE3c tr\u1EA1ng th\xE1i b\u1EA3o m\u1EADt. Vui l\xF2ng th\u1EED l\u1EA1i sau."));return}if(b.protected){u.appendChild(v("div","oa-card-title","\u{1F512} M\xC3 \u0110\xC3 \u0110\u01AF\u1EE2C B\u1EA2O M\u1EACT")),u.appendChild(v("p","oa-card-text","M\xE3 "+a+" \u0111\xE3 \u0111\u01B0\u1EE3c b\u1EA3o m\u1EADt. \u0110\u0103ng nh\u1EADp \u0111\u1EC3 xem h\u1ED3 s\u01A1 v\xE0 s\u1EED d\u1EE5ng c\xE1c ch\u1EE9c n\u0103ng h\u1ECDc t\u1EADp."));const I=v("button","oa-btn","\u0110\u0102NG NH\u1EACP");I.type="button",I.onclick=function(){le({code:a,onSuccess:f})},u.appendChild(I);return}u.appendChild(v("div","oa-card-title","\u{1F512} B\u1EA2O M\u1EACT T\xC0I KHO\u1EA2N")),u.appendChild(v("p","oa-card-text","Hi\u1EC7n ai bi\u1EBFt m\xE3 "+a+" c\u0169ng xem \u0111\u01B0\u1EE3c h\u1ED3 s\u01A1 v\xE0 d\xF9ng m\xE3 n\xE0y tr\xEAn c\xE1c trang. N\xE2ng c\u1EA5p \u0111\u1EC3 ch\u1EC9 b\u1EA1n xem v\xE0 d\xF9ng \u0111\u01B0\u1EE3c."));const T=v("button","oa-btn","N\xC2NG C\u1EA4P B\u1EA2O M\u1EACT");T.type="button",T.onclick=function(){Ke({code:a,onSuccess:f})},u.appendChild(T)})(),u}function G(a){return a&&(a.publicList||a.ocdAuthBulk)||window.OCD_AUTH_PUBLIC_LIST===!0?!0:!!document.getElementById("rankingContent")}const D={};function _(){try{const a=window.OCDStudentSession;return z(a&&a.getCode?a.getCode():"")}catch{return""}}function m(a){const s=new Error("\u{1F512} H\u1ED3 s\u01A1 "+z(a)+" \u0111\xE3 \u0111\u01B0\u1EE3c ch\u1EE7 t\xE0i kho\u1EA3n b\u1EA3o m\u1EADt. N\u1EBFu \u0111\xE2y l\xE0 b\u1EA1n, h\xE3y \u0111\u0103ng nh\u1EADp t\u1EA1i icon Minh H\u1ED3ng.");return s.code="STUDENT_PROTECTED",s.studentCode=z(a),s}function w(a){if(!a||a.__ocdAuthGuard||typeof a.assertStudentActive!="function")return;a.__ocdAuthGuard=!0;const s=a.assertStudentActive.bind(a);a.assertStudentActive=async function(u,f){if(!G(f)&&!await xe(u)){const b=z(u);throw(b===_()||f&&f.interactive)&&!D[b]&&(D[b]=1,y(u)),Q("ocdProfileLocked",{code:b,silent:b!==_()}),m(u)}return s(u,f)},a.auth=window.OCDAuth}window.OCDAuth={version:"1.1.1",acceptSession:function(a){a&&a.token&&a.expires&&Ie(a)},setLook:Te,lookCached:qe,token:x,me:X,isMe:ge,refreshMe:Ae,publicInfo:be,isProtected:Ee,canView:xe,lookOf:Pe,post:Y,ensureAccess:p,securityCard:C,lockedToast:y,openLogin:le,openUpgrade:Ke,openForgot:Ge,openAccount:i,close:ie,logout:async function(a){x()&&await Y("authLogout",{token:x(),all:!!a}),Z(!0)},lockedError:m},w(U),window.StudentRewardSystemReady&&window.StudentRewardSystemReady.then&&window.StudentRewardSystemReady.then(function(a){w(a||window.StudentRewardSystem)}).catch(function(){}),x()&&setTimeout(Ae,1500),setTimeout(function(){be().catch(function(){})},600)})();

Nhận xét

Bài đăng phổ biến từ blog này

theme/thudao-footer.kho.js · Gộp Reward Core (css v4.2.2 + js f827add) + Minh Hồng footer (css v1.5.7.4 + js 4bff33d) cho chân trang thudao.com

trang/thudao/dang-ky-hoc.html · Bản trước khi chuyển sang kho (tải từ GitHub/jsDelivr)

trang/thudao/bai-viet/benh-cua-thu-dan-duong-dai-the-trien-lam-xu-thu-va-nguy-menh-de-vuot-co-nhan.html · Bản trước khi chuyển sang kho (có video, tải từ GitHub/jsDelivr)