"use strict";(()=>{var e={};e.id=3654,e.ids=[3654],e.modules={2934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},4580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},5869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},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")},4770:e=>{e.exports=require("crypto")},6813:(e,a,t)=>{t.r(a),t.d(a,{originalPathname:()=>T,patchFetch:()=>$,requestAsyncStorage:()=>x,routeModule:()=>y,serverHooks:()=>S,staticGenerationAsyncStorage:()=>P});var r={};t.r(r),t.d(r,{POST:()=>A,maxDuration:()=>f});var n=t(9303),s=t(8716),i=t(670),o=t(7070),u=t(5655),l=t(2822),p=t(6097),c=t(2582),d=t(1789),g=t(7939),m=t(987);let k={tiktok:{label:"TikTok",icon:"\uD83D\uDCF1",durations:["15s","30s","60s","3min"]},shopee_video:{label:"Shopee Video",icon:"\uD83D\uDECD️",durations:["15s","30s","60s"]},instagram_reels:{label:"Instagram Reels",icon:"\uD83D\uDCF8",durations:["15s","30s","60s","90s"]},youtube_shorts:{label:"YouTube Shorts",icon:"▶️",durations:["30s","60s"]},facebook_reels:{label:"Facebook Reels",icon:"\uD83D\uDC65",durations:["15s","30s","60s"]}},h={santai_gaul:{label:"Santai / Gaul",desc:"Kasual, akrab, cocok Gen-Z"},formal_profesional:{label:"Formal / Profesional",desc:"Sopan, kredibel, brand image"},emosional_cerita:{label:"Emosional / Cerita",desc:"Story-driven, touching, relatable"},energik_hype:{label:"Energik / Hype",desc:"High energy, excitement, viral"},informatif_edukatif:{label:"Informatif / Edukatif",desc:"Edukasi, fakta, review detail"}},b={pertanyaan:{label:"Pertanyaan",example:'"Pernah nggak kamu ngerasa kulit makin sensitif?"'},shocking_fact:{label:"Shocking Fact",example:'"90% orang salah pilih moisturizer buat kulit sensitif"'},masalah_solusi:{label:"Masalah → Solusi",example:'"Kulit kemerahan terus? Akhirnya nemu solusinya!"'},testimoni:{label:"Testimoni",example:'"Udah 2 minggu pakai, dan nggak nyangka hasilnya..."'},challenge:{label:"Challenge/Garansi",example:'"Coba 7 hari, kalau nggak ada perubahan, aku minta maaf"'},before_after:{label:"Before & After",example:'"Ini kondisi kulit aku sebelum vs sesudah pakai ini"'}},f=60;async function A(e){try{let a,t;if(!(0,m._)(e))return o.NextResponse.json((0,m.E)(),{status:403});let r=(0,u.e)(),{data:{user:n},error:s}=await r.auth.getUser();if(s||!n)return o.NextResponse.json({success:!1,error:"Unauthorized"},{status:401});let i=await (0,p.D)(n.id);if(!i.allowed)return o.NextResponse.json({success:!1,error:"Rate limit exceeded. Coba lagi dalam 1 menit."},{status:429});let f=await (0,c.Sb)(r,n.id);if(!(0,c.q9)(f))return o.NextResponse.json({success:!1,error:"Belum ada AI API key. Tambahkan di Settings → API Keys.",redirectTo:"/settings"},{status:402});let A=await (0,d.T)(r,n.id,1);if("quota_exceeded"===A)return o.NextResponse.json({success:!1,error:"Kuota habis. Upgrade plan untuk lebih banyak generasi."},{status:403});let{product:y,platform:x,durasi:P,gayaBahasa:S,presenter:T,hookStyle:$,language:_="id",customInstructions:R,brandVoice:N}=await e.json();if(!y?.namaProduk)return o.NextResponse.json({success:!1,error:"Data produk tidak lengkap"},{status:400});if(!x||!P)return o.NextResponse.json({success:!1,error:"Platform dan durasi wajib diisi"},{status:400});let v=k[x],U=h[S??"santai_gaul"],j=b[$??"masalah_solusi"],D="id"===_?"Bahasa Indonesia":"English",w=T??"wanita",I=`Kamu adalah copywriter UGC (User Generated Content) profesional kelas dunia.
Spesialisasimu: membuat script video produk yang autentik, relatable, dan convert tinggi untuk platform ${v?.label??x}.

