/* global React, ReactDOM */
const { useState, useEffect, useMemo, useCallback } = React;

/* ---------------- icons ---------------- */
const Ic = {
  pin:(p)=>(<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0Z"/><circle cx="12" cy="10" r="3"/></svg>),
  bed:(p)=>(<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M2 10v8M2 14h20v4M2 14V8a2 2 0 0 1 2-2h6v8M22 14v-2a4 4 0 0 0-4-4h-6"/></svg>),
  bath:(p)=>(<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4 12h16a1 1 0 0 1 1 1v3a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4v-3a1 1 0 0 1 1-1Z"/><path d="M6 12V6a2 2 0 0 1 2-2 2 2 0 0 1 2 2"/><path d="M9 5h2"/><path d="M7 20l-1 2M18 20l1 2"/></svg>),
  area:(p)=>(<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M3 3h18v18H3z"/><path d="M9 3v4M3 9h4M21 15h-4M15 21v-4"/></svg>),
  cam:(p)=>(<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M14.5 4l1.5 2h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h3l1.5-2Z"/><circle cx="12" cy="13" r="3.5"/></svg>),
  phone:(p)=>(<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6 19.8 19.8 0 0 1-3.1-8.7A2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 1.9.7 2.8a2 2 0 0 1-.5 2.1L8.1 9.9a16 16 0 0 0 6 6l1.3-1.3a2 2 0 0 1 2.1-.4c.9.3 1.8.6 2.8.7a2 2 0 0 1 1.7 2Z"/></svg>),
  mail:(p)=>(<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="2" y="4" width="20" height="16" rx="2"/><path d="m22 7-10 6L2 7"/></svg>),
  wa:(p)=>(<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" {...p}><path d="M.06 24l1.68-6.16a11.87 11.87 0 0 1-1.6-5.95C.14 5.34 5.5 0 12.06 0a11.82 11.82 0 0 1 8.42 3.49 11.78 11.78 0 0 1 3.48 8.41c0 6.56-5.36 11.9-11.92 11.9a12 12 0 0 1-5.7-1.45L.06 24Zm6.6-3.8c1.68.99 3.28 1.59 5.4 1.59 5.45 0 9.9-4.43 9.9-9.88A9.86 9.86 0 0 0 12.07 2c-5.46 0-9.9 4.43-9.9 9.88 0 2.23.65 3.9 1.74 5.66l-1 3.63 3.75-.98Zm11.39-5.55c-.07-.12-.27-.2-.57-.35-.3-.15-1.76-.87-2.03-.97-.27-.1-.47-.15-.67.15-.2.3-.77.97-.94 1.17-.17.2-.35.22-.65.07-.3-.15-1.26-.46-2.4-1.48-.89-.79-1.49-1.77-1.66-2.07-.17-.3-.02-.46.13-.61.13-.13.3-.35.45-.52.15-.17.2-.3.3-.5.1-.2.05-.37-.02-.52-.08-.15-.67-1.62-.92-2.22-.24-.58-.49-.5-.67-.51l-.57-.01c-.2 0-.52.07-.8.37-.27.3-1.04 1.02-1.04 2.49 0 1.47 1.07 2.89 1.22 3.09.15.2 2.1 3.2 5.08 4.49.71.3 1.26.49 1.69.62.71.23 1.36.2 1.87.12.57-.09 1.76-.72 2-1.41.25-.7.25-1.29.18-1.41Z"/></svg>),
  clock:(p)=>(<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>),
  x:(p)=>(<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" {...p}><path d="M18 6 6 18M6 6l12 12"/></svg>),
  chevL:(p)=>(<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="m15 18-6-6 6-6"/></svg>),
  chevR:(p)=>(<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="m9 18 6-6-6-6"/></svg>),
};

const Logo = ({size=46}) => (
  <svg className="mark" width={size} height={size} viewBox="0 0 100 100" fill="none" aria-label="Claudia Lima">
    <rect x="8" y="8" width="84" height="84" stroke="#8f824a" strokeWidth="2.2"/>
    <path d="M50 30 L82 80 L18 80 Z" stroke="#8f824a" strokeWidth="4.5" strokeLinejoin="round"/>
    <path d="M34 46 L54 80 L14 80 Z" stroke="#8f824a" strokeWidth="4.5" strokeLinejoin="round"/>
  </svg>
);

/* ---------------- data ---------------- */
const U = (id,w=900)=>`https://images.unsplash.com/photo-${id}?auto=format&fit=crop&w=${w}&q=72`;
const eur = (n)=> n.toLocaleString("pt-PT")+" €";

const PROPS = [
  { id:1, title:"Moradia T3 com jardim", zona:"Dume", tipo:"Moradia", t:3, preco:295000, quartos:3, wc:2, area:180, estado:"À venda",
    desc:"Moradia familiar em zona tranquila de Dume, com jardim privativo, cozinha equipada e garagem para dois carros. A poucos minutos do centro de Braga.",
    feats:["Jardim privativo","Garagem 2 carros","Cozinha equipada","Lareira","Painéis solares"],
    fotos:[U("1568605114967-8130f3a36994"),U("1570129477492-45c003edd2be"),U("1600585154340-be6161a56a0c"),U("1600566753086-00f18fb6b3ea")] },
  { id:2, title:"Apartamento T2 renovado", zona:"São Vítor", tipo:"Apartamento", t:2, preco:185000, quartos:2, wc:1, area:85, estado:"À venda",
    desc:"Apartamento totalmente renovado no coração de São Vítor, com excelente exposição solar, varanda e lugar de garagem. Pronto a habitar.",
    feats:["Varanda","Garagem","Elevador","Ar condicionado","Mobilado"],
    fotos:[U("1502672260266-1c1ef2d93688"),U("1493809842364-78817add7ffb"),U("1493663284031-b7e3aefcae8e"),U("1505691938895-1758d7feb511")] },
  { id:3, title:"Moradia T4 com piscina", zona:"Adaúfe", tipo:"Moradia", t:4, preco:420000, quartos:4, wc:3, area:260, estado:"À venda",
    desc:"Espaçosa moradia de luxo em Adaúfe, com piscina aquecida, amplo terreno e acabamentos de qualidade superior. Ideal para grandes famílias.",
    feats:["Piscina aquecida","Terreno 800m²","Suite","Garagem 3 carros","Domótica"],
    fotos:[U("1613490493576-7fde63acd811"),U("1564013799919-ab600027ffc6"),U("1600607687939-ce8a6c25118c"),U("1600210492486-724fe5c67fb0")] },
  { id:4, title:"Apartamento T3 no centro", zona:"Braga Centro", tipo:"Apartamento", t:3, preco:245000, quartos:3, wc:2, area:110, estado:"À venda",
    desc:"Apartamento luminoso no centro histórico de Braga, a passos de todos os serviços e comércio. Varanda ampla com vista de cidade.",
    feats:["Varanda ampla","Elevador","Arrecadação","Cozinha equipada"],
    fotos:[U("1560448204-e02f11c3d0e2"),U("1556909114-f6e7ad7d3136"),U("1556912173-3bb406ef7e77"),U("1484154218962-a197022b5858")] },
  { id:5, title:"Moradia T3 geminada", zona:"Nogueira", tipo:"Moradia", t:3, preco:315000, quartos:3, wc:2, area:165, estado:"À venda",
    desc:"Moradia geminada nova em Nogueira, com logradouro, garagem fechada e excelentes acabamentos. Bons acessos à A11 e A3.",
    feats:["Construção nova","Logradouro","Garagem fechada","Aquecimento central"],
    fotos:[U("1576941089067-2de3c901e126"),U("1605276374104-dee2a0ed3cd6"),U("1583608205776-bfd35f0d9f83"),U("1600585154526-990dced4db0d")] },
  { id:6, title:"Apartamento T1 mobilado", zona:"Gualtar", tipo:"Apartamento", t:1, preco:135000, quartos:1, wc:1, area:55, estado:"À venda",
    desc:"Apartamento T1 totalmente mobilado junto à Universidade do Minho, excelente para investimento ou primeira habitação. Boa rentabilidade potencial.",
    feats:["Mobilado","Junto à UMinho","Investimento","Varanda"],
    fotos:[U("1522708323590-d24dbb6b0267"),U("1512917774080-9991f1c4c750"),U("1540518614846-7eded433c457"),U("1502005229762-cf1b2da7c5d6")] },
  { id:7, title:"Moradia T5 de luxo", zona:"Lamaçães", tipo:"Moradia", t:5, preco:560000, quartos:5, wc:4, area:340, estado:"À venda",
    desc:"Moradia exclusiva em Lamaçães, com amplos espaços, jardim paisagístico, piscina e garagem para quatro viaturas. Privacidade e conforto de excelência.",
    feats:["Piscina","Jardim paisagístico","Ginásio","Garagem 4 carros","Suite com closet"],
    fotos:[U("1613977257363-707ba9348227"),U("1600596542815-ffad4c1539a9"),U("1600573472550-8090b5e0745e"),U("1616594039964-ae9021a400a0")] },
  { id:8, title:"Apartamento T2 com varanda", zona:"Maximinos", tipo:"Apartamento", t:2, preco:169000, quartos:2, wc:1, area:80, estado:"À venda",
    desc:"Apartamento acolhedor em Maximinos, com varanda, boa exposição solar e perto de transportes e comércio local. Ótima relação qualidade-preço.",
    feats:["Varanda","Perto de transportes","Cozinha equipada","Arrecadação"],
    fotos:[U("1554995207-c18c203602cb"),U("1567767292278-a4f21aa2d36e"),U("1574739782594-db4ead022697"),U("1586023492125-27b2c045efd7")] },
  { id:9, title:"Moradia T3 renovada", zona:"Real", tipo:"Moradia", t:3, preco:268000, quartos:3, wc:2, area:155, estado:"Reservada",
    desc:"Charmosa moradia recentemente renovada em Real, combinando o conforto moderno com o carácter tradicional. Quintal e zona de churrasco.",
    feats:["Renovada","Quintal","Churrasqueira","Sótão"],
    fotos:[U("1605146769289-440113cc3d00"),U("1512915922686-57c11dde9b6b"),U("1598928506311-c55ded91a20c"),U("1560185007-cde436f6a4d0")] },
];

const ZONAS = ["Todas",...Array.from(new Set(PROPS.map(p=>p.zona)))];
const TIPOS = ["Todos","Moradia","Apartamento"];
const TIPOLOGIAS = ["Todas","T1","T2","T3","T4+"];
const PRECOS = [
  {label:"Qualquer preço",min:0,max:Infinity},
  {label:"Até 150.000 €",min:0,max:150000},
  {label:"150.000 – 250.000 €",min:150000,max:250000},
  {label:"250.000 – 400.000 €",min:250000,max:400000},
  {label:"Acima de 400.000 €",min:400000,max:Infinity},
];

const WA = (msg)=>`https://wa.me/351913354281?text=${encodeURIComponent(msg)}`;

Object.assign(window,{ Ic, Logo, PROPS, ZONAS, TIPOS, TIPOLOGIAS, PRECOS, U, eur, WA, React, ReactDOM, useState, useEffect, useMemo, useCallback });
