import{__assign as e,__awaiter as t,__generator as n}from"tslib";import{jsxs as a,jsx as s}from"react/jsx-runtime";import{useState as r,useEffect as i}from"react";import{Search as o,RadioTower as c}from"lucide-react";import{getStationsByScopeId as l}from"../apis/scopeApis.js";import d from"../components/ErrorStateDisplay.js";import u from"../components/EmptyLearningState.js";import{useLearningTemplateStore as m}from"../store/useLearningTemplateStore.js";import p from"../styles/StationsContent.module.css.js";import h from"../RuleContent/RuleHeader.js";var v=function(v){var f=v.scopeId,N=v.scopeName,g=v.stationsCount,S=void 0===g?0:g,C=v.onViewStation,y=v.onDeleteStation,b=r([]),w=b[0],D=b[1],j=r(""),I=j[0],L=j[1],W=r(!1),R=W[0],x=W[1],B=r(null),A=B[0],M=B[1],O=m(function(e){return e.setStationModalOpen}),T=function(){return t(void 0,void 0,void 0,function(){var e,t;return n(this,function(n){switch(n.label){case 0:if(!f)return[2];x(!0),M(null),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,l()];case 2:return(e=n.sent())&&e.data?D(e.data):D([]),[3,5];case 3:return t=n.sent(),console.error("Failed to fetch stations:",t),M("Failed to load stations. Please try again."),[3,5];case 4:return x(!1),[7];case 5:return[2]}})})};i(function(){T()},[f]);var k=w.filter(function(e){return e.stationName.toLowerCase().includes(I.toLowerCase())});return a("div",e({className:p.container},{children:[a("div",{children:[s(h,{ruleSetName:"".concat(N," > Stations (").concat(w.length||S,")"),ruleSetDescription:"Manage the stations assigned to the ".concat(N," scope."),onOnboardStation:function(){return O(!0)}}),s("div",e({className:p.searchBarWrapper},{children:a("div",e({className:p.searchRelative},{children:[s("div",e({className:p.searchIconWrapper},{children:s(o,{className:p.searchIcon})})),s("input",{type:"text",className:p.searchInput,placeholder:"Search station...",value:I,onChange:function(e){return L(e.target.value)}})]}))}))]}),s("div",e({className:p.contentArea},{children:R?s("div",e({className:p.loadingWrapper},{children:s("p",{children:"Loading stations..."})})):A?s(d,{errorMessage:A,onRetry:T}):0===w.length?s("div",e({className:p.emptyWrapper},{children:s(u,{title:"No stations in this scope yet!",desc:"Add stations to ".concat(N," to define which ones this scope applies to."),button:"Onboard a Station",onCreate:function(){return O(!0)}})})):0===k.length?s("div",e({className:p.noResultsWrapper},{children:s("p",{children:"No stations match your search query."})})):s("div",e({className:p.stationList},{children:k.map(function(t){return a("div",e({className:p.stationCard},{children:[a("div",e({className:p.stationCardLeft},{children:[s("div",e({className:p.stationIconWrapper},{children:s(c,{size:20})})),a("div",e({className:p.stationDetails},{children:[a("div",e({className:p.stationHeaderRow},{children:[s("span",e({className:p.stationNameText},{children:t.stationName})),a("span",e({className:p.learningsBadge},{children:[t.learningsCount," learnings"]}))]})),t.stationDesc&&s("span",e({className:p.stationDescText},{children:t.stationDesc}))]}))]})),a("div",e({className:p.actionButtonsWrapper},{children:[s("button",e({onClick:function(){return null==y?void 0:y(t.stationId)},className:p.deleteBtn},{children:"Delete"})),s("button",e({onClick:function(){return null==C?void 0:C(t)},className:p.viewBtn},{children:"View"}))]}))]}),t.stationId)})}))}))]}))};export{v as default};
//# sourceMappingURL=StationsContent.js.map
