(()=>{var e={};e.id=4817,e.ids=[4817],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")},91846:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>O,routeModule:()=>C,serverHooks:()=>w,workAsyncStorage:()=>R,workUnitAsyncStorage:()=>L});var s={};r.r(s),r.d(s,{GET:()=>$,PATCH:()=>N});var i=r(42706),n=r(28203),a=r(45994),o=r(39187),u=r(98095),l=r(53721),c=r(71747),d=r(23951),p=r(522);let _=[{id:"diagnostica",label:"Diagnostica"},{id:"formativa",label:"Formativa"},{id:"sumativa",label:"Sumativa"},{id:"ensayo_simce",label:"Ensayo SIMCE"},{id:"control",label:"Control"},{id:"prueba_parcial",label:"Prueba Parcial"},{id:"prueba_final",label:"Prueba Final"}],S=[{id:"facil",label:"Facil"},{id:"media",label:"Media"},{id:"dificil",label:"Dificil"}];function f(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 A(e,t=0){let r=Number(e);return Number.isFinite(r)?Math.trunc(r):t}function g(e){return String(e??"").trim()}function T(e){return"single_form"===String(e||"").trim().toLowerCase()?"single_form":"multi_form"}function E(e){if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(Boolean);let t=String(e??"").trim();if(!t)return[];if(t.startsWith("[")&&t.endsWith("]"))try{let e=JSON.parse(t);if(Array.isArray(e))return e.map(e=>String(e||"").trim()).filter(Boolean)}catch{}return t.split(",").map(e=>e.trim()).filter(Boolean)}function j(e){let t=(()=>{if(Array.isArray(e))return e;let t=String(e??"").trim();if(!t)return[];try{let e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}})();if(!t.length)return!1;let r=t[0];return!!r&&"object"==typeof r&&null!=r.bbox}async function h(e){let t=(0,d.T)(),[r]=await t.query("SHOW TABLES LIKE ?",[e]);return r.length>0}async function v(e){for(let t of e){let e=f(t,t);if(await h(e))return e}return null}async function b(e){let t=(0,d.T)(),[r]=await t.query(`SHOW COLUMNS FROM ${(0,p.j)(e)}`);return new Set(r.map(e=>String(e.Field||"").trim()).filter(e=>!!e))}async function y(e,t,r){if(!e)return 0;let s=await b(e),i=m(s,["test_id","testId"]);if(!i)return 0;let n=m(s,["org_id","orgId"]),a=[`${(0,p.j)(i)} = ?`],o=[t];n&&(a.push(`${(0,p.j)(n)} = ?`),o.push(r));let u=`
    SELECT COUNT(*) AS total
    FROM ${(0,p.j)(e)}
    WHERE ${a.join(" AND ")}
  `,l=(0,d.T)(),[c]=await l.query(u,o);return A(c[0]?.total,0)}async function U(e){let t=f(process.env.AUTH_SUBJECTS_TABLE||"subjects","subjects");if(!await h(t))return[];let r=await b(t),s=m(r,["id"]),i=m(r,["name"]),n=m(r,["code"]),a=m(r,["org_id","orgId"]);if(!s||!i||!a)return[];let o=`
    SELECT
      ${(0,p.j)(s)} AS id,
      ${(0,p.j)(i)} AS name,
      ${n?`${(0,p.j)(n)} AS code`:"NULL AS code"}
    FROM ${(0,p.j)(t)}
    WHERE ${(0,p.j)(a)} = ?
    ORDER BY ${(0,p.j)(i)} ASC
  `,u=(0,d.T)(),[l]=await u.query(o,[e]);return l.map(e=>({id:g(e.id),name:g(e.name),code:g(e.code)||null}))}async function $(e,{params:t}){try{var r;if("mysql"!==(0,u.f)())return o.NextResponse.json({error:"Tests API local deshabilitada."},{status:404});let s=(0,l.Z)(e);if(!s)return o.NextResponse.json({error:"No autenticado."},{status:401});if(!(0,c.s)(s,"tests:get")&&!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")}(s.permissions))return o.NextResponse.json({error:"Sin permisos para ver prueba."},{status:403});let i=g(s.orgId);if(!i)return o.NextResponse.json({error:"Sesion sin orgId."},{status:403});let n=g((await t).id);if(!n)return o.NextResponse.json({error:"ID de prueba invalido."},{status:400});let a=f(process.env.AUTH_TESTS_TABLE||"tests","tests");if(!await h(a))return o.NextResponse.json({error:"Tabla tests no existe en MySQL."},{status:500});let $=await b(a),N=m($,["id"]),C=m($,["org_id","orgId"]),R=m($,["name","type_name","title"]),L=m($,["test_title","testTitle","title"]),w=m($,["subject_id","subjectId"]),O=m($,["level","grade_level"]),q=m($,["term","period"]),M=m($,["generation_mode","generationMode"]),x=m($,["passage_count","passageCount"]),I=m($,["alternative_quantity","alternativeQuantity"]),H=m($,["is_child_format","isChildFormat"]),D=m($,["status"]),P=m($,["pdf_path","pdfPath"]);if(!N||!C||!R||!w||!O||!q)return o.NextResponse.json({error:"Esquema tests incompatible en MySQL (faltan columnas clave)."},{status:500});let B=`
      SELECT
        ${(0,p.j)(N)} AS id,
        ${(0,p.j)(R)} AS name,
        ${L?`${(0,p.j)(L)} AS test_title`:"NULL AS test_title"},
        ${(0,p.j)(w)} AS subject_id,
        ${(0,p.j)(O)} AS level,
        ${(0,p.j)(q)} AS term,
        ${M?`${(0,p.j)(M)} AS generation_mode`:"'multi_form' AS generation_mode"},
        ${x?`${(0,p.j)(x)} AS passage_count`:"0 AS passage_count"},
        ${I?`${(0,p.j)(I)} AS alternative_quantity`:"5 AS alternative_quantity"},
        ${H?`${(0,p.j)(H)} AS is_child_format`:"0 AS is_child_format"},
        ${D?`${(0,p.j)(D)} AS status`:"'draft' AS status"},
        ${P?`${(0,p.j)(P)} AS pdf_path`:"NULL AS pdf_path"}
      FROM ${(0,p.j)(a)}
      WHERE ${(0,p.j)(N)} = ?
        AND ${(0,p.j)(C)} = ?
      LIMIT 1
    `,F=(0,d.T)(),[W]=await F.query(B,[n,i]);if(!W.length)return o.NextResponse.json({error:"Prueba no encontrada."},{status:404});let k=W[0],Q={id:g(k.id),name:g(k.name),testTitle:g(k.test_title),subjectId:g(k.subject_id),level:A(k.level,1),term:g(k.term),generationMode:T(k.generation_mode),passageCount:Math.max(0,A(k.passage_count,0)),alternativeQuantity:Math.min(5,Math.max(2,A(k.alternative_quantity,5))),isChildFormat:function(e){if("boolean"==typeof e)return e;let t=String(e??"").trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}(k.is_child_format),status:(r=k.status,"approved"===String(r||"").trim().toLowerCase()?"approved":"draft"),pdfPath:g(k.pdf_path)},J=await v([process.env.AUTH_TEST_QUESTIONS_TABLE||"test_questions","tests_questions","questions"]),Z=[],z=!0;if(J){let e=await b(J),t=m(e,["id","question_id"]),r=m(e,["test_id","testId"]),s=m(e,["org_id","orgId"]),a=m(e,["number","question_number"]),o=m(e,["correct_answer","correctAnswer"]),u=m(e,["learning_objectives","learningObjectives"]),l=m(e,["difficulty"]),c=m(e,["question_points","questionPoints","points"]),d=m(e,["indicators"]),_=m(e,["habilidad","skill"]),S=m(e,["tags"]),f=m(e,["segments"]);if(t&&r){let e=[`${(0,p.j)(r)} = ?`],m=[n];s&&(e.push(`${(0,p.j)(s)} = ?`),m.push(i));let T=a?`ORDER BY ${(0,p.j)(a)} ASC, ${(0,p.j)(t)} ASC`:`ORDER BY ${(0,p.j)(t)} ASC`,h=`
          SELECT
            ${(0,p.j)(t)} AS id,
            ${a?`${(0,p.j)(a)} AS number`:"0 AS number"},
            ${o?`${(0,p.j)(o)} AS correct_answer`:"'' AS correct_answer"},
            ${u?`${(0,p.j)(u)} AS learning_objectives`:"NULL AS learning_objectives"},
            ${l?`${(0,p.j)(l)} AS difficulty`:"NULL AS difficulty"},
            ${c?`${(0,p.j)(c)} AS question_points`:"1 AS question_points"},
            ${d?`${(0,p.j)(d)} AS indicators`:"NULL AS indicators"},
            ${_?`${(0,p.j)(_)} AS habilidad`:"NULL AS habilidad"},
            ${S?`${(0,p.j)(S)} AS tags`:"NULL AS tags"},
            ${f?`${(0,p.j)(f)} AS segments`:"NULL AS segments"}
          FROM ${(0,p.j)(J)}
          WHERE ${e.join(" AND ")}
          ${T}
        `,[v]=await F.query(h,m);Z=v.map((e,t)=>({id:g(e.id)||`q${String(t+1).padStart(2,"0")}`,number:Math.max(1,A(e.number,t+1)),correctAnswer:g(e.correct_answer).toUpperCase(),learningObjectives:E(e.learning_objectives),difficulty:g(e.difficulty),questionPoints:Math.max(1,A(e.question_points,1)),indicators:E(e.indicators),habilidad:g(e.habilidad),tags:E(e.tags)})),f&&v.length>0&&(z=v.every(e=>j(e.segments)))}}let G=await v([process.env.AUTH_TEST_PASSAGES_TABLE||"test_passages","tests_passages","passages"]),Y=await v([process.env.AUTH_TEST_VERSIONS_TABLE||"test_versions","tests_versions","versions"]),K=await v([process.env.AUTH_TEST_ASSIGNMENTS_TABLE||"test_assignments","tests_assignments","assignments"]),V=!0;if(G){let e=await b(G),t=m(e,["test_id","testId"]),r=m(e,["org_id","orgId"]),s=m(e,["segments"]);if(t&&s&&Q.passageCount>0){let e=[`${(0,p.j)(t)} = ?`],a=[n];r&&(e.push(`${(0,p.j)(r)} = ?`),a.push(i));let o=`
          SELECT ${(0,p.j)(s)} AS segments
          FROM ${(0,p.j)(G)}
          WHERE ${e.join(" AND ")}
        `,[u]=await F.query(o,a);V=u.length===Q.passageCount&&u.every(e=>j(e.segments))}}let X=await y(Y,n,i),ee=await y(K,n,i),et={step2:!!Q.pdfPath,step3:"single_form"===Q.generationMode?!!Q.pdfPath:z&&V,step4:"approved"===Q.status||X>0,step5:ee>0},er=await U(i),es=_.some(e=>e.label.toLowerCase()===Q.name.toLowerCase())||!Q.name?_:[{id:`custom_${Q.name.toLowerCase().replace(/\s+/g,"_")}`,label:Q.name},..._];return o.NextResponse.json({test:Q,questions:Z,stepProgress:et,lookups:{subjects:er,evaluationTypes:es,difficultyOptions:S}})}catch(e){return console.error("[GET /api/tests/[id]] error:",e),o.NextResponse.json({error:"Error interno."},{status:500})}}async function N(e,{params:t}){try{let r;if("mysql"!==(0,u.f)())return o.NextResponse.json({error:"Tests API local deshabilitada."},{status:404});let s=(0,l.Z)(e);if(!s)return o.NextResponse.json({error:"No autenticado."},{status:401});if(!(0,c.s)(s,"tests:update"))return o.NextResponse.json({error:"Sin permisos para actualizar prueba."},{status:403});let i=g(s.orgId);if(!i)return o.NextResponse.json({error:"Sesion sin orgId."},{status:403});let n=g((await t).id);if(!n)return o.NextResponse.json({error:"ID de prueba invalido."},{status:400});let a=await e.json().catch(()=>null);if(!a||"object"!=typeof a)return o.NextResponse.json({error:"Payload invalido."},{status:400});try{r=function(e){let t=T(e?.generationMode),r=Math.min(5,Math.max(2,A(e?.alternativeQuantity,5))),s=Math.min(12,Math.max(1,A(e?.level,1))),i=Math.max(0,A(e?.passageCount,0)),n=(Array.isArray(e?.questions)?e.questions:[]).map((e,t)=>{let r=Math.max(1,A(e?.number,t+1)),s=g(e?.correctAnswer).toUpperCase();if(!s)throw Error(`Pregunta ${r} sin respuesta correcta.`);let i=Math.max(1,A(e?.questionPoints,1)),n=Array.isArray(e?.tags)?e.tags:"string"==typeof e?.tags?e.tags.split(",").map(e=>e.trim()).filter(Boolean):[];return{id:g(e?.id)||void 0,number:r,correctAnswer:s,learningObjectives:E(e?.learningObjectives),difficulty:g(e?.difficulty),questionPoints:i,indicators:E(e?.indicators),habilidad:g(e?.habilidad),tags:n}});if(!n.length)throw Error("Debes enviar al menos una pregunta.");return{name:g(e?.name),testTitle:g(e?.testTitle),subjectId:g(e?.subjectId),level:s,term:g(e?.term),generationMode:t,passageCount:i,alternativeQuantity:r,isChildFormat:!!e?.isChildFormat,questions:n}}(a)}catch(e){return o.NextResponse.json({error:e?.message||"Payload invalido."},{status:400})}let _=f(process.env.AUTH_TESTS_TABLE||"tests","tests");if(!await h(_))return o.NextResponse.json({error:"Tabla tests no existe en MySQL."},{status:500});let S=await b(_),j=m(S,["id"]),y=m(S,["org_id","orgId"]),U=m(S,["name","type_name","title"]),$=m(S,["test_title","testTitle","title"]),N=m(S,["subject_id","subjectId"]),C=m(S,["level","grade_level"]),R=m(S,["term","period"]),L=m(S,["generation_mode","generationMode"]),w=m(S,["passage_count","passageCount"]),O=m(S,["alternative_quantity","alternativeQuantity"]),q=m(S,["is_child_format","isChildFormat"]),M=m(S,["question_count","questionCount"]),x=m(S,["updated_by","updatedBy"]),I=m(S,["updated_at","updatedAt"]);if(!j||!y||!U||!N||!C||!R)return o.NextResponse.json({error:"Esquema tests incompatible en MySQL (faltan columnas clave)."},{status:500});let H=(0,d.T)(),D=await H.getConnection();try{await D.beginTransaction();let[e]=await D.query(`
          SELECT ${(0,p.j)(j)} AS id
          FROM ${(0,p.j)(_)}
          WHERE ${(0,p.j)(j)} = ?
            AND ${(0,p.j)(y)} = ?
          LIMIT 1
        `,[n,i]);if(!e.length)return await D.rollback(),o.NextResponse.json({error:"Prueba no encontrada."},{status:404});let t=[],a=[],u=(e,r)=>{e&&(t.push(`${(0,p.j)(e)} = ?`),a.push(r))};u(U,r.name),u($,r.testTitle||null),u(N,r.subjectId),u(C,r.level),u(R,r.term),u(L,r.generationMode),u(w,r.passageCount),u(O,r.alternativeQuantity),u(q,r.isChildFormat?1:0),u(M,r.questions.length),u(x,g(s.id)||null),I&&t.push(`${(0,p.j)(I)} = UTC_TIMESTAMP()`),t.length>0&&await D.query(`
            UPDATE ${(0,p.j)(_)}
            SET ${t.join(", ")}
            WHERE ${(0,p.j)(j)} = ?
              AND ${(0,p.j)(y)} = ?
            LIMIT 1
          `,[...a,n,i]);let l=await v([process.env.AUTH_TEST_QUESTIONS_TABLE||"test_questions","tests_questions","questions"]);if(l){let e=await b(l),t=m(e,["id","question_id"]),a=m(e,["test_id","testId"]),o=m(e,["org_id","orgId"]),u=m(e,["number","question_number"]),c=m(e,["correct_answer","correctAnswer"]),d=m(e,["learning_objectives","learningObjectives"]),_=m(e,["difficulty"]),S=m(e,["alternative_quantity","alternativeQuantity"]),f=m(e,["question_points","questionPoints","points"]),A=m(e,["indicators"]),T=m(e,["habilidad","skill"]),E=m(e,["tags"]),j=m(e,["updated_by","updatedBy"]),h=m(e,["updated_at","updatedAt"]);if(t&&a)for(let e of r.questions){let m=e.id||`q${String(e.number).padStart(2,"0")}`,v=[t,a],b=[m,n],y=(e,t)=>{e&&(v.push(e),b.push(t))};y(o,i),y(u,e.number),y(c,e.correctAnswer),y(d,JSON.stringify(e.learningObjectives||[])),y(_,e.difficulty||null),y(S,r.alternativeQuantity),y(f,e.questionPoints||1),y(A,JSON.stringify(e.indicators||[])),y(T,e.habilidad||null),y(E,JSON.stringify(Array.isArray(e.tags)?e.tags:[])),y(j,g(s.id)||null);let U=v.map(()=>"?").join(", "),$=v.filter(e=>e!==t).map(e=>`${(0,p.j)(e)} = VALUES(${(0,p.j)(e)})`);h&&$.push(`${(0,p.j)(h)} = UTC_TIMESTAMP()`);let N=`
              INSERT INTO ${(0,p.j)(l)} (
                ${v.map(e=>(0,p.j)(e)).join(", ")}
              ) VALUES (${U})
              ON DUPLICATE KEY UPDATE
                ${$.join(", ")}
            `;await D.query(N,b)}}await D.commit()}catch(e){throw await D.rollback(),e}finally{D.release()}return o.NextResponse.json({success:!0})}catch(e){return console.error("[PATCH /api/tests/[id]] error:",e),o.NextResponse.json({error:"Error interno."},{status:500})}}let C=new i.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/tests/[id]/route",pathname:"/api/tests/[id]",filename:"route",bundlePath:"app/api/tests/[id]/route"},resolvedPagePath:"C:\\omrwebapp-git-roregar.cl\\src\\app\\api\\tests\\[id]\\route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:R,workUnitAsyncStorage:L,serverHooks:w}=C;function O(){return(0,a.patchFetch)({workAsyncStorage:R,workUnitAsyncStorage:L})}},96487:()=>{},78335:()=>{},71747:(e,t,r)=>{"use strict";function s(e){return String(e||"").trim().toLowerCase()}function i(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:()=>i})},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:()=>u});var s=r(60820);let i=null;function n(e){for(let t of e){let e=process.env[t];if(e&&String(e).trim())return String(e).trim()}}function a(e,t){let r=n(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 u(){if(i)return i;let e=a(["AUTH_DB_HOST","DB_HOST"],"database host"),t=a(["AUTH_DB_USER","DB_USERNAME","DB_USER"],"database user"),r=a(["AUTH_DB_PASSWORD","DB_PASSWORD"],"database password"),u=a(["AUTH_DB_NAME","DB_DATABASE"],"database name"),l=o(n(["AUTH_DB_PORT","DB_PORT"]),3306),c=o(n(["AUTH_DB_POOL_SIZE","DB_POOL_SIZE"]),10);return i=s.createPool({host:e,port:l,user:t,password:r,database:u,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 i(e,t){let r=String(e||t||"").trim();if(r&&"-"!==r)return s(r)}function n(e){return`\`${s(e)}\``}function a(){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:i(process.env.AUTH_USERS_STATUS_COLUMN,"status"),firebaseUidColumn:i(process.env.AUTH_USERS_FIREBASE_UID_COLUMN,"firebase_uid"),firstNameColumn:i(process.env.AUTH_USERS_FIRST_NAME_COLUMN,"first_name"),lastNameColumn:i(process.env.AUTH_USERS_LAST_NAME_COLUMN,"last_name"),displayNameColumn:i(process.env.AUTH_USERS_DISPLAY_NAME_COLUMN,"display_name"),phoneColumn:i(process.env.AUTH_USERS_PHONE_COLUMN,"phone"),roleColumn:i(process.env.AUTH_USERS_ROLE_COLUMN,"role"),orgIdColumn:i(process.env.AUTH_USERS_ORG_ID_COLUMN,"org_id"),institutionIdsColumn:i(process.env.AUTH_USERS_INSTITUTION_IDS_COLUMN,"institution_ids"),createdAtColumn:i(process.env.AUTH_USERS_CREATED_AT_COLUMN,"created_at"),updatedAtColumn:i(process.env.AUTH_USERS_UPDATED_AT_COLUMN,"updated_at")}}r.d(t,{M:()=>a,j:()=>n})},53721:(e,t,r)=>{"use strict";r.d(t,{Z:()=>i});var s=r(89249);function i(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:()=>S,C0:()=>f,CA:()=>l,Q7:()=>d,zP:()=>_});var s=r(77598),i=r.n(s);let n="omr_local_session";function a(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 u(){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||n).trim()||n}function c(){let e=Number(process.env.AUTH_SESSION_TTL_HOURS||168);return Math.round(3600*(Number.isFinite(e)&&e>0?e:168))}function d(e){let t=Math.floor(Date.now()/1e3),r={v:1,iat:t,exp:t+c(),user:e},s=a(JSON.stringify({alg:"HS256",typ:"JWT"})),n=a(JSON.stringify(r)),o=`${s}.${n}`,l=a(i().createHmac("sha256",u()).update(o).digest());return`${o}.${l}`}function p(e){try{return JSON.parse(e)}catch{return null}}function _(e){let t=String(e||"").trim().split(".");if(3!==t.length)return null;let[r,s,n]=t;if(!r||!s||!n)return null;let l=`${r}.${s}`,c=a(i().createHmac("sha256",u()).update(l).digest()),d=Buffer.from(c),_=Buffer.from(n);if(d.length!==_.length||!i().timingSafeEqual(d,_))return null;let S=p(o(r).toString("utf8"));if(!S||"HS256"!==S.alg||"JWT"!==S.typ)return null;let f=p(o(s).toString("utf8"));if(!f||1!==f.v)return null;let m=Math.floor(Date.now()/1e3);if(!Number.isFinite(f.exp)||f.exp<=m)return null;let A=f.user;return A&&String(A.id||"").trim()&&String(A.email||"").trim()?f:null}function S(e,t){e.cookies.set(l(),t,{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:c()})}function f(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(91846));module.exports=s})();