1import{d as Qe,u as Ye,z as Ze,r as d,G as es,s as g,v as p,j as e,D as ss,f as rs,g as ts,h as as,i as os,E as ns,I as Ee,B as x,l as is,J as ee,C as De,a as Ue,X as ls}from"./index-BkXX1jM4.js";import{T as cs}from"./textarea-FktuWBif.js";import{O as ds}from"./OrbAnimation-C1TgZQjU.js";import{I as ms}from"./ImageModificationChat-DlKwDklg.js";import{u as us,C as N}from"./useCredits-DkygUqBh.js";import{C as hs}from"./CreditCostBadge-BAY0FiL8.js";import{L as gs}from"./LowCreditWarning-CW2wtOrF.js";import{u as ps}from"./useAgencyCredits-Bw4hSGDW.js";import{A as xs}from"./AgencyProjectSelector-DXxZiKfZ.js";import{c as se,g as fs}from"./contentlyStudioApi-G0V88yD5.js";import{u as bs}from"./useLeaveConfirmation-BYQNug_1.js";import{A as ys}from"./arrow-right-C-wpBS12.js";import{C as ws}from"./coins-D5nU1AAH.js";import{D as Ae}from"./download-6tWh1GIC.js";import{S as Le}from"./sparkles-C_SyXNKS.js";import{R as re}from"./refresh-cw-D-rPzfAS.js";import{L as js}from"./lightbulb-DRbvYNpY.js";import"./loader-circle-CCPo_TM_.js";import"./triangle-alert-D7SqPwNc.js";import"./folder-open-DZ5nAnFb.js";import"./check-CSNF23FR.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const vs=Qe("Paperclip",[["path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48",key:"1u3ebp"}]]);function Hs(){var we,je,ve,Ne,_e;
6const Te=Ye(),te=Ze(),{credits:Pe,checkCredits:ae,deductCredits:oe}=us(),[S,ne]=d.useState(""),[_,$e]=d.useState(null),[L,ie]=d.useState(!1),[k,le]=d.useState([]),[ce,Me]=d.useState(0),[E,de]=d.useState(""),[me,ue]=d.useState(!0),[Re,F]=d.useState(!1),[D,J]=d.useState([]),[U,z]=d.useState(0),[K,T]=d.useState(""),[P,C]=d.useState(null),[Oe,he]=d.useState(!1),[Ns,I]=d.useState(null),[u,q]=d.useState([]),[f,$]=d.useState([]),[l,M]=d.useState(0),[Ge,X]=d.useState(!1),[R,ge]=d.useState([]),[O,pe]=d.useState(!1),[Q,B]=d.useState(null),{agency:b,selectedProject:y,isAgencyUser:w}=es(),{pointsBalance:Fe,checkCredits:xe,deductCredits:fe}=ps((b==null?void 0:b.id)||null),{LeaveConfirmationDialog:ze}=bs({isActive:L,title:"ÙÙ ØªØ±ÙØ¯ Ø¥ÙØºØ§Ø¡ تÙÙÙØ¯ Ø§ÙØµÙرةØ",description:"عÙ
ÙÙØ© تÙÙÙØ¯ Ø§ÙØµÙرة ÙÙØ¯ Ø§ÙØªÙÙÙØ° ÙÙØ¯ تستغر٠بعض اÙÙÙØª. ÙÙ Ø£ÙØª Ù
ØªØ£ÙØ¯ Ø£ÙÙ ØªØ±ÙØ¯ Ø¥ÙØºØ§Ø¡ Ø§ÙØ¹Ù
ÙÙØ© ÙØ§ÙÙ
غادرةØ"}),Y=["ØµÙØ±Ø© Ø§ØØªØ±Ø§ÙÙØ© ÙÙ
ÙØªØ¬ عÙÙ Ø®ÙÙÙØ© Ø¨ÙØ¶Ø§Ø¡ ÙØ¸ÙÙØ©...","تصÙ
ÙÙ
Ø¨ÙØ³Øª Ø¥Ø¹ÙØ§Ù٠جذاب ÙÙØ³Ø§Ø¦Ù Ø§ÙØªÙØ§ØµÙ Ø§ÙØ§Ø¬ØªÙ
اعÙ...","ØµÙØ±Ø© ØªØ¹Ø¨ÙØ±ÙØ© ع٠اÙÙØ¬Ø§Ø ÙØ§ÙØ¥ÙØ¬Ø§Ø² ÙÙ Ø§ÙØ¹Ù
Ù...","تصÙ
ÙÙ
ÙÙÙØ± ÙÙØµØ© Ø§ÙØ³ØªØ¬Ø±Ø§Ù
بأÙÙØ§Ù جذابة...","ØµÙØ±Ø© Ø§ØØªØ±Ø§ÙÙØ© ÙÙØ±Ù٠عÙ
Ù ÙÙ Ù
ÙØªØ¨ عصرÙ...","تصÙ
ÙÙ
Ø¥ÙÙÙØ¬Ø±Ø§ÙÙÙ ØªÙØ¶ÙØÙ بأسÙÙØ¨ عصرÙ..."];d.useEffect(()=>{He(),Be();const s=te.state;s!=null&&s.imageUrl&&(C(s.imageUrl),I(s.htmlCode||null),q([[{url:s.imageUrl,html:s.htmlCode||"",prompt:s.prompt||"ØµÙØ±Ø© Ù
ØÙÙØ¸Ø©"}]]),$([0]),M(0))},[te]);const Be=async()=>{try{const{data:{user:s}}=await g.auth.getUser();if(!s)return;const{data:r,error:t}=await g.from("image_prompt_suggestions").select("id, suggestion").eq("user_id",s.id).order("created_at",{ascending:!1});if(t)throw t;r&&(B(null),ge(r),r.length===0&&Z({showToast:!1}))}catch(s){console.error("Error loading suggestions:",s),B("ØªØ¹Ø°ÙØ± تØÙ
ÙÙ Ø§ÙØªØ±Ø§ØØ§Øª Ø§ÙØ°Ùاء Ø§ÙØ§ØµØ·ÙاعÙ.")}},Z=async({showToast:s=!0}={})=>{pe(!0);try{B(null);const{data:{user:r}}=await g.auth.getUser();if(!r)return;const t=await se("/api/v1/image/suggest-prompts",{method:"POST",body:JSON.stringify({user_id:r.id,count:5})});if(!t.ok)throw new Error("Failed to fetch suggestions");const a=await t.json(),i=Array.isArray(a==null?void 0:a.suggestions)?a.suggestions:Array.isArray(a==null?void 0:a.prompts)?a.prompts:[];if(i.length===0)return;const v=i.map(h=>({user_id:r.id,suggestion:h}
6)),{data:c,error:n}=await g.from("image_prompt_suggestions").insert(v).select("id, suggestion");if(n)throw n;c&&c.length>0&&(ge(h=>[...c,...h]),s&&p.success("ت٠تØÙ ÙÙ Ø§ÙØªØ±Ø§ØØ§Øª Ø¬Ø¯ÙØ¯Ø©!"))}catch(r){console.error("Error fetching suggestions:",r),B("ÙØ´Ù Ù٠تØÙ ÙÙ Ø§ÙØ§ÙØªØ±Ø§ØØ§Øª."),s&&p.error("ÙØ´Ù Ù٠تØÙ ÙÙ Ø§ÙØ§ÙØªØ±Ø§ØØ§Øª")}finally{pe(!1)}},Ve=s=>{ne(s)};d.useEffect(()=>{const s=Y[ce];let r;return me?E.length<s.length?r=setTimeout(()=>{de(s.slice(0,E.length+1))},50):r=setTimeout(()=>{ue(!1)},2e3):E.length>0?r=setTimeout(()=>{de(E.slice(0,-1))},30):(Me(t=>(t+1)%Y.length),ue(!0)),()=>clearTimeout(r)},[E,me,ce,Y]);const He=async()=>{try{const{data:{user:s}}=await g.auth.getUser();if(!s)return;const{data:r,error:t}=await g.from("branding").select("*").eq("user_id",s.id).maybeSingle();if(t)throw t;r&&$e({business_name:r.business_name||"",logo_url:r.logo_url||"",brand_colors:r.brand_colors||[],brand_fonts:r.brand_fonts||[],business_brief:r.business_brief||"",tagline:r.tagline||"",additional_info:r.additional_info||""})}catch(s){console.error("Error loading branding data:",s)}},We=s=>{const r=s.target.files;if(r){const t=Array.from(r);J(t),z(0),T(""),F(!0)}s.target.value=""},be=()=>{if(!K.trim()){p.error("Ø§ÙØ±Ø¬Ø§Ø¡ Ø¥Ø¯Ø®Ø§Ù ÙØµÙ ÙÙØµÙرة");return}const r={file:D[U],description:K.trim()};le(t=>[...t,r]),U<D.length-1?(z(t=>t+1),T("")):(F(!1),J([]),z(0),T(""))},Je=s=>{le(r=>r.filter((t,a)=>a!==s))},ye=async()=>{var r;if(!S.trim()){p.error("Ø§ÙØ±Ø¬Ø§Ø¡ Ø¥Ø¯Ø®Ø§Ù ÙØµÙ ÙÙØµÙرة");return}if(w&&!y){X(!0);return}if(w?xe(N.IMAGE):await ae(N.IMAGE)){ie(!0);try{const{data:{user:t}}=await g.auth.getUser();if(!t){p.error("ÙØ¬Ø¨ تسجÙÙ Ø§ÙØ¯Ø®Ù٠أÙÙØ§Ù");return}const a=[];if(k.length>0)for(const o of k){const m=o.file.name.split(".").pop(),j=`${t.id}/${Date.now()}_${Math.random().toString(36).substring(7)}.${m}`,{data:Ce,error:W}=await g.storage.from("user-uploads").upload(j,o.file);if(W){console.error("Error uploading image:",W);continue}const{data:{publicUrl:G}}=g.storage.from("user-uploads").getPublicUrl(j);a.push(G),o.url=G}let i=S;k.length>0&&(i+=` 7 8Reference images: 9`,k.forEach((o,m)=>{i+=`${m+1}. ${o.description}`,o.url&&(i+=` (URL: ${o.url})`),i+=` 10`})),_&&(_.business_name&&(i+=` For ${_.business_name}.`),_.brand_colors&&_.brand_colors.length>0&&(i+=` Use brand colors: ${_.brand_colors.join(", ")}.`),_.business_brief&&(i+=` Brand style: ${_.business_brief}`));const v=await se("/api/v1/image/generate-ai",{method:"POST",body:JSON.stringify({prompt:i,width:1080,height:1080,user_id:t.id})});if(!v.ok)throw new Error("ÙØ´Ù ÙÙ Ø§ÙØ§ØªØµØ§Ù Ø¨Ø§ÙØ®Ø§Ø¯Ù ");const c=await v.json();if(!c.success)throw new Error(c.error||"ÙØ´Ù ÙÙ Ø¥ÙØ´Ø§Ø¡ Ø§ÙØµÙرة");const n=[];if(c.results&&Array.isArray(c.results)&&c.results.length>0){for(const o of c.results)if(o.image_url){const m=fs(o.image_url);n.push({image_url:m,html_code:o.html_code||null})}}else if(c.image_urls&&c.image_urls.length>0)c.image_urls.forEach(o=>{const m=o.startsWith("http")?o:`https://contently-studio.onrender.com${o}`;n.push({image_url:m,html_code:c.html_code||null})});else if(c.image_url){const o=c.image_url.startsWith("http")?c.image_url:`https://contently-studio.onrender.com${c.image_url}`;n.push({image_url:o,html_code:c.html_code||null})}if(n.length===0)throw new Error("ÙÙ ÙØªÙ إرجاع Ø£Ù ØµÙØ±");const h=[];for(let o=0;o<n.length;o++){const m=n[o];try{const j=await fetch(m.image_url);if(!j.ok){console.error(`Failed to fetch image ${o+1}`);continue}const Ce=await j.blob(),W=Date.now(),G=`${t.id}/${W}_${o}.png`,{error:Ie}=await g.storage.from("generated-images").upload(G,Ce,{contentType:"image/png",upsert:!1});if(Ie){console.error(`Failed to upload image ${o+1}:`,Ie);continue}const{data:Xe}=g.storage.from("generated-images").getPublicUrl(G),Se=Xe.publicUrl;h.push({url:Se,html_code:m.html_code||null});const{error:ke}=await g.from("archived_images").insert({user_id:t.id,prompt:S,image_url:Se,html_code:m.html_code||null,agency_id:w&&y?b==null?void 0:b.id:null,agency_project_id:w&&y?y.id:null});ke&&console.error(`Error saving image ${o+1} to database:`,ke)}catch(j){console.error(`Error processing image ${o+1}:`,j)}}if(h.length===0)throw new Error("ÙØ´Ù ÙÙ ØÙظ Ø§ÙØµÙر");if(w&&b&&y){const{data:o}=await g.auth.getUser();await fe(N.IMAGE,"image",((r=o.user)==null?void 0:r.id)||"",y.id)}else await oe(N.IMAGE,"تÙÙÙØ¯ ØµÙØ±Ø© Ø¨Ø§ÙØ°Ùاء Ø§ÙØ§ØµØ·ÙاعÙ");const A=h.map(o=>[{url:o.url,html:o.html_code||"",prompt:S}]);q(A),$(h.map(()=>0));const V=h[0];C(V.url),I(V.html_code),M(0);const H=h.length>1?`ØªÙ Ø¥ÙØ´Ø§Ø¡ ${h.length} ØµÙØ± Ø¨ÙØ¬Ø§Ø!`:"ØªÙ Ø¥ÙØ´Ø§Ø¡ Ø§ÙØµÙرة Ø¨ÙØ¬Ø§Ø!";p.success(H)}catch(t){console.error("Error generating image:",t),p.error("ÙØ´Ù Ø¥ÙØ´Ø§Ø¡ Ø§ÙØµÙرة")}finally{ie(!1)}}},Ke=async s=>{if(!P||u.length===0)return;const r=u[l],t=f[l]||0;if(!(!r||r.length===0||!(w?xe(N.IMAGE_EDIT):await ae(N.IMAGE_EDIT)))){he(!0);try{const{data:{user:i}}=await g.auth.getUser();if(!i)return;const v=r[t].html,c=await se("/api/v1/html/edit",{method:"POST",body:JSON.stringify({html_code:v,prompt:s,model:"gpt-5.1",width:1080,height:1080,render_image:!0})});let n=null;try{n=await c.json()}catch(o){console.error("Error parsing HTML edit response:",o)}if(!c.ok||(n==null?void 0:n.success)===!1)throw console.error("HTML edit API error:",c.status,n),new Error((n==null?void 0:n.message)||"ÙØ´Ù ÙÙ Ø§ÙØ§ØªØµØ§Ù Ø¨Ø§ÙØ®Ø§Ø¯Ù ");const h=(n==null?void 0:n.edited_html)||(n==null?void 0:n.html_code)||v,A=n!=null&&n.image_url?`https://contently-studio.onrender.com${n.image_url}`:P;if(!h||!A)throw console.error("Invalid HTML edit response payload:",n),new Error("استجابة ØºÙØ± ØµØ§ÙØØ© Ù Ù Ø§ÙØ®Ø§Ø¯Ù ");C(A),I(h);const V={url:A,html:h,prompt:s};q(o=>{const m=[...o];return m[l]=[...m[l]||[],V],m}),$(o=>{var j;const m=[...o];return m[l]=((j=u[l])==null?void 0:j.length)||0,m});const{error:H}=await g.from("archived_images").insert({user_id:i.id,prompt:s,image_url:A,html_code:h,agency_id:w&&y?b==null?void 0:b.id:null,agency_project_id:w&&y?y.id:null});H&&console.error("Error saving modified image:",H),w&&b&&y?await fe(N.IMAGE_EDIT,"image_edit",i.id,y.id):await oe(N.IMAGE_EDIT,"تعدÙÙ ØµÙØ±Ø© Ø¨Ø§ÙØ°Ùاء Ø§ÙØ§ØµØ·ÙاعÙ"),p.success("ت٠تعدÙÙ Ø§ÙØµÙرة Ø¨ÙØ¬Ø§Ø!")}catch(i){console.error("Error modifying image:",i),p.error("ÙØ´Ù تعدÙÙ Ø§ÙØµÙرة")}finally{he(!1)}}},qe=async()=>{var a;const s=u[l],r=f[l]||0,t=((a=s==null?void 0:s[r])==null?void 0:a.url)||P;if(t)try{const v=await(await fetch(t)).blob(),c=window.URL.createObjectURL(v),n=document.createElement("a");n.href=c,n.download=`contently-image-${Date.now()}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n),window.URL.revokeObjectURL(c),p.success("ØªÙ ØªÙØ²ÙÙ Ø§ÙØµÙرة Ø¨ÙØ¬Ø§Ø!")}catch(i){console.error("Error downloading image:",i),p.error("ÙØ´Ù ØªÙØ²ÙÙ Ø§ÙØµÙرة")}};return e.jsxs("div",{className:"min-h-screen bg-background",dir:"rtl",children:[e.jsx(ze,{}),e.jsx(ss,{open:Re,onOpenChange:F,children:e.jsxs(rs,{className:"sm:max-w-md border-0 shadow-2xl rounded-3xl backdrop-blur-xl",dir:"rtl",children:[e.jsxs(ts,{children:[e.jsx(as,{className:"text-right",children:"ÙØµÙ Ø§ÙØµÙرة"}),e.jsxs(os,{className:"text-right",children:["Ø§ÙØµÙرة ",U+1," Ù Ù ",D.length]})]}),e.jsxs("div",{className:"space-y-4",children:[D[U]&&e.jsx("div",{className:"flex justify-center",children:e.jsx("img",{src:URL.createObjectURL(D[U]),alt:"Preview",className:"max-h-48 rounded-lg border-0 shadow-sm"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ns,{htmlFor:"image-description",className:"text-right block",children:"ÙØµÙ Ø§ÙØµÙرة (٠ثاÙ: Ø´Ø¹Ø§Ø±Ø Ù ÙØªØ¬Ø Ø®ÙÙÙØ©)"}),e.jsx(Ee,{id:"image-description",value:K,onChange:s=>T(s.target.value),placeholder:"Ø§ÙØªØ¨ ÙØµÙ Ø§ÙØµÙرة...",className:"text-right",onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),be())}})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(x,{variant:"outline",onClick:()=>{F(!1),J([]),z(0),T("")},children:"Ø¥ÙØºØ§Ø¡"}
10),e.jsx(x,{onClick:be,children:U<D.length-1?"Ø§ÙØªØ§ÙÙ":"Ø¥Ø¶Ø§ÙØ©"})]})]})]})}),L&&e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-background/95 backdrop-blur-sm",children:e.jsx(ds,{title:"جار٠تÙÙÙØ¯ Ø§ÙØµÙرة...",subtitle:"ÙÙÙØªÙتÙÙ ÙØ¹Ù
٠عÙÙ Ø¥ÙØ´Ø§Ø¡ ØµÙØ±Ø© Ø§ØØªØ±Ø§ÙÙØ© ÙÙ"})}),e.jsx("header",{className:"sticky top-0 z-10 backdrop-blur-xl bg-background/90 border-b border-border/10",children:e.jsx("div",{className:"container mx-auto px-4 sm:px-6 py-3 sm:py-4",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx(x,{variant:"ghost",size:"icon",onClick:()=>Te("/studio"),className:"hover:bg-primary/10 hover:text-primary transition-all rounded-xl h-9 w-9 sm:h-10 sm:w-10",children:e.jsx(ys,{className:"h-4 w-4 sm:h-5 sm:w-5"})}),e.jsx("div",{className:"h-6 sm:h-8 w-px bg-border/30 hidden sm:block"}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx("img",{src:is,alt:"Contently Logo",className:"h-5 sm:h-7 w-auto brightness-0 dark:brightness-100"}),e.jsx("h1",{className:"text-base sm:text-xl font-semibold text-foreground hidden sm:block",children:"Ø¥ÙØ´Ø§Ø¡ ØµÙØ±Ø© Ø¬Ø¯ÙØ¯Ø©"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 px-2.5 sm:px-4 py-1.5 sm:py-2 rounded-xl bg-gradient-to-l from-primary/10 to-primary/5 border border-primary/20",children:[e.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground",children:w?Fe??0:Pe??0}),e.jsx(ws,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-primary"}),e.jsx("span",{className:"text-[10px] sm:text-xs text-muted-foreground",children:"ÙÙØ·Ø©"})]})]})})}),e.jsxs("main",{className:"container mx-auto px-4 sm:px-6 py-4 sm:py-8",children:[e.jsx(gs,{}),P?e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 sm:gap-6 min-h-[calc(100vh-10rem)] lg:h-[calc(100vh-12rem)]",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4",children:[e.jsx(ee,{className:"p-4 bg-card/50 backdrop-blur-sm border-0 shadow-sm rounded-2xl",children:e.jsx("img",{src:((je=(we=u[l])==null?void 0:we[f[l]||0])==null?void 0:je.url)||P,alt:"Generated",className:"max-w-full max-h-[calc(100vh-20rem)] rounded-xl shadow-lg"})}),u.length>1&&e.jsxs("div",{className:"flex items-center gap-2 bg-card/50 backdrop-blur-sm border-0 shadow-sm rounded-xl px-4 py-2",children:[e.jsx(x,{variant:"ghost",size:"sm",disabled:l===0,onClick:()=>{var a;const s=l-1;M(s);const r=f[s]||0,t=(a=u[s])==null?void 0:a[r];t&&(C(t.url),I(t.html))},className:"h-8 w-8 p-0 hover:bg-primary/10 disabled:opacity-30",children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex gap-1.5",children:u.map((s,r)=>e.jsx("button",{onClick:()=>{var i;M(r);const t=f[r]||0,a=(i=u[r])==null?void 0:i[t];a&&(C(a.url),I(a.html))},className:`w-2 h-2 rounded-full transition-all ${r===l?"bg-primary w-4":"bg-muted-foreground/30 hover:bg-muted-foreground/50"}`},r))}),e.jsx(x,{variant:"ghost",size:"sm",disabled:l===u.length-1,onClick:()=>{var a;const s=l+1;M(s);const r=f[s]||0,t=(a=u[s])==null?void 0:a[r];t&&(C(t.url),I(t.html))},className:"h-8 w-8 p-0 hover:bg-primary/10 disabled:opacity-30",children:e.jsx(Ue,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-sm text-muted-foreground mr-2",children:["ØµÙØ±Ø© ",l+1," Ù
Ù ",u.length]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(x,{onClick:qe,className:"bg-gradient-to-l from-primary to-primary/80 hover:from-primary/90 hover:to-primary/70 text-primary-foreground shadow-lg hover:shadow-xl transition-all rounded-xl",children:[e.jsx(Ae,{className:"w-4 h-4 ml-2"}),"تØÙ
ÙÙ Ø§ÙØµÙرة"]}),(((ve=u[l])==null?void 0:ve.length)||0)>1&&e.jsxs("div",{className:"flex items-center gap-2 bg-gradient-to-l from-secondary/80 to-secondary/40 backdrop-blur-sm border border-border/20 shadow-sm rounded-xl px-4 py-2",children:[e.jsx(x,{variant:"ghost",size:"sm",disabled:(f[l]||0)===(((Ne=u[l])==null?void 0:Ne.length)||1)-1,onClick:()=>{var t;const s=(f[l]||0)+1;$(a=>{const i=[...a];return i[l]=s,i});const r=(t=u[l])==null?void 0:t[s];r&&(C(r.url),I(r.html))},className:"h-8 w-8 p-0 hover:bg-primary/10 disabled:opacity-30",title:"اÙÙØ³Ø®Ø© Ø§ÙØªØ§ÙÙØ©",children:e.jsx(De,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex flex-col items-center min-w-[80px]",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Ø³Ø¬Ù Ø§ÙØªØ¹Ø¯ÙÙØ§Øª"}),e.jsxs("span",{className:"text-sm font-medium text-foreground",children:["ÙØ³Ø®Ø© ",(f[l]||0)+1," Ù
Ù ",((_e=u[l])==null?void 0:_e.length)||1]})]}),e.jsx(x,{variant:"ghost",size:"sm",disabled:(f[l]||0)===0,onClick:()=>{var t;const s=(f[l]||0)-1;$(a=>{const i=[...a];return i[l]=s,i});const r=(t=u[l])==null?void 0:t[s];r&&(C(r.url),I(r.html))},className:"h-8 w-8 p-0 hover:bg-primary/10 disabled:opacity-30",title:"اÙÙØ³Ø®Ø© Ø§ÙØ³Ø§Ø¨ÙØ©",children:e.jsx(Ue,{className:"h-4 w-4"})})]})]})]}),e.jsx("div",{className:"h-full",children:e.jsx(ms,{onModify:Ke,isModifying:Oe})})]}):e.jsx(e.Fragment,{children:e.jsxs("div",{className:`max-w-3xl mx-auto
10space-y-6 sm:space-y-8 transition-opacity duration-300 ${L?"opacity-0 pointer-events-none":"opacity-100"}`,children:[e.jsx(ee,{className:"p-4 sm:p-6 md:p-8 bg-gradient-to-br from-card/80 to-card/40 backdrop-blur-xl border border-border/10 shadow-2xl rounded-2xl sm:rounded-3xl",children:e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-6 sm:h-8 w-1 bg-gradient-to-b from-primary to-primary/40 rounded-full"}),e.jsx("h2",{className:"text-base sm:text-lg font-medium text-foreground",children:"Ø§ÙØªØ¨ ÙØµÙ Ø§ÙØµÙرة"})]}),e.jsx(cs,{id:"prompt-input",value:S,onChange:s=>ne(s.target.value),placeholder:E,className:"min-h-[120px] sm:min-h-[140px] text-right resize-none text-sm sm:text-base rounded-xl sm:rounded-2xl border-0 bg-background/60 backdrop-blur-sm shadow-inner focus-visible:ring-2 focus-visible:ring-primary/20 focus-visible:ring-offset-0 transition-all placeholder:text-muted-foreground/50",onKeyDown:s=>{s.key==="Enter"&&s.ctrlKey&&(s.preventDefault(),ye())}})]}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row items-stretch sm:items-center justify-between gap-3 sm:gap-4 pt-2",children:[e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground text-center sm:text-right",children:"Ctrl+Enter ÙÙØ¥Ùشاء Ø§ÙØ³Ø±Ùع"}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsxs("label",{htmlFor:"image-upload",className:"cursor-pointer flex-1 sm:flex-none",children:[e.jsx(x,{type:"button",variant:"outline",className:"rounded-xl border border-border/30 hover:border-primary/30 hover:bg-primary/5 hover:text-primary transition-all h-10 sm:h-11 px-3 sm:px-5 w-full sm:w-auto text-sm",asChild:!0,children:e.jsxs("div",{children:[e.jsx(vs,{className:"w-4 h-4 ml-1.5 sm:ml-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Ø¥Ø±ÙØ§Ù ØµÙØ±Ø©"}),e.jsx("span",{className:"sm:hidden",children:"Ø¥Ø±ÙØ§Ù"})]})}),e.jsx(Ee,{id:"image-upload",type:"file",accept:"image/*",multiple:!0,onChange:We,className:"hidden"})]}),e.jsx(x,{onClick:ye,disabled:L||!S.trim(),className:"bg-gradient-to-l from-primary to-primary/80 hover:from-primary/90 hover:to-primary/70 text-primary-foreground shadow-lg hover:shadow-xl hover:scale-[1.02] transition-all rounded-xl h-10 sm:h-11 px-4 sm:px-6 gap-1.5 sm:gap-2 flex-1 sm:flex-none text-sm",children:L?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-2 border-primary-foreground/30 border-t-primary-foreground ml-1.5 sm:ml-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Ø¬Ø§Ø±Ù Ø§ÙØ¥Ùشاء..."}),e.jsx("span",{className:"sm:hidden",children:"جارÙ..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"w-4 h-4 ml-1 sm:ml-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Ø¥ÙØ´Ø§Ø¡ ØµÙØ±Ø©"}),e.jsx("span",{className:"sm:hidden",children:"Ø¥ÙØ´Ø§Ø¡"}),e.jsx(hs,{cost:N.IMAGE})]})})]})]})]})}),(R.length>0||O||Q)&&e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>Z({showToast:!0}),disabled:O,className:"text-[10px] sm:text-xs text-muted-foreground hover:text-primary hover:bg-primary/5 rounded-lg gap-1 sm:gap-1.5 h-7 sm:h-8 px-2 sm:px-3",children:[O?e.jsx(re,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5 animate-spin"}):e.jsx(re,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"}),"ØªØØ¯ÙØ«"]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[e.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground",children:"Ø§ÙØªØ±Ø§ØØ§Øª ذÙÙØ©"}),e.jsx("div",{className:"p-1 sm:p-1.5 rounded-lg bg-primary/10",children:e.jsx(js,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4 text-primary"})})]})]}),R.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 sm:gap-2 justify-end",children:R.slice(0,8).map(s=>{let r=s.suggestion,t=s.suggestion;try{const a=JSON.parse(s.suggestion);r=a.title||s.suggestion,t=a.prompt||s.suggestion}catch{}return e.jsx("button",{onClick:()=>Ve(t),className:"px-2.5 sm:px-4 py-1.5 sm:py-2 text-xs sm:text-sm bg-background/60 hover:bg-primary/10 text-foreground rounded-lg sm:rounded-xl border border-border/20 hover:border-primary/30 hover:text-primary transition-all text-right shadow-sm hover:shadow-md active:scale-95",title:t,children:r.length>
10(window.innerWidth<640?25:40)?r.substring(0,window.innerWidth<640?25:40)+"...":r},s.id)})}),R.length===0&&O&&e.jsxs("div",{className:"flex items-center justify-center gap-3 py-8",children:[e.jsx(re,{className:"w-5 h-5 animate-spin text-primary"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"جار٠تØÙ
ÙÙ Ø§ÙØ§ÙØªØ±Ø§ØØ§Øª..."})]}),R.length===0&&!O&&Q&&e.jsxs("div",{className:"text-center py-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:Q}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>Z({showToast:!0}),className:"mt-3 rounded-xl",children:[e.jsx(Le,{className:"w-4 h-4 ml-2"}),"تØÙ
ÙÙ Ø§ÙØªØ±Ø§ØØ§Øª"]})]})]}),k.length>0&&e.jsx(ee,{className:"p-4 sm:p-6 bg-card/50 backdrop-blur-sm border border-border/10 rounded-xl sm:rounded-2xl",children:e.jsxs("div",{className:"space-y-3 sm:space-y-4",children:[e.jsx("h3",{className:"text-xs sm:text-sm font-medium text-foreground text-right",children:"Ø§ÙØµÙر اÙÙ
رÙÙØ©"}),e.jsx("div",{className:"space-y-2 sm:space-y-3",children:k.map((s,r)=>e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 p-2 sm:p-3 bg-background/60 rounded-lg sm:rounded-xl",children:[e.jsx("img",{src:URL.createObjectURL(s.file),alt:s.description,className:"w-10 h-10 sm:w-14 sm:h-14 object-cover rounded-md sm:rounded-lg shadow-sm"}),e.jsxs("div",{className:"flex-1 text-right min-w-0",children:[e.jsx("p",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:s.description}),e.jsx("p",{className:"text-[10px] sm:text-xs text-muted-foreground truncate",children:s.file.name})]}),e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>{const t=URL.createObjectURL(s.file),a=document.createElement("a");a.href=t,a.download=s.file.name,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(t),p.success("تÙ
ØªÙØ²ÙÙ Ø§ÙØµÙرة")},className:"bg-primary/10 text-primary hover:bg-primary/20 rounded-full w-7 h-7 sm:w-8 sm:h-8 flex items-center justify-center transition-colors active:scale-95",children:e.jsx(Ae,{className:"w-3 h-3 sm:w-3.5 sm:h-3.5"})}),e.jsx("button",{onClick:()=>Je(r),className:"bg-destructive/10 text-destructive hover:bg-destructive/20 rounded-full w-7 h-7 sm:w-8 sm:h-8 flex items-center justify-center transition-colors active:scale-95",children:e.jsx(ls,{className:"w-3.5 h-3.5 sm:w-4 sm:h-4"})})]})]},r))})]})})]})})]}),e.jsx(xs,{open:Ge,onOpenChange:X,onSelect:()=>{X(!1)},title:"اختر Ù
ÙÙ Ø§ÙØ¹Ù
ÙÙ",description:"ÙØ±Ø¬Ù Ø§Ø®ØªÙØ§Ø± Ù
ÙÙ Ø§ÙØ¹Ù
ÙÙ ÙØ¨Ù تÙÙÙØ¯ Ø§ÙØµÙرة"})]})}export{Hs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.