PageSourceSearch

https://karrotmarket.com/_assets/useHandleRegionSelection-BsRgAgAz.js

js karrotmarket.com collected 2026-10-01 10:42:25 UTC 13,255 bytes, 6 lines download raw bytes

1
2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="64b26268-c667-5734-893e-a6b8a5299627")}catch(e){}}();
3var ce=Object.defineProperty;var le=(o,e,t)=>e in o?ce(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var w=(o,e,t)=>le(o,typeof e!="symbol"?e+"":e,t);import{q as B,l as $,V as f,T as I,u as ue,N as W,_ as M}from"./Link-BOm1qwNN.js";import{o as de,s as F,t as me,w as he,d as ge,c as X,C as pe,q as fe,I as ye}from"./variants-BpGuSOo8.js";import{j as n,r as l}from"./constants-psci6gc1.js";import{F as U,W as Ce,X as z,Z as xe,w as _e,r as Re,s as be,o as Z,y as Se,R as Ee,q as J,_ as Ne,$ as y,a0 as Ie,z as Le,a1 as Te,x as we}from"./Header-Ccpd0HQe.js";import{u as je,C as Y}from"./CurrentLocationButton-26i1ZBlY.js";import{C as ve}from"./CurrentLocationCircle-Dk_fZggF.js";import{I as Oe}from"./IconMagnifyingglassLine-B3UgUX6o.js";import{u as ke,g as Ae,A as K}from"./useAutoCompleteSessionToken-bvyvCXkH.js";import{u as Fe,f as Pe}from"./services-VIymWOJT.js";import{L as qe}from"./Loader-B6W929u-.js";import{c as P}from"./exports-Bqt9E6uA.js";const ct="0__0",q={parse:o=>{if(!(o!=null&&o.includes("__")))return{from:void 0,to:void 0};const[e,t]=o.split("__"),r=Number.parseInt(e,10),s=Number.parseInt(t,10);return{from:Number.isNaN(r)?void 0:r,to:Number.isNaN(s)?void 0:s}},stringify:({from:o,to:e})=>o===void 0&&e===void 0?"":[o,e].join("__")};function lt({prevPrice:o,target:e,value:t}){const r=t===""?void 0:Number.parseInt(t,10);return Number.isNaN(r)||r!==void 0&&r<0?o:q.stringify({...q.parse(o??""),[e]:r})}const H="5",V=de({category_id:he(o=>typeof o=="string"?Number(o):o,ge().int().optional()),price:F().optional(),search:F().min(1).optional(),only_on_sale:me().optional(),h3_range_level:F().optional().refine(o=>{if(!o)return!0;const e=Number(o);return!Number.isNaN(e)&&e>=1&&e<=5&&Number.isInteger(e)},{message:"h3_range_level must be between 1 and 5"})}),ut="__all__";function dt(o){return!!(o.categoryId||o.price||o.onlyOnSale)}class ee{constructor({queryString:e,karrotInfraCountryCode:t}){w(this,"queryString");w(this,"karrotInfraCountryCode");this.queryString=e,this.karrotInfraCountryCode=t}getQueryString(){return this.queryString}parseQueryString(){const e=B.parse(this.queryString,{parseBooleans:!0}),t=V.safeParse(e);if(t.success)return t.data;const r=Object.keys(t.error.format());return V.parse($.omit(e,r))}toCommonFilterValues(){var t;const e=this.parseQueryString();return{categoryId:(t=e.category_id)==null?void 0:t.toString(),price:e.price,search:e.search,onlyOnSale:e.only_on_sale,h3RangeLevel:e.h3_range_level??H}}toCommonRequestBody(){const e=this.parseQueryString(),{from:t,to:r}=q.parse(e.price??"");return{karrotInfraCountryCode:this.karrotInfraCountryCode,h3RangeLevel:Number(e.h3_range_level??H),search:e.search,categoryId:e.category_id,priceGte:t==null?void 0:t.toString(),priceLte:r==null?void 0:r.toString(),showOnlyAvailable:e.only_on_sale}}}class te extends ee{constructor({queryString:e,karrotInfraCountryCode:t}){super({queryString:e,karrotInfraCountryCode:t})}static of({queryString:e,karrotInfraCountryCode:t}){return new te({queryString:e,karrotInfraCountryCode:t})}pickH3IndexFromQueryString(){const e=B.parse(this.getQueryString()).h3_index;if(!$.isString(e))throw new Error("h3_index is required");return e}toFilterValues(){return{...this.toCommonFilterValues(),h3Index:this.pickH3IndexFromQueryString()}}static fromFilterValuesToQueryString({filterValues:e}){const t=re(e);return ne({...t,h3_index:e.h3Index})}toRequestBody(){return{...this.toCommonRequestBody(),h3Index:this.pickH3IndexFromQueryString()}}}class oe extends ee{constructor({queryString:t,karrotInfraCountryCode:r,h3Index:s}){super({queryString:t,karrotInfraCountryCode:r});w(this,"h3Index");this.h3Index=s}static of({queryString:t,karrotInfraCountryCode:r,h3Index:s}){return new oe({queryString:t,karrotInfraCountryCode:r,h3Index:s})}toFilterValues(){return{...this.toCommonFilterValues(),h3Index:this.h3Index}}static fromFilterValuesToQueryString({filterValues:t}){const r=re(t);return ne(r)}toRequestBody(){return{...this.toCommonRequestBody(),h3Index:this.h3Index}}}function re(o){return{category_id:o.categoryId?Number(o.categoryId):void 0,price:o.price,search:o.search,only_on_sale:o.onlyOnSale,h3_range_level:o.h3RangeLevel}}
3function ne(o){const e=B.stringify(o,{skipNull:!0,skipEmptyString:!0}),t=new URLSearchParams(e);return t.sort(),`?${t.toString()}`}var Be="h1zozo0";function De({label:o,description:e,group:t,children:r,className:s}){return n.jsx(f,{className:X(Be,s),paddingTop:4,paddingBottom:4,children:n.jsxs(U,{group:t,children:[n.jsxs(f,{paddingBottom:e?2:3,children:[n.jsx(U.Label,{children:n.jsx(I,{variant:"body-2",weight:"medium",color:"neutral",children:o})}),e&&n.jsx(I,{variant:"caption-1",weight:"medium",color:"neutral-faded",children:e})]}),r]})})}function mt({selectedFilterValues:o}){const[e,t]=l.useState(o),r=l.useCallback(()=>{t(c=>({search:c.search,h3Index:c.h3Index,h3RangeLevel:c.h3RangeLevel}))},[]),s=l.useCallback(c=>{t(p=>({...p,...c}))},[]);return l.useEffect(function(){t(o)},[o]),{filterState:e,onChangeFilterState:s,onClearAll:r}}function ht(o){if(!o)return!1;const e=o.trim();if(e.length===0||e.length>30)return!1;const t=e.split(/\s+/).filter(Boolean);if(t.length===0||t.length>3)return!1;for(const r of t)if(/\d/.test(r))return!1;return!0}function gt(){const{region:o,language:e}=Ce();return l.useCallback(async t=>{var s,c;const r=typeof window<"u"?(c=(s=window.google)==null?void 0:s.maps)==null?void 0:c.Geocoder:void 0;if(!r)return null;try{const p=new r,{results:m}=await p.geocode({location:t,region:o,language:e}),h=m==null?void 0:m[0];return h?{formattedAddress:h.formatted_address,addressComponents:h.address_components}:null}catch{return null}},[o,e])}const pt="Could not resolve your location, please search by name.",ft="Please allow location access to determine your location.",yt="Could not determine your location, please try again.";var Ge="_1ctkcbe0",Qe="_1ctkcbe2",Me="_1ctkcbe3",Ue="_1ctkcbe4",ze="_1ctkcbe5";const Ke=300;function He({placeholder:o="Search by address or postal code",defaultValue:e="",onSelect:t,includedRegionCodes:r,showCurrentLocationButton:s=!0,currentLocationDisplayName:c,isLoading:p=!1}){const m=z("places"),h=z("geocoding"),{sessionToken:S,renewSessionToken:L}=ke({placesLibrary:m}),[v,x]=l.useState(e),[E,C]=l.useState([]),d=Fe(),O=l.useRef(0),_=l.useRef(0),g=l.useRef(null);l.useEffect(()=>{g.current&&(clearTimeout(g.current),g.current=null),_.current+=1,x(e),C([])},[e]);const k=l.useCallback(async a=>{if(!S||!a||!m)return;const i=++O.current;_.current=i;try{const u=await Ae({input:a,sessionToken:S,placesLibrary:m,includedRegionCodes:r?[...r]:void 0});_.current===i&&C(u)}catch(u){d.error({text:"The place search failed, please try again later."}),P(u)}},[S,m,d,r]),A=l.useCallback(a=>
3{if(x(a),g.current&&clearTimeout(g.current),a){g.current=setTimeout(()=>{k(a)},Ke);return}_.current+=1,C([])},[k]),T=l.useCallback(async a=>{if(a.placePrediction)try{const i=a.placePrediction.toPlace();await i.fetchFields({fields:["displayName","formattedAddress","location","addressComponents"]});const u=xe({displayName:i.displayName??null,formattedAddress:i.formattedAddress??null,location:i.location?{lat:i.location.lat(),lng:i.location.lng()}:null,addressComponents:i.addressComponents});if(!u){d.error({text:"Could not get details for that place, please try another one."});return}x(u.displayName),C([]),t(u),L()}catch(i){d.error({text:"Could not get details for that place, please try again."}),P(i)}},[t,L,d]),N=l.useCallback(async a=>{if(!h){d.error({text:"Location service is not ready yet, please try again."});return}try{const i=new h.Geocoder,{results:u}=await i.geocode({location:a}),R=u==null?void 0:u[0];if(!R){d.error({text:"Could not resolve your location, please search by name."});return}const b=_e({formatted_address:R.formatted_address,address_components:R.address_components},a,c);if(!b){d.error({text:"Could not resolve your location, please search by name."});return}x(b.displayName),C([]),t(b)}catch(i){d.error({text:"Could not resolve your location, please search by name."}),P(i)}},[h,t,d,c]),ae=l.useCallback(a=>
3{if(E.length!==0){if(a.key==="Enter"){a.preventDefault();return}if(a.key==="Tab"&&!a.shiftKey){const i=a.currentTarget.getAttribute("aria-activedescendant"),u=i?document.getElementById(i):null;(u==null?void 0:u.getAttribute("role"))==="option"&&(a.preventDefault(),u.click())}}},[E.length>0]),{isLoading:se,getGeolocation:ie}=je({onError:a=>{const i=a.code===GeolocationPositionError.PERMISSION_DENIED?"Please allow location access to determine your location.":"Could not determine your location, please try again.";d.error({text:i})},onSuccess:a=>{N(a)}});return l.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]),n.jsx(pe,{children:n.jsxs(f,{direction:"row",align:"center",gap:2,className:Ge,children:[n.jsx(f.Item,{grow:!0,children:n.jsx(K,{name:"region",placeholder:o,value:v,onInput:({value:a})=>A(a),attributes:{"aria-label":"Search location by address"},inputAttributes:{onKeyDown:ae},variant:"faded",size:"large",icon:n.jsx("span",{className:Me,children:p?n.jsx(qe,{size:"small"}):n.jsx(Oe,{className:X(Qe,Ue)})}),children:E.map((a,i)=>{var u,R,b,D,G,Q;return n.jsxs(K.Item,{value:((u=a.placePrediction)==null?void 0:u.placeId)??"",onClick:()=>{T(a)},className:ze,children:[n.jsx(I,{color:"neutral",children:(b=(R=a.placePrediction)==null?void 0:R.mainText)==null?void 0:b.text}),n.jsx(I,{color:"neutral-faded",children:(G=(D=a.placePrediction)==null?void 0:D.secondaryText)==null?void 0:G.text})]},((Q=a.placePrediction)==null?void 0:Q.placeId)??`suggestion-${i}`)})})}),s?n.jsx(Y,{loading:se,onClick:ie}):null]})})}const j={[y.INTERNAL_ERROR]:{description:"Something went wrong.",alert:"Something went wrong. Please try again later."},[y.NOT_OPENED]:{description:"Unsupported location by Karrot",alert:"This location is not supported by Karrot. Please move the map to another area."}};function Ve({error:o,isSyncing:e,location:t}){return W({error:o,isSyncing:e,location:t}).with({error:y.NOT_OPENED},()=>j[y.NOT_OPENED].description).with({error:y.INTERNAL_ERROR},()=>j[y.INTERNAL_ERROR].description).with({error:null,isSyncing:!0},()=>"Updating address…").with({error:null,location:M.not(M.nullish)},({location:r})=>`Showing listing within ${J(r.countryCode)(r.h3RangeLevel)} of ${r.locationName}`).otherwise(()=>"")}function Ct({label:o,value:e,cameraProps:t,circleCenter:r,hideCircleDuringDrag:s,error:c,isSyncing:p,hideLabel:m=!1,mapHeight:h=75,onChangeRangeLevel:S,onCameraChange:L,onDragEnd:v,onSelectRegion:x,onRequestCurrentLocation:E,geolocation:C,isGeolocationLoading:d,reset:O}){const[_,g]=l.useState(!0),A=ue().karrotLocalCountryCode.toUpperCase(),T=n.jsxs(n.Fragment,{children:[n.jsx(f,{paddingTop:3,children:n.jsx(He,{onSelect:x,defaultValue:e.locationName,includedRegionCodes:[A],isLoading:p,showCurrentLocationButton:!1})}),n.jsx(f,{paddingTop:3,children:n.jsxs(f,{width:"100%",height:h,borderRadius:"small",backgroundColor:"neutral-faded",overflow:"hidden",position:"relative",className:fe,attributes:{onTouchMove:N=>{N.stopPropagation()},onTouchEnd:N=>{N.stopPropagation()}},children:[n.jsxs(Re,{reuseMaps:!0,...t,onCameraChanged:L,onDragstart:()=>{s&&g(!1)},onDragend:()=>{s&&g(!0),v()},children:[n.jsx(We,{setVisibleCircle:g}),_&&n.jsx(be,{center:r,radius:Z(e.h3RangeLevel,e.countryCode).radius,strokeColor:"#E14D00",strokeWeight:1}),C&&n.jsx(Se,{position:C,children:n.jsx(ve,{})})]}),n.jsx(f,{position:"absolute",insetTop:3,insetEnd:3,borderRadius:"circular",backgroundColor:"page",children:n.jsx(Y,{onClick:E,loading:d,disabled:d})})]})}),n.jsxs(f,{paddingTop:3,children:[!c&&e&&n.jsx(Ee,{name:"h3RangeLevel",value:e.h3RangeLevel,onChange:S,displayRangeLevel:J(e.countryCode)}),c&&n.jsx(Ne,{color:"critical",icon:n.jsx(ye,{size:5,svg:n.jsx(Ie,{}),color:"neutral"}),actionsSlot:[n.jsx(Pe,{onClick:O,children:n.jsx(I,{variant:"body-3",weight:"medium",color:"critical",children:"Reset"})},"reset")],children:W(c).with(y.NOT_OPENED,()=>j[y.NOT_OPENED].alert).otherwise(()=>j[y.INTERNAL_ERROR].alert)})]})]});return m?T:n.jsx(De,{group:!0,label:o,description:Ve({error:c,isSyncing:p,location:e}),children:T})}const $e=600;function We({setVisibleCircle:o}){const e=Le();return l.useEffect(()=>{if(!e)return;o(!0);let t=null;const r=()=>{t&&clearTimeout(t),t=setTimeout(()=>{o(!0),t=null},$e)},s=e.addListener("zoom_changed",()=>{o(!1),r()}),c=e.addListener("idle",()=>{t&&(clearTimeout(t),t=null),o(!0)});return()=>{t&&clearTimeout(t),s.remove(),c.remove()}},[e,o]),null}
3function xt({fallbackCountryCode:o,rangeLevel:e,onChangeFilterState:t,setByRegionSelection:r}){return l.useCallback(s=>{var h;const c=(h=s.countryCode)==null?void 0:h.toLowerCase(),p=Te(c)?c:o,m=Z(e,p).zoom;t({h3Index:we(s.coord)}),r(s,{zoom:m})},[o,e,t,r])}export{ut as A,q as B,ct as F,ft as G,pt as L,Ct as U,De as a,mt as b,oe as c,gt as d,xt as e,yt as f,te as g,dt as h,ht as i,Ve as j,lt as u};
4//# sourceMappingURL=useHandleRegionSelection-BsRgAgAz.js.map
5
6//# debugId=64b26268-c667-5734-893e-a6b8a5299627

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.