1import{c as S,s as j,u as P,j as e,a as O,r as w,b as I,R,U as T}from"./index-BDDeZ-RJ.js";import{toast as v}from"./index-u3G1Sozw.js";import{T as L}from"./thumbs-up-wUY1nFD5.js";const U=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],M=S("file-text",U);const W=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],D=S("log-out",W);var H={version:"1.1.2"},B="authorization_response",F="/~oauth/initiate",V=["https://oauth.lovable.app","https://lovable.dev"],$="lovable://oauth-callback",z="http://127.0.0.1/iframe-oauth/callback",G=500,K=12e4;function Y(t){let n;const s=new Promise(c=>{n=c}),o=c=>{if(!t.some(m=>c.origin===m))return;const i=c.data;!i||typeof i!="object"||i.type===B&&n(i.response)},u=()=>{window.removeEventListener("message",o)};return window.addEventListener("message",o),{cleanup:u,messagePromise:s}}function q(t){const n=window.screenX!==0||window.screenY!==0||!t,s=n?window.outerWidth*.5:window.screen.width*.5,o=n?window.outerHeight*.5:window.screen.height*.5,u=n?window.screenX+(window.outerWidth-s)/2:(window.screen.width-s)/2,c=n?window.screenY+(window.outerHeight-o)/2:(window.screen.height-o)/2;return{width:s,height:o,left:u,top:c}}function A(t,n){return t.state!==n?{error:new Error("State is invalid")}:t.error?t.error==="legacy_flow"?{error:new Error("This flow is not supported in Preview mode. Please open the app in a new tab to sign in.")}:{error:new Error(t.error_description??"Sign in failed")}:!t.access_token||!t.refresh_token?{error:new Error("No tokens received")}:{tokens:{access_token:t.access_token,refresh_token:t.refresh_token},error:null}}function X(){const t=navigator.userAgent;return!!(/iPhone|iPad|iPod|Android/i.test(t)||/Macintosh/i.test(t)&&navigator.maxTouchPoints>1)}function J(){return typeof crypto<"u"&&crypto.getRandomValues?[...crypto.getRandomValues(new Uint8Array(16))].map(t=>t.toString(16).padStart(2,"0")).join(""):Math.random().toString(36).substring(2)+Date.now().toString(36)}function Q(t={}){const n=t.oauthBrokerUrl??F,s=t.supportedOAuthOrigins??V;async function o(u,c={}){let d=!1;try{d=window.self!==window.top}catch{d=!0}const i=navigator.userAgent,m=/LovableApp\//.test(i),x=!m&&/lovable/i.test(i),p=J();let a=c.redirect_uri??window.location.origin;m&&d?a=$:x&&d&&(a=z);const g=new URLSearchParams({...c.extraParams,provider:u,redirect_uri:a,state:p});if(!d)return window.location.href=`${n}?${g.toString()}`,{error:null,redirected:!0};!m&&!x&&g.set("response_mode","web_message");const r=`${n}?${g.toString()}`,h=x?[...s,window.location.origin]:s,{messagePromise:k,cleanup:_}=Y(h);let b;if(X())b=window.open(r,"_blank");else{const{width:l,height:y,left:f,top:E}=q(d);b=window.open(r,"oauth",`width=${l},height=${y},left=${f},top=${E}`)}if(!b&&(m||x)){let l;const y=new Promise((f,E)=>{l=setTimeout(()=>{E(new Error("OAuth timed out waiting for response"))},K)});try{const f=await Promise.race([k,y]);return A(f,p)}catch(f){return{error:f instanceof Error?f:new Error(String(f))}}finally{l&&clearTimeout(l),_()}}if(!b)return _(),{error:new Error("Popup was blocked")};let N;const C=new Promise((l,y)=>{N=setInterval(()=>{b.closed&&(clearInterval(N),y(new Error("Sign in was cancelled")))},G)});try{const l=await Promise.race([k,C]);return A(l,p)}catch(l){return{error:l instanceof Error?l:new Error(String(l))}}finally{clearInterval(N),_(),b?.close()}}return{signInWithOAuth:o}}typeof window<"u"&&(window.__lovable_cloud_auth_js_version=H.version);function Z(t={}){return Q(t)}const ee=Z(),te={auth:{signInWithOAuth:async(t,n)=>{const s=await ee.signInWithOAuth(t,{redirect_uri:n?.redirect_uri,extraParams:{...n?.extraParams}});if(s.redirected||s.error)return s;try{await j.auth.setSession(s.tokens)}catch(o){return{error:o instanceof Error?o:new Error(String(o))}}return s}}};function ae(){const{user:t,loading:n,signOut:s}=P();return n?e.jsx("div",{className:"px-4 py-12 text-center text-sm text-muted-foreground",children:"Loadingâ¦"}):t?e.jsx(se,{}):e.jsx(re,{})}function re(){const[t,n]=w.useState("signin"),[s,o]=w.useState(""),[u,c]=w.useState(""),[d,i]=w.useState(!1),m=I(),x=R.useSearch(),p=()=>{const r=x.redirect;r&&r.startsWith("/")&&!r.startsWith("//")&&!r.startsWith("/\\")?window.location.href=r:m({to:"/map"})},a=async r=>{r.preventDefault(),i(!0);try{if(t==="signup"){const{error:h}=await j.auth.signUp({email:s,password:u,options:{emailRedirectTo:`${window.location.origin}/profile`}});if(h)throw h;v.success("Check your email to confirm your account.")}else{const{error:h}=await j.auth.signInWithPassword({email:s,password:u});if(h)throw h;v.success("Welcome back!"),p()}}catch(h){v.error(h instanceof Error?h.message:"Authentication failed")}finally{i(!1)}},g=async()=>{i(!0);try{const r=await te.auth.signInWithOAuth("google",{redirect_uri:window.location.origin+"/profile"});if(r.error)throw r.error;if(r.redirected)return;v.success("Welcome!"),p()}catch(r){v.error(r instanceof Error?r.message:"Google sign-in failed")}finally{i(!1)}};return e.jsxs("div",{className:"px-4 md:px-10 py-12 max-w-md mx-auto",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-primary/10 text-primary",children:e.jsx(T,{className:"h-7 w-7"})}),e.jsx("h1",{className:"text-3xl mb-1",children:t==="signin"?"Welcome back":"Create account"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==="signin"?"Sign in to track y
1our reports.":"Join your neighbors making Chicago better."})]}),e.jsxs("form",{onSubmit:a,className:"space-y-4 bg-card border border-border rounded-xl p-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",children:"Email"}),e.jsx("input",{type:"email",required:!0,value:s,onChange:r=>o(r.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",children:"Password"}),e.jsx("input",{type:"password",required:!0,minLength:6,value:u,onChange:r=>c(r.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm"})]}),e.jsx("button",{disabled:d,className:"w-full rounded-md bg-primary text-primary-foreground py-2.5 text-sm font-medium hover:bg-primary/90 disabled:opacity-50",children:d?"Workingâ¦":t==="signin"?"Sign in":"Create account"}),e.jsxs("p",{className:"text-xs text-center text-muted-foreground",children:[t==="signin"?"New here?":"Already have an account?"," ",e.jsx("button",{type:"button",onClick:()=>n(t==="signin"?"signup":"signin"),className:"text-primary font-medium hover:underline",children:t==="signin"?"Create account":"Sign in"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 my-4",children:[e.jsx("div",{className:"h-px flex-1 bg-border"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsxs("button",{type:"button",onClick:g,disabled:d,className:"w-full inline-flex items-center justify-center gap-2 rounded-md border border-border bg-background py-2.5 text-sm font-medium hover:bg-accent disabled:opacity-50",children:[e.jsxs("svg",{className:"h-4 w-4",viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.75h3.57c2.08-1.92 3.28-4.74 3.28-8.07z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.75c-.99.66-2.25 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84A11 11 0 0 0 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.12A6.6 6.6 0 0 1 5.5 12c0-.74.13-1.45.34-2.12V7.04H2.18A11 11 0 0 0 1 12c0 1.78.43 3.46 1.18 4.96l3.66-2.84z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.04l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z"})]}),"Continue with Google"]}),e.jsx("button",{onClick:p,className:"w-full mt-4 text-xs text-center text-muted-foreground hover:text-foreground py-2",children:"Continue as guest â"}),e.jsx("p",{className:"text-[11px] text-center text-muted-foreground mt-2",children:"Guests can browse the map and feed but can't upvote or submit reports."})]})}function se(){const{user:t,signOut:n}=P(),s=O(),[o,u]=w.useState([]),[c,d]=w.useState(0),[i,m]=w.useState(!0);w.useEffect(()=>{if(!t)return;let a=!1;return(async()=>{const[g,r]=await Promise.all([j.from("reports").select("id, type, address, ward, status, created_at").eq("created_by",t.id).order("created_at",{ascending:!1}),j.from("upvotes").select("id",{count:"exact",head:!0}).eq("user_id",t.id)]);a||(g.data&&u(g.data),d(r.count??0),m(!1))})(),()=>{a=!0}},[t]);const x=async()=>{await n(),v.success("Signed out"),s.navigate({to:"/map"})},p=(t?.email??"?").slice(0,2).toUpperCase();return e.jsxs("div",{className:"px-4 md:px-10 py-10 max-w-3xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-primary text-primary-foreground text-xl font-semibold",children:p}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h1",{className:"text-2xl truncate",children:t?.email}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Chi311 Plus member"})]}),e.jsxs("button",{onClick:x,className:"inline-flex items-center gap-1.5 rounded-md border border-border bg-background px-3 py-2 text-sm hover:bg-accent",children:[e.jsx(D,{className:"h-4 w-4"})," Sign out"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-8",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(M,{className:"h-4 w-4"})," Reports submitted"]}),e.jsx("div",{className:"text-3xl font-semibold",children:i?"â":o.length})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(L,{className:"h-4 w-4"})," Issues upvoted"]}),e.jsx("div",{className:"text-3xl font-semibold",children:i?"â":c})]})]}),e.jsx("h2",{className:"text-lg font-medium mb-3",children:"Your reports"}),i?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loadingâ¦"}):o.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-border p-8 text-center text-sm text-muted-foreground",children:"You haven't submitted any reports yet."}):e.jsx("ul",{className:"space-y-2",children:o.map(a=>e.jsxs("li",{className:"flex items-center gap-3 rounded-lg border border-border bg-card px-4 py-3",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:a.status==="open"?"#E24B4A":a.status==="in_progress"?"#EF9F27":"#3FB67A"}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:a.type}),e.jsxs("div",{className:"text-xs text-muted-foreground truncate",children:[a.address," · Ward ",a.ward]})]}),e.jsx("span",{className:"text-xs text-muted-foreground capitalize shrink-0",children:a.status.replace("_"," ")})]},a.id))})]})}export{ae as component};
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.