(()=>{var e={};e.id=318,e.ids=[318],e.modules={28303:e=>{function r(e){var r=Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}r.keys=()=>[],r.resolve=r,r.id=28303,e.exports=r},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")},99862:(e,r,t)=>{"use strict";t.r(r),t.d(r,{patchFetch:()=>_,routeModule:()=>f,serverHooks:()=>g,workAsyncStorage:()=>d,workUnitAsyncStorage:()=>S});var s={};t.r(s),t.d(s,{GET:()=>m});var i=t(42706),n=t(28203),u=t(45994),o=t(39187),a=t(98095),l=t(53721),c=t(71747),p=t(23951);async function m(e){try{if("mysql"!==(0,a.f)())return o.NextResponse.json({error:"Users API local deshabilitada."},{status:404});let r=(0,l.Z)(e);if(!r)return o.NextResponse.json({error:"No autenticado."},{status:401});if(!(0,c.s)(r,"users:list"))return o.NextResponse.json({error:"Sin permisos para listar usuarios."},{status:403});let t=String(r.orgId||"").trim();if(!t)return o.NextResponse.json({error:"Sesion sin orgId."},{status:403});let s=(0,p.T)(),i=`
      SELECT
        u.id,
        u.email,
        u.status,
        u.display_name,
        u.first_name,
        u.last_name,
        u.role_id,
        r.name AS role_name
      FROM users u
      LEFT JOIN roles r ON r.id = u.role_id
      WHERE u.org_id = ?
      ORDER BY
        COALESCE(NULLIF(u.display_name, ''), NULLIF(CONCAT(TRIM(u.first_name), ' ', TRIM(u.last_name)), ''), u.email) ASC
    `,[n]=await s.query(i,[t]),u=n.map(e=>{let r=String(e.role_id||"").trim(),t=String(e.role_name||"").trim()||r||"sin_rol";return{id:String(e.id||"").trim(),displayName:function(e){let r=String(e.display_name||"").trim();if(r)return r;let t=String(e.first_name||"").trim(),s=String(e.last_name||"").trim();return String(`${t} ${s}`).trim()||String(e.email||"").trim()}(e),email:String(e.email||"").trim().toLowerCase(),role:t,roleId:r,status:function(e){let r=String(e||"").trim().toLowerCase();return"inactive"===r?"inactive":"pending_invitation"===r?"pending_invitation":"active"}(e.status)}});return o.NextResponse.json({users:u})}catch(e){return console.error("[GET /api/users] error:",e),o.NextResponse.json({error:"Error interno."},{status:500})}}let f=new i.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/users/route",pathname:"/api/users",filename:"route",bundlePath:"app/api/users/route"},resolvedPagePath:"C:\\omrwebapp-git-roregar.cl\\src\\app\\api\\users\\route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:d,workUnitAsyncStorage:S,serverHooks:g}=f;function _(){return(0,u.patchFetch)({workAsyncStorage:d,workUnitAsyncStorage:S})}},96487:()=>{},78335:()=>{},71747:(e,r,t)=>{"use strict";function s(e){return String(e||"").trim().toLowerCase()}function i(e,r){if(!e)return!1;if(function(e){let r=s(e);return"admin"===r||r.startsWith("admin_")||r.includes(":admin")}(e.roleId))return!0;let t=s(r);return(e.permissions||[]).some(e=>s(e)===t)}t.d(r,{s:()=>i})},98095:(e,r,t)=>{"use strict";function s(){return"mysql"===String(process.env.AUTH_MODE||process.env.NEXT_PUBLIC_AUTH_MODE||"").trim().toLowerCase()?"mysql":"firebase"}t.d(r,{f:()=>s})},23951:(e,r,t)=>{"use strict";t.d(r,{T:()=>a});var s=t(60820);let i=null;function n(e){for(let r of e){let e=process.env[r];if(e&&String(e).trim())return String(e).trim()}}function u(e,r){let t=n(e);if(!t)throw Error(`Missing ${r}. Set one of: ${e.join(", ")}`);return t}function o(e,r){if(!e)return r;let t=Number(e);return Number.isFinite(t)?t:r}function a(){if(i)return i;let e=u(["AUTH_DB_HOST","DB_HOST"],"database host"),r=u(["AUTH_DB_USER","DB_USERNAME","DB_USER"],"database user"),t=u(["AUTH_DB_PASSWORD","DB_PASSWORD"],"database password"),a=u(["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:r,password:t,database:a,waitForConnections:!0,connectionLimit:c,queueLimit:0,charset:"utf8mb4"})}},53721:(e,r,t)=>{"use strict";t.d(r,{Z:()=>i});var s=t(89249);function i(e){let r=String(e.cookies.get(s.CA())?.value||"").trim();if(!r)return null;let t=(0,s.zP)(r);return t?.user||null}},89249:(e,r,t)=>{"use strict";t.d(r,{$G:()=>d,C0:()=>S,CA:()=>l,Q7:()=>p,zP:()=>f});var s=t(77598),i=t.n(s);let n="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 r=String(e||"").replace(/-/g,"+").replace(/_/g,"/"),t=r.length%4==0?"":"=".repeat(4-r.length%4);return Buffer.from(r+t,"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||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 p(e){let r=Math.floor(Date.now()/1e3),t={v:1,iat:r,exp:r+c(),user:e},s=u(JSON.stringify({alg:"HS256",typ:"JWT"})),n=u(JSON.stringify(t)),o=`${s}.${n}`,l=u(i().createHmac("sha256",a()).update(o).digest());return`${o}.${l}`}function m(e){try{return JSON.parse(e)}catch{return null}}function f(e){let r=String(e||"").trim().split(".");if(3!==r.length)return null;let[t,s,n]=r;if(!t||!s||!n)return null;let l=`${t}.${s}`,c=u(i().createHmac("sha256",a()).update(l).digest()),p=Buffer.from(c),f=Buffer.from(n);if(p.length!==f.length||!i().timingSafeEqual(p,f))return null;let d=m(o(t).toString("utf8"));if(!d||"HS256"!==d.alg||"JWT"!==d.typ)return null;let S=m(o(s).toString("utf8"));if(!S||1!==S.v)return null;let g=Math.floor(Date.now()/1e3);if(!Number.isFinite(S.exp)||S.exp<=g)return null;let _=S.user;return _&&String(_.id||"").trim()&&String(_.email||"").trim()?S:null}function d(e,r){e.cookies.set(l(),r,{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:c()})}function S(e){e.cookies.set(l(),"",{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:0})}}};var r=require("../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[1989,5452,820],()=>t(99862));module.exports=s})();