(()=>{var e={};e.id=9289,e.ids=[9289],e.modules={28303:e=>{function t(e){var t=Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=28303,e.exports=t},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},79428:e=>{"use strict";e.exports=require("buffer")},55511:e=>{"use strict";e.exports=require("crypto")},94735:e=>{"use strict";e.exports=require("events")},91645:e=>{"use strict";e.exports=require("net")},19771:e=>{"use strict";e.exports=require("process")},27910:e=>{"use strict";e.exports=require("stream")},41204:e=>{"use strict";e.exports=require("string_decoder")},66136:e=>{"use strict";e.exports=require("timers")},34631:e=>{"use strict";e.exports=require("tls")},79551:e=>{"use strict";e.exports=require("url")},28354:e=>{"use strict";e.exports=require("util")},74075:e=>{"use strict";e.exports=require("zlib")},4573:e=>{"use strict";e.exports=require("node:buffer")},77598:e=>{"use strict";e.exports=require("node:crypto")},53053:e=>{"use strict";e.exports=require("node:diagnostics_channel")},76430:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>N,routeModule:()=>g,serverHooks:()=>T,workAsyncStorage:()=>A,workUnitAsyncStorage:()=>E});var s={};r.r(s),r.d(s,{GET:()=>U});var n=r(42706),i=r(28203),u=r(45994),o=r(39187),a=r(98095),l=r(53721),c=r(71747),_=r(23951),p=r(522);function S(e,t){let r=String(e||t).trim();if(!/^[A-Za-z0-9_]+$/.test(r))throw Error(`Invalid SQL identifier: ${r}`);return r}function m(e,t){for(let r of t)if(e.has(r))return r;return null}function d(e){return new Set(e.map(e=>String(e.Field||"").trim()).filter(e=>!!e))}function f(e){let t=Number(e);return Number.isFinite(t)?Math.trunc(t):0}async function U(e){try{if("mysql"!==(0,a.f)())return o.NextResponse.json({error:"Tests API local deshabilitada."},{status:404});let t=(0,l.Z)(e);if(!t)return o.NextResponse.json({error:"No autenticado."},{status:401});if(!(0,c.s)(t,"tests:list")&&!function(e=[]){let t=new Set(e.map(e=>String(e||"").trim().toLowerCase()));return t.has("tests:list")||t.has("tests:get")||t.has("tests:update")||t.has("tests:create")||t.has("tests:assign")}(t.permissions))return o.NextResponse.json({error:"Sin permisos para listar pruebas."},{status:403});let r=String(t.orgId||"").trim();if(!r)return o.NextResponse.json({error:"Sesion sin orgId."},{status:403});let s=S(process.env.AUTH_TESTS_TABLE||"tests","tests"),n=S(process.env.AUTH_SUBJECTS_TABLE||"subjects","subjects"),i=(0,_.T)(),[u]=await i.query(`SHOW COLUMNS FROM ${(0,p.j)(s)}`),U=d(u),g=m(U,["id"]),A=m(U,["org_id","orgId"]),E=m(U,["name","type_name","title"]),T=m(U,["test_title","testTitle","title"]),N=m(U,["status"]),O=m(U,["subject_id","subjectId"]),C=m(U,["level","grade_level"]),R=m(U,["term","period"]),v=m(U,["question_count","questionCount"]),L=m(U,["passage_count","passageCount"]),b=m(U,["created_at","createdAt"]);if(!g||!A||!E||!O||!C||!R)return o.NextResponse.json({error:"Esquema tests incompatible en MySQL (faltan columnas clave)."},{status:500});let h=new Set;try{let[e]=await i.query(`SHOW COLUMNS FROM ${(0,p.j)(n)}`);h=d(e)}catch{h=new Set}let x=m(h,["id"]),H=m(h,["org_id","orgId"]),D=m(h,["name"]),$=m(h,["code"]),M=!!(x&&D),j=e=>`t.${(0,p.j)(e)}`,q=e=>`s.${(0,p.j)(e)}`,w=(e,t)=>`${e} AS ${(0,p.j)(t)}`,I=[w(j(g),"id"),w(j(E),"name"),w(T?j(T):"NULL","test_title"),w(N?j(N):"'draft'","status"),w(j(O),"subject_id"),w(j(C),"level"),w(j(R),"term"),w(v?j(v):"NULL","question_count"),w(L?j(L):"NULL","passage_count"),w(b?j(b):"NULL","created_at"),w(M&&D?q(D):"NULL","subject_name"),w(M&&$?q($):"NULL","subject_code")],B=M?`LEFT JOIN ${(0,p.j)(n)} s ON ${q(x)} = ${j(O)}${H?` AND ${q(H)} = ${j(A)}`:""}`:"",y=b?`${j(b)} DESC, ${j(g)} DESC`:`${j(g)} DESC`,P=`
      SELECT
        ${I.join(",\n        ")}
      FROM ${(0,p.j)(s)} t
      ${B}
      WHERE ${j(A)} = ?
      ORDER BY ${y}
    `,[F]=await i.query(P,[r]),W=F.map(e=>({id:String(e.id||"").trim(),name:String(e.name||"").trim()||"Prueba",testTitle:String(e.test_title||"").trim()||null,status:String(e.status||"").trim().toLowerCase()||"draft",subjectId:String(e.subject_id||"").trim(),level:f(e.level),term:String(e.term||"").trim(),questionCount:null==e.question_count?null:Number.isFinite(Number(e.question_count))?f(e.question_count):null,passageCount:null==e.passage_count?null:Number.isFinite(Number(e.passage_count))?f(e.passage_count):null,createdAt:function(e){if(null==e)return 0;if(e instanceof Date)return e.getTime();let t=Number(e);if(Number.isFinite(t)&&t>0)return t;let r=Date.parse(String(e));return Number.isFinite(r)?r:0}(e.created_at)})),k=[];if(M&&x&&D&&H){let e=`
        SELECT
          ${(0,p.j)(x)} AS id,
          ${(0,p.j)(D)} AS name,
          ${$?`${(0,p.j)($)} AS code`:"NULL AS code"}
        FROM ${(0,p.j)(n)}
        WHERE ${(0,p.j)(H)} = ?
        ORDER BY ${(0,p.j)(D)} ASC
      `,[t]=await i.query(e,[r]);k=t.map(e=>({id:String(e.id||"").trim(),name:String(e.name||"").trim(),code:String(e.code||"").trim()||null}))}return o.NextResponse.json({tests:W,subjects:k})}catch(e){return console.error("[GET /api/tests] error:",e),o.NextResponse.json({error:"Error interno."},{status:500})}}let g=new n.AppRouteRouteModule({definition:{kind:i.RouteKind.APP_ROUTE,page:"/api/tests/route",pathname:"/api/tests",filename:"route",bundlePath:"app/api/tests/route"},resolvedPagePath:"C:\\omrwebapp-git-roregar.cl\\src\\app\\api\\tests\\route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:A,workUnitAsyncStorage:E,serverHooks:T}=g;function N(){return(0,u.patchFetch)({workAsyncStorage:A,workUnitAsyncStorage:E})}},96487:()=>{},78335:()=>{},71747:(e,t,r)=>{"use strict";function s(e){return String(e||"").trim().toLowerCase()}function n(e,t){if(!e)return!1;if(function(e){let t=s(e);return"admin"===t||t.startsWith("admin_")||t.includes(":admin")}(e.roleId))return!0;let r=s(t);return(e.permissions||[]).some(e=>s(e)===r)}r.d(t,{s:()=>n})},98095:(e,t,r)=>{"use strict";function s(){return"mysql"===String(process.env.AUTH_MODE||process.env.NEXT_PUBLIC_AUTH_MODE||"").trim().toLowerCase()?"mysql":"firebase"}r.d(t,{f:()=>s})},23951:(e,t,r)=>{"use strict";r.d(t,{T:()=>a});var s=r(60820);let n=null;function i(e){for(let t of e){let e=process.env[t];if(e&&String(e).trim())return String(e).trim()}}function u(e,t){let r=i(e);if(!r)throw Error(`Missing ${t}. Set one of: ${e.join(", ")}`);return r}function o(e,t){if(!e)return t;let r=Number(e);return Number.isFinite(r)?r:t}function a(){if(n)return n;let e=u(["AUTH_DB_HOST","DB_HOST"],"database host"),t=u(["AUTH_DB_USER","DB_USERNAME","DB_USER"],"database user"),r=u(["AUTH_DB_PASSWORD","DB_PASSWORD"],"database password"),a=u(["AUTH_DB_NAME","DB_DATABASE"],"database name"),l=o(i(["AUTH_DB_PORT","DB_PORT"]),3306),c=o(i(["AUTH_DB_POOL_SIZE","DB_POOL_SIZE"]),10);return n=s.createPool({host:e,port:l,user:t,password:r,database:a,waitForConnections:!0,connectionLimit:c,queueLimit:0,charset:"utf8mb4"})}},522:(e,t,r)=>{"use strict";function s(e,t){let r=String(e||t||"").trim();if(!r)return"";if(!/^[A-Za-z0-9_]+$/.test(r))throw Error(`Invalid SQL identifier: ${r}`);return r}function n(e,t){let r=String(e||t||"").trim();if(r&&"-"!==r)return s(r)}function i(e){return`\`${s(e)}\``}function u(){return{usersTable:s(process.env.AUTH_USERS_TABLE,"users"),passwordResetsTable:s(process.env.AUTH_PASSWORD_RESETS_TABLE,"auth_password_resets"),idColumn:s(process.env.AUTH_USERS_ID_COLUMN,"id"),emailColumn:s(process.env.AUTH_USERS_EMAIL_COLUMN,"email"),passwordColumn:s(process.env.AUTH_USERS_PASSWORD_COLUMN,"password"),statusColumn:n(process.env.AUTH_USERS_STATUS_COLUMN,"status"),firebaseUidColumn:n(process.env.AUTH_USERS_FIREBASE_UID_COLUMN,"firebase_uid"),firstNameColumn:n(process.env.AUTH_USERS_FIRST_NAME_COLUMN,"first_name"),lastNameColumn:n(process.env.AUTH_USERS_LAST_NAME_COLUMN,"last_name"),displayNameColumn:n(process.env.AUTH_USERS_DISPLAY_NAME_COLUMN,"display_name"),phoneColumn:n(process.env.AUTH_USERS_PHONE_COLUMN,"phone"),roleColumn:n(process.env.AUTH_USERS_ROLE_COLUMN,"role"),orgIdColumn:n(process.env.AUTH_USERS_ORG_ID_COLUMN,"org_id"),institutionIdsColumn:n(process.env.AUTH_USERS_INSTITUTION_IDS_COLUMN,"institution_ids"),createdAtColumn:n(process.env.AUTH_USERS_CREATED_AT_COLUMN,"created_at"),updatedAtColumn:n(process.env.AUTH_USERS_UPDATED_AT_COLUMN,"updated_at")}}r.d(t,{M:()=>u,j:()=>i})},53721:(e,t,r)=>{"use strict";r.d(t,{Z:()=>n});var s=r(89249);function n(e){let t=String(e.cookies.get(s.CA())?.value||"").trim();if(!t)return null;let r=(0,s.zP)(t);return r?.user||null}},89249:(e,t,r)=>{"use strict";r.d(t,{$G:()=>m,C0:()=>d,CA:()=>l,Q7:()=>_,zP:()=>S});var s=r(77598),n=r.n(s);let i="omr_local_session";function u(e){return(Buffer.isBuffer(e)?e:Buffer.from(e)).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function o(e){let t=String(e||"").replace(/-/g,"+").replace(/_/g,"/"),r=t.length%4==0?"":"=".repeat(4-t.length%4);return Buffer.from(t+r,"base64")}function a(){return String(process.env.AUTH_SESSION_SECRET||process.env.NEXTAUTH_SECRET||process.env.AUTH_DB_PASSWORD||"").trim()||"omr-local-session-dev-secret-change-me"}function l(){return String(process.env.AUTH_SESSION_COOKIE_NAME||i).trim()||i}function c(){let e=Number(process.env.AUTH_SESSION_TTL_HOURS||168);return Math.round(3600*(Number.isFinite(e)&&e>0?e:168))}function _(e){let t=Math.floor(Date.now()/1e3),r={v:1,iat:t,exp:t+c(),user:e},s=u(JSON.stringify({alg:"HS256",typ:"JWT"})),i=u(JSON.stringify(r)),o=`${s}.${i}`,l=u(n().createHmac("sha256",a()).update(o).digest());return`${o}.${l}`}function p(e){try{return JSON.parse(e)}catch{return null}}function S(e){let t=String(e||"").trim().split(".");if(3!==t.length)return null;let[r,s,i]=t;if(!r||!s||!i)return null;let l=`${r}.${s}`,c=u(n().createHmac("sha256",a()).update(l).digest()),_=Buffer.from(c),S=Buffer.from(i);if(_.length!==S.length||!n().timingSafeEqual(_,S))return null;let m=p(o(r).toString("utf8"));if(!m||"HS256"!==m.alg||"JWT"!==m.typ)return null;let d=p(o(s).toString("utf8"));if(!d||1!==d.v)return null;let f=Math.floor(Date.now()/1e3);if(!Number.isFinite(d.exp)||d.exp<=f)return null;let U=d.user;return U&&String(U.id||"").trim()&&String(U.email||"").trim()?d:null}function m(e,t){e.cookies.set(l(),t,{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:c()})}function d(e){e.cookies.set(l(),"",{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:0})}}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[1989,5452,820],()=>r(76430));module.exports=s})();