"use strict";(()=>{var e={};e.id=998,e.ids=[998],e.modules={399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},2048:e=>{e.exports=require("fs")},5315:e=>{e.exports=require("path")},7566:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>j,patchFetch:()=>M,requestAsyncStorage:()=>P,routeModule:()=>w,serverHooks:()=>y,staticGenerationAsyncStorage:()=>v});var a={};r.r(a),r.d(a,{POST:()=>x,maxDuration:()=>h,runtime:()=>f});var n=r(3278),o=r(5002),i=r(4877),s=r(1309);let u=require("child_process");var l=r(2048),p=r(5315),c=r.n(p);let m=require("os");var d=r.n(m),g=r(2466);let f="nodejs",h=300;async function x(e){try{let t=await e.formData(),r=t.get("pdf");if(!(r instanceof File))return s.NextResponse.json({error:"Aucun fichier PDF re\xe7u."},{status:400});if(!r.name.toLowerCase().endsWith(".pdf"))return s.NextResponse.json({error:"Le fichier doit \xeatre un PDF."},{status:400});let a=Buffer.from(await r.arrayBuffer()),n=c().join(d().tmpdir(),`cadotk_${Date.now()}.pdf`);await l.promises.writeFile(n,a);let o=t.get("name")?.trim()||r.name.replace(/\.pdf$/i,"").slice(0,80),i=await new Promise((e,t)=>{let r=process.env.PYTHON_BIN||"python",a=c().join(process.cwd(),"scripts","extract.py"),i=(0,u.spawn)(r,[a,n,o],{cwd:process.cwd()}),s="",l="";i.stdout.on("data",e=>s+=e.toString()),i.stderr.on("data",e=>l+=e.toString()),i.on("error",e=>t(Error(`Python introuvable (${r}) : ${e.message}`))),i.on("close",r=>0===r?e(s):t(Error(l||`extract.py code ${r}`)))});await l.promises.unlink(n).catch(()=>{});let p=(0,g.FK)();return s.NextResponse.json({ok:!0,catalog:(0,g.Ze)(),total:p.total,log:i.trim()})}catch(e){return s.NextResponse.json({error:e?.message||"\xc9chec de l'extraction."},{status:500})}}let w=new n.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/upload/route",pathname:"/api/upload",filename:"route",bundlePath:"app/api/upload/route"},resolvedPagePath:"C:\\Users\\ERP 07\\Documents\\AppliTK\\app\\api\\upload\\route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:P,staticGenerationAsyncStorage:v,serverHooks:y}=w,j="/api/upload/route";function M(){return(0,i.patchFetch)({serverHooks:y,staticGenerationAsyncStorage:v})}},2466:(e,t,r)=>{r.d(t,{FK:()=>P,UQ:()=>h,Xp:()=>f,Ze:()=>x,aN:()=>w});var a=r(2048),n=r.n(a),o=r(5315),i=r.n(o);let s=i().join(process.cwd(),"data"),u=i().join(s,"products.json"),l=i().join(s,"pages.json");function p(e,t){try{return JSON.parse(n().readFileSync(e,"utf-8"))}catch{return t}}let c={"Technology & Accessories":"High-tech","Office & Writing":"Bureau","Eating & Drinking":"Repas & Boissons","Bags & Travel":"Nomade & Voyage","Umbrellas & Rain":"Pluie & Ext\xe9rieur","Recreation & Kids":"Loisirs & Enfants"};function m(e){var t;let r=`${e.name} ${e.description}`;return{...e,image:e.image??null,gamme:null==(t=e.priceFrom)?"Ind\xe9termin\xe9":t<5?"Promotionnel":t<=15?"Milieu de gamme":"Premium",usage:c[e.category]??"Autre",persona:/enfant|kids|b[ée]b[ée]|jouet|colori/i.test(r)?"Enfant":"Mixte",season:/parapluie|pluie|umbrella|imperm|poncho/i.test(r)?"Pluie / Hiver":/plage|solaire|[ée]ventail|glaci[èe]re|pique-nique|ext[ée]rieur/i.test(r)?"\xc9t\xe9":"Toute saison"}}let d=null;function g(){let e=0;try{e=Math.max(n().statSync(u).mtimeMs,n().statSync(l).mtimeMs)}catch{}if(d&&d.mtime===e)return d;let t=p(u,[]),r=p(l,{catalog:"Catalogue",pages:[]});return d={mtime:e,products:t.map(m),catalog:r.catalog??"Catalogue",pages:r.pages??[]}}function f(){return g().products}function h(){return g().pages}function x(){return g().catalog}function w(e){let t=new Map(f().map(e=>[e.id,e]));return e.map(e=>t.get(e)).filter(Boolean)}function P(){let e=f(),t=[...new Set(e.map(e=>e.category))].sort(),r=[...new Set(e.map(e=>e.technique?.split(/[*,]/)[0]?.trim()).filter(e=>!!e&&e.length>2))].sort(),a=[...new Set(e.map(e=>e.usage))].sort(),n=e.map(e=>e.priceFrom).filter(e=>null!=e);return{categories:t,techniques:r,usages:a,gammes:["Promotionnel","Milieu de gamme","Premium"],priceMin:n.length?Math.floor(Math.min(...n)):0,priceMax:n.length?Math.ceil(Math.max(...n)):100,total:e.length}}}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[787,833],()=>r(7566));module.exports=a})();