"use strict";(()=>{var e={};e.id=1487,e.ids=[1487],e.modules={20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},39491:e=>{e.exports=require("assert")},14300:e=>{e.exports=require("buffer")},32081:e=>{e.exports=require("child_process")},6113:e=>{e.exports=require("crypto")},82361:e=>{e.exports=require("events")},57147:e=>{e.exports=require("fs")},13685:e=>{e.exports=require("http")},85158:e=>{e.exports=require("http2")},95687:e=>{e.exports=require("https")},41808:e=>{e.exports=require("net")},15673:e=>{e.exports=require("node:events")},97742:e=>{e.exports=require("node:process")},47261:e=>{e.exports=require("node:util")},22037:e=>{e.exports=require("os")},71017:e=>{e.exports=require("path")},77282:e=>{e.exports=require("process")},85477:e=>{e.exports=require("punycode")},63477:e=>{e.exports=require("querystring")},12781:e=>{e.exports=require("stream")},24404:e=>{e.exports=require("tls")},76224:e=>{e.exports=require("tty")},57310:e=>{e.exports=require("url")},73837:e=>{e.exports=require("util")},59796:e=>{e.exports=require("zlib")},76226:(e,r,s)=>{s.r(r),s.d(r,{originalPathname:()=>v,patchFetch:()=>y,requestAsyncStorage:()=>q,routeModule:()=>x,serverHooks:()=>m,staticGenerationAsyncStorage:()=>g});var t={};s.r(t),s.d(t,{POST:()=>h});var a=s(49303),o=s(88716),p=s(60670),i=s(97816),u=s(87070),n=s(71017),d=s.n(n),l=s(57147),c=s.n(l);async function h(e){try{let{sheetName:r,data:s,spreadsheet_id:t}=await e.json();if(!r||!Array.isArray(s)||!s.length)return u.NextResponse.json({success:!1,message:"sheetName & non-empty data array required"},{status:400});let a=r.trim(),o=d().join(process.cwd(),"json-service.json"),p=JSON.parse(c().readFileSync(o,"utf8")),n=new i.lkr.auth.GoogleAuth({credentials:p,scopes:["https://www.googleapis.com/auth/spreadsheets"]}),l=i.lkr.sheets({version:"v4",auth:n}),h=(await l.spreadsheets.get({spreadsheetId:t})).data.sheets.some(e=>e.properties.title===a);if(!h)try{await l.spreadsheets.batchUpdate({spreadsheetId:t,requestBody:{requests:[{addSheet:{properties:{title:a}}}]}})}catch(e){if(!e.message.includes("already exists"))throw e;h=!0}let x=Array.from(new Set(s.flatMap(e=>Object.keys(e)))),q=s.map(e=>x.map(r=>e?.[r]??""));return h?await l.spreadsheets.values.append({spreadsheetId:t,range:`${a}!A:A`,valueInputOption:"USER_ENTERED",insertDataOption:"INSERT_ROWS",requestBody:{values:q}}):await l.spreadsheets.values.update({spreadsheetId:t,range:`${a}!A1`,valueInputOption:"USER_ENTERED",requestBody:{values:[x,...q]}}),u.NextResponse.json({success:!0,rowsInserted:q.length})}catch(e){return console.error("Google Sheets API Error:",e),u.NextResponse.json({success:!1,error:e.message},{status:500})}}let x=new a.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/assign_leads/route",pathname:"/api/assign_leads",filename:"route",bundlePath:"app/api/assign_leads/route"},resolvedPagePath:"C:\\Users\\Design Collection\\OneDrive\\Desktop\\Jitendra Vishwakarma\\Next Dashboard\\web crawler for user dev\\Scrape Genius\\app\\api\\assign_leads\\route.js",nextConfigOutput:"",userland:t}),{requestAsyncStorage:q,staticGenerationAsyncStorage:g,serverHooks:m}=x,v="/api/assign_leads/route";function y(){return(0,p.patchFetch)({serverHooks:m,staticGenerationAsyncStorage:g})}}};var r=require("../../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[8948,5972,6577,820,7816],()=>s(76226));module.exports=t})();