(()=>{var e={};e.id=2314,e.ids=[2314],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},12909:(e,t,r)=>{"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 t=e.headers.get("authorization");if(t&&t.startsWith("Bearer "))return t.slice(7);let r=e.cookies.get("admin_token")?.value;if(r)return r;let a=e.cookies.get("token")?.value;return a||null}r.d(t,{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")},53500:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>w,routeModule:()=>y,serverHooks:()=>g,workAsyncStorage:()=>h,workUnitAsyncStorage:()=>x});var a={};r.r(a),r.d(a,{POST:()=>k});var s=r(96559),n=r(48088),i=r(37719),o=r(32190),p=r(43205),c=r.n(p),u=r(96330),l=r(12909),d=r(81437);let m=new u.PrismaClient,f=(0,l.u)();async function k(e){try{let t,r=(0,l.V)(e);if(!r)return o.NextResponse.json({error:"Authorization token gerekli"},{status:401});try{t=c().verify(r,f)}catch(e){return o.NextResponse.json({error:"Ge\xe7ersiz token"},{status:401})}let a=(await e.formData()).get("file");if(!a)return await m.$disconnect(),o.NextResponse.json({error:"Excel dosyası gerekli"},{status:400});let s=await m.user.findUnique({where:{id:t.userId},include:{company:{include:{companyMarketplaces:{include:{marketplace:!0}}}},userMarketplacePermissions:{include:{companyMarketplace:{include:{marketplace:!0}}}}}});if(!s)return await m.$disconnect(),o.NextResponse.json({error:"Kullanıcı bulunamadı"},{status:404});let n=s.userMarketplacePermissions.map(e=>e.companyMarketplaceId),i=s.company.companyMarketplaces.filter(e=>n.includes(e.id)||s.isAdmin),p=await a.arrayBuffer(),u=d.LF(p),k=u.SheetNames[0],y=u.Sheets[k],h=d.Wp.sheet_to_json(y);if(!Array.isArray(h)||0===h.length)return await m.$disconnect(),o.NextResponse.json({error:"Excel dosyası boş veya ge\xe7ersiz format"},{status:400});let x=new Map;i.forEach(e=>{x.has(e.marketplaceId)||x.set(e.marketplaceId,{marketplaceId:e.marketplaceId,marketplaceName:e.marketplace.name,companyMarketplaceIds:[]}),x.get(e.marketplaceId).companyMarketplaceIds.push(e.id)});let g=[],w=h[0],j=Object.keys(w),v=j.find(e=>e.toLowerCase().includes("desi")||"desi"===e.toLowerCase());if(!v)return await m.$disconnect(),o.NextResponse.json({error:'Excel dosyasında "Desi" s\xfctunu bulunamadı'},{status:400});for(let e of h){let t=e[v];if(null==t||""===t)continue;let r="number"==typeof t?t:parseInt(t);if(!isNaN(r)&&!(r<0))for(let[t,a]of x.entries()){let t,s=j.find(e=>{let t=e.toLowerCase(),r=a.marketplaceName.toLowerCase();return t.includes(r)||t===r||t===a.marketplaceName});if(!s)continue;let n=e[s];if(null!=n&&""!==n&&"-"!==n){if("number"==typeof n)t=n;else{if("string"!=typeof n)continue;let e=n.replace(/₺/g,"").replace(/[^\d,.-]/g,"").replace(",",".").trim();t=parseFloat(e)}if(!isNaN(t)&&!(t<0))for(let e of a.companyMarketplaceIds)g.push({companyMarketplaceId:e,desi:r,shippingFee:t})}}}if(0===g.length)return await m.$disconnect(),o.NextResponse.json({error:"Excel dosyasından ge\xe7erli veri bulunamadı"},{status:400});let M=[...new Set(g.map(e=>e.companyMarketplaceId))],N=[...new Set(g.map(e=>e.desi))];return await m.companyMarketplaceShippingFee.deleteMany({where:{companyMarketplaceId:{in:M},desi:{in:N}}}),await m.companyMarketplaceShippingFee.createMany({data:g}),await m.$disconnect(),o.NextResponse.json({message:`${g.length} kargo fiyatı başarıyla y\xfcklendi`,count:g.length})}catch(e){return console.error("Shipping fees import error:",e),await m.$disconnect(),o.NextResponse.json({error:"Sunucu hatası"},{status:500})}}let y=new s.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/shipping-fees/import/route",pathname:"/api/shipping-fees/import",filename:"route",bundlePath:"app/api/shipping-fees/import/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/shipping-fees/import/route.ts",nextConfigOutput:"standalone",userland:a}),{workAsyncStorage:h,workUnitAsyncStorage:x,serverHooks:g}=y;function w(){return(0,i.patchFetch)({workAsyncStorage:h,workUnitAsyncStorage:x})}},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")},78335:()=>{},79428:e=>{"use strict";e.exports=require("buffer")},96330:e=>{"use strict";e.exports=require("@prisma/client")},96487:()=>{}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[4447,580,3205,1437],()=>r(53500));module.exports=a})();