ATURAN OUTPUT:
1. Hook harus langsung menarik perhatian dalam 3 detik pertama
2. Gunakan gaya bahasa: ${U?.label} — ${U?.desc}
3. Hook style: ${j?.label} — contoh: ${j?.example}
4. Presenter: ${w}
5. Durasi total video: ${P}
6. Semua teks dalam ${D}
7. Script harus terasa AUTENTIK seperti UGC asli, bukan iklan korporat
8. Output HARUS valid JSON — tidak ada teks di luar JSON
${N?`9. Brand voice: ${N}`:""}
${R?`10. Instruksi khusus: ${R}`:""}

OUTPUT FORMAT (JSON):
{
  "hook": "kalimat pembuka yang paling menarik (diucapkan di 0-3 detik pertama)",
  "script": [
    {
      "durasi": "0-3 detik",
      "aksi": "apa yang dilakukan presenter di depan kamera",
      "dialog": "teks yang diucapkan / voiceover",
      "visualNote": "catatan untuk kameraman/editor"
    }
  ],
  "fullScript": "seluruh script dalam satu paragraf mengalir, siap dibaca presenter",
  "caption": "caption untuk posting di ${v?.label??x} (dengan emoji, engaging)",
  "hashtags": ["hashtag1", "hashtag2", ...],
  "callToAction": "CTA spesifik di akhir video",
  "tipsProduction": [
    "tip produksi 1",
    "tip produksi 2",
    "tip produksi 3"
  ]
}`,C=`Buat UGC Package untuk produk berikut:

NAMA PRODUK: ${y.namaProduk}
KATEGORI: ${y.kategori}
DESKRIPSI: ${y.deskripsiProduk}
MASALAH / PAIN POINT: ${y.masalahPainPoint}
MANFAAT UTAMA: ${y.manfaatUtama}
FITUR / KANDUNGAN: ${y.fiturKandungan}
TARGET AUDIENS: ${y.targetAudiens}
${y.harga?`HARGA: ${y.harga}`:""}
${y.sourceUrl?`SUMBER: ${y.sourceUrl}`:""}

KONFIGURASI:
- Platform: ${v?.label??x}
- Durasi: ${P}
- Gaya Bahasa: ${U?.label}
- Hook Style: ${j?.label}
- Presenter: ${w}
- Bahasa: ${D}

