1import{r as n,j as r}from"./react-CC1faa-K.js";import{f as P,O as J,V as Q,a as X,b as Z,t as $,F as ee,P as te,S as re,I as ne}from"./neshan-D5pLIdoN.js";import{u as oe,D as z}from"./index-BgY_HW_c.js";import{S as se,B as w,j as ae,I as B,bq as ce,br as ie,aI as le,T as I,ah as de,bs as ue,ai as pe,af as he,bo as ge,bp as me}from"./mui-DWCKKmMe.js";import"./dates-DjetTc6v.js";import"./query-DMVz0aUJ.js";import"./icons-BnvIFHtd.js";import"./forms-Cz4Q3b43.js";import"./motion-CrTrTS3t.js";const U={search:"service.226cc4d7548d44d6acdcfd6b882c6edd",reverse:"web.1e6d226d441648509c7bbfdde1e37b99"},xe="web.1e6d226d441648509c7bbfdde1e37b99",fe="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png";function ye(l){return l?.options?.iconUrl??l?.iconUrl}function ke({onLocationChange:l,defaultPosition:L={lat:35.6892,lng:51.389},height:O="300px",searchPlaceholder:T,showCurrentLocationButton:_=!0,disabled:c=!1,value:o,editingIcon:N,fullScreenButton:V=!1}){const{t:s}=oe();T??s("components.neshanMap.searchPlaceholder");const M=n.useRef(null),d=n.useRef(null),x=n.useRef(null),[u,f]=n.useState(o?{lat:o.lat,lng:o.lng}:L),[A,y]=n.useState(o?.address||""),[b,p]=n.useState([]),[h,g]=n.useState(!1),[K,C]=n.useState(o?.address||""),[F,v]=n.useState(""),[S,D]=n.useState(!1),m=n.useRef(null);n.useEffect(()=>{o&&o.lat&&o.lng&&(f({lat:o.lat,lng:o.lng}),o.address&&(y(o.address),C(o.address)))},[o]);const E=e=>{if(!x.current)return;x.current.clear();const t=ye(N)||fe,a=new ee({geometry:new te(e)});a.setStyle(new re({image:new ne({src:t,anchor:[.5,1]})})),x.current.addFeature(a)},H=e=>{if(!d.current)return;const t=P([e.lng,e.lat]);d.current.getView().animate({center:t,duration:400}),E(t)};n.useEffect(()=>{if(!M.current)return;const e=P([L.lng,L.lat]),t=new J({mapType:"neshan",target:M.current,key:xe,view:new Q({center:e,zoom:13})});d.current=t;const a=new X({});return x.current=a,t.addLayer(new Z({source:a})),E(e),t.on("click",i=>{if(c)return;const[j,R]=$(i.coordinate);f({lat:R,lng:j}),E(i.coordinate),k(R,j)}),()=>{t.setTarget(void 0),d.current=null}},[]),n.useEffect(()=>{d.current&&H(u)},[u.lat,u.lng]);const Y=()=>{if(!navigator.geolocation){alert(s("components.neshanMap.geolocationUnsupported"));return}g(!0),navigator.geolocation.getCurrentPosition(e=>{const t={lat:e.coords.latitude,lng:e.coords.longitude};f(t),g(!1),k(t.lat,t.lng)},e=>{console.error(s("components.neshanMap.locationFetchErrorLog"),e),alert(s("components.neshanMap.locationFetchError")),g(!1)},{enableHighAccuracy:!0,timeout:1e4,maximumAge:6e4})},k=async(e,t)=>{try{v("");const{data:a}=await z.get("https://api.neshan.org/v5/reverse",{params:{lat:e,lng:t},headers:{"Api-Key":U.reverse}}),i=a.formatted_address||s("components.neshanMap.addressNotFound");C(i),y(i);const j={lat:e,lng:t,address:i,city:a.city||"",district:a.district||"",province:a.province||"",state:(a.state||"").replace(s("components.neshanMap.provincePrefix"),"").replace(s("components.neshanMap.countyPrefix"),"").trim()};l?.(j)}catch(a){console.error(s("components.neshanMap.addressFetchErrorLog"),a),l?.({lat:e,lng:t,address:K||"",city:"",district:"",province:""})}},q=async e=>{if(y(e),m.current&&clearTimeout(m.current),e.length<2){p([]);return}m.current=setTimeout(async()=>{try{g(!0),v("");const{data:t}=await z.get("https://api.neshan.org/v1/search",{params:{term:e,lat:u.lat,lng:u.lng},headers:{"Api-Key":U.search}});p(t.items||[])}catch(t){console.error(s("components.neshanMap.searchError"),t),v(s("components.neshanMap.searchError")),p([])}finally{g(!1)}},500)},W=e=>{const t={lat:e.location.y,lng:e.location.x};f(t),p([]),y(e.title),k(t.lat,t.lng)},G=()=>{setTimeout(()=>p([]),150)};return n.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]),r.jsxs(se,{sx:{width:"100%",position:"relative",...S&&{position:"fixed",top:0,left:0,width:"98.5vw",height:"100vh",zIndex:2e4,backgroundColor:"white"}},children:[r.jsxs(w,{sx:{mb:1,position:"relative",p:S?2:0},children:[r.jsx(ae,{dir:"rtl",fullWidth:!0,value:A,onChange:e=>q(e.target.value),onBlur:G,placeholder:T,disabled:c,slotProps:{input:{startAdornment:r.jsx(ie,{sx:{mr:1,color:"text.secondary"}}),endAdornment:_&&r.jsx(B,{onClick:Y,disabled:c||h,size:"small",title:s("components.neshanMap.currentLocation"),children:r.jsx(ce,{})}),sx:{direction:"rtl","& input":{textAlign:"left"}}}}}),(b.length>0||A.length>=2&&h)&&!c&&r.jsx(le,{sx:{position:"absolute",top:"100%",left:0,right:0,zIndex:1e3,maxHeight:200,overflowY:"auto",mt:.5},children:h?r.jsx(w,{sx:{p:2,textAlign:"center"},children:r.jsx(I,{variant:"body2",color:"text.secondary",children:s("components.neshanMap.searching")})}):b.length>0?r.jsx(de,{dense:!0,children:b.map((e,t)=>r.jsx(ue,{disablePadding:!0,sx:{borderBottom:t<b.length-1?"1px solid #eee":"none"},children:r.jsx(pe,{onClick:()=>W(e),sx:{"&:hover":{backgroundColor:"action.hover"}},children:r.jsx(he,{primary:e.title,sx:{textAlign:"left","& .MuiListItemText-primary":{fontSize:"0.875rem"}}})})},t))}):A.length>=2&&!h&&r.jsx(w,{sx:{p:2,textAlign:"center"},children:r.jsx(I,{variant:"body2",color:"text.secondary",children:s("components.neshanMap.noResults")})})})]}),r.jsxs(w,{sx:{height:S?"calc(100vh - 120px)":O,width:"100%",border:"1px solid #e0e0e0",borderRadius:1,overflow:"hidden",opacity:c?.6:1,pointerEvents:c?"none":"auto",position:"relative"},children:[V&&r.jsx(B,{onClick:()=>D(e=>!e),sx:{position:"absolute",top:"10px",left:"10px",zIndex:1e3,backgroundColor:"white",py:1,borderRadius:"4px",boxShadow:1,fontSize:"0.875rem","&:hover":{backgroundColor:"grey.100"}},children:S?r.jsx(ge,{}):r.jsx(me,{})}),r.jsx("div",{ref:M,style:{height:"100%",width:"100%"}})]}),h&&r.jsx(I,{variant:"body2",color:"primary",sx:{mt:1,textAlign:"center"},children:s("components.neshanMap.loading")}),F&&r.jsx(I,{variant:"body2",color:"error",sx:{mt:1,textAlign:"center"},children:F})]})}export{ke as default};
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.