"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=require("react/jsx-runtime"),n=require("react"),a=require("lucide-react"),s=require("../../apis/scopeApis.js"),r=require("../../styles/StationAutocomplete.module.css.js");exports.default=function(i){var u=i.value,c=i.onChange,l=i.onStationSelect,o=i.className,d=i.style,f=n.useState([]),m=f[0],_=f[1],h=n.useState(!1),p=h[0],v=h[1],g=n.useState(!1),j=g[0],x=g[1],N=n.useRef(null),b=n.useRef(null),y=n.useRef(!1);return n.useEffect(function(){var e=function(e){b.current&&!b.current.contains(e.target)&&j&&(x(!1),y.current||(c(""),l(null)))};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}},[j,c,l]),n.useEffect(function(){return u.trim()?(N.current&&clearTimeout(N.current),v(!0),N.current=setTimeout(function(){return e.__awaiter(void 0,void 0,void 0,function(){var t,n;return e.__generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,3,4]),[4,s.fetchStationsByKeyword(u,!0)];case 1:return(t=e.sent())&&t.data?_(t.data):_([]),[3,4];case 2:return n=e.sent(),console.error("Error fetching stations:",n),_([]),[3,4];case 3:return v(!1),[7];case 4:return[2]}})})},500)):(_([]),v(!1)),function(){N.current&&clearTimeout(N.current)}},[u]),t.jsxs("div",e.__assign({className:"".concat(r.default.wrapper," ").concat(o||""),style:d,ref:b},{children:[t.jsxs("div",e.__assign({className:r.default.inputWrapper},{children:[t.jsx("input",{type:"text",value:u,onChange:function(e){c(e.target.value),x(!0),l(null),y.current=!1},onFocus:function(){(m.length>0||u.length>0)&&x(!0)},placeholder:"Search for a station...",className:r.default.input}),p&&t.jsx("div",e.__assign({className:r.default.spinnerWrapper},{children:t.jsx(a.Loader2,{className:r.default.spinner})}))]})),j&&u&&t.jsx("div",e.__assign({className:r.default.dropdown},{children:m.length>0?m.map(function(n){var s=!!n.ruleset_id;return t.jsxs("div",e.__assign({className:"".concat(r.default.item," ").concat(s?r.default.itemOnboarded:r.default.itemClickable),onClick:function(){s||(c(n.station_name),l(n),x(!1),y.current=!0)}},{children:[t.jsxs("div",e.__assign({className:r.default.itemLeft},{children:[s&&t.jsx("div",e.__assign({className:r.default.checkWrapper},{children:t.jsx(a.Check,{size:12,strokeWidth:3})})),t.jsxs("div",{children:[t.jsx("div",e.__assign({className:"".concat(r.default.stationName," ").concat(s?r.default.stationNameOnboarded:r.default.stationNameUnonboarded)},{children:n.station_name})),t.jsx("div",e.__assign({className:r.default.market},{children:n.market}))]})]})),s&&t.jsx("span",e.__assign({className:r.default.badge},{children:"Onboarded"}))]}),n.station_guid)}):!p&&t.jsx("div",e.__assign({className:r.default.noResults},{children:"No stations found"}))}))]}))};
//# sourceMappingURL=StationAutocomplete.js.map
