1import{u as O,a as $,r as o,b as z,g as D,j as e,S as E,d as G,C as M,e as U,f as F,ah as B,ai as Q}from"./index-BEqAodlh.js";import{l as Y,f as K}from"./listings-hero-98cwUtuH.js";import{L as V}from"./ListingsSidebar-DqIZNpAW.js";import{P as W}from"./PropertyGrid-hNG7rntn.js";const J=[{label:"Any Price",value:""},{label:"R1,000 â R1,500",value:"1000-1500"},{label:"R1,500 â R2,000",value:"1500-2000"},{label:"R2,000 â R2,500",value:"2000-2500"},{label:"R2,500 â R3,000",value:"2500-3000"},{label:"R3,000 â R4,000",value:"3000-4000"},{label:"R4,000 â R5,000",value:"4000-5000"},{label:"R5,000 â R7,500",value:"5000-7500"},{label:"R7,500 â R10,000",value:"7500-10000"},{label:"R10,000+",value:"10000-999999"}],X=[{label:"Any Price",value:""},{label:"R250,000 â R500,000",value:"250000-500000"},{label:"R500,000 â R1,000,000",value:"500000-1000000"},{label:"R1,000,000 â R2,000,000",value:"1000000-2000000"},{label:"R2,000,000 â R3,000,000",value:"2000000-3000000"},{label:"R3,000,000 â R4,000,000",value:"3000000-4000000"},{label:"R4,000,000+",value:"4000000-999999999"}],T=[{value:"residential",label:"Residential"},{value:"retail",label:"Retail"},{value:"student",label:"Student Housing"}];function Z(m){return m==="For Sale"?"for_sale":"to_let"}function ee(m){if(!m)return[];const h=m.toLowerCase(),i=T.find(d=>d.value===h||d.label.toLowerCase()===h);return i?[i.value]:[]}function te({bannerImage:m,title:h,description:i,defaultListingType:d,defaultCategory:j}){const{t:r}=O(),u=$(),[p,k]=o.useState([]),P=o.useMemo(()=>z(p),[p]),[g,L]=o.useState(""),[n,w]=o.useState(ee(j)),[b,y]=o.useState(!1),[x,N]=o.useState(Z(d)),[l,c]=o.useState(""),[_,A]=o.useState(""),s=o.useRef(null);o.useEffect(()=>{let t=!1;return(async()=>{try{const a=await D(),{data:R}=await a.from("properties").select("address,suburb,region").eq("is_published",!0);if(t)return;k((R??[]).filter(S=>S.address||S.suburb||S.region))}catch{t||k([])}})(),()=>{t=!0}},[]),o.useEffect(()=>{const t=a=>{s.current&&!s.current.contains(a.target)&&y(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[]);const f=t=>w(a=>a.includes(t)?a.filter(R=>R!==t):[...a,t]),v=()=>{const t=new URLSearchParams;g&&t.set("suburb",g),n.length&&t.set("type",n.join(",")),x&&t.set("listing_type",x),l&&t.set("price",l),F({event:"property_search",search_intent:x,search_location:g||"all",search_property_type:n.length?n.join(","):"all",search_price_range:l||"any"}),u({to:"/search/",search:Object.fromEntries(t)})},C=t=>{const a=_.trim();a&&(F({event:"ai_property_search",search_term:a,search_language:navigator.language||"en"}),u({to:"/search/",search:{ai:a}}))},I=x==="for_sale"?X:J,H=x==="for_sale"?T.filter(t=>t.value!=="retail"):T,q="w-full border border-input rounded-lg px-3 py-3 text-sm bg-background focus:outline-none focus:ring-2 focus:ring-primary text-foreground";return e.jsxs("section",{className:"bg-primary relative overflow-hidden","data-no-translate":"true",children:[e.jsxs("div",{className:"absolute top-0 left-0 right-0 h-[50%] overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:`url('${m}')`,backgroundSize:"cover",backgroundPosition:"center"}}),e.jsx("div",{className:"absolute inset-0 bg-primary/30"}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-24 bg-gradient-to-b from-transparent to-primary"})]}),e.jsxs("div",{className:"container mx-auto px-6 pt-20 pb-16 md:pt-28 md:pb-20 relative z-10",children:[e.jsxs("div",{className:"max-w-4xl mx-auto mb-10 text-center",children:[e.jsx("h1",{className:"text-3xl md:text-5xl lg:text-6xl font-black text-primary-foreground leading-tight mb-3",children:h}),e.jsx("p",{className:"text-primary-foreground/80 text-sm md:text-base",children:i})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(E,{className:"w-4 h-4 text-accent"}),e.jsx("span",{className:"text-xs font-semibold text-primary-foreground/70 uppercase tracking-widest",children:r("Or ask AI to find your perfect property")})]}),e.jsxs("div",{className:"flex items-center gap-2 bg-white/95 backdrop-blur-sm rounded-xl p-3 shadow-lg",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(E,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-accent"}),e.jsx("input",{placeholder:"e.g. 'Affordable 1 bedroom in Hillbrow under R2500 with WiFi'",value:_,onCh
1ange:t=>A(t.target.value),onKeyDown:t=>t.key==="Enter"&&_.trim()&&C(),className:"w-full pl-11 h-12 text-base pr-4 border-0 bg-transparent focus:outline-none text-foreground placeholder:text-muted-foreground"})]}),e.jsxs("button",{onClick:()=>C(),disabled:!_.trim(),className:"h-12 px-6 rounded-lg bg-accent text-accent-foreground font-semibold flex items-center gap-2 disabled:opacity-50 shrink-0",children:[e.jsx(G,{className:"w-4 h-4"}),r("Ask AI")]})]})]}),e.jsxs("div",{className:"bg-card rounded-2xl shadow-2xl p-6 mt-6",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-widest mb-2 block",children:r("To Let or For Sale")}),e.jsxs("select",{value:x,onChange:t=>{const a=t.target.value;N(a),c(""),a==="for_sale"&&w(R=>R.filter(S=>S!=="retail"))},className:q,children:[e.jsx("option",{value:"to_let",children:r("To Let")}),e.jsx("option",{value:"for_sale",children:r("For Sale")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-widest mb-2 block",children:r("Location")}),e.jsxs("select",{value:g,onChange:t=>L(t.target.value),className:q,children:[e.jsx("option",{value:"",children:r("All Areas")}),P.map(t=>e.jsx("optgroup",{label:t.label,children:t.options.map(a=>e.jsx("option",{value:a,children:a},a))},t.label))]})]}),e.jsxs("div",{ref:s,className:"relative",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-widest mb-2 block",children:r("Property Type")}),e.jsxs("button",{type:"button",onClick:()=>y(t=>!t),className:"w-full border border-input rounded-lg px-3 py-3 text-sm bg-background text-left flex items-center justify-between",children:[e.jsx("span",{className:n.length===0?"text-muted-foreground":"text-foreground",children:n.length===0?r("All Types"):n.length===1?T.find(t=>t.value===n[0])?.label:`${n.length} ${r("selected")}`}),e.jsx(M,{className:`w-4 h-4 text-muted-foreground transition-transform ${b?"rotate-180":""}`})]}),b&&e.jsxs("div",{className:"absolute z-50 top-full left-0 right-0 mt-1 bg-card border border-border rounded-lg shadow-lg overflow-hidden",children:[H.map(({value:t,label:a})=>e.jsxs("label",{className:"flex items-center gap-3 px-4 py-3 hover:bg-muted cursor-pointer text-sm",children:[e.jsx("input",{type:"checkbox",checked:n.includes(t),onChange:()=>f(t),className:"w-4 h-4 rounded accent-primary"}),a]},t)),n.length>0&&e.jsx("button",{type:"button",onClick:()=>w([]),className:"w-full px-4 py-2 text-xs text-muted-foreground hover:text-foreground border-t border-border text-left",children:r("Clear selection")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-widest mb-2 block",children:r("Price Range")}),e.jsx("select",{value:l,onChange:t=>c(t.target.value),className:q,children:I.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]})]}),e.jsxs("button",{onClick:v,className:"bg-accent hover:bg-accent/90 text-accent-foreground font-bold py-3 px-8 rounded-lg flex items-center gap-2 text-sm",children:[e.jsx(U,{className:"w-4 h-4"}),r("Search Properties")]})]})]})]})}function ne({title:m,description:h,listingType:i,category:d,promotionCategory:j,allPromotions:r,otherPromotionsExcluding:u,initialProperties:p=[],bannerImage:k=Y,locationLinks:P}){const{t:g}=O(),[L,n]=o.useState(p),[w,b]=o.useState(p.length===0);return o.useEffect(()=>{if(p.length>0){n(p),b(!1);return}let y=!1;return(async()=>{b(!0);const N=await D();let l=N.from("properties").select("id, name, slug, address, description, is_on_promotion, promotion_type, hero_image_url, listing_type, property_categories, promotion_category, is_rent_to_buy, has_subsidy, subsidy_amount, sale_promo_details, display_units_left, units_left").eq("is_published",!0);i&&(l=l.eq("listing_type",i)),d&&(l=l.contains("property_categories",[d])),j?l=l.eq("is_on_promotion",!0).contains("promotion_category",[j]):(r||u&&u.length>0)&&(l=l.eq("is_on_promotion",!0));let{data:c}=await l.order("name",{ascending:!0});if(u&&u.length>0&&c){const s=new Set(u.map(f=>f.toLowerCase()));c=c.filter(f=>{const v=f.promotion_category||[];return v.length===0||!v.every(C=>s.has(String(C).toLowerCase()))})}if(y)return;if(!c||c.length===0){n([]),b(!1);return}const _=await K(N,c.map(s=>s.id)),A=await Promise.all(c.map(async s=>{const{data:f}=await N.from("property_images").select("url").eq("property_id",s.id).order("display_order").limit(1),v=B(s.hero_image_url||f?.[0]?.url,{width:600});return{id:s.id,priceFrom:_[s.id]??null,image:v,name:s.name,location:s.address||"",listingType:s.listing_type,categories:s.property_categories||[],category:[s.listing_type,...s.property_categories||[],...s.is_on_promotion&&s.promotion_category?.length?["Promotions",...s.promotion_category]:[]].filter(
1Boolean).join(", ")||"Residential",description:s.description||"",badge:s.is_on_promotion&&s.promotion_type?.length?s.promotion_type:null,link:Q(s.slug,s.listing_type,s.property_categories||[]),isRentToBuy:s.is_rent_to_buy||!1,hasSubsidy:s.listing_type==="For Sale"&&s.has_subsidy||!1,subsidyAmount:s.listing_type==="For Sale"?s.subsidy_amount??null:null,salePromoDetails:s.listing_type==="For Sale"&&s.sale_promo_details||"",displayUnitsLeft:!!s.display_units_left,unitsLeft:s.units_left??null}}));y||(n(A),b(!1))})(),()=>{y=!0}},[i,d,j,r,u?.join(","),p.length]),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(te,{bannerImage:k,title:m,description:h,defaultListingType:i,defaultCategory:d}),e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsxs("div",{className:"flex flex-col gap-8 lg:flex-row",children:[e.jsx("div",{className:"flex-1 min-w-0",children:w?e.jsx("div",{className:"text-center py-20 text-muted-foreground",children:g("Loading properties...")}):L.length===0?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("h2",{className:"text-xl font-bold text-foreground mb-2",children:g("No Properties Available")}),e.jsx("p",{className:"text-muted-foreground",children:g("There are currently no properties available in this category. Please check back soon or browse our other listings.")})]}):e.jsx(W,{properties:L})}),e.jsx("div",{className:"shrink-0 lg:w-72 xl:w-80 lg:self-start",children:e.jsx(V,{locationLinks:P,listingType:i})})]})})]})}export{ne as L};
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.