(()=>{var e={};e.id=7819,e.ids=[7819],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},5486:e=>{"use strict";e.exports=require("bcrypt")},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},12909:(e,r,t)=>{"use strict";function a(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}function s(e){let r=e.headers.get("authorization");if(r&&r.startsWith("Bearer "))return r.slice(7);let t=e.cookies.get("admin_token")?.value;if(t)return t;let a=e.cookies.get("token")?.value;return a||null}t.d(r,{V:()=>s,u:()=>a})},27910:e=>{"use strict";e.exports=require("stream")},28354:e=>{"use strict";e.exports=require("util")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},55511:e=>{"use strict";e.exports=require("crypto")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},63696:(e,r,t)=>{"use strict";t.r(r),t.d(r,{patchFetch:()=>P,routeModule:()=>k,serverHooks:()=>j,workAsyncStorage:()=>w,workUnitAsyncStorage:()=>v});var a={};t.r(a),t.d(a,{GET:()=>g,POST:()=>h});var s=t(96559),n=t(48088),o=t(37719),i=t(32190),u=t(43205),c=t.n(u),p=t(5486),d=t.n(p),l=t(96330),m=t(12909);let x=new l.PrismaClient,f=(0,m.u)();async function y(e){let r=(0,m.V)(e);if(!r)return null;try{let e=c().verify(r,f);if(e.isGlobalAdmin&&e.globalAdminId)return e}catch{}return null}async function g(e){try{if(!await y(e))return i.NextResponse.json({error:"Unauthorized"},{status:401});let r=(await x.company.findMany({include:{_count:{select:{users:!0,products:!0,companyMarketplaces:!0,companyPackages:!0}},companyPackages:{where:{status:!0},include:{package:!0},orderBy:{packageEndDate:"asc"}}},orderBy:{id:"desc"}})).map(e=>{let r=new Date,t=e.companyPackages.filter(e=>new Date(e.packageEndDate)>=r),a=t.length>0?t[0]:null;return{id:e.id,name:e.name,address:e.address,taxOffice:e.taxOffice,taxNumber:e.taxNumber,contactPerson:e.contactPerson,phone:e.phone,email:e.email,isApproved:e.isApproved,createdAt:e.createdAt.toISOString(),updatedAt:e.updatedAt.toISOString(),userCount:e._count.users,productCount:e._count.products,marketplaceCount:e._count.companyMarketplaces,packageCount:e._count.companyPackages,activePackage:a?{name:a.package.name,endDate:a.packageEndDate.toISOString()}:null}});return i.NextResponse.json({companies:r})}catch(e){return console.error("Companies list error:",e),i.NextResponse.json({error:"Server error"},{status:500})}}async function h(e){try{if(!await y(e))return i.NextResponse.json({error:"Unauthorized"},{status:401});let{name:r,address:t,taxOffice:a,taxNumber:s,contactPerson:n,phone:o,email:u}=await e.json();if(!r)return i.NextResponse.json({error:"Company name is required"},{status:400});if(await x.company.findUnique({where:{name:r}}))return i.NextResponse.json({error:"Company with this name already exists"},{status:400});let c=await x.company.create({data:{name:r,address:t,taxOffice:a,taxNumber:s,contactPerson:n,phone:o,email:u}});if(n&&u)if(await x.user.findUnique({where:{email:u}}))console.warn(`Email ${u} already exists, skipping user creation`);else{let e=n.trim().split(/\s+/),r=e[0]||n,t=e.slice(1).join(" ")||"Admin",a=await d().hash("123456",10);await x.user.create({data:{email:u,password:a,name:r,surname:t,phoneNumber:o||null,companyId:c.id,isAdmin:!0}})}return i.NextResponse.json({company:c},{status:201})}catch(e){return console.error("Create company error:",e),i.NextResponse.json({error:"Server error"},{status:500})}}let k=new s.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/admin/companies/route",pathname:"/api/admin/companies",filename:"route",bundlePath:"app/api/admin/companies/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/admin/companies/route.ts",nextConfigOutput:"standalone",userland:a}),{workAsyncStorage:w,workUnitAsyncStorage:v,serverHooks:j}=k;function P(){return(0,o.patchFetch)({workAsyncStorage:w,workUnitAsyncStorage:v})}},78335:()=>{},79428:e=>{"use strict";e.exports=require("buffer")},96330:e=>{"use strict";e.exports=require("@prisma/client")},96487:()=>{}};var r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[4447,580,3205],()=>t(63696));module.exports=a})();