1import{j as e}from"./query-vendor-DYY6GVNB.js";import{r as _,e as Be,d as Ke}from"./react-vendor-nrvd3ntZ.js";import{r as le,s as C,B as X,p as q,I as Ne,q as Ve}from"./index-BuoCNTHT.js";import{I as M}from"./input-BgY1jp76.js";import{T as Me,a as Te,b as re,c as oe,d as ee,S as te}from"./tabs-9oDcUuCO.js";import{C as H,c as J}from"./card-PJUoQwxj.js";import{L as g}from"./label-DEo6a61x.js";import{B as we}from"./badge-C78r8jyF.js";import{S as me,a as ue,b as ge,c as he,d as K}from"./select-Chp6N4pq.js";import{c as Ze,P as We}from"./PropertyImageUpload-CKgZxBlf.js";import{P as Ae}from"./progress-B6g24Liw.js";import{a5 as je,m as _e,a6 as Xe,a7 as Ie,X as ye,E as Le,O as qe,a8 as ne,e as ze,a2 as pe,q as Re,z as ae,Q as He,i as Je,a9 as Qe,aa as Ye,J as es,h as ss,T as ke,ab as as,Z as ts,ac as is,ad as rs,ae as os,af as ns,ag as ls}from"./icons-vendor-B8vviyZF.js";import"./supabase-vendor-C5xCEaJj.js";import"./i18n-vendor-DXVYSRAW.js";import"./index-BbFzfkI7.js";import"./index-Cqb0Mja9.js";import"./Combination-CtLII_w1.js";import"./form-vendor-M6LuE28c.js";import"./alert-B0nu-JGd.js";const cs=Ne.MEDIA_MAX_SIZE,ds=i=>{if(i===0)return"0 Bytes";const p=1024,n=["Bytes","KB","MB","GB"],m=Math.floor(Math.log(i)/Math.log(p));return`${parseFloat((i/Math.pow(p,m)).toFixed(2))} ${n[m]}`},_s=({propertyId:i,promoVideoUrl:p,brochurePdfUrl:n,audioDescriptionUrl:m,videoAdUrl:b,onMediaUpdate:F})=>{const{toast:f}=le(),[z,s]=_.useState({uploading:!1,progress:0,error:null,isDragging:!1}),[$,R]=_.useState({uploading:!1,progress:0,error:null,isDragging:!1}),[P,c]=_.useState({uploading:!1,progress:0,error:null,isDragging:!1}),[S,w]=_.useState({uploading:!1,progress:0,error:null,isDragging:!1}),O=_.useRef(null),l=_.useRef(null),L=_.useRef(null),D=_.useRef(null),T=(t,a,r=cs)=>{if(t.size>r)return`El archivo excede el lÃmite de ${ds(r)}`;const o="."+t.name.toLowerCase().split(".").pop();return a.includes(o)?null:`Tipo de archivo no permitido. Formatos aceptados: ${a.join(", ")}`},E=async(t,a,r,o,h)=>{o(u=>({...u,uploading:!0,progress:0,error:null}));try{const u=setInterval(()=>{o(N=>({...N,progress:Math.min(N.progress+10,90)}))},200),{error:I}=await C.storage.from(a).upload(r,t,{upsert:!0,cacheControl:"3600"});if(clearInterval(u),I)throw I;const{data:k}=C.storage.from(a).getPublicUrl(r);o(N=>({...N,uploading:!1,progress:100,error:null})),F(h,k.publicUrl),f({title:"â
Ãxito",description:`${a==="property-videos"?"Video":a==="property-brochures"?"PDF":"Audio"} subido correctamente`}),setTimeout(()=>{o(N=>({...N,progress:0}))},1500)}catch(u){o(I=>({...I,uploading:!1,progress:0,error:u.message||"Error al subir el archivo"})),f({title:"Error",description:u.message||"Error al subir el archivo",variant:"destructive"})}},j=async(t,a,r)=>{if(confirm("¿Estás seguro de que deseas eliminar este archivo?"))try{const o=a.split(`${t}/`);if(o.length<2)throw new Error("URL inválida");const h=o[1],{error:u}=await C.storage.from(t).remove([h]);if(u)throw u;F(r,null),f({title:"â
Ãxito",description:"Archivo eliminado"})}catch(o){f({title:"Error",description:o.message||"Error al eliminar el archivo",variant:"destructive"})}},A=_.useCallback((t,a)=>{t.preventDefault(),t.stopPropagation(),a(r=>({...r,isDragging:!0}))},[]),G=_.useCallback((t,a)=>{t.preventDefault(),t.stopPropagation(),a(r=>({...r,isDragging:!1}))},[]),U=_.useCallback((t,a,r,o,h,u)=>{t.preventDefault(),t.stopPropagation(),h(d=>({...d,isDragging:!1}));const I=t.dataTransfer.files[0];if(!I)return;const k=T(I,a);if(k){h(d=>({...d,error:k})),f({title:"Error",description:k,variant:"destructive"});return}E(I,r,o,h,u)},[]),V=t=>{const a=t.target.files?.[0];if(!a)return;const r=T(a,[".mp4"]);if(r){s(h=>({...h,error:r})),f({title:"Error",description:r,variant:"destructive"});return}const o=`${i}-promo.mp4`;E(a,"property-videos",o,s,"promo_video_url"),O.current&&(O.current.value="")},B=t=>{const a=t.target.files?.[0];if(!a)return;const r=T(a,[".mp4",".mov"]);if(r){w(u=>({...u,error:r})),f({title:"Error",description:r,variant:"destructive"});return}const o=a.name.toLowerCase().split(".").pop(),h=`${i}-ad.${o}`;E(a,"property-videos",h,w,"video_ad_url"),D.current&&(D.current.value="")},y=t=>{const a=t.target.files?.[0];if(!a)return;const r=T(a,[".pdf"]);if(r){R(h=>({...h,error:r})),f({title:"Error",description:r,variant:"destructive"});return}const o=`${i}-brochure.pdf`;E(a,"property-brochures",o,R,"brochure_pdf_url"),l.current&&(l.current.value="")},v=t=>{const a=t.target.files?.[0];if(!a)return;const r=T(a,[".mp3",".ogg"]);if(r){c(u=>({...u,error:r})),f({title:"Error",description:r,variant:"destructive"});return}const o=a.name.toLowerCase().split(".").pop(),h=`${i}-audio.${o}`;E(a,"property-audio",h,c,"audio_description_url"),L.current&&(L.current.value="")},x=({icon:t,label:a,accept:r,inputRef:o,onChange:h,uploadState:u,setUploadState:I,currentUrl:k,bucket:d,fieldName:N,fileName:Z,allowedExtensions:Q,dropText:Ue})=>{const Ge=!!k;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(t,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:a})]}),u.uploading&&e.jsxs("div",{className:"space-y-2 mb-3",children:[e.jsx(Ae,{value:u.progress,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:["Subiendo... ",u.progress,"%"]})]}),u.progress===100&&!u.uploading&&e.jsxs("div",{className:"flex items-center gap-2 text-green-600 mb-3",children:[e.jsx(Ie,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Subido correctamente"})]}),u.error&&e.jsxs("div",{className:"flex items-center gap-2 text-destructive mb-3 text-sm",children:[e.jsx(ye,{className:"h-4 w-4"}),e.jsx("span",{children:u.error})]}),e.jsx("div",{className:"flex-1",children:Ge&&!u.uploading?e.jsxs("div",{className:"space-y-3",children:[d==="property-videos"&&e.jsx("video",{src:k,controls:!0,className:"w-full rounded-lg max-h-40 object-contain bg-black"}),d==="property-brochures"&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(_e,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:k?.split("/").pop()}),e.jsxs(X,{type:"button",variant:"link",size:"sm",className:"h-auto p-0 text-primary",onClick:()=>window.open(k,"_blank"),children:[e.jsx(Le,{className:"h-3 w-3 mr-1"}),"Ver PDF"]})]})]}),d==="property-audio"&&e.jsxs("audio",{controls:!0,className:"w-full",children:[e.jsx("source",{src:k,type:k.endsWith(".ogg")?"audio/ogg":"audio/mpeg"}),"Tu navegador no soporta el elemento de audio."]}),e.jsxs(X,{type:"button",variant:"destructive",size:"sm",className:"w-full",onClick:()=>j(d,k,N),children:[e.jsx(qe,{className:"h-4 w-4 mr-1"}),"Eliminar"]})]}):u.uploading?null:e.jsxs("div",{className:q("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors","hover:border-primary/50 hover:bg-muted/50",u.isDragging&&"border-primary bg-primary/10"),onClick:()=>o.current?.click(),onDragOver:ce=>A(ce,I),onDragLeave:ce=>G(ce,I),onDrop:ce=>U(ce,Q,d,Z,I,N),children:[e.jsx(ne,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Ue})]})}),e.jsx("input",{ref:o,type:"file",accept:r,onChange:h,className:"hidden"})]})};return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(x,{icon:je,label:"ð¬ Video Promocional",accept:".mp4,video/mp4",inputRef:O,onChange:V,uploadState:z,setUploadState:s,currentUrl:p,bucket:"property-videos",fieldName:"promo_video_url",fileName:`${i}-promo.mp4`,allowedExtensions:[".mp4"],dropText:"Arrastra un video MP4 o haz clic para seleccionar"})}),e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(x,{icon:_e,label:"ð Brochure PDF",accept:".pdf,application/pdf",inputRef:l,onChange:y,uploadState:$,setUploadState:R,currentUrl:n,bucket:"property-brochures",fieldName:"brochure_pdf_url",fileName:`${i}-brochure.pdf`,allowedExtensions:[".pdf"],dropText:"Arrastra un PDF o haz clic para seleccionar"})}),e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(x,{icon:Xe,label:"ðï¸ Audio Descripción",accept:".mp3,.ogg,audio/mpeg,audio/ogg",inputRef:L,onChange:v,uploadState:P,setUploadState:c,currentUrl:m,bucket:"property-audio",fieldName:"audio_description_url",fileName:`${i}-audio.mp3`,allowedExtensions:[".mp3",".ogg"],dropText:"Arrastra un audio MP3 o haz clic para seleccionar"})}),e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(x,{icon:je,label:"ðº Video Ad (Pauta)",accept:".mp4,.mov,video/mp4,video/quicktime",inputRef:D,onChange:B,uploadState:S,setUploadState:w,currentUrl:b,bucket:"property-videos",fieldName:"video_ad_url",fileName:`${i}-ad.mp4`,allowedExtensions:[".mp4",".mov"],dropText:"Arrastra un video MP4/MOV o haz clic para seleccionar"})})]})},Ee=16*1024*1024,ie="property-documents",xe={uploading:!1,progress:0,error:null,isDragging:!1},ps=i=>{const n=["Bytes","KB","MB","GB"],m=Math.floor(Math.log(i)/Math.log(1024));return`${parseFloat((i/Math.pow(1024,m)).toFixed(2))} ${n[m]}`},Oe=i=>{const p=i.name.toLowerCase().split(".");return p.length>1?`.${p.pop()}`:""},ms=(i,p,n)=>{const m=Oe(n);return`${i}/${p}-${Date.now()}${m}`},ve=i=>i.split("?")[0],Ce=i=>{const p=ve(i),n=`/storage/v1/object/public/${ie}/`,m=p.indexOf(n);return m===-1?null:decodeURIComponent(p.substring(m+n.length))},us=({src:i,alt:p})=>{const[n,m]=_.useState(!1),[b,F]=_.useState(!1);return e.jsxs("div",{className:"relative w-full rounded-lg bg-muted min-h-[100px] max-h-[160px] flex items-center justify-center overflow-hidden",children:[!n&&!b&&e.jsx(ae,{className:"h-6 w-6 animate-spin text-muted-foreground absolute"}),b&&e.jsx("p",{className:"text-sm text-destructive",children:"Error al cargar imagen"}),e.jsx("img",{src:i,alt:p,onLoad:()=>m(!0),onError:()=>F(!0),className:q("w-full max-h-[160px] object-contain transition-opacity duration-200",n?"opacity-100":"opacity-0")})]})},gs=({propertyId:i,locationPdfUrl:p,locationPhotoUrl:n,financingPdfUrl:m,financingPhotoUrl:b,onDocumentUpdate:F})=>{const{toast:f}=le(),[z,s]=_.useState(xe),[$,R]=_.useState(xe),[P,c]=_.useState(xe),[S,w]=_.useState(xe),O=_.useRef(null),l=_.useRef(null),L=_.useRef(null),D=_.useRef(null);_.useEffect(()=>{const y={location_pdf_url:p,location_photo_url:n,financing_pdf_url:m,financing_photo_url:b},v={};for(const[x,t]of Object.entries(y))t&&t.includes("?")&&(v[x]=ve(t));Object.keys(v).length>0&&C.from("properties").update(v).eq("id",i).then(()=>{for(const[x,t]of Object.entries(v))F(x,t)})},[i]);const T=(y,v)=>{if(y.size>Ee)return`El archivo excede el lÃmite de ${ps(Ee)}`;const x=Oe(y);return v.includes(x)?null:`Tipo de archivo no permitido. Formatos aceptados: ${v.join(", ")}`},E=async(y,v,x,t,a)=>{x({uploading:!0,progress:10,error:null,isDragging:!1});const r=ms(i,v,y);try{if(a){const k=Ce(a);k&&await C.storage.from(ie).remove([k])}x(k=>({...k,progress:30}));const{error:o}=await C.storage.from(ie).upload(r,y,{upsert:!1,cacheControl:"31536000"});if(o)throw o;const{data:h}=C.storage.from(ie).getPublicUrl(r),u=ve(h.publicUrl);x(k=>({...k,progress:70}));const{error:I}=await C.from("properties").update({[t]:u}).eq("id",i);if(I)throw await C.storage.from(ie).remove([r]),I;F(t,u),x({uploading:!1,progress:100,error:null,isDragging:!1}),f({title:"â
Ãxito",description:"Archivo subido y guardado"}),setTimeout(()=>{x(k=>({...k,progress:0}))},1500)}catch(o){x({uploading:!1,progress:0,error:o.message||"Error al subir",isDragging:!1}),f({title:"Error",description:o.message||"Error al subir el archivo",variant:"destructive"})}},j=async(y,v)=>{if(confirm("¿Estás seguro de que deseas eliminar este archivo?")&&y)try{const{error:x}=await C.from("properties").update({[v]:null}).eq("id",i);if(x)throw x;const t=Ce(y);t&&await C.storage.from(ie).remove([t]),F(v,null),f({title:"â
Ãxito",description:"Archivo eliminado"})}catch(x){f({title:"Error",description:x.message||"Error al eliminar",variant:"destructive"})}},A=_.useCallback((y,v)=>{y.preventDefault(),y.stopPropagation(),v(x=>({...x,isDragging:!0}))},[]),G=_.useCallback((y,v)=>{y.preventDefault(),y.stopPropagation(),v(x=>({...x,isDragging:!1}))},[]),U=_.useCallback((y,v,x,t,a,r)=>{y.preventDefault(),y.stopPropagation(),t(u=>({...u,isDragging:!1}));const o=y.dataTransfer.files[0];if(!o)return;const h=T(o,v);if(h){t(u=>({...u,error:h})),f({title:"Error",description:h,variant:"destructive"});return}E(o,x,t,a,r)},[i]),V=(y,v,x,t,a,r,o)=>{const h=y.target.files?.[0];if(!h)return;const u=T(h,v);if(u){t(I=>({...I,error:u})),f({title:"Error",description:u,variant:"destructive"});return}E(h,x,t,a,o),r.current&&(r.current.value="")},B=({icon:y,label:v,accept:x,inputRef:t,uploadState:a,setUploadState:r,currentUrl:o,slotName:h,fieldName:u,allowedExtensions:I,dropText:k,isImage:d})=>{const N=o?ve(o):null,Z=!!N;return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(y,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:v})]}),a.uploading&&e.jsxs("div",{className:"space-y-2 mb-3",children:[e.jsx(Ae,{value:a.progress,className:"h-2"}),e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:["Subiendo... ",a.progress,"%"]})]}),a.progress===100&&!a.uploading&&e.jsxs("div",{className:"flex items-center gap-2 text-green-600 mb-3",children:[e.jsx(Ie,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Guardado â"})]}),a.error&&e.jsxs("div",{className:"flex items-center gap-2 text-destructive mb-3 text-sm",children:[e.jsx(ye,{className:"h-4 w-4"}),e.jsx("span",{children:a.error})]}),e.jsx("div",{className:"flex-1",children:Z&&!a.uploading?e.jsxs("div",{className:"space-y-3",children:[d?e.jsx(us,{src:N,alt:v},N):e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg",children:[e.jsx(_e,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:N.split("/").pop()}),e.jsxs(X,{type:"button",variant:"link",size:"sm",className:"h-auto p-0 text-primary",onClick:()=>window.open(N,"_blank"),children:[e.jsx(Le,{className:"h-3 w-3 mr-1"}),"Ver PDF"]})]})]}),e.jsxs(X,{type:"button",variant:"destructive",size:"sm",className:"w-full",onClick:()=>j(o,u),children:[e.jsx(qe,{className:"h-4 w-4 mr-1"}),"Eliminar"]})]}):a.uploading?null:e.jsxs("div",{className:q("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors","hover:border-primary/50 hover:bg-muted/50",a.isDragging&&"border-primary bg-primary/10"),onClick:()=>t.current?.click(),onDragOver:Q=>A(Q,r),onDragLeave:Q=>G(Q,r),onDrop:Q=>U(Q,I,h,r,u,o),children:[e.jsx(ne,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:k})]})}),e.jsx("input",{ref:t,type:"file",accept:x,onChange:Q=>V(Q,I,h,r,u,t,o),className:"hidden"})]})};return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:[e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(B,{icon:ze,label:"ð PDF Cómo Llegar",accept:".pdf,application/pdf",inputRef:O,uploadState:z,setUploadState:s,currentUrl:p,slotName:"ubicacion",fieldName:"location_pdf_url",allowedExtensions:[".pdf"],dropText:"Arrastra un PDF o haz clic para seleccionar",isImage:!1})}),e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(B,{icon:pe,label:"ð Foto Ubicación/Mapa",accept:".jpg,.jpeg,.png,image/jpeg,image/png",inputRef:l,uploadState:$,setUploadState:R,currentUrl:n,slotName:"ubicacion-foto",fieldName:"location_photo_url",allowedExtensions:[".jpg",".jpeg",".png"],dropText:"Arrastra una imagen JPG/PNG o haz clic",isImage:!0})}),e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:e.jsx(B,{icon:Re,label:"ð° PDF Financiamiento",accept:".pdf,application/pdf",inputRef:L,uploadState:P,setUploadState:c,currentUrl:m,slotName:"financiamiento",fieldName:"financing_pdf_url",allowedExtensions:[".pdf"],dropText:"Arrastra un PDF o haz clic para seleccionar",isImage:!1})}),e.jsx("div",{className:"p-4 border rounded-lg bg-card",children:
1e.jsx(B,{icon:pe,label:"ð° Foto Financiamiento",accept:".jpg,.jpeg,.png,image/jpeg,image/png",inputRef:D,uploadState:S,setUploadState:w,currentUrl:b,slotName:"financiamiento-foto",fieldName:"financing_photo_url",allowedExtensions:[".jpg",".jpeg",".png"],dropText:"Arrastra una imagen JPG/PNG o haz clic",isImage:!0})})]})},hs=["image/jpeg","image/png","image/webp"],xs=5*1024*1024,de="property-images",Se=i=>{const p=`/storage/v1/object/public/${de}/`,n=i.indexOf(p);return n===-1?null:decodeURIComponent(i.substring(n+p.length).split("?")[0])},fs=({value:i,onChange:p,propertyId:n,folder:m="value_hook",className:b})=>{const[F,f]=_.useState(!1),[z,s]=_.useState(!1),[$,R]=_.useState(!1),P=_.useRef(null),{toast:c}=le(),S=j=>hs.includes(j.type)?j.size>xs?"La imagen no puede ser mayor a 5MB":null:"Solo se permiten imágenes JPG, PNG o WebP",w=async j=>{const A=S(j);if(A){c({title:"Error de validación",description:A,variant:"destructive"});return}f(!0);try{if(i){const v=Se(i);v&&await C.storage.from(de).remove([v]).catch(()=>{})}s(!0);const G=await Ze(j,{maxWidth:1600,quality:.8,format:"webp"});s(!1);const U=Date.now(),V=`followup/${n}/${m}_${U}.webp`,{error:B}=await C.storage.from(de).upload(V,G,{cacheControl:"3600",upsert:!1});if(B)throw B;const{data:y}=C.storage.from(de).getPublicUrl(V);p(y.publicUrl),c({title:"â
Imagen subida",description:"La imagen se subió correctamente"})}catch(G){c({title:"Error al subir",description:G.message||"Error al subir la imagen. Intenta de nuevo.",variant:"destructive"})}finally{s(!1),f(!1)}},O=_.useCallback(j=>{j.preventDefault(),R(!1);const A=j.dataTransfer.files;A.length>0&&w(A[0])},[n,m,i]),l=_.useCallback(j=>{j.preventDefault(),R(!0)},[]),L=_.useCallback(j=>{j.preventDefault(),R(!1)},[]),D=()=>P.current?.click(),T=j=>{const A=j.target.files;A&&A.length>0&&w(A[0]),j.target.value=""},E=async()=>{if(i){const j=Se(i);j&&await C.storage.from(de).remove([j]).catch(()=>{})}p(""),c({title:"ðï¸ Imagen eliminada",description:"La imagen se eliminó correctamente"})};return i?e.jsxs("div",{className:q("relative inline-block",b),children:[e.jsx("img",{src:i,alt:"Preview",className:"max-w-[200px] h-auto rounded-lg border shadow-sm",onError:j=>{j.target.style.display="none"}}),e.jsx(X,{type:"button",variant:"destructive",size:"icon",className:"absolute -top-2 -right-2 h-6 w-6 rounded-full shadow-md",onClick:E,children:e.jsx(ye,{className:"h-3 w-3"})})]}):F?e.jsxs("div",{className:q("flex flex-col items-center justify-center p-6 rounded-lg border-2 border-dashed border-muted-foreground/30 bg-muted/20",b),children:[e.jsx(ae,{className:"h-8 w-8 text-primary animate-spin mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:z?"Comprimiendo...":"Subiendo..."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:D,onDrop:O,onDragOver:l,onDragLeave:L,className:q("flex flex-col items-center justify-center p-6 rounded-lg border-2 border-dashed cursor-pointer transition-all",$?"border-primary bg-primary/5":"border-muted-foreground/30 bg-muted/10 hover:border-muted-foreground/50 hover:bg-muted/20",b),children:[$?e.jsx(ne,{className:"h-8 w-8 text-primary mb-2"}):e.jsx(pe,{className:"h-8 w-8 text-muted-foreground/60 mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"Arrastra una imagen aquà o haz clic para seleccionar"}),e.jsx("p",{className:"text-xs text-muted-foreground/60 mt-1",children:"JPG, PNG o WebP"})]}),e.jsx("input",{ref:P,type:"file",accept:".jpg,.jpeg,.png,.webp",onChange:T,className:"hidden"})]})},vs=({messages:i,photo:p,attachmentLabel:n,className:m})=>{const b=i.filter(F=>F.trim());return b.length===0&&!p&&!n?e.jsx("div",{className:q("bg-[#efeae2] rounded-xl p-4 min-h-[120px] flex items-center justify-center",m),children:e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"Sin mensajes aún â escribe algo para ver el preview"})}):e.jsxs("div",{className:q("bg-[#efeae2] rounded-xl p-4 space-y-1.5 max-h-[400px] overflow-y-auto",m),children:[n&&e.jsx("div",{className:"flex justify-end",children:e.jsxs("div",{className:"bg-[#d9fdd3] rounded-lg px-3 py-2 max-w-[85%] shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-emerald-700",children:[e.jsx("span",{children:"ð"}),e.jsx("span",{className:"italic",children:n})]}),e.jsx("p",{className:"text-[10px] text-gray-500 text-right mt-0.5",children:"10:00 AM ââ"})]})}),p&&e.jsx("div",{className:"flex justify-end",children:e.jsxs("div",{className:"bg-[#d9fdd3] rounded-lg p-1 max-w-[85%] shadow-sm",children:[e.jsx("img",{src:p,alt:"Preview",className:"rounded-md max-h-[140px] w-auto object-cover"}),e.jsx("p",{className:"text-[10px] text-gray-500 text-right mt-0.5 px-2 pb-1",children:"10:00 AM ââ"})]})}),b.map((F,f)=>e.jsx("div",{className:"flex justify-end",children:e.jsxs("div",{className:"bg-[#d9fdd3] rounded-lg px-3 py-2 max-w-[85%] shadow-sm",children:[e.jsx("p",{className:"text-sm text-gray-800 whitespace-pre-wrap leading-relaxed",children:F}),e.jsxs("p",{className:"text-[10px] text-gray-500 text-right mt-0.5",children:[`10:0${f} AM`," ââ"]})]})},f))]})},Pe={blue:{border:"border-blue-500",bg:"bg-blue-50",text:"text-blue-700",badge:"bg-blue-100 text-blue-700"},rose:{border:"border-rose-500",bg:"bg-rose-50",text:"text-rose-700",badge:"bg-rose-100 text-rose-700"},orange:{border:"border-orange-500",bg:"bg-orange-50",text:"text-orange-700",badge:"bg-orange-100 text-orange-700"},purple:{border:"border-purple-500",bg:"bg-purple-50",text:"text-purple-700",badge:"bg-purple-100 text-purple-700"},amber:{border:"border-amber-500",bg:"bg-amber-50",text:"text-amber-700",badge:"bg-amber-100 text-amber-700"},sky:{border:"border-sky-500",bg:"bg-sky-50",text:"text-sky-700",badge:"bg-sky-100 text-sky-700"},indigo:{border:"border-indigo-500",bg:"bg-indigo-50",text:"text-indigo-700",badge:"bg-indigo-100 text-indigo-700"},emerald:{border:"border-emerald-500",bg:"bg-emerald-50",text:"text-emerald-700",badge:"bg-emerald-100 text-emerald-700"},cyan:{border:"border-cyan-500",bg:"bg-cyan-50",text:"text-cyan-700",badge:"bg-cyan-100 text-cyan-700"}},Fe=16*1024*1024,se="property-media",De=(i,p)=>{const n=i.split("?")[0],m=`/storage/v1/object/public/${p}/`,b=n.indexOf(m);return b===-1?null:decodeURIComponent(n.substring(b+m.length))},js=i=>{const p=[];for(let n=1;n<=i;n++)p.push(`photo${n}`);return p.push("video","pdf"),p},ys=(i,p)=>{const n=js(p);if(!i)return n;try{const m=JSON.parse(i);if(Array.isArray(m)&&m.length===n.length)return m}catch{}return n},bs=i=>i==="video"?{label:"Video",icon:je,color:"text-purple-600"}:i==="pdf"?{label:"PDF",icon:Ye,color:"text-red-600"}:{label:`Foto ${i.replace("photo","")}`,icon:pe,color:"text-blue-600"},$e=({value:i,onChange:p,propertyId:n,folder:m,fieldKey:b,isEdit:F,accept:f,fileType:z,allowedExts:s}
1)=>{const[$,R]=_.useState(!1),[P,c]=_.useState(null),S=_.useRef(null),{toast:w}=le(),O=z==="pdf"?"PDF":"Video",l=async D=>{c(null);const T="."+D.name.split(".").pop()?.toLowerCase();if(!s.includes(T)){const E=`Solo se permiten: ${s.join(", ")}`;c(E),w({title:"Error de validación",description:E,variant:"destructive"});return}if(D.size>Fe){const E=`El archivo no puede ser mayor a ${Math.round(Fe/1024/1024)}MB`;c(E),w({title:"Error de validación",description:E,variant:"destructive"});return}R(!0);try{if(i){const U=De(i,se);U&&await C.storage.from(se).remove([U]).catch(()=>{})}const E=z==="pdf"?"application/pdf":D.type,j=`properties/${n}/${m}/${Date.now()}_${D.name}`,{error:A}=await C.storage.from(se).upload(j,D,{contentType:E,upsert:!1});if(A)throw A;const{data:{publicUrl:G}}=C.storage.from(se).getPublicUrl(j);if(F&&n){const{error:U}=await C.from("properties").update({[b]:G}).eq("id",n);if(U)throw await C.storage.from(se).remove([j]).catch(()=>{}),U}p(G),w({title:`â
${O} subido`,description:`El ${O.toLowerCase()} se subió correctamente`})}catch(E){const j=E.message||`Error al subir el ${O.toLowerCase()}`;c(j),w({title:"Error al subir",description:j,variant:"destructive"})}finally{R(!1)}},L=async()=>{if(i){const D=De(i,se);if(D&&await C.storage.from(se).remove([D]).catch(()=>{}),F&&n)try{await C.from("properties").update({[b]:null}).eq("id",n)}catch{}}p(""),c(null),w({title:`ðï¸ ${O} eliminado`})};if(i){const D=decodeURIComponent(i.split("/").pop()||`archivo.${z==="pdf"?"pdf":"mp4"}`),T=z==="pdf"?_e:je,E=z==="pdf"?"text-red-500":"text-purple-500";return e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/50 rounded-md",children:[e.jsx(T,{className:q("h-4 w-4 shrink-0",E)}),e.jsx("span",{className:"text-xs truncate flex-1",children:D}),e.jsx(X,{type:"button",variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:L,children:e.jsx(ye,{className:"h-3 w-3"})})]})}return e.jsxs("div",{className:"space-y-1",children:[e.jsx("input",{ref:S,type:"file",accept:f,className:"hidden",onChange:D=>{const T=D.target.files?.[0];T&&l(T),D.target.value=""}}),e.jsxs(X,{type:"button",variant:"outline",size:"sm",className:"w-full gap-2 text-xs h-8",disabled:$,onClick:()=>S.current?.click(),children:[$?e.jsx(ae,{className:"h-3 w-3 animate-spin"}):e.jsx(ne,{className:"h-3 w-3"}),$?"Subiendo...":`Subir ${O}`]}),P&&e.jsxs("p",{className:"text-[10px] text-destructive flex items-center gap-1",children:[e.jsx(es,{className:"h-3 w-3 shrink-0"}),P]})]})},Ns=({order:i,onReorder:p,slots:n})=>{const[m,b]=_.useState(null),[F,f]=_.useState(null),z=P=>c=>{b(P),c.dataTransfer.effectAllowed="move",c.dataTransfer.setData("text/plain",P.toString())},s=P=>c=>{c.preventDefault(),c.dataTransfer.dropEffect="move",f(P)},$=P=>c=>{if(c.preventDefault(),m===null||m===P){b(null),f(null);return}const S=[...i],[w]=S.splice(m,1);S.splice(P,0,w),p(S),b(null),f(null)},R=()=>{b(null),f(null)};return e.jsx("div",{className:"space-y-2",children:i.map((P,c)=>{const S=bs(P),w=n[P];if(!w)return null;const O=S.icon,l=m===c,L=F===c&&m!==c;return e.jsxs("div",{draggable:!0,onDragStart:z(c),onDragOver:s(c),onDrop:$(c),onDragEnd:R,className:q("border rounded-lg p-2.5 transition-all duration-150",l&&"opacity-40 scale-[0.97]",L&&"border-primary border-dashed bg-primary/5",!l&&!L&&"bg-background hover:bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx(Qe,{className:"h-3.5 w-3.5 text-muted-foreground/50 cursor-grab active:cursor-grabbing shrink-0"}),e.jsx(O,{className:q("h-3.5 w-3.5 shrink-0",S.color)}),e.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:S.label}),e.jsxs("span",{className:"text-[9px] text-muted-foreground/50 ml-auto",children:["#",c+1]})]}),w.renderUploader()]},P)})})},ws=({stepNumber:i,title:p,description:n,timing:m,emoji:b,accentColor:F,messages:f,photoKeys:z,videoKey:s,pdfKey:$,mediaOrderKey:R,attachmentNote:P,formData:c,onFieldChange:S,propertyId:w,imageFolder:O,isEdit:l})=>{const[L,D]=_.useState(!1),[T,E]=_.useState("en"),{toast:j}=le(),A=Pe[F]||Pe.blue,G=O||`step_${i}`,U=z.length,V=ys(c[R],U),B=f.map(d=>`${d.key}_en`),y=B.filter(d=>c[d]?.trim()).length,v=f.filter(d=>d.required).length,x=y>=v,t=[...z,s,$],a=t.filter(d=>c[d]?.trim()).length,r=d=>f.map(N=>c[`${N.key}_${d}`]||""),o=async(d,N)=>{if(l&&w)try{await C.from("properties").update({[d]:N}).eq("id",w)}catch{}},h=async(d,N)=>{S(d,N),N&&await o(d,N)},u=async d=>{S(d,""),await o(d,null)},I=async d=>{const N=JSON.stringify(d);S(R,N),await o(R,N),j({title:"â
Orden actualizado",description:"El orden de envÃo se guardó"})},k={};return z.forEach((d,N)=>{k[`photo${N+1}`]={renderUploader:()=>l&&w?e.jsx(fs,{value:c[d]||"",onChange:Z=>Z?h(d,Z):u(d),propertyId:w,folder:G}):e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Guarda primero"})}}),k.video={renderUploader:()=>l&&w?e.jsx($e,{value:c[s]||"",onChange:d=>S(s,d),propertyId:w,folder:G,fieldKey:s,isEdit:!!l,accept:".mp4,.mov,.webm,video/mp4,video/quicktime,video/webm",fileType:"video",allowedExts:[".mp4",".mov",".webm"]}):e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Guarda primero"})},k.pdf={renderUploader:()=>l&&w?e.jsx($e,{value:c[$]||"",onChange:d=>S($,d),propertyId:w,folder:G,fieldKey:$,isEdit:!!l,accept:".pdf,application/pdf",fileType:"pdf",allowedExts:[".pdf"]}):e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Guarda primero"})},e.jsxs("div",{className:q("border rounded-lg overflow-hidden transition-all duration-200",L?"shadow-md":"hover:shadow-sm"),children:[e.jsxs("button",{type:"button",onClick:()=>D(!L),className:q("w-full flex items-center gap-3 p-4 text-left transition-colors",L?A.bg:"hover:bg-muted/50"),children:[e.jsx("div",{className:q("flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center text-sm font-bold",x?"bg-green-100 text-green-700":A.badge),children:x?e.jsx(He,{className:"h-4 w-4"}):i+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:b}),e.jsx("span",{className:"font-semibold text-sm",children:p})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Paso ",i+1]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:q("text-xs px-2 py-0.5 rounded-full",x?"bg-green-100 text-green-700":"bg-gray-100 text-gray-500"),children:[y,"/",B.length," EN"]}),a>0&&e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-600",children:["ð ",a]}),e.jsx(Je,{className:q("h-4 w-4 text-muted-foreground transition-transform duration-200",L&&"rotate-180")}
1)]})]}),L&&e.jsxs("div",{className:"border-t p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:n}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Me,{defaultValue:"en",className:"w-full",children:[e.jsxs(Te,{className:"grid w-full grid-cols-2",children:[e.jsx(re,{value:"en",children:"ðºð¸ English"}),e.jsx(re,{value:"es",children:"ð²ð½ Español"})]}),e.jsx(oe,{value:"en",className:"space-y-3 mt-3",children:f.map((d,N)=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs(g,{className:"text-xs",children:["Message ",N+1," ",d.required&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(ee,{value:c[`${d.key}_en`]||"",onChange:Z=>{S(`${d.key}_en`,Z.target.value.slice(0,500)),E("en")},placeholder:d.placeholder_en,rows:2,maxLength:500,className:"text-sm"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground text-right",children:[(c[`${d.key}_en`]||"").length,"/500"]})]},d.key))}),e.jsx(oe,{value:"es",className:"space-y-3 mt-3",children:f.map((d,N)=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs(g,{className:"text-xs",children:["Mensaje ",N+1]}),e.jsx(ee,{value:c[`${d.key}_es`]||"",onChange:Z=>{S(`${d.key}_es`,Z.target.value.slice(0,500)),E("es")},placeholder:d.placeholder_es,rows:2,maxLength:500,className:"text-sm"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground text-right",children:[(c[`${d.key}_es`]||"").length,"/500"]})]},d.key))})]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(g,{className:"text-xs font-semibold",children:["Adjuntos del paso (",t.length,")"]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Arrastra para cambiar orden de envÃo"})]}),e.jsx(Ns,{order:V,onReorder:I,slots:k})]}),P&&e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 p-2 rounded flex items-center gap-1.5",children:[e.jsx("span",{children:"ð"}),e.jsx("span",{children:P})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(g,{className:"text-xs text-muted-foreground",children:"Preview WhatsApp"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>E("en"),className:q("text-xs px-2 py-0.5 rounded transition-colors",T==="en"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"EN"}),e.jsx("button",{type:"button",onClick:()=>E("es"),className:q("text-xs px-2 py-0.5 rounded transition-colors",T==="es"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"),children:"ES"})]})]}),e.jsx(vs,{messages:r(T),photo:c[z[0]]||void 0,attachmentLabel:c[$]?"ð "+(c[$].split("/").pop()||"documento.pdf"):c[s]?"ð¬ "+(c[s].split("/").pop()||"video.mp4"):P?P.replace("Se enviará automáticamente el ","").replace(' de "Documentos de Conversión".',""):void 0})]})]})]})]})},ks={title:"",price:"",size_acres:"",location:"",county:"",description:"",status:"available",photos:[],latitude:"",longitude:"",keyFeature1:"",keyFeature2:"",keyFeature3:"",keyFeature4:"",keyFeature5:"",keyFeature6:"",financing_enabled:!1,financing_down_payment:"",financing_interest_rate:"",financing_term_years:"",title_type:"",title_notes:"",mineral_rights:"",survey_available:!1,survey_notes:"",road_access:!1,road_access_type:"",road_frontage:"",flood_zone:"",electricity:!1,electricity_details:"",water_well:!1,water_details:"",has_restrictions:!1,restrictions_details:"",proximity_notes:"",proximity_notes_es:"",google_maps_link:"",visit_instructions:"",visit_instructions_es:"",visit_contact:"",visit_availability:"",description_es:"",promo_video_url:null,brochure_pdf_url:null,audio_description_url:null,video_ad_url:null,location_pdf_url:null,location_photo_url:null,financing_pdf_url:null,financing_photo_url:null,lot_map_satellite:null,lot_map_plat:null,initial_msg_1_es:"",initial_msg_1_en:"",initial_msg_2_es:"",initial_msg_2_en:"",initial_msg_3_es:"",initial_msg_3_en:"",initial_photo_1:"",initial_photo_2:"",initial_photo_3:"",initial_photo_4:"",initial_photo_5:"",initial_photo_6:"",initial_video:"",initial_pdf:"",initial_media_order:"",value_hook_msg_1_es:"",value_hook_msg_2_es:"",value_hook_msg_3_es:"",value_hook_msg_1_en:"",value_hook_msg_2_en:"",value_hook_msg_3_en:"",value_hook_photo:"",value_hook_photo_2:"",value_hook_pdf:"",value_hook_video:"",value_hook_media_order:"",location_msg_1_en:"",location_msg_1_es:"",location_msg_2_en:"",location_msg_2_es:"",location_step_photo_1:"",location_step_photo_2:"",location_step_pdf:"",location_step_video:"",location_step_media_order:"",no_restrictions_msg_1_en:"",no_restrictions_msg_1_es:"",no_restrictions_msg_2_en:"",no_restrictions_msg_2_es:"",no_restrictions_photo:"",no_restrictions_photo_2:"",no_restrictions_pdf:"",no_restrictions_video:"",no_restrictions_media_order:"",financing_msg_1_en:"",financing_msg_1_es:"",financing_msg_2_en:"",financing_msg_2_es:"",financing_step_photo_1:"",financing_step_photo_2:"",financing_step_pdf:"",financing_step_video:"",f
1inancing_step_media_order:"",owner_msg_1_en:"",owner_msg_1_es:"",owner_photo:"",owner_photo_2:"",owner_pdf:"",owner_video:"",owner_media_order:"",social_proof_msg_1_en:"",social_proof_msg_1_es:"",social_proof_msg_2_en:"",social_proof_msg_2_es:"",social_proof_photo:"",social_proof_photo_2:"",social_proof_pdf:"",social_proof_video:"",social_proof_media_order:"",dream_msg_1_en:"",dream_msg_1_es:"",dream_msg_2_en:"",dream_msg_2_es:"",dream_photo_1:"",dream_photo_2:"",dream_pdf:"",dream_video:"",dream_media_order:"",urgency_msg_1_es:"",urgency_msg_2_es:"",urgency_msg_1_en:"",urgency_msg_2_en:"",urgency_photo:"",final_value_msg_1_es:"",final_value_msg_2_es:"",final_value_msg_1_en:"",final_value_msg_2_en:"",final_value_photo:"",final_value_photo_2:"",final_value_pdf:"",final_value_video:"",final_value_media_order:""},be=[{stepNumber:0,title:"Paso Inicial",timing:"Inmediato â Al primer contacto",emoji:"ð",accentColor:"cyan",imageFolder:"initial",description:"Primer mensaje que se envÃa cuando un prospecto escribe por primera vez. Incluye la presentación de la propiedad con fotos, video y PDF.",messages:[{key:"initial_msg_1",placeholder_en:"E.g.: Hi! ð Thanks for your interest in our lot in {{property_county}}. Here's all the info:",placeholder_es:"Ej: ¡Hola! ð Muchas gracias por tu interés en nuestro terreno en {{property_county}}. Te comparto toda la información:",required:!0},{key:"initial_msg_2",placeholder_en:"E.g.: This {{property_acres}} acre lot has a total price of ${{property_price}} with down payment from ${{property_down_payment}}.",placeholder_es:"Ej: Este terreno de {{property_acres}} acres tiene un precio total de ${{property_price}} con enganche desde ${{property_down_payment}}.",required:!1},{key:"initial_msg_3",placeholder_en:"E.g.: Any questions? I'm here to help ð",placeholder_es:"Ej: ¿Tienes alguna pregunta? Estoy aquà para ayudarte ð",required:!1}],photoKeys:["initial_photo_1","initial_photo_2","initial_photo_3","initial_photo_4","initial_photo_5","initial_photo_6"],pdfKey:"initial_pdf",videoKey:"initial_video",mediaOrderKey:"initial_media_order"},{stepNumber:1,title:"Gancho de Valor",timing:"DÃa 1 â Inmediato",emoji:"ð",accentColor:"blue",imageFolder:"value_hook",description:"Información valiosa del terreno que NO está en el PDF. Se usa en mensajes de seguimiento para aportar valor.",messages:[{key:"value_hook_msg_1",placeholder_en:"E.g.: By the way, there's something not in the PDF...",placeholder_es:"Ej: Oye, hay algo que no está en el PDF...",required:!0},{key:"value_hook_msg_2",placeholder_en:"E.g.: Another thing that makes this property special...",placeholder_es:"Ej: Otra cosa especial de esta propiedad...",required:!1},{key:"value_hook_msg_3",placeholder_en:"E.g.: I looked on Zillow for similar lots...",placeholder_es:"Ej: Busqué en Zillow lotes similares...",required:!1}],photoKeys:["value_hook_photo","value_hook_photo_2"],pdfKey:"value_hook_pdf",videoKey:"value_hook_video",mediaOrderKey:"value_hook_media_order"},{stepNumber:2,title:"Ubicación",timing:"DÃa 2 â 1:00 PM",emoji:"ð",accentColor:"rose",imageFolder:"location_step",description:"Introduce el PDF de ubicación. Invita a visitar el terreno y comparte coordenadas.",messages:[{key:"location_msg_1",placeholder_en:"E.g.: I want to share something cool â here's exactly where the property is...",placeholder_es:"Ej: Te quiero compartir algo â mira dónde está el terreno...",required:!0},{key:"location_msg_2",placeholder_en:"E.g.: You can visit anytime â here are the coordinates...",placeholder_es:"Ej: Puedes visitar cuando quieras â aquà las coordenadas...",required:!1}],photoKeys:["location_step_photo_1","location_step_photo_2"],pdfKey:"location_step_pdf",videoKey:"location_step_video",mediaOrderKey:"location_step_media_order",attachmentNote:'También se envÃa automáticamente el PDF de Ubicación de "Documentos de Conversión".'},{stepNumber:3,title:"Sin Restricciones",timing:"DÃa 3 â 6:00 PM",emoji:"ðï¸",accentColor:"orange",imageFolder:"no_restrictions",description:"Tu tierra, tus reglas. Destaca la libertad de construir sin HOA ni restricciones.",messages:[{key:"no_restrictions_msg_1",placeholder_en:"E.g.: One thing people love â there are no restrictions...",placeholder_es:"Ej: Algo que le encanta a la gente â no tiene restricciones...",required:!0},{key:"no_restrictions_msg_2",placeholder_en:"E.g.: House, barndominium, mobile home â your land, your rules...",placeholder_es:"Ej: Casa, barndominium, mobile home â tu tierra, tus reglas...",required:!1}],photoKeys:["no_restrictions_photo","no_restrictions_photo_2"],pdfKey:"no_restrictions_pdf",videoKey:"no_restrictions_video",mediaOrderKey:"no_restrictions_media_order"},{stepNumber:4,title:"Financiamiento â Proceso",timing:"DÃa 4 â 1:00 PM",emoji:"ð¦",accentColor:"purple",imageFolder:"financing_step",description:"Explica paso a paso cómo funciona el financiamiento. Se envÃa con el PDF de financiamiento.",messages:[{key:"financing_msg_1",placeholder_en:"E.g.: I wanted to explain how the financing works step by step...",placeholder_es:"Ej: Te querÃa explicar paso a paso cómo funciona el financiamiento...",required:!0},{key:"financing_msg_2",placeholder_en:"E.g.: The process is simple: Step 1 â reserve with $500...",placeholder_es:"Ej: El proceso es sencillo: Paso 1 â apartas con $500...",required:!1}],photoKeys:["financing_step_photo_1","financing_step_photo_2"],pdfKey:"financing_step_pdf",videoKey:"financing_step_video",mediaOrderKey:"financing_step_media_order",attachmentNote:'También se envÃa automáticamente el PDF de Financiamiento de "Documentos de Conversión".'},{stepNumber:5,title:"Mensaje del Dueño",timing:"DÃa 5 â 6:00 PM",emoji:"ð§âð¼",accentColor:"amber",imageFolder:"owner",description:"Mensaje personal del dueño con su foto y WhatsApp. Genera confianza humana.",messages:[{key:"owner_msg_1",placeholder_en:"E.g.: Hi, I'm Rodrigo, the owner of TerraFunded...",placeholder_es:"Ej: Hola, soy Rodrigo, el dueño de TerraFunded...",required:!0}],photoKeys:["owner_photo","owner_photo_2"],pdfKey:"owner_pdf",videoKey:"owner_video",mediaOrderKey:"owner_media_order"},{stepNumber:6,title:"Social Proof",timing:"DÃa 6 â 1:00 PM",emoji:"â",accentColor:"sky",imageFolder:"social_proof",description:"Testimonios de clientes, datos de ventas, o historias de éxito que generan confianza.",messages:[{key:"social_proof_msg_1",placeholder_en:"E.g.: I wanted to share this â last month 3 families purchased land with us...",placeholder_es:"Ej: Te querÃa compartir esto â el mes pasado 3 familias compraron terreno...",required:!0},{key:"social_proof_msg_2",placeholder_en:"E.g.: One of them told me he'd been looking for 2 years...",placeholder_es:"Ej: Uno de ellos me dijo que tenÃa 2 años buscando...",required:!1}
1],photoKeys:["social_proof_photo","social_proof_photo_2"],pdfKey:"social_proof_pdf",videoKey:"social_proof_video",mediaOrderKey:"social_proof_media_order"},{stepNumber:7,title:"Sueño Americano",timing:"DÃa 7 â 1:00 PM",emoji:"ðºð¸",accentColor:"indigo",imageFolder:"dream",description:"Mensaje emocional sobre ser dueño de tierra en América. El sueño hecho realidad.",messages:[{key:"dream_msg_1",placeholder_en:"E.g.: Owning land in America is more than property â it's building a legacy...",placeholder_es:"Ej: Ser dueño de un terreno en América es más que una propiedad...",required:!0},{key:"dream_msg_2",placeholder_en:"E.g.: With just $X down, you can start building that future today...",placeholder_es:"Ej: Con solo $X de enganche, puedes empezar a construir ese futuro hoy...",required:!1}],photoKeys:["dream_photo_1","dream_photo_2"],pdfKey:"dream_pdf",videoKey:"dream_video",mediaOrderKey:"dream_media_order"},{stepNumber:8,title:"Ãltimo Valor (cierre)",timing:"DÃa 8 â Nurturing",emoji:"ð°",accentColor:"emerald",imageFolder:"final_value",description:"Ãltimo mensaje de valor antes de pasar al lead a nurturing. Ideal para detallar el financiamiento.",messages:[{key:"final_value_msg_1",placeholder_en:"E.g.: Let me break down how the financing works...",placeholder_es:"Ej: Mira, te explico cómo funciona el financiamiento...",required:!0},{key:"final_value_msg_2",placeholder_en:"E.g.: The process is really simple: you reserve with $X...",placeholder_es:"Ej: El proceso es muy sencillo: apartas con $X...",required:!1}],photoKeys:["final_value_photo","final_value_photo_2"],pdfKey:"final_value_pdf",videoKey:"final_value_video",mediaOrderKey:"final_value_media_order"}],W=i=>typeof i=="boolean"?!1:!i||i.trim()==="",Y=({icon:i,title:p})=>e.jsxs("div",{className:"flex items-center gap-2 pb-3 mb-4 border-b",children:[i,e.jsx("h3",{className:"font-semibold text-sm",children:p})]}),fe=({saving:i,onClick:p,label:n="Guardar Sección"})=>e.jsx("div",{className:"flex justify-end pt-4 border-t mt-6",children:e.jsxs(X,{type:"button",onClick:p,disabled:i,className:"gap-2",size:"sm",children:[i?e.jsx(ae,{className:"h-4 w-4 animate-spin"}):e.jsx(ls,{className:"h-4 w-4"}),i?"Guardando...":n]})}),Ks=()=>{const{id:i}=Be(),p=Ke();Ve();const{toast:n}=le(),m=!!i,[b,F]=_.useState(null),[f,z]=_.useState(m),[s,$]=_.useState(ks),[R,P]=_.useState("info"),[c,S]=_.useState(!1),w=_.useRef(!1);_.useEffect(()=>{const t=a=>{c&&(a.preventDefault(),a.returnValue="")};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[c]),_.useEffect(()=>{m&&i&&O(i)},[i,m]);const O=async t=>{try{const{data:a,error:r}=await C.from("properties").select("*").eq("id",t).single();if(r)throw r;if(a){const o=a.special_features||[];$({title:a.title||"",price:a.price?.toString()||"",size_acres:a.size_acres?.toString()||"",location:a.location||"",county:a.county||"",description:a.description||"",status:a.status||"available",photos:a.photos||[],latitude:a.latitude?.toString()||"",longitude:a.longitude?.toString()||"",keyFeature1:o[0]||"",keyFeature2:o[1]||"",keyFeature3:o[2]||"",keyFeature4:o[3]||"",keyFeature5:o[4]||"",keyFeature6:o[5]||"",financing_enabled:a.financing_enabled||!1,financing_down_payment:a.financing_down_payment?.toString()||"",financing_interest_rate:a.financing_interest_rate?.toString()||"",financing_term_years:a.financing_term_years?.toString()||"",title_type:a.title_type||"",title_notes:a.title_notes||"",mineral_rights:a.mineral_rights||"",survey_available:a.survey_available||!1,survey_notes:a.survey_notes||"",road_access:a.road_access||!1,road_access_type:a.road_access_type||"",road_frontage:a.road_frontage||"",flood_zone:a.flood_zone||"",electricity:a.electricity||!1,electricity_details:a.electricity_details||"",water_well:a.water_well||!1,water_details:a.water_details||"",has_restrictions:a.has_restrictions||!1,restrictions_details:a.restrictions_details||"",proximity_notes:a.proximity_notes||"",proximity_notes_es:a.proximity_notes_es||"",google_maps_link:a.google_maps_link||"",visit_instructions:a.visit_instructions||"",visit_instructions_es:a.visit_instructions_es||"",description_es:a.description_es||"",visit_contact:a.visit_contact||"",visit_availability:a.visit_availability||"",promo_video_url:a.promo_video_url||null,brochure_pdf_url:a.brochure_pdf_url||null,audio_description_url:a.audio_description_url||null,video_ad_url:a.video_ad_url||null,location_pdf_url:a.location_pdf_url||null,location_photo_url:a.location_photo_url||null,financing_pdf_url:a.financing_pdf_url||null,financing_photo_url:a.financing_photo_url||null,lot_map_satellite:a.lot_map_satellite||null,lot_map_plat:a.lot_map_plat||null,initial_msg_1_es:a.initial_msg_1_es||"",initial_msg_1_en:a.initial_msg_1_en||"",initial_msg_2_es:a.initial_msg_2_es||"",initial_msg_2_en:a.initial_msg_2_en||"",initial_msg_3_es:a.initial_msg_3_es||"",initial_msg_3_en:a.initial_msg_3_en||"",initial_photo_1:a.initial_photo_1||"",initial_photo_2:a.initial_photo_2||"",initial_photo_3:a.initial_photo_3||"",initial_photo_4:a.initial_photo_4||"",initial_photo_5:a.initial_photo_5||"",initial_photo_6:a.initial_photo_6||"",initial_video:a.initial_video||"",initial_pdf:a.initial_pdf||"",initial_media_order:a.initial_media_order||"",value_hook_msg_1_es:a.value_hook_msg_1_es||"",value_hook_msg_2_es:a.value_hook_msg_2_es||"",value_hook_msg_3_es:a.value_hook_msg_3_es||"",value_hook_msg_1_en:a.value_hook_msg_1_en||"",value_hook_msg_2_en:a.value_hook_msg_2_en||"",value_hook_msg_3_en:a.value_hook_msg_3_en||"",value_hook_photo:a.value_hook_photo||"",value_hook_photo_2:a.value_hook_photo_2||"",value_hook_pdf:a.value_hook_pdf||"",value_hook_video:a.value_hook_video||"",value_hook_media_order:a.value_hook_media_order||"",location_msg_1_en:a.location_msg_1_en||"",location_msg_1_es:a.location_msg_1_es||"",location_msg_2_en:a.location_msg_2_en||"",location_msg_2_es:a.location_msg_2_es||"",location_step_photo_1:a.location_step_photo_1||"",location_step_photo_2:a.location_step_photo_2||"",location_step_pdf:a.location_step_pdf||"",location_step_video:a.location_step_video||"",location_step_media_order:a.location_step_media_order||"",no_restrictions_msg_1_en:a.no_restrictions_msg_1_en||"",no_restrictions_msg_1_es:a.no_restrictions_msg_1_es||"",no_restrictions_msg_2_en:a.no_restrictions_msg_2_en||"",no_restrictions_msg_2_es:a.no_restrictions_msg_2_es||"",no_restrictions_photo:a.no_restrictions_photo||"",no_restrictions_photo_2:a.no_restrictions_photo_2||"",no_restrictions_pdf:a.no_restrictions_pdf||"",no_restrictions_video:a.no_restrictions_video||"",no_restrictions_media_order:a.no_restrictions_media_order||"",financing_msg_1_en:a.financing_msg_1_en||"",financing_msg_1_es:a.financing_msg_1_es||"",financing_msg_2_en:a.financing_msg_2_en||"",financing_msg_2_es:a.financing_msg_2_es||"",financing_step_photo_1:a.financing_step_photo_1||"",financing_step_photo_2:a.financing_step_photo_2||"",financing_step_pdf:a.financing_step_pdf||"",financing_step_video:a.financing_step_video||"",financing_step_media_order:a.financing_step_media_order||"",owner_msg_1_en:a.owner_msg_1_en||"",owner_msg_1_es:a.owner_msg_1_es||"",owner_photo:a.owner_photo||"",owner_photo_2:a.owner_photo_2||"",owner_pdf:a.owner_pdf||"",owner_video:a.owner_video||"",owner_media_order:a.owner_media_order||"",social_proof_msg_1_en:a.social_proof_msg_1_en||"",social_proof_msg_1_es:a.social_proof_msg_1_es||"",social_proof_msg_2_en:a.social_proof_msg_2_en||"",social_proof_msg_2_es:a.social_proof_msg_2_es||"",social_proof_photo:a.social_proof_photo||"",social_proof_photo_2:a.social_proof_photo_2||"",social_proof_pdf:a.social_proof_pdf||"",social_proof_video:a.social_proof_video||"",social_proof_media_order:a.social_proof_media_order||"",dream_msg_1_en:a.dream_msg_1_en||"",dream_msg_1_es:a.dream_msg_1_es||"",dream_msg_2_en:a.dream_msg_2_en||"",dream_msg_2_es:a.dream_msg_2_es||"",dream_photo_1:a.dream_photo_1||"",dream_photo_2:a.dream_photo_2||"",dream_pdf:a.dream_pdf||"",dream_video:a.dream_video||"",dream_media_order:a.dream_media_order||"",urgency_msg_1_es:a.urgency_msg_1_es||"",urgency_msg_2_es:a.urgency_msg_2_es||"",urgency_msg_1_en:a.urgency_msg_1_en||"",urgency_msg_2_en:a.urgency_msg_2_en||"",urgency_photo:a.urgency_photo||"",final_value_msg_1_es:a.final_value_msg_1_es||"",final_value_msg_2_es:a.final_value_msg_2_es||"",final_value_msg_1_en:a.final_value_msg_1_en||"",final_value_msg_2_en:a.final_value_msg_2_en||"",final_value_photo:a.final_value_photo||"",final_value_photo_2:a.final_value_photo_2||"",final_value_pdf:a.final_value_pdf||"",final_value_video:a.final_value_video||"",final_value_media_order:a.final_value_media_order||""})}}catch{n({title:"Error",description:"Error al cargar la propiedad",variant:"destructive"})}finally{z(!1),w.current=!0}},l=_.useCallback((t,a)=>{$(r=>({...r,[t]:a})),w.current&&S(!0)},[]),[L,D]=_.useState({lot_map_satellite:!1,lot_map_plat:!1}),T=async(t,a)=>{if(!i){n({title:"Guarda primero",description:"Primero crea el terreno y luego sube los mapas.",variant:"destructive"});return}if(!Ne.ALLOWED_IMAGE_TYPES.includes(t.type)){n({title:"Formato inválido",description:"Solo se permiten imágenes JPG, PNG o WEBP.",variant:"destructive"});return}if(t.size>Ne.IMAGE_MAX_SIZE){n({title:"Archivo muy grande",description:"Máximo 10MB por imagen.",variant:"destructive"});return}D(r=>({...r,[a]:!0}));try{const r=t.name.split(".").pop()?.toLowerCase()||"jpg",o=`${i}/lot-maps/${a}-${Date.now()}.${r}`,{error:h}=await C.storage.from("property-images").upload(o,t,{upsert:!0,cacheControl:"3600"});if(h)throw h;const{data:u}=C.storage.from("property-images").getPublicUrl(o),I=u.publicUrl;$(k=>({...k,[a]:I})),S(!0),n({title:"â
Mapa subido",description:'Ahora solo haz clic en "Guardar Media".'})}catch(r){n({title:"Error",description:r.message||"No se pudo subir el mapa",variant:"destructive"})}finally{D(r=>({...r,[a]:!1}))}},E=(t,a)=>{const r=t.target.files?.[0];r&&(T(r,a),t.currentTarget.value="")},j=t=>$(a=>({...a,photos:t})),A=(t,a)=>$(r=>({...r,[t]:a})),G=_.useCallback(()=>{const t=[s.keyFeature1,s.keyFeature2,s.keyFeature3,s.keyFeature4,s.keyFeature5,s.keyFeature6].filter(a=>a.trim()!=="");return{title:s.title,price:parseFloat(s.price)||0,size_acres:parseFloat(s.size_acres)||0,location:s.location,county:s.county,description:s.description,status:s.status,photos:s.photos,image_url:s.photos[0]||null,latitude:s.latitude?parseFloat(s.latitude):null,longitude:s.longitude?parseFloat(s.longitude):null,special_features:t,financing_enabled:s.financing_enabled,financing_down_payment:s.financing_down_payment?parseFloat(s.financing_down_payment):null,financing_interest_rate:s.financing_interest_rate?parseFloat(s.financing_interest_rate):null,financing_term_years:s.financing_term_years?parseInt(s.financing_term_years):null,title_type:s.title_type||null,title_notes:s.title_notes||null,mineral_rights:s.mineral_rights||null,survey_available:s.survey_available,survey_notes:s.survey_notes||null,road_access:s.road_access,road_access_type:s.road_access_type||null,road_frontage:s.road_frontage||null,flood_zone:s.flood_zone||null,electricity:s.electricity,electricity_details:s.electricity_details||null,water_well:s.water_well,water_details:s.water_details||null,has_restrictions:s.has_restrictions,restrictions_details:s.restrictions_details||null,proximity_n
1otes:s.proximity_notes||null,proximity_notes_es:s.proximity_notes_es||null,google_maps_link:s.google_maps_link||null,visit_instructions:s.visit_instructions||null,visit_instructions_es:s.visit_instructions_es||null,visit_contact:s.visit_contact||null,visit_availability:s.visit_availability||null,description_es:s.description_es||null,promo_video_url:s.promo_video_url||null,brochure_pdf_url:s.brochure_pdf_url||null,audio_description_url:s.audio_description_url||null,video_ad_url:s.video_ad_url||null,location_pdf_url:s.location_pdf_url||null,location_photo_url:s.location_photo_url||null,financing_pdf_url:s.financing_pdf_url||null,financing_photo_url:s.financing_photo_url||null,lot_map_satellite:s.lot_map_satellite||null,lot_map_plat:s.lot_map_plat||null,initial_msg_1_es:s.initial_msg_1_es||null,initial_msg_1_en:s.initial_msg_1_en||null,initial_msg_2_es:s.initial_msg_2_es||null,initial_msg_2_en:s.initial_msg_2_en||null,initial_msg_3_es:s.initial_msg_3_es||null,initial_msg_3_en:s.initial_msg_3_en||null,initial_photo_1:s.initial_photo_1||null,initial_photo_2:s.initial_photo_2||null,initial_photo_3:s.initial_photo_3||null,initial_photo_4:s.initial_photo_4||null,initial_photo_5:s.initial_photo_5||null,initial_photo_6:s.initial_photo_6||null,initial_video:s.initial_video||null,initial_pdf:s.initial_pdf||null,initial_media_order:s.initial_media_order||null,value_hook_msg_1_es:s.value_hook_msg_1_es||null,value_hook_msg_2_es:s.value_hook_msg_2_es||null,value_hook_msg_3_es:s.value_hook_msg_3_es||null,value_hook_msg_1_en:s.value_hook_msg_1_en||null,value_hook_msg_2_en:s.value_hook_msg_2_en||null,value_hook_msg_3_en:s.value_hook_msg_3_en||null,value_hook_photo:s.value_hook_photo||null,value_hook_photo_2:s.value_hook_photo_2||null,value_hook_pdf:s.value_hook_pdf||null,value_hook_video:s.value_hook_video||null,value_hook_media_order:s.value_hook_media_order||null,location_msg_1_en:s.location_msg_1_en||null,location_msg_1_es:s.location_msg_1_es||null,location_msg_2_en:s.location_msg_2_en||null,location_msg_2_es:s.location_msg_2_es||null,location_step_photo_1:s.location_step_photo_1||null,location_step_photo_2:s.location_step_photo_2||null,location_step_pdf:s.location_step_pdf||null,location_step_video:s.location_step_video||null,location_step_media_order:s.location_step_media_order||null,no_restrictions_msg_1_en:s.no_restrictions_msg_1_en||null,no_restrictions_msg_1_es:s.no_restrictions_msg_1_es||null,no_restrictions_msg_2_en:s.no_restrictions_msg_2_en||null,no_restrictions_msg_2_es:s.no_restrictions_msg_2_es||null,no_restrictions_photo:s.no_restrictions_photo||null,no_restrictions_photo_2:s.no_restrictions_photo_2||null,no_restrictions_pdf:s.no_restrictions_pdf||null,no_restrictions_video:s.no_restrictions_video||null,no_restrictions_media_order:s.no_restrictions_media_order||null,financing_msg_1_en:s.financing_msg_1_en||null,financing_msg_1_es:s.financing_msg_1_es||null,financing_msg_2_en:s.financing_msg_2_en||null,financing_msg_2_es:s.financing_msg_2_es||null,financing_step_photo_1:s.financing_step_photo_1||null,financing_step_photo_2:s.financing_step_photo_2||null,financing_step_pdf:s.financing_step_pdf||null,financing_step_video:s.financing_step_video||null,financing_step_media_order:s.financing_step_media_order||null,owner_msg_1_en:s.owner_msg_1_en||null,owner_msg_1_es:s.owner_msg_1_es||null,owner_photo:s.owner_photo||null,owner_photo_2:s.owner_photo_2||null,owner_pdf:s.owner_pdf||null,owner_video:s.owner_video||null,owner_media_order:s.owner_media_order||null,social_proof_msg_1_en:s.social_proof_msg_1_en||null,social_proof_msg_1_es:s.social_proof_msg_1_es||null,social_proof_msg_2_en:s.social_proof_msg_2_en||null,social_proof_msg_2_es:s.social_proof_msg_2_es||null,social_proof_photo:s.social_proof_photo||null,social_proof_photo_2:s.social_proof_photo_2||null,social_proof_pdf:s.social_proof_pdf||null,social_proof_video:s.social_proof_video||null,social_proof_media_order:s.social_proof_media_order||null,dream_msg_1_en:s.dream_msg_1_en||null,dream_msg_1_es:s.dream_msg_1_es||null,dream_msg_2_en:s.dream_msg_2_en||null,dream_msg_2_es:s.dream_msg_2_es||null,dream_photo_1:s.dream_photo_1||null,dream_photo_2:s.dream_photo_2||null,dream_pdf:s.dream_pdf||null,dream_video:s.dream_video||null,dream_media_order:s.dream_media_order||null,urgency_msg_1_es:s.urgency_msg_1_es||null,urgency_msg_2_es:s.urgency_msg_2_es||null,urgency_msg_1_en:s.urgency_msg_1_en||null,urgency_msg_2_en:s.urgency_msg_2_en||null,urgency_photo:s.urgency_photo||null,final_value_msg_1_es:s.final_value_msg_1_es||null,final_value_msg_2_es:s.final_value_msg_2_es||null,final_value_msg_1_en:s.final_value_msg_1_en||null,final_value_msg_2_en:s.final_value_msg_2_en||null,final_value_photo:s.final_value_photo||null,final_value_photo_2:s.final_value_photo_2||null,final_value_pdf:s.final_value_pdf||null,final_value_video:s.final_value_video||null,final_value_media_order:s.final_value_media_order||null,updated_at:new Date().toISOString()}},[s]),U=async t=>{if(!m||!i){await y();return}F(t);try{const{error:a}=await C.from("properties").update(G()).eq("id",i);if(a)throw a;n({title:"â
Guardado",description:`${t} actualizada correctamente`}),S(!1)}catch(a){n({title:"Error",description:`Error: ${a.message}`,variant:"destructive"})}finally{F(null)}},V=t=>/^[A-Za-z0-9]{1,3}$/.test(t),B=async()=>{for(let t=0;t<50;t++){const a=Math.floor(100+Math.random()*900).toString(),{data:r,error:o}=await C.from("properties").select("short_id").eq("short_id",a).maybeSingle();if(o)throw o;if(!r&&V(a))return a}for(let t=0;t<30;t++){const a=Math.random().toString(36).slice(2,5).toUpperCase();if(!V(a))continue;const{data:r,error:o}=await C.from("properties").select("short_id").eq("short_id",a).maybeSingle();if(o)throw o;if(!r)return a}throw new Error("No se pudo generar un short_id válido. Intenta de nuevo.")},y=async()=>{F("create");try{let t=!1;for(let a=0;a<5;a++){const r=await B();if(!V(r))throw new Error("short_id generado inválido");const o={...G(),id:`prop_${Date.now()}_${Math.random().toString(36).slice(2,11)}`,short_id:r,created_at:new Date().toISOString()},{error:h}=await C.from("properties").insert(o).select();if(!h){t=!0;break}if(!(h.code==="23505"||h.code==="23514"))throw h}if(!t)throw new Error("No se pudo crear la propiedad por conflicto de short_id. Re
1intenta.");n({title:"â
Creado",description:"Terreno creado exitosamente"}),S(!1),p("/admin")}catch(t){n({title:"Error",description:`Error: ${t.message}`,variant:"destructive"})}finally{F(null)}},v=_.useMemo(()=>({filled:be.map(a=>a.messages.some(r=>r.required&&s[r.key+"_en"])).filter(Boolean).length,total:be.length}),[s]),x=_.useMemo(()=>["price","size_acres","title_type","mineral_rights","flood_zone"].filter(a=>W(s[a])),[s]);return f?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(ae,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"max-w-5xl mx-auto px-4 sm:px-6 py-6",children:[e.jsx("div",{className:"sticky top-0 z-30 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 border-b pb-3 mb-6 -mx-4 sm:-mx-6 px-4 sm:px-6 pt-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(X,{variant:"ghost",size:"sm",onClick:()=>{c&&!confirm("Tienes cambios sin guardar. ¿Seguro que quieres salir?")||p("/admin")},className:"gap-1 text-muted-foreground hover:text-foreground",children:[e.jsx(ss,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Dashboard"})]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold",children:m?"Editar Terreno":"Nuevo Terreno"}),s.title&&e.jsx(we,{variant:"outline",className:"text-xs mt-0.5",children:s.title})]})]}),c&&e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 text-blue-600 text-xs mr-3",children:[e.jsx("div",{className:"h-2 w-2 rounded-full bg-blue-500 animate-pulse"}),e.jsx("span",{children:"Sin guardar"})]}),x.length>0&&e.jsxs("div",{className:"hidden sm:flex items-center gap-1.5 text-amber-600 text-xs",children:[e.jsx(ke,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:[x.length," campos crÃticos sin llenar"]})]})]})}),e.jsx("div",{children:e.jsxs(Me,{value:R,onValueChange:P,children:[e.jsxs(Te,{className:"grid w-full grid-cols-4 mb-6",children:[e.jsxs(re,{value:"info",children:[e.jsx("span",{className:"hidden sm:inline",children:"Información"}),e.jsx("span",{className:"sm:hidden",children:"Info"})]}),e.jsx(re,{value:"media",children:"Media"}),e.jsxs(re,{value:"financing",children:[e.jsx("span",{className:"hidden sm:inline",children:"Financiamiento"}),e.jsx("span",{className:"sm:hidden",children:"Finanzas"})]}),e.jsxs(re,{value:"sequence",className:"gap-1.5",children:[e.jsx("span",{className:"hidden sm:inline",children:"Secuencia"}),e.jsx("span",{className:"sm:hidden",children:"Seq"}),e.jsxs(we,{variant:"secondary",className:"text-[10px] px-1.5",children:[v.filled,"/",v.total]})]})]}),e.jsxs(oe,{value:"info",className:"space-y-6 pb-8",children:[e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(as,{className:"h-4 w-4 text-primary"}),title:"Información Básica"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(g,{className:"text-xs",children:"TÃtulo del terreno"}),e.jsx(M,{value:s.title,onChange:t=>l("title",t.target.value),placeholder:"10 Acres en Paris TX"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(g,{className:"text-xs",children:["Precio ($) ",W(s.price)&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{type:"number",value:s.price,onChange:t=>l("price",t.target.value),placeholder:"89900",className:q(W(s.price)&&"ring-2 ring-red-300")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(g,{className:"text-xs",children:["Acres ",W(s.size_acres)&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{type:"number",step:"0.01",value:s.size_acres,onChange:t=>l("size_acres",t.target.value),placeholder:"10.0",className:q(W(s.size_acres)&&"ring-2 ring-red-300")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Ubicación"}),e.jsx(M,{value:s.location,onChange:t=>l("location",t.target.value),placeholder:"Paris, TX"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Condado"}),e.jsx(M,{value:s.county,onChange:t=>l("county",t.target.value),placeholder:"Lamar County"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Status"}),e.jsxs(me,{value:s.status,onValueChange:t=>l("status",t),children:[e.jsx(ue,{children:e.jsx(ge,{})}),e.jsxs(he,{children:[e.jsx(K,{value:"available",children:"Disponible"}),e.jsx(K,{value:"pending",children:"Pendiente"}),e.jsx(K,{value:"sold",children:"Vendido"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Latitud"}),e.jsx(M,{value:s.latitude,onChange:t=>l("latitude",t.target.value),placeholder:"33.6609"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Longitud"}),e.jsx(M,{value:s.longitude,onChange:t=>l("longitude",t.target.value),placeholder:"-95.5555"})]}),e.jsxs("div",{className:"space-y-1.5 md:col-span-2 lg:col-span-3",children:[e.jsx(g,{className:"text-xs",children:"Descripción"}),e.jsx(ee,{value:s.description,onChange:t=>l("description",t.target.value),rows:3,placeholder:"Descripción detallada del terreno..."})]}),e.jsxs("div",{className:"space-y-1.5 md:col-span-2 lg:col-span-3",children:[e.jsx(g,{className:"text-xs",children:"Descripción (Español)"}),e.jsx(ee,{value:s.description_es,onChange:t=>l("description_es",t.target.value),rows:3,placeholder:"Traducción al español (opcional)..."})]})]})]})}),e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(ts,{className:"h-4 w-4 text-primary"}),title:"CaracterÃsticas & Servicios"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{checked:s.road_access,onCheckedChange:t=>l("road_access",t)}),e.jsx(g,{className:"text-xs cursor-pointer",children:"Road Access"})]}),s.road_access&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Tipo de Acceso"}
1),e.jsx(M,{value:s.road_access_type,onChange:t=>l("road_access_type",t.target.value),placeholder:"County road"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Frontage"}),e.jsx(M,{value:s.road_frontage,onChange:t=>l("road_frontage",t.target.value),placeholder:"200ft"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(g,{className:"text-xs",children:["Flood Zone ",W(s.flood_zone)&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(me,{value:s.flood_zone,onValueChange:t=>l("flood_zone",t),children:[e.jsx(ue,{className:q(W(s.flood_zone)&&"ring-2 ring-red-300"),children:e.jsx(ge,{placeholder:"Seleccionar"})}),e.jsxs(he,{children:[e.jsx(K,{value:"Zone X",children:"Zone X (fuera)"}),e.jsx(K,{value:"Zone A",children:"Zone A"}),e.jsx(K,{value:"Zone AE",children:"Zone AE"}),e.jsx(K,{value:"None",children:"Ninguna"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{checked:s.electricity,onCheckedChange:t=>l("electricity",t)}),e.jsx(g,{className:"text-xs cursor-pointer",children:"Electricidad"})]}),s.electricity&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Detalles"}),e.jsx(M,{value:s.electricity_details,onChange:t=>l("electricity_details",t.target.value)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{checked:s.water_well,onCheckedChange:t=>l("water_well",t)}),e.jsx(g,{className:"text-xs cursor-pointer",children:"Agua / Pozo"})]}),s.water_well&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Detalles"}),e.jsx(M,{value:s.water_details,onChange:t=>l("water_details",t.target.value)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{checked:s.has_restrictions,onCheckedChange:t=>l("has_restrictions",t)}),e.jsx(g,{className:"text-xs cursor-pointer",children:"Restricciones"})]}),s.has_restrictions&&e.jsxs("div",{className:"space-y-1.5 md:col-span-2",children:[e.jsx(g,{className:"text-xs",children:"Detalles"}),e.jsx(M,{value:s.restrictions_details,onChange:t=>l("restrictions_details",t.target.value)})]}),e.jsxs("div",{className:"lg:col-span-3",children:[e.jsx(g,{className:"text-xs font-semibold block mb-2",children:"Key Features (6 max)"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-3",children:[1,2,3,4,5,6].map(t=>e.jsx(M,{value:s[`keyFeature${t}`],onChange:a=>l(`keyFeature${t}`,a.target.value),placeholder:`Feature ${t}`,className:"text-sm"},t))})]})]})]})}),e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(is,{className:"h-4 w-4 text-primary"}),title:"Legal"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(g,{className:"text-xs",children:["Tipo TÃtulo ",W(s.title_type)&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(me,{value:s.title_type,onValueChange:t=>l("title_type",t),children:[e.jsx(ue,{className:q(W(s.title_type)&&"ring-2 ring-red-300"),children:e.jsx(ge,{placeholder:"Seleccionar"})}),e.jsxs(he,{children:[e.jsx(K,{value:"Warranty Deed",children:"Warranty Deed"}),e.jsx(K,{value:"Special Warranty Deed",children:"Special Warranty"}),e.jsx(K,{value:"Quitclaim Deed",children:"Quitclaim Deed"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(g,{className:"text-xs",children:["Derechos Minerales ",W(s.mineral_rights)&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs(me,{value:s.mineral_rights,onValueChange:t=>l("mineral_rights",t),children:[e.jsx(ue,{className:q(W(s.mineral_rights)&&"ring-2 ring-red-300"),children:e.jsx(ge,{placeholder:"Seleccionar"})}),e.jsxs(he,{children:[e.jsx(K,{value:"Included",children:"Incluidos"}),e.jsx(K,{value:"Excluded",children:"Excluidos"}),e.jsx(K,{value:"Unknown",children:"Desconocido"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Notas TÃtulo"}),e.jsx(M,{value:s.title_notes,onChange:t=>l("title_notes",t.target.value),placeholder:"TÃtulo limpio"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{checked:s.survey_available,onCheckedChange:t=>l("survey_available",t)}),e.jsx(g,{className:"text-xs cursor-pointer",children:"Survey disponible"})]}),s.survey_available&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Notas Survey"}),e.jsx(M,{value:s.survey_notes,onChange:t=>l("survey_notes",t.target.value)})]})]})]})}),e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(ze,{className:"h-4 w-4 text-primary"}),title:"Ubicación & Visitas"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Qué hay cerca"}
1),e.jsx(ee,{value:s.proximity_notes,onChange:t=>l("proximity_notes",t.target.value),placeholder:"8 min de Paris TX...",rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Qué hay cerca (Español)"}),e.jsx(ee,{value:s.proximity_notes_es,onChange:t=>l("proximity_notes_es",t.target.value),placeholder:"Traducción al español (opcional)...",rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Google Maps"}),e.jsx(M,{type:"url",value:s.google_maps_link,onChange:t=>l("google_maps_link",t.target.value),placeholder:"https://maps.google.com/..."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Cómo llegar"}),e.jsx(ee,{value:s.visit_instructions,onChange:t=>l("visit_instructions",t.target.value),rows:2})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Instrucciones de visita (Español)"}),e.jsx(ee,{value:s.visit_instructions_es,onChange:t=>l("visit_instructions_es",t.target.value),placeholder:"Traducción al español (opcional)...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Contacto"}),e.jsx(M,{value:s.visit_contact,onChange:t=>l("visit_contact",t.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Horarios"}),e.jsx(M,{value:s.visit_availability,onChange:t=>l("visit_availability",t.target.value),placeholder:"Lun-Sab 9-5"})]})]})]})]})}),e.jsx(fe,{saving:b==="info",onClick:()=>U("Información"),label:m?"Guardar Información":"Crear Terreno"})]}),e.jsxs(oe,{value:"media",className:"space-y-6 pb-8",children:[e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(pe,{className:"h-4 w-4 text-primary"}),title:"Imágenes del Terreno"}),e.jsx(We,{propertyId:i||"new-property",existingImages:s.photos,onImagesUploaded:j})]})}),m&&i&&e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(rs,{className:"h-4 w-4 text-primary"}),title:"Media WhatsApp"}),e.jsx(_s,{propertyId:i,promoVideoUrl:s.promo_video_url,brochurePdfUrl:s.brochure_pdf_url,audioDescriptionUrl:s.audio_description_url,videoAdUrl:s.video_ad_url,onMediaUpdate:A})]})}),m&&i&&e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(_e,{className:"h-4 w-4 text-primary"}),title:"Documentos de Conversión"}),e.jsx(gs,{propertyId:i,locationPdfUrl:s.location_pdf_url,locationPhotoUrl:s.location_photo_url,financingPdfUrl:s.financing_pdf_url,financingPhotoUrl:s.financing_photo_url,onDocumentUpdate:A})]})}),m&&i&&e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(os,{className:"h-4 w-4 text-primary"}),title:"Mapas de Lotes (Lot Availability)"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{className:"text-xs font-medium",children:"Satellite Lot Map"}),s.lot_map_satellite?e.jsxs("div",{className:"space-y-2",children:[e.jsx("img",{src:s.lot_map_satellite,alt:"Satellite map",className:"w-full h-auto rounded-lg border"}),e.jsx(X,{type:"button",variant:"destructive",size:"sm",onClick:()=>A("lot_map_satellite",null),children:"Eliminar"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{type:"file",accept:"image/jpeg,image/jpg,image/png,image/webp",onChange:t=>E(t,"lot_map_satellite"),disabled:L.lot_map_satellite}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[L.lot_map_satellite?e.jsx(ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ne,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Sube JPG/PNG/WEBP (máx 10MB)"})]}),e.jsx(M,{type:"url",value:s.lot_map_satellite??"",onChange:t=>l("lot_map_satellite",t.target.value),placeholder:"O pega URL de imagen satelital"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{className:"text-xs font-medium",children:"Subdivision Plat Map"}),s.lot_map_plat?e.jsxs("div",{className:"space-y-2",children:[e.jsx("img",{src:s.lot_map_plat,alt:"Plat map",className:"w-full h-auto rounded-lg border"}),e.jsx(X,{type:"button",variant:"destructive",size:"sm",onClick:()=>A("lot_map_plat",null),children:"Eliminar"})]}
1):e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{type:"file",accept:"image/jpeg,image/jpg,image/png,image/webp",onChange:t=>E(t,"lot_map_plat"),disabled:L.lot_map_plat}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[L.lot_map_plat?e.jsx(ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ne,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Sube JPG/PNG/WEBP (máx 10MB)"})]}),e.jsx(M,{type:"url",value:s.lot_map_plat??"",onChange:t=>l("lot_map_plat",t.target.value),placeholder:"O pega URL de plano de subdivisión"})]})]})]})]})}),e.jsx(fe,{saving:b==="media",onClick:()=>U("Media"),label:"Guardar Media"})]}),e.jsxs(oe,{value:"financing",className:"space-y-6 pb-8",children:[e.jsx(H,{children:e.jsxs(J,{className:"pt-6",children:[e.jsx(Y,{icon:e.jsx(Re,{className:"h-4 w-4 text-primary"}),title:"Configuración de Financiamiento"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(te,{checked:s.financing_enabled,onCheckedChange:t=>l("financing_enabled",t)}),e.jsx(g,{className:"cursor-pointer font-medium",children:"Habilitar Financiamiento"})]}),s.financing_enabled&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 pl-6 pt-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Enganche ($)"}),e.jsx(M,{type:"number",value:s.financing_down_payment,onChange:t=>l("financing_down_payment",t.target.value),placeholder:"7000"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Tasa (%)"}),e.jsx(M,{type:"number",step:"0.01",value:"10.0",disabled:!0,className:"bg-muted/50 cursor-not-allowed"}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-tight",children:"Fixed rate â all TerraFunded properties use 10% APR."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(g,{className:"text-xs",children:"Plazo (años)"}),e.jsx(M,{type:"number",value:"10",disabled:!0,className:"bg-muted/50 cursor-not-allowed"}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-tight",children:"Fixed term â all TerraFunded properties use a 10-year term."})]})]})]})]})}),e.jsx(fe,{saving:b==="financing",onClick:()=>U("Financiamiento"),label:"Guardar Financiamiento"})]}),e.jsxs(oe,{value:"sequence",className:"space-y-4 pb-8",children:[e.jsx(H,{children:e.jsxs(J,{className:"py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ns,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-semibold text-sm",children:"Secuencia de Seguimiento"})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[v.filled,"/",v.total," pasos"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2",children:e.jsx("div",{className:"bg-primary h-2 rounded-full transition-all duration-500",style:{width:`${v.filled/v.total*100}%`}})}),!s.value_hook_msg_1_en&&e.jsxs("p",{className:"text-xs text-amber-600 mt-2 flex items-center gap-1",children:[e.jsx(ke,{className:"h-3 w-3"}),"Los mensajes EN son obligatorios (fallback si no hay ES)"]})]})}),e.jsx("div",{className:"space-y-2",children:be.map(t=>e.jsx(ws,{...t,formData:s,onFieldChange:(a,r)=>l(a,r),propertyId:i,isEdit:m},t.stepNumber))}),e.jsx(fe,{saving:b==="sequence",onClick:()=>U("Secuencia de Ventas"),label:"Guardar Secuencia"})]})]})})]})};export{Ks 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.