1import{u as Le,r as c,b as f,ad as es,j as s,a1 as Me,s as ss,a as ts,i as rs,Z as os,$ as ns,g as is,B as as,a0 as ls,c as Ne,a2 as cs}from"./index-Cfj6LykL.js";import{U as ds}from"./upload-B4Zo3TKG.js";import{V as us,P as ps,E as ms,D as hs,a as ys}from"./index-CffjRDOW.js";import{l as _e,a as Re}from"./Uploading_Dark-FZsmQu_U.js";import{u as fs}from"./useServiceByKey-Dcz6-Bh5.js";import"./proxy-CFgXQT6n.js";import"./sortable.esm-DG0QnPZd.js";import"./index-DqcSo0E4.js";import"./SearchOutlined-CR9yyVBB.js";const gs=({selectedPhoto:$,onPhotoClick:b,modalType:he="photo",serviceId:g,limit:F=4})=>{var ae,a;const C=Le(),[oe,Z]=c.useState(!1),[ye,fe]=c.useState(1),[ne,Y]=c.useState(null),{recentImages:p,recentImagesLoading:A,recentImagesError:N}=f(t=>t.services),{processExistingFile:Ie,processExistingFileLoading:Q,processExistingFileError:I}=f(t=>t.services);c.useEffect(()=>{g&&C(es({serviceId:g,page:ye,limit:F}))},[C,g,ye,F]);const z=()=>{Z(!0)},ie=()=>{Z(!1)},d=((ae=p==null?void 0:p.data)==null?void 0:ae.data)||[],U=((a=p==null?void 0:p.data)==null?void 0:a.pagination)||{},D=async t=>{var x,v,O,ee,T,_,B,G,K,P,V,W,le,ge,xe,ve;try{Y(t==null?void 0:t.id);const J={fileId:((x=t==null?void 0:t.generated_file)==null?void 0:x.id)||((v=t==null?void 0:t.original_file)==null?void 0:v.id),serviceId:g,serviceName:"service-day-to-dusk"},j=await C(Me(J));if(((ee=(O=j.payload)==null?void 0:O.meta)==null?void 0:ee.success)===!0){const je={...t,processResult:(T=j.payload)==null?void 0:T.data,image_id:(B=(_=j.payload)==null?void 0:_.data)==null?void 0:B.image_id,order_id:(K=(G=j.payload)==null?void 0:G.data)==null?void 0:K.order_id,file_key:(V=(P=j.payload)==null?void 0:P.data)==null?void 0:V.file_key,processing_status:(le=(W=j.payload)==null?void 0:W.data)==null?void 0:le.processing_status,actionResult:{data:(ge=j.payload)==null?void 0:ge.data}};b(je)}else{const je=((ve=(xe=j.payload)==null?void 0:xe.meta)==null?void 0:ve.message)||"Failed to process existing Day to Dusk file"}}catch{}finally{Y(null)}};return A&&d.length===0?s.jsxs("div",{children:[s.jsx("div",{className:"flex justify-between items-center mb-4",children:s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"Recent Images"}),s.jsx("p",{className:"text-sm text-gray-600",children:"Loading your recent transformations..."})]})}),s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4",children:[1,2,3,4].map(t=>s.jsx("div",{className:"aspect-[4/3] rounded-3xl overflow-hidden bg-gray-200 animate-pulse",children:s.jsx("div",{className:"w-full h-full bg-gradient-to-br from-gray-300 to-gray-400"})},t))})]}):N&&d.length===0?s.jsxs("div",{children:[s.jsx("div",{className:"flex justify-between items-center mb-4",children:s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"Recent Images"}),s.jsx("p",{className:"text-sm text-red-500",children:"Failed to load recent Day to Dusk transformations"})]})}),s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4",children:s.jsx("div",{className:"aspect-[4/3] rounded-3xl overflow-hidden bg-gradient-to-br from-red-100 to-red-200 flex items-center justify-center",children:s.jsxs("div",{className:"text-center",children:[s.jsx("i",{className:"icon-alert text-red-500 text-2xl mb-2 block"}),s.jsx("span",{className:"text-red-600 text-sm",children:"Failed to load"})]})})})]}):!A&&d.length===0?s.jsx("div",{children:s.jsx("div",{className:"flex justify-between items-center mb-4",children:s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-semibold",children:"Recent Images"}),s.jsx("p",{className:"text-sm text-secondary",children:"No recent images found"})]})})}):s.jsxs("div",{children:[s.jsxs("div",{className:"flex justify-between items-center mb-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-medium ",children:"Recent Images"}),s.jsxs("p",{className:"text-sm text-secondary",children:["Choose from ",(U==null?void 0:U.totalRecords)||d.length," transformed images"]})]}),d.length>0&&s.jsxs("button",{className:"text-md text-primary flex gap-1 items-center font-medium transition-colors",onClick:z,children:["View All",s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[s.jsx("path",{d:"M14.4297 5.92969L20.4997 11.9997L14.4297 18.0697",stroke:"var(--primary)",strokeWidth:"1.5",strokeMiterlimit:"10",strokeLinecap:"round",strokeLinejoin:"round"}),s.jsx("path",{d:"M11.0098 12H20.3298",stroke:"var(--primary)",strokeWidth:"1.5",strokeMiterlimit:"10",strokeLinecap:"round",strokeLinejoin:"round"}),s.jsx("path",{d:"M3.5 12H6.97",stroke:"var(--primary)",strokeWidth:"1.5",strokeMiterlimit:"10",strokeLinecap:"round",strokeLinejoin:"round"})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4",children:[d.map((t,x)=>{var K,P;const v=(K=t==null?void 0:t.generated_file)==null?void 0:K.key,O=(P=t==null?void 0:t.original_file)==null?void 0:P.key,ee="https://d11ajandb8h4fn.cloudfront.net",T=v||O,_=T?T.startsWith("https://")?T:`${ee}${T}`:null,B=($==null?void 0:$.id)===(t==null?void 0:t.id)||$===_,G=ne===(t==null?void 0:t.id);return s.jsxs("div",{className:`aspect-[4/3] rounded-3xl overflow-hidden bg-gray-200 hover:shadow-md transition-shadow cursor-pointer relative ${B?"border-4 border-green-500":""} ${G?"opacity-75":""}`,onClick:()=>!G&&D(t),children:[_?s.jsx("img",{src:_,alt:`Recent image ${x+1}`,className:"w-full h-full object-cover",onError:V=>{V.target.style.display="none",V.target.nextSibling.style.display="flex"}}):s.jsx("div",{className:"w-full h-full bg-gradient-to-br from-gray-300 to-gray-400 flex items-center justify-center",children:s.jsx("span",{className:"text-gray-500 text-sm",children:"No image available"})}),s.jsx("div",{className:"w-full h-full bg-gradient-to-br from-gray-300 to-gray-400 flex items-center justify-center",style:{display:"none"},children:s.jsx("span",{className:"text-gray-500 text-sm",children:"Image not found"})}),A&&s.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-20 flex items-center justify-center",children:s.jsx("div",{className:"w-6 h-6 border-2 border-white border-t-transparent roun
1ded-full animate-spin"})})]},(t==null?void 0:t.id)||x)}),A&&d.length>0&&d.length<F&&s.jsx(s.Fragment,{children:Array.from({length:F-d.length}).map((t,x)=>s.jsx("div",{className:"aspect-[4/3] rounded-3xl overflow-hidden bg-gray-200 animate-pulse",children:s.jsx("div",{className:"w-full h-full bg-gradient-to-br from-gray-300 to-gray-400"})},`loading-${x}`))})]}),oe&&(he==="video"?s.jsx(us,{recentPhotos:d,onClose:ie,onPhotoClick:D,initialIndex:0,pagination:U,serviceId:g,title:"Day to Dusk Transformations",theme:"dayToDusk"}):s.jsx(ps,{recentPhotos:d,onClose:ie,onPhotoClick:D,initialIndex:0,pagination:U,serviceId:g,title:"Day to Dusk Transformations",theme:"dayToDusk"}))]})},$e=50,xs=$e*1024*1024,Es=()=>{var Pe;const[$,b]=c.useState(!1),[he,g]=c.useState(null),[F,C]=c.useState(!1),[oe,Z]=c.useState(!1),[ye,fe]=c.useState(null),ne=c.useRef(null);c.useRef(null);const Y=f(ss),p=ts(),A=rs(),N=Le(),{serviceId:Ie}=os();fs("service-day-to-dusk");const[Q,I]=c.useState({isChunking:!1,currentFile:0,totalFiles:0,currentFileName:"",chunkProgress:0,overallProgress:0}),z=A.state||{},{serviceId:ie,serviceName:d,serviceTitle:U,serviceDescription:D,serviceKey:ae}=z,a=Ie||ie,t=U||"Day to Dusk AI",x=D||"Transform your daytime property photos into stunning dusk scenes with AI",v=ae||"service-day-to-dusk",{userImageUploadLoading:O,userImageUpload:ee,userImageUploadError:T}=f(e=>e.services),{imageUpload:_,imageUploadLoading:B,imageUploadError:G}=f(e=>e.services),{processExistingFile:K,processExistingFileLoading:P,processExistingFileError:V}=f(e=>e.services),{devoreImages:W,devoreImagesLoading:le}=f(e=>e==null?void 0:e.aryeoSync),{recentImages:ge,recentImagesLoading:xe,recentImagesError:ve}=f(e=>e.services),{spacesByService:J,spacesByServiceLoading:j,spacesByServiceError:je}=f(e=>e.spaces),{userForEdit:vs}=f(e=>(e==null?void 0:e.usersmanagement)||{});c.useEffect(()=>{a&&N(ns({serviceId:a,params:{}}))},[N,a]),c.useEffect(()=>()=>{I({isChunking:!1,currentFile:0,totalFiles:0,currentFileName:"",chunkProgress:0,overallProgress:0})},[]);const we=is("user",!0),ce=()=>{let e=we==null?void 0:we.token;const o={"X-Requested-With":"XMLHttpRequest",Accept:"application/json"};return e&&(o.Authorization=`Bearer ${e}`),o},de=()=>"https://api-server.devore.ai/api",Ae=async e=>{var o,r,n,i,u,S;try{const m=new AbortController,E=setTimeout(()=>m.abort(),1e4),h=await fetch(`${de()}/image-upload/generate-presigned-url`,{method:"POST",headers:{...ce(),"Content-Type":"application/json"},body:JSON.stringify({fileName:e.name,fileType:e.type,fileSize:e.size,serviceId:a,serviceName:v}),signal:m.signal});if(clearTimeout(E),!h.ok){const H=await h.text();throw new Error(`Failed to get presigned URL: ${h.statusText}`)}const w=await h.json();if(!((o=w.meta)!=null&&o.success))throw new Error(((r=w.meta)==null?void 0:r.message)||"Failed to get presigned URL");const{presignedUrl:R,fileKey:y,fileName:k,fileType:L,finalUrl:M}=w.data,q=await fetch(R,{method:"PUT",body:e,headers:{"Content-Type":e.type}});if(!q.ok){const H=await q.text();throw new Error(`Failed to upload to S3: ${q.statusText}`)}const ue={serviceId:a,serviceName:v,fileKey:y,fileName:k,fileType:L,fileSize:e.size},l=await N(cs(ue));if((i=(n=l.payload)==null?void 0:n.meta)!=null&&i.success)return{key:y,name:k,type:L,url:M||R.split("?")[0],size:e.size,actionResult:l.payload};throw new Error(((S=(u=l.payload)==null?void 0:u.meta)==null?void 0:S.message)||"Failed to process Day to Dusk image upload")}catch(m){throw m.name==="AbortError"?new Error("Upload request timed out. Please try again."):m}},ze=async(e,o)=>{var r,n,i,u,S,m;try{const h=Math.ceil(e.size/5242880),w=new AbortController,R=setTimeout(()=>w.abort(),1e4),y=await fetch(`${de()}/image-upload/initialize-multipart-upload`,{method:"POST",headers:{...ce(),"Content-Type":"application/json"},body:JSON.stringify({fileName:e.name,fileType:e.type}),signal:w.signal});if(clearTimeout(R),!y.ok){const X=await y.text();throw new Error(`Failed to initialize multipart upload: ${y.statusText}`)}const k=await y.json();if(!((r=k.meta)!=null&&r.success))throw new Error(((n=k.meta)==null?void 0:n.message)||"Failed to initialize multipart upload");const{uploadId:L,fileKey:M,fileName:q,fileType:ue}=k.data,l=new AbortController,H=setTimeout(()=>l.abort(),1e4),se=await fetch(`${de()}/image-upload/generate-upload-part-urls`,{method:"POST",headers:{...ce(),"Content-Type":"application/json"},body:JSON.stringify({uploadId:L,fileKey:M,totalParts:h}),signal:l.signal});if(clearTimeout(H),!se.ok){const X=await se.text();throw new Error(`Failed to get upload part URLs: ${se.statusText}`)}const te=await se.json();if(!((i=te.meta)!=null&&i.success))throw new Error(((u=te.meta)==null?void 0:u.message)||"Failed to get upload part URLs");const{presignedUrls:Se}=te.data,Ee=[];for(let X=0;X<Se.length;X++){const{partNumber:re,url:Ze}=Se[X],Ce=(re-1)*5242880,Ye=Math.min(Ce+5242880,e.size),Qe=e.slice(Ce,Ye),me=await fetch(Ze,{method:"PUT",body:Qe,headers:{"Content-Type":e.type}});if(!me.ok){const Ue=await me.text();throw new Error(`Failed to upload part ${re}: ${me.statusText}`)}const De=me.headers.get("ETag");if(Ee.push({PartNumber:re,ETag:De}),o){const Ue=Math.round(re/h*100);o({currentChunk:re,totalChunks:h,progress:Ue,fileName:e.name})}}const Fe=new AbortController,Xe=setTimeout(()=>Fe.abort(),6e5),pe=await fetch(`${de()}/image-upload/complete-multipart-upload`,{method:"POST",headers:{...ce(),"Content-Type":"application/json"},body:JSON.stringify({uploadId:N,fileKey:M,parts:Ee,fileType:e.type,fileSize:e.size,serviceId:a,serviceName:v}),signal:Fe.signal});if(clearTimeout(Xe),!pe.ok){const X=await pe.text();throw new Error(`Failed to complete multipart upload: ${pe.statusText}`)}const be=await pe.json();if(!((S=be.meta)!=null&&S.success))throw new Error(((m=be.meta)==null?void 0:m.message)||"Failed to complete multipart upload");return be.data}catch(E){throw E.name==="AbortError"?new Error("Upload request timed out. Please try again."):E}},Oe=async e=>{const r=e.size>5242880;I({isChunking:!0,currentFile:1,totalFiles:1,currentFileName:e.name,chunkProgress:0,overallProgress:0});try{let n;return r?n=await ze(e,i=>{I(u=>({...u,chunkProgress:i.progress,overallProgress:i.progress}))}):(I(i=>({...i,chunkProgress:50,overallProgress:50})),n=await Ae(e),I(i=>({...i,chunkProgress:100,overallProgress:100}))),I(i=>({...i,isChunking:!1})),n}catch(n){throw I(i=>({...i,isChunking:!1})),n}},Be=e=>{if(e.size>xs)return Ne.error({message:"File too large",description:`Image size must be less than ${$e}MB`,duration:5}),!1;
1if(!["image/jpeg","image/png","image/gif","image/webp","image/jpg"].includes(e.type)){const n=(e.name||"").toLowerCase().split(".").pop();if(!["jpg","jpeg","png","gif","webp"].includes(n))return Ne.error({message:"Invalid file type",description:"Please upload a valid image file (JPEG, PNG, GIF, WebP)",duration:5}),!1}return!0},Te=async e=>{const o=e.target.files[0];if(o&&Be(o)){b(!0);try{const r=await Oe(o),n=new FileReader;n.onload=i=>{const u=i.target.result;p(`/service-day-to-dusk/${a}/uploaded-image`,{state:{...z,uploadedImageData:r,uploadedImagePreview:u,s3FileData:r,spacesData:J,timestamp:Date.now()},replace:!1})},n.readAsDataURL(o)}catch(r){b(!1),Ne.error({message:"Upload failed",description:r.message||"Failed to upload Day to Dusk image. Please try again.",duration:5})}}},Ge=e=>{b(!0),g(e);const r=e==null?void 0:e.file_key,n=r&&r.startsWith("https://")?r:`https://d11ajandb8h4fn.cloudfront.net${r}`;p(`/service-day-to-dusk/${a}/uploaded-image`,{state:{...z,uploadedImageData:e,uploadedImagePreview:n,spacesData:J,isRecentPhoto:!0,timestamp:Date.now()}})},Ke=async e=>{var o,r,n,i,u,S,m,E,h,w,R,y,k,L,M;try{fe((e==null?void 0:e.id)||(e==null?void 0:e.file_key)),b(!0);const ue={fileId:(o=e==null?void 0:e.original_file)==null?void 0:o.id,serviceId:a,serviceName:v},l=await N(Me(ue));if(((n=(r=l.payload)==null?void 0:r.meta)==null?void 0:n.success)===!0){const H={...e,processResult:(i=l.payload)==null?void 0:i.data,image_id:(S=(u=l.payload)==null?void 0:u.data)==null?void 0:S.image_id,order_id:(E=(m=l.payload)==null?void 0:m.data)==null?void 0:E.order_id,file_key:(w=(h=l.payload)==null?void 0:h.data)==null?void 0:w.file_key,processing_status:(y=(R=l.payload)==null?void 0:R.data)==null?void 0:y.processing_status,actionResult:{data:(k=l.payload)==null?void 0:k.data}},se=e!=null&&e.is_aryeo?(L=e==null?void 0:e.original_file)==null?void 0:L.key:e==null?void 0:e.file_key,te=e!=null&&e.is_aryeo?(M=e==null?void 0:e.original_file)==null?void 0:M.key:`https://d11ajandb8h4fn.cloudfront.net${e==null?void 0:e.file_key}`;g(H),setTimeout(()=>{p(`/service-day-to-dusk/${a}/uploaded-image`,{state:{...z,uploadedImageData:H,uploadedImagePreview:te,spacesData:J,isRecentPhoto:!0,isDevorePhoto:!0,timestamp:Date.now()}})},1e3),C(!1)}else b(!1)}catch{b(!1)}finally{fe(null)}},Ve=e=>{e.preventDefault()},We=e=>{e.preventDefault();const o=e.dataTransfer.files;if(o.length>0){const r=o[0];r.type.startsWith("image/")&&Te({target:{files:[r]}})}},Je=()=>{var e;(e=ne.current)==null||e.click()},qe=()=>{N(ls({page:1,limit:3})).then(e=>{var r,n;const o=(r=e.payload)==null?void 0:r.data;if(((n=o==null?void 0:o.images)==null?void 0:n.length)>0){if(F)return;C(!0)}else{if(oe)return;Z(!0)}})},He=()=>{p("/home")},ke=$||O||B||Q.isChunking||P;return s.jsxs("div",{className:"min-h-screen bg-background p-6",children:[s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-start mb-6",children:[s.jsx(as,{type:"text",icon:s.jsx("i",{className:"icon-back text-[var(--headPrimary)]",style:{fontSize:"24px"}}),onClick:He,className:"flex items-center justify-center bg-primaryOpacity border-0",size:"large"}),s.jsxs("div",{className:"flex-col ml-3",children:[s.jsx("h1",{className:"text-lg sm:text-2xl font-semibold text-textPrimary",children:t}),s.jsx("p",{className:"text-xs sm:text-sm text-secondary",children:x})]})]}),s.jsxs("div",{className:`max-w-5xl mx-auto my-10 ${ke?"":"border border-liteGrayV1"} p-8 rounded-3xl relative`,children:[s.jsxs("div",{className:"rounded-3xl py-16 px-4 sm:px-10 sm:py-12 text-center mb-8 border-2 border-dashed border-[var(--headPrimary)] bg-primaryOpacity",onDragOver:Ve,onDrop:We,children:[Q.isChunking&&s.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full py-20 px-4 sm:px-10",children:[s.jsx("div",{className:"relative mb-4",children:s.jsx("div",{className:"relative w-20 h-20 sm:w-24 sm:h-24 flex justify-center items-center",children:s.jsx("div",{className:"w-16 h-16 sm:w-20 sm:h-20 bg-primaryOpacity flex justify-center items-center rounded-xl",children:s.jsx("img",{src:Y?_e:Re,alt:"",className:"w-8 h-8 sm:w-10 sm:h-10"})})})}),s.jsx("h3",{className:"text-xl sm:text-2xl font-medium text-primary mt-3 mb-2",children:"Uploading image..."})]}),ke&&!Q.isChunking?s.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full py-20 px-4 sm:px-10",children:[s.jsx("div",{className:"relative mb-4",children:s.jsx("div",{className:"relative w-20 h-20 sm:w-24 sm:h-24 flex justify-center items-center",children:s.jsx("div",{className:"w-16 h-16 sm:w-20 sm:h-20 bg-primaryOpacity flex justify-center items-center rounded-xl",children:s.jsx("img",{src:Y?_e:Re,alt:"",className:"w-8 h-8 sm:w-10 sm:h-10"})})})}),s.jsx("h3",{className:"text-xl sm:text-2xl font-medium text-primary mt-3 mb-2",children:P?"Processing Day to Dusk image...":"Finalizing Day to Dusk Upload..."})]}):!Q.isChunking&&s.jsx(ms,{description:"Upload your property photos to get started with AI Day to Dusk. You can also select photos from your linked DeVore Design account.",onUploadClick:Je,onDeVoreGallery:qe,Upload_Icon:ds,isDevoreLoading:le})]}),!ke&&s.jsx(gs,{selectedPhoto:he,onPhotoClick:Ge,serviceId:a,limit:4}),s.jsx("input",{type:"file",ref:ne,onChange:Te,accept:"image/*",className:"hidden"})]})]}),s.jsx(hs,{isOpen:F,setIsOpen:C,syncTime:(Pe=W==null?void 0:W.data)==null?void 0:Pe.synced_at,onPhotoSelect:Ke}),s.jsx(ys,{isOpen:oe,setIsOpen:Z})]})};export{Es 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.