import{f as N,r as d,j as e,a as E,R as P}from"./index.esm-CCV7wibp.js";import{f as D}from"./formatting-CY-a60T7.js";import"./index.esm-2kXzBSck.js";const A={apiKey:"AIzaSyDnxNVvnsEg8GBsQtYqX5o3kFVRZM39MR4",authDomain:"guess-63e3d.firebaseapp.com",projectId:"guess-63e3d",storageBucket:"guess-63e3d.firebasestorage.app",messagingSenderId:"423189681412",appId:"1:423189681412:web:144b96dc110ed3ceb12c51"};N.apps.length||N.initializeApp(A);const u=N.firestore(),T=()=>{const[b,h]=d.useState(!0),[g,m]=d.useState(null),[a,k]=d.useState(null),[s,U]=d.useState(null),[v,C]=d.useState(null),[I,w]=d.useState(!1),[x,R]=d.useState(!1),j=(o,r={})=>{if(!v)return;const l=sessionStorage.getItem("vyo_session")||`sess_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;sessionStorage.getItem("vyo_session")||sessionStorage.setItem("vyo_session",l),u.collection("vyo_analytics_public").add({eventName:o,category:"engagement",actorId:l,ownerId:v,sessionId:l,platform:"public_web",metadata:{...r,userAgent:navigator.userAgent,screenSize:`${screen.width}x${screen.height}`,referrer:document.referrer||"direct",pageUrl:window.location.href},createdAt:N.firestore.FieldValue.serverTimestamp()}).catch(()=>{})};d.useEffect(()=>{(async()=>{try{console.log("--- Digital Handshake Debug ---"),console.log("Full URL:",window.location.href);const r=new URLSearchParams(window.location.search);let l=r.get("id")||r.get("u");const p=window.location.pathname;if(!l&&p.length>1){const n=p.replace(/^\//,"").split("/")[0];if(console.log("Parsed slug:",n),n&&!n.endsWith(".html")){console.log("Fetching slug mapping for:",n);const i=await u.collection("slug_mappings").doc(n).get();console.log("Slug mapping exists?",i.exists),i.exists?(console.log("Slug resolved to User ID:",i.data().userId),l=i.data().userId):(console.log("Slug not found in mappings, treating as ID:",n),l=n)}}if(!l){console.error("No ID resolved"),m("No profile specified"),h(!1);return}C(l),console.log("Fetching Public Profile for ID:",l);const t=await u.collection("public_profiles").doc(l).get();if(console.log("Public Profile Document Exists?",t.exists),!t.exists){m("Profile not found"),h(!1);return}const f=t.data();if(k(f.profile||{}),f.tenantId){const n=await u.collection("tenants").doc(f.tenantId).get();n.exists&&U(n.data())}setTimeout(()=>j("page_viewed"),100),h(!1)}catch(r){console.error("Load error:",r),m("Failed to load profile"),h(!1)}})()},[]);const S=()=>{if(!a)return;const o=(a.displayName||"").split(" "),r=o[0]||"",l=o.slice(1).join(" ")||"",p=a.headshotUrl||a.avatarUrl;let t=`BEGIN:VCARD
`;t+=`VERSION:3.0
`,t+=`N:${l};${r};;;
`,t+=`FN:${a.displayName||""}
`,a.title&&(t+=`TITLE:${a.title}
`),s?.name&&(t+=`ORG:${s.name}
`),a.mobile&&(t+=`TEL;TYPE=CELL:${a.mobile}
`),a.email&&(t+=`EMAIL:${a.email}
`),p&&(t+=`PHOTO;VALUE=URI:${p}
`),t+=`URL:${window.location.href}
`,t+="END:VCARD";const f=new Blob([t],{type:"text/vcard"}),n=URL.createObjectURL(f),i=document.createElement("a");i.href=n,i.download=`${a.displayName||"contact"}.vcf`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(n),j("vcard_downloaded")},_=(o,r,l)=>{j("bio_link_clicked",{linkLabel:o,destinationUrl:r,positionOnPage:l})};if(b)return e.jsxs("div",{className:"loading",children:[e.jsx("div",{className:"spinner"}),e.jsx("span",{style:{color:"#666",fontSize:"14px"},children:"Loading profile..."})]});if(g)return e.jsxs("div",{className:"error-state",children:[e.jsx("h1",{children:"😕 Oops!"}),e.jsx("p",{children:g})]});const c=a.socials||{},$=a.customLinks||[],y=a.headshotUrl||a.avatarUrl,L=s?.assets?.brandColor||"#cc0000";return e.jsxs("div",{className:"handshake light-theme",style:{"--brand-color":L},children:[e.jsx("header",{className:"header",children:(s?.assets?.logoUrl||s?.logoUrl)&&e.jsx("img",{src:s.assets?.logoUrl||s.logoUrl,alt:s.name||"Logo",className:"main-logo",style:{height:"140px",width:"auto",objectFit:"contain"}})}),e.jsxs("div",{className:"hero",children:[y?e.jsx("img",{src:y,alt:a.displayName,className:"avatar"}):e.jsx("div",{className:"avatar-placeholder",children:a.displayName?.charAt(0)?.toUpperCase()||"?"}),e.jsx("h1",{className:"name",children:a.displayName||"Sales Professional"}),a.title&&e.jsx("p",{className:"title",children:a.title}),s?.name&&e.jsx("p",{className:"dealership",children:s.name}),a.bio&&e.jsx("p",{className:"bio",children:a.bio})]}),e.jsx("div",{className:"actions-wrapper",children:e.jsxs("div",{className:"actions-grid",children:[a.mobile&&e.jsxs("a",{href:`tel:${a.mobile}`,className:"action-btn action-primary",children:[e.jsx("span",{children:"📞"})," Call Me"]}),a.mobile&&e.jsxs("a",{href:`sms:${a.mobile}`,className:"action-btn action-secondary",children:[e.jsx("span",{children:"💬"})," Text Me"]}),a.email&&e.jsxs("a",{href:`mailto:${a.email}`,className:"action-btn action-secondary",children:[e.jsx("span",{children:"✉️"})," Email Me"]}),e.jsxs("button",{onClick:S,className:"action-btn action-primary",children:[e.jsx("span",{children:"💾"})," Save Contact"]}),e.jsxs("div",{className:"split-share-container",children:[e.jsxs("button",{className:"share-main-btn",onClick:()=>{navigator.share?navigator.share({title:`${a.displayName||"My Profile"} | ${s?.name}`,url:window.location.href}).catch(console.error):(navigator.clipboard.writeText(window.location.href),alert("Link copied!"))},children:[e.jsx("span",{children:"📤"})," Share"]}),e.jsx("button",{className:"share-qr-btn",onClick:()=>{w(!0),j("qr_code_viewed")},title:"QR Code",children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"}),e.jsx("path",{d:"M3 16v5h5"})]})})]}),$.map((o,r)=>e.jsxs("a",{href:o.url,target:"_blank",rel:"noopener noreferrer",className:"action-btn action-secondary",onClick:()=>_(o.label,o.url,r+1),children:["🔗 ",o.label]},r))]})}),s?.name&&e.jsxs("div",{className:"dealership-section",children:[e.jsxs("div",{className:"dealership-header",children:[(s.assets?.logoUrl||s.logoUrl)&&e.jsx("img",{src:s.assets?.logoUrl||s.logoUrl,alt:s.name,className:"dealership-logo-large"}),s.phone&&e.jsx("div",{className:"dealership-phone-wrapper",children:e.jsx("a",{href:`tel:${s.phone}`,className:"dealership-main-phone",children:D(s.phone)})}),e.jsxs("div",{className:"dealership-links",children:[s.website&&e.jsx("a",{href:s.website,target:"_blank",rel:"noopener noreferrer",children:"Website"}),s.inventoryUrlNew&&e.jsx("a",{href:s.inventoryUrlNew,target:"_blank",rel:"noopener noreferrer",children:"New Inv"}),s.inventoryUrlUsed&&e.jsx("a",{href:s.inventoryUrlUsed,target:"_blank",rel:"noopener noreferrer",children:"Used Inv"}),s.creditAppUrl&&e.jsx("a",{href:s.creditAppUrl,target:"_blank",rel:"noopener noreferrer",children:"Financing"})]})]}),s.aboutUs&&e.jsxs("div",{className:"dealership-about",children:[e.jsx("h4",{children:"About Us"}),e.jsx("div",{className:"about-toggle-wrapper",children:e.jsxs("button",{className:"about-toggle-link",onClick:()=>R(!x),children:[e.jsx("span",{children:x?"Show Less":"Read Our Story"}),e.jsx("span",{className:`chevron ${x?"open":""}`,children:"▼"})]})}),x&&e.jsx("div",{className:"dealership-about-content",dangerouslySetInnerHTML:{__html:s.aboutUs}})]}),s.hours&&e.jsxs("div",{className:"dealership-hours",children:[e.jsx("h4",{children:"Store Hours"}),e.jsx("div",{className:"hours-grid",children:["monday","tuesday","wednesday","thursday","friday","saturday","sunday"].map(o=>{const r=s.hours[o];let l="Closed";return typeof r=="string"?l=r||"Closed":r&&typeof r=="object"&&(r.isClosed?l="Closed":r.open&&r.close?l=`${r.open} - ${r.close}`:l="Closed"),e.jsxs("div",{className:"hour-row",children:[e.jsx("span",{className:"day",children:o}),e.jsx("span",{className:`time ${l==="Closed"?"text-red-500":""}`,children:l})]},o)})})]}),s.staff&&s.staffEnabled&&e.jsxs("div",{className:"dealership-staff",children:[e.jsx("h4",{children:"Meet Our Team"}),e.jsx("div",{className:"staff-grid",children:s.staff.map((o,r)=>e.jsxs("div",{className:"staff-card",children:[o.photoUrl?e.jsx("img",{src:o.photoUrl,alt:o.name}):e.jsx("div",{className:"staff-placeholder",children:o.name?.charAt(0)}),e.jsxs("div",{className:"staff-info",children:[e.jsx("strong",{children:o.name}),e.jsx("span",{children:o.position})]})]},r))})]}),e.jsxs("div",{className:"dealership-footer",children:[e.jsxs("div",{className:"footer-info-row",children:[e.jsxs("div",{className:"footer-address-left",children:[e.jsxs("h5",{children:["📍 ",s.name]}),e.jsxs("a",{href:`https://maps.google.com/?q=${encodeURIComponent(s.address1+" "+(s.address2||""))}`,target:"_blank",rel:"noopener noreferrer",className:"simple-address-link",children:[e.jsx("p",{children:s.address1}),s.address2&&e.jsx("p",{children:s.address2})]})]}),e.jsx("div",{className:"footer-button-right",children:e.jsx("a",{href:`https://maps.google.com/?q=${encodeURIComponent(s.address1+" "+(s.address2||""))}`,target:"_blank",rel:"noopener noreferrer",className:"directions-hint",children:"👆 TAP FOR DIRECTIONS"})})]}),e.jsx("div",{className:"footer-map",children:e.jsx("iframe",{width:"100%",height:"100%",frameBorder:"0",scrolling:"no",marginHeight:"0",marginWidth:"0",src:`https://maps.google.com/maps?q=${encodeURIComponent(s.address1+" "+(s.address2||""))}&t=&z=14&ie=UTF8&iwloc=&output=embed`,title:"Dealership Location"})})]})]}),Object.values(c).some(o=>o)&&e.jsxs("div",{className:"socials",children:[c.instagram&&e.jsx("a",{href:c.instagram,target:"_blank",rel:"noopener",className:"social-link",children:"📸"}),c.linkedin&&e.jsx("a",{href:c.linkedin,target:"_blank",rel:"noopener",className:"social-link",children:"💼"}),c.tiktok&&e.jsx("a",{href:c.tiktok,target:"_blank",rel:"noopener",className:"social-link",children:"🎵"}),c.facebook&&e.jsx("a",{href:c.facebook,target:"_blank",rel:"noopener",className:"social-link",children:"👤"})]}),e.jsx("div",{className:"footer",children:e.jsx("a",{href:"https://vyomotiv.com",target:"_blank",rel:"noopener",children:"Powered by Vyomotiv"})}),I&&e.jsx(M,{profileName:a.displayName,onClose:()=>w(!1)})]})},M=({profileName:b,onClose:h})=>{const g=`https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(window.location.href)}`;return e.jsx("div",{className:"modal-overlay",onClick:h,children:e.jsxs("div",{className:"modal",onClick:m=>m.stopPropagation(),children:[e.jsx("h3",{children:"📱 Scan to Connect"}),e.jsxs("p",{children:["Share this QR code to let others access ",b||"this"," profile"]}),e.jsx("div",{className:"qr-container",children:e.jsx("img",{src:g,alt:"QR Code"})}),e.jsx("button",{className:"modal-close",onClick:h,children:"Close"})]})})};E.createRoot(document.getElementById("root")).render(e.jsx(P.StrictMode,{children:e.jsx(T,{})}));
