var R=Object.defineProperty;var B=(e,s,t)=>s in e?R(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t;var l=(e,s,t)=>B(e,typeof s!="symbol"?s+"":s,t);/* empty css */import{a as k}from"./leaflet-src-DKb5ysSI.js";import{V as N,f as $,e as E,y as I,C as P,_ as V,g,h as u,i as m,j as n,a3 as O,a0 as F,m as z,s as q,q as A,k as x,t as S,l as w,w as j,F as D,x as v,z as Z}from"./index-BLqts8WY.js";import{i as U,v as Q}from"./vue-leaflet.es-D17g3l39.js";import{Q as G}from"./QuickNav-DgCyvgDx.js";import{I as _}from"./InfiniteScroll-B5tl9k_n.js";import{P as H}from"./ProjectIcon-BlrP4rvy.js";import{O as J}from"./OnboardingDialog-CiAZLb6o.js";import{T as K}from"./TopMessage-BE0GBIgW.js";import{h as W,e as X,ao as Y,g as T,x as ee}from"./index-MyY_xqVN.js";import"./index-CsfPLOYu.js";var te=Object.defineProperty,se=Object.getOwnPropertyDescriptor,oe=(e,s,t,o)=>{for(var i=o>1?void 0:o?se(s,t):s,a=e.length-1,h;a>=0;a--)(h=e[a])&&(i=(o?h(s,t,i):h(i))||i);return o&&i&&te(s,t,i),i};let C=class extends N{constructor(){super(...arguments);l(this,"$notify");l(this,"activeDid","");l(this,"allContacts",[]);l(this,"allMyDids",[]);l(this,"apiServer","");l(this,"searchTerms","");l(this,"projects",[]);l(this,"isLoading",!1);l(this,"isLocalActive",!0);l(this,"isMappedActive",!1);l(this,"isRemoteActive",!1);l(this,"isSearchVisible",!0);l(this,"localCenterLat",0);l(this,"localCenterLong",0);l(this,"localCount",-1);l(this,"markers",{});l(this,"remoteCount",-1);l(this,"searchBox",null);l(this,"tempSearchBox",null);l(this,"zoomedSoDoNotMove",!1);l(this,"didInfo",W)}async mounted(){var o;const t=await $();if(this.activeDid=t.activeDid||"",this.apiServer=t.apiServer||"",this.searchBox=((o=t.searchBoxes)==null?void 0:o[0])||null,this.allContacts=await E.contacts.toArray(),this.allMyDids=await X(),this.searchTerms=this.$route.query.searchText||"",t.finishedOnboarding||this.$refs.onboardingDialog.open(Y.Discover),this.searchBox){await this.searchLocal();const i=this.searchBox.bbox;this.localCenterLat=(i.maxLat+i.minLat)/2,this.localCenterLong=(i.eastLong+i.westLong)/2}else this.isLocalActive=!1,this.isMappedActive=!1,this.isRemoteActive=!0,await this.searchAll()}resetCounts(){this.localCount=-1,this.remoteCount=-1}async searchSelected(){this.isLocalActive?await this.searchLocal():this.isMappedActive?(this.isRemoteActive=!0,await this.searchAll()):await this.searchAll()}async searchAll(t){this.resetCounts(),t||(this.projects=[]);let o="claimContents="+encodeURIComponent(this.searchTerms);t&&(o=o+`&beforeId=${t}`);try{this.isLoading=!0;const i=await fetch(this.apiServer+"/api/v2/report/plans?"+o,{method:"GET",headers:await T(this.activeDid)});if(i.status!==200){const c=await i.text();throw console.error("Problem with full search:",c),this.$notify({group:"alert",type:"danger",title:"Error",text:"There was a problem accessing the server. Try again later."},-1),c}const a=await i.json(),h=a.data;if(h){for(const c of h){const{name:p,description:r,handleId:b,image:L,issuerDid:y,rowid:f}=c;this.projects.push({name:p,description:r,handleId:b,image:L,issuerDid:y,rowid:f})}this.remoteCount=this.projects.length}else throw JSON.stringify(a)}catch(i){console.error("Error with feed load:",i),console.error("Error with feed load (error added): "+i),this.$notify({group:"alert",type:"danger",title:"Error",text:i.userMessage||"There was a problem retrieving projects."},-1)}finally{this.isLoading=!1}}async searchLocal(t){var h;this.resetCounts();const o=this.isMappedActive&&this.tempSearchBox||this.isLocalActive&&((h=this.searchBox)==null?void 0:h.bbox);if(!o){this.projects=[];return}t||(this.projects=[]);let a=["claimContents="+encodeURIComponent(this.searchTerms),"minLocLat="+o.minLat,"maxLocLat="+o.maxLat,"westLocLon="+o.westLong,"eastLocLon="+o.eastLong].join("&");t&&(a=a+`&beforeId=${t}`);try{this.isLoading=!0;const c=await fetch(this.apiServer+"/api/v2/report/plansByLocation?"+a,{method:"GET",headers:await T(this.activeDid)});if(c.status!==200){const r=await c.text();throw console.error("Problem with nearby search:",r),this.$notify({group:"alert",type:"danger",title:"Error",text:"There was a problem accessing the server. Try again later."},-1),await c.text()}const p=await c.json();if(p.data){if(t){const r=p.data;for(const b of r){const{name:L,description:y,handleId:f,issuerDid:d,rowid:M}=b;this.projects.push({name:L,description:y,handleId:f,issuerDid:d,rowid:M})}}else this.projects=p.data;this.localCount=this.projects.length}else throw JSON.stringify(p)}catch(c){console.error("Error with feed load:",c),this.$notify({group:"alert",type:"danger",title:"Error",text:c.userMessage||"There was a problem retrieving projects."},-1)}finally{this.isLoading=!1}}async loadMoreData(t){if(this.projects.length>0&&t){const o=this.projects[this.projects.length-1];this.isLocalActive?this.searchLocal(o.rowid):this.isMappedActive?this.searchLocal(o.rowid):this.isRemoteActive&&this.searchAll(o.rowid)}}async onMapReady(t){t.setView([this.localCenterLat,this.localCenterLong],2),this.requestTiles(t)}onMoveStart(){}async onMoveEnd(t){this.zoomedSoDoNotMove?this.zoomedSoDoNotMove=!1:await this.requestTiles(t.target)}onZoomStart(){Object.values(this.markers).forEach(t=>t.remove()),this.markers={},this.zoomedSoDoNotMove=!0}async onZoomEnd(t){await this.requestTiles(t.target)}async requestTiles(t){var o,i;try{const a=t.getBounds(),h=["minLocLat="+(a==null?void 0:a.getSouthWest().lat),"maxLocLat="+(a==null?void 0:a.getNorthEast().lat),"westLocLon="+(a==null?void 0:a.getSouthWest().lng),"eastLocLon="+(a==null?void 0:a.getNorthEast().lng)].join("&"),c=await fetch(this.apiServer+"/api/v2/report/planCountsByBBox?"+h);if(c.status===200){Object.values(this.markers).forEach(r=>r.remove()),this.markers={};const p=await c.json();if(((i=(o=p.data)==null?void 0:o.tiles)==null?void 0:i.length)>0)for(const r of p.data.tiles){const b=(r.minFoundLat+r.maxFoundLat)/2,L=(r.minFoundLon+r.maxFoundLon)/2,y=k.divIcon({className:"numbered-marker",html:`${r.recordCount}`,iconSize:[24,24],iconAnchor:[12,12]}),f=k.marker([b,L],{icon:y});f.addTo(t),f.on("click",()=>{this.tempSearchBox={minLat:r.minFoundLat,maxLat:r.maxFoundLat,westLong:r.minFoundLon,eastLong:r.maxFoundLon},this.searchLocal()}),this.markers[""+r.indexLat+"X"+r.indexLon]=f}await this.searchLocal()}else throw{message:"Got an error loading projects on the map.",response:{status:c.status,statusText:c.statusText,url:c.url}}}catch(a){I("Error loading projects on the map: "+ee(a),!0),this.$notify({group:"alert",type:"danger",title:"Map Error",text:"There was a problem loading projects on the map."},3e3)}}onClickLoadProject(t){const o={path:"/project/"+encodeURIComponent(t)};this.$router.push(o)}computedLocalTabStyleClassNames(){return{"inline-block":!0,"py-3":!0,"rounded-t-lg":!0,"border-b-2":!0,active:this.isLocalActive,"text-black":this.isLocalActive,"border-black":this.isLocalActive,"font-semibold":this.isLocalActive,"text-blue-600":!this.isLocalActive,"border-transparent":!this.isLocalActive,"hover:border-slate-400":!this.isLocalActive}}computedMappedTabStyleClassNames(){return{"inline-block":!0,"py-3":!0,"rounded-t-lg":!0,"border-b-2":!0,active:this.isMappedActive,"text-black":this.isMappedActive,"border-black":this.isMappedActive,"font-semibold":this.isMappedActive,"text-blue-600":!this.isMappedActive,"border-transparent":!this.isMappedActive,"hover:border-slate-400":!this.isMappedActive}}computedRemoteTabStyleClassNames(){return{"inline-block":!0,"py-3":!0,"rounded-t-lg":!0,"border-b-2":!0,active:this.isRemoteActive,"text-black":this.isRemoteActive,"border-black":this.isRemoteActive,"font-semibold":this.isRemoteActive,"text-blue-600":!this.isRemoteActive,"border-transparent":!this.isRemoteActive,"hover:border-slate-400":!this.isRemoteActive}}};C=oe([P({components:{InfiniteScroll:_,LMap:U,LTileLayer:Q,OnboardingDialog:J,ProjectIcon:H,QuickNav:G,TopMessage:K}})],C);const ae={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},ie={class:"text-center text-slate-500 border-b border-slate-300"},re={class:"flex flex-wrap justify-center gap-4 -mb-px"},ne={key:0},le={class:"text-center"},ce={key:1},de={class:"mt-4 h-96 w-5/6 mx-auto"},he={key:2,class:"fixed left-6 bottom-24 text-center text-4xl leading-none bg-slate-400 text-white w-14 py-2.5 rounded-full"},pe={key:3,class:"text-center mt-8"},me={class:"text-lg text-slate-500"},ue={key:0},ve={key:0},fe={key:1},ge={id:"listDiscoverResults"},be=["onClick"],Le={class:"grow"},ye={class:"text-base font-semibold"},we={class:"text-sm"};function Ae(e,s,t,o,i,a){const h=g("QuickNav"),c=g("TopMessage"),p=g("OnboardingDialog"),r=g("fa"),b=g("l-tile-layer"),L=g("l-map"),y=g("ProjectIcon"),f=g("InfiniteScroll");return v(),u(D,null,[m(h,{selected:"Discover"}),m(c),n("section",ae,[s[7]||(s[7]=n("h1",{id:"ViewHeading",class:"text-4xl text-center font-light"}," Discover Projects ",-1)),m(p,{ref:"onboardingDialog"},null,512),n("div",{id:"QuickSearch",class:"mt-8 mb-4 flex",onKeyup:s[2]||(s[2]=O(d=>e.searchSelected(),["enter"])),style:F({visibility:e.isSearchVisible?"visible":"hidden"})},[z(n("input",{type:"text","onUpdate:modelValue":s[0]||(s[0]=d=>e.searchTerms=d),placeholder:"Search…",class:"block w-full rounded-l border border-r-0 border-slate-400 px-3 py-2"},null,512),[[q,e.searchTerms]]),n("button",{onClick:s[1]||(s[1]=d=>e.searchSelected()),class:"px-4 rounded-r bg-slate-200 border border-l-0 border-slate-400"},[m(r,{icon:"magnifying-glass",class:"fa-fw"})])],36),n("div",ie,[n("ul",re,[n("li",null,[n("a",{href:"#",onClick:s[3]||(s[3]=d=>{e.projects=[],e.isLocalActive=!0,e.isMappedActive=!1,e.isRemoteActive=!1,e.isSearchVisible=!0,e.tempSearchBox=null,e.searchLocal()}),class:A(e.computedLocalTabStyleClassNames())}," Nearby ",2)]),n("li",null,[n("a",{href:"#",onClick:s[4]||(s[4]=d=>{e.projects=[],e.isLocalActive=!1,e.isMappedActive=!0,e.isRemoteActive=!1,e.isSearchVisible=!1,e.searchTerms="",e.tempSearchBox=null}),class:A(e.computedMappedTabStyleClassNames())}," Mapped ",2)]),n("li",null,[n("a",{href:"#",onClick:s[5]||(s[5]=d=>{e.projects=[],e.isLocalActive=!1,e.isMappedActive=!1,e.isRemoteActive=!0,e.isSearchVisible=!0,e.tempSearchBox=null,e.searchAll()}),class:A(e.computedRemoteTabStyleClassNames())}," Anywhere ",2)])])]),e.isLocalActive?(v(),u("div",ne,[n("div",le,[n("button",{class:"ml-2 mt-2 px-4 py-2 rounded-md bg-blue-200 text-blue-500",onClick:s[6]||(s[6]=d=>e.$router.push({name:"search-area"}))},[m(r,{icon:"location-dot",class:"fa-fw"}),x(" Select a "+S(e.searchBox?"Different":"")+" Location for Nearby Search ",1)])])])):w("",!0),e.isMappedActive&&!e.tempSearchBox?(v(),u("div",ce,[n("div",de,[m(L,{ref:"projectMap",onReady:e.onMapReady,onMoveend:e.onMoveEnd,onMovestart:e.onMoveStart,onZoomend:e.onZoomEnd,onZoomstart:e.onZoomStart},{default:j(()=>[m(b,{url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png","layer-type":"base",name:"OpenStreetMap"})]),_:1},8,["onReady","onMoveend","onMovestart","onZoomend","onZoomstart"])])])):w("",!0),e.isLoading?(v(),u("div",he,[m(r,{icon:"spinner",class:"fa-spin-pulse"})])):e.projects.length===0?(v(),u("div",pe,[n("p",me,[e.isLocalActive?(v(),u("span",ue,[e.searchBox?(v(),u("span",ve," None found in the selected area. ")):w("",!0)])):e.isRemoteActive?(v(),u("span",fe,"No projects were found with that search.")):w("",!0)])])):w("",!0),m(f,{onReachedBottom:e.loadMoreData},{default:j(()=>[n("ul",ge,[(v(!0),u(D,null,Z(e.projects,d=>(v(),u("li",{class:"border-b border-slate-300",key:d.handleId},[n("a",{onClick:M=>e.onClickLoadProject(d.handleId),class:"block py-4 flex gap-4 cursor-pointer"},[n("div",null,[m(y,{entityId:d.handleId,iconSize:48,imageUrl:d.image,class:"block border border-slate-300 rounded-md max-h-12 max-w-12"},null,8,["entityId","imageUrl"])]),n("div",Le,[n("h2",ye,S(d.name),1),n("div",we,[m(r,{icon:"user",class:"fa-fw text-slate-400"}),x(" "+S(e.didInfo(d.issuerDid,e.activeDid,e.allMyDids,e.allContacts)),1)])])],8,be)]))),128))])]),_:1},8,["onReachedBottom"])])],64)}const Ie=V(C,[["render",Ae]]);export{Ie as default};