Buat script yang terasa seperti review/unboxing dari user asli, bukan iklan brand langsung.
Sesuaikan jumlah scene dengan durasi ${P}.`,O="",G="unknown",E="unknown",K=null;for(let e=0;e<=2;e++)try{let e=await (0,l.SN)([{role:"system",content:I},{role:"user",content:C}],{temperature:.8,maxTokens:6e3},f);O=e.content,G=e.model,E=e.provider,a=e.usage,K=null;break}catch(a){K=a,e<2&&await new Promise(a=>setTimeout(a,1e3*(e+1)))}if(K)return o.NextResponse.json({success:!1,error:K.message},{status:500});try{let e=O.replace(/^```(?:json)?\s*/i,"").replace(/\s*```$/i,"").trim();t=JSON.parse(e)}catch{let e=O.match(/\{[\s\S]*\}/);if(!e)return o.NextResponse.json({success:!1,error:"AI menghasilkan output tidak valid. Coba lagi."},{status:500});try{t=JSON.parse(e[0])}catch{return o.NextResponse.json({success:!1,error:"Gagal memparse output AI. Coba lagi."},{status:500})}}let q={hook:t.hook??"",script:Array.isArray(t.script)?t.script:[],fullScript:t.fullScript??"",caption:t.caption??"",hashtags:Array.isArray(t.hashtags)?t.hashtags:[],callToAction:t.callToAction??"",tipsProduction:Array.isArray(t.tipsProduction)?t.tipsProduction:[],metadata:{generatedAt:new Date().toISOString(),model:`${E}/${G}`,platform:x,durasi:P,language:_}},F=(0,g.n)(E,G,a??null);return await Promise.all([r.from("ugc_history").insert({user_id:n.id,product_name:y.namaProduk,product_url:y.sourceUrl??null,platform:x,durasi:P,gaya_bahasa:S??"santai_gaul",presenter:T??"wanita",hook_style:$??"masalah_solusi",language:_,output:q}),a?r.from("usage_logs").insert({user_id:n.id,action:"ugc_generate",platform:x,metadata:{model:G,provider:E,durasi:P,product_name:y.namaProduk},prompt_tokens:a.promptTokens,completion_tokens:a.completionTokens,total_tokens:a.totalTokens,estimated_cost_usd:F}):Promise.resolve()]),o.NextResponse.json({success:!0,data:q},{headers:{"X-RateLimit-Remaining":String(i.remaining)}})}catch(e){return console.error("[ugc-generator]",e),o.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}let y=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/ugc-generator/route",pathname:"/api/ugc-generator",filename:"route",bundlePath:"app/api/ugc-generator/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/ugc-generator/route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:x,staticGenerationAsyncStorage:P,serverHooks:S}=y,T="/api/ugc-generator/route";function $(){return(0,i.patchFetch)({serverHooks:S,staticGenerationAsyncStorage:P})}},7939:(e,a,t)=>{t.d(a,{n:()=>s});let r={"gpt-4o-mini":{input:15e-5,output:6e-4},"gpt-4o":{input:.005,output:.015},"gpt-4o-2024-11-20":{input:.0025,output:.01},"claude-3-haiku-20240307":{input:25e-5,output:.00125},"claude-3-5-haiku-20241022":{input:8e-4,output:.004},"claude-3-5-sonnet-20240620":{input:.003,output:.015},"claude-3-5-sonnet-20241022":{input:.003,output:.015},"gemini-1.5-flash":{input:75e-6,output:3e-4},"gemini-1.5-pro":{input:.00125,output:.005},"gemini-2.0-flash":{input:1e-4,output:4e-4},"gemini-2.5-flash":{input:15e-5,output:6e-4},"agentrouter/claude-3-haiku-20240307":{input:22e-5,output:.0011},"agentrouter/claude-3-5-haiku-20241022":{input:7e-4,output:.0035},"agentrouter/claude-3-5-sonnet-20240620":{input:.0028,output:.014},"agentrouter/claude-3-5-sonnet-20241022":{input:.0028,output:.014},"agentrouter/gpt-4o-mini":{input:14e-5,output:55e-5},"agentrouter/gpt-4o":{input:.0045,output:.014},"agentrouter/gemini-1.5-flash":{input:7e-5,output:28e-5},"agentrouter/gemini-2.0-flash":{input:95e-6,output:38e-5},"agentrouter/deepseek-chat":{input:27e-5,output:.0011},"agentrouter/deepseek-reasoner":{input:55e-5,output:.00219}},n={input:.001,output:.002};function s(e,a,t){if(!t)return null;let s=r["agentrouter"===e?`agentrouter/${a}`:a]??n;return t.promptTokens/1e3*s.input+t.completionTokens/1e3*s.output}}};var a=require("../../../webpack-runtime.js");a.C(e);var t=e=>a(a.s=e),r=a.X(0,[9276,6164,5972,3454],()=>t(6813));module.exports=r})();