import{j as W,y as A,z as B,bx as I,C as U,cs as M,F as z,I as H,B as S,bT as R,N as V,ds as $}from"./index-DXdAv5n3.js";import{r as h,j as t}from"./vendor-react-CVHocMAO.js";import{a as q,g as K,r as Z,b as G,c as Y}from"./wishlists-mdsVtVG_.js";import{I as J}from"./ImageWithFallback-BEJkpOin.js";import{P as Q}from"./plus-gZD8KbAO.js";import{g as D}from"./listing-utils-DWgPJQzT.js";import{p as E}from"./parseISO-BeqhIhSi.js";import{d as X}from"./differenceInDays-st7ugZrd.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ue=W("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]);function me({open:s,onOpenChange:d,listingId:r,listingTitle:a,listingImageUrl:f,onSavedChange:p}){const[i,o]=h.useState([]),[v,u]=h.useState(new Set),[L,w]=h.useState(!1),[N,j]=h.useState(null),[P,b]=h.useState(!1),[C,m]=h.useState(""),[y,k]=h.useState(!1),{toast:x}=R(),F=h.useCallback(async()=>{if(!(!s||!r)){w(!0);try{const[e,c]=await Promise.all([q(),K(r)]);o(e),u(new Set(c))}catch(e){console.warn("Failed to load wishlists",e),o([]),u(new Set),x({title:"Couldn't load wishlists",description:"Please try again.",variant:"destructive"})}finally{w(!1)}}},[s,r,x]);h.useEffect(()=>{F()},[F]);const T=async e=>{var g,_;if(N)return;j(e);const c=v.has(e);try{c?(await Z(e,r),u(n=>{const l=new Set(n);return l.delete(e),l}),o(n=>n.map(l=>l.id===e?{...l,itemCount:Math.max(0,l.itemCount-1)}:l)),x({title:"Removed from list",description:`Removed from ${((g=i.find(n=>n.id===e))==null?void 0:g.name)??"list"}.`})):(await G(e,r,{coverImageUrl:f}),u(n=>new Set(n).add(e)),o(n=>n.map(l=>l.id===e?{...l,itemCount:l.itemCount+1,coverImageUrl:l.coverImageUrl||f}:l)),x({title:"Saved to list",description:`Added to ${((_=i.find(n=>n.id===e))==null?void 0:_.name)??"list"}.`})),p==null||p()}catch(n){x({title:"Something went wrong",description:n instanceof Error?n.message:"Please try again.",variant:"destructive"})}finally{j(null)}},O=async()=>{const e=C.trim();if(!(!e||y)){k(!0);try{const c=await Y(e,{addListingId:r,coverImageUrl:f});o(g=>[...g,{...c,itemCount:1}]),u(g=>new Set(g).add(c.id)),m(""),b(!1),x({title:"Wishlist created",description:`"${c.name}" created and listing added.`}),p==null||p()}catch(c){x({title:"Couldn't create list",description:c instanceof Error?c.message:"Please try again.",variant:"destructive"})}finally{k(!1)}}};return t.jsx(A,{open:s,onOpenChange:d,children:t.jsxs(B,{className:"max-w-md grid gap-0 p-0 overflow-hidden",hideCloseButton:!1,children:[t.jsx("div",{className:"p-6 pb-0",children:t.jsx(I,{className:"text-left",children:t.jsx(U,{className:"text-xl font-semibold",children:"Save to wishlist"})})}),L?t.jsx("div",{className:"px-6 grid grid-cols-2 gap-4 min-h-[220px]",children:[1,2,3,4].map(e=>t.jsxs("div",{className:"rounded-2xl overflow-hidden bg-gray-100 animate-pulse border border-gray-100",children:[t.jsx("div",{className:"aspect-[4/3]"}),t.jsxs("div",{className:"p-4 space-y-2",children:[t.jsx("div",{className:"h-4 bg-gray-200 rounded w-3/4"}),t.jsx("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]})]},e))}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"px-6 pt-4 grid grid-cols-2 gap-4 max-h-[300px] overflow-y-auto pb-4",children:i.map(e=>{const c=v.has(e.id),g=N===e.id;return t.jsxs("button",{type:"button",onClick:()=>T(e.id),disabled:g,className:z("rounded-2xl overflow-hidden text-left transition-all duration-200","border-2 focus:outline-none focus:ring-2 focus:ring-brand focus:ring-offset-2 focus:ring-offset-background","hover:shadow-md active:scale-[0.98]",c?"border-brand shadow-sm ring-2 ring-brand/20":"border-gray-200 hover:border-gray-300 bg-white"),children:[t.jsxs("div",{className:"relative aspect-[4/3] bg-gray-100 overflow-hidden",children:[e.itemCount>0&&e.coverImageUrl?t.jsx(J,{src:e.coverImageUrl,alt:"",className:"w-full h-full object-cover"}):t.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-gray-50",children:t.jsx("span",{className:"text-4xl text-gray-300","aria-hidden":!0,children:"♥"})}),c&&t.jsx("span",{className:"absolute top-2.5 right-2.5 w-8 h-8 rounded-full bg-gray-900 flex items-center justify-center text-white shadow-lg","aria-hidden":!0,children:t.jsx(M,{className:"h-4 w-4",strokeWidth:2.5})}),g&&t.jsx("div",{className:"absolute inset-0 bg-white/50 flex items-center justify-center","aria-hidden":!0,children:t.jsx("span",{className:"text-sm font-medium text-gray-600",children:"Updating…"})})]}),t.jsxs("div",{className:"p-4 bg-white",children:[t.jsx("p",{className:"font-semibold text-gray-900 truncate text-sm",children:e.name}),t.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:[e.itemCount," ",(e.itemCount===1,"saved")]})]})]},e.id)})}),t.jsx("div",{className:"border-t border-gray-100 p-4 bg-gray-50/50",children:P?t.jsxs("div",{className:"flex gap-2",children:[t.jsx(H,{placeholder:"Wishlist name",value:C,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key==="Enter"&&O(),e.key==="Escape"&&b(!1)},className:"flex-1 rounded-xl border-gray-200 bg-white",autoFocus:!0}),t.jsx(S,{size:"sm",onClick:O,disabled:!C.trim()||y,className:"rounded-xl shrink-0",children:y?"Creating…":"Create"}),t.jsx(S,{size:"sm",variant:"ghost",onClick:()=>{b(!1),m("")},className:"rounded-xl shrink-0",children:"Cancel"})]}):t.jsxs(S,{variant:"outline",className:"w-full rounded-xl h-11 border-gray-200 bg-white hover:bg-gray-50 hover:border-gray-300 font-medium",onClick:()=>b(!0),children:[t.jsx(Q,{className:"mr-2 h-4 w-4"}),"Create new wishlist"]})})]})]})})}function ee(s){return s.status==="published"||s.status==="published_pending_updates"}function te(s){var a;const d=D(s)??s.draftData,r=(d==null?void 0:d.onboardingMetadata)??((a=s.draftData)==null?void 0:a.onboardingMetadata);return!!(r!=null&&r.onboardedBy||r!=null&&r.onboardedByPublicId)}function se(s,d){var a,f;const r=D(s)??s.draftData;return((a=r==null?void 0:r.plecMetadata)==null?void 0:a.isPopular)===!0?!0:(((f=r==null?void 0:r.plecMetadata)==null?void 0:f.isPopular)===!1,!1)}function fe(s,d){var b,C;const r=[],a=D(s)??s.draftData,{createdAt:f,listingKind:p}=s,i=a==null?void 0:a.plecMetadata,o=a==null?void 0:a.serviceData,v=(a==null?void 0:a.metadata)??{};i!=null&&i.isFeatured&&r.push({type:"plec_featured",label:"Featured",priority:1,category:"plec",showOnCard:!0}),i!=null&&i.partnerSince&&r.push({type:"plec_partner",label:"PLEC Partner",priority:1,category:"plec",showOnCard:!0});const u=(i==null?void 0:i.partnerSince)||(i==null?void 0:i.onboardingDate)||s.createdAt;if(u){const m=E(u),y=Number.isNaN(m.getTime())?u:V(m,"MMMM yyyy");r.push({type:"hosting_since",label:`Hosting with PLEC since ${y}`,priority:1,category:"plec",showOnCard:!1,metadata:{sinceDate:u}})}ee(s)&&te(s)&&r.push({type:"plec_onboarded",label:"Onboarded Partner",priority:1,category:"plec",showOnCard:!1});const w=v.hostProfile,N=v.host,j=v.user;if(((w==null?void 0:w.verified)||(N==null?void 0:N.verified)||(j==null?void 0:j.verified)||s.userVerified)&&r.push({type:"verified",label:"Verified",priority:2,category:"trust",showOnCard:!0}),se(s)&&r.push({type:"popular",label:"Popular",priority:3,category:"status",showOnCard:!0}),f){const m=E(f);X(new Date,m)<=30&&r.push({type:"new",label:"New",priority:3,category:"status",showOnCard:!0})}return p==="service"&&(o==null?void 0:o.travelPolicy)==="travels_to_you"&&r.push({type:"travels_to_you",label:"Travels to You",priority:4,category:"feature",showOnCard:!1}),p==="service"&&((b=o==null?void 0:o.requirements)!=null&&b.insurance)&&(((C=o.requirements.licenses)==null?void 0:C.length)??0)>0&&r.push({type:"licensed_insured",label:"Licensed & Insured",priority:4,category:"feature",showOnCard:!1}),r.sort((m,y)=>m.priority-y.priority)}const pe=$,ge=s=>s==null||Number.isNaN(s)?null:new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(s);function he(s){return!s||typeof s!="string"?s:s.split(/[\s_-]+/).map(d=>d.charAt(0).toUpperCase()+d.slice(1).toLowerCase()).join(" ")}export{pe as F,me as S,ue as Z,he as a,fe as c,ge as f};