"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T=require("react/jsx-runtime"),D=require("react"),F=require("react-redux"),I=require("react-intl"),C=require("./DataContext.js"),g=require("../reducers/data.js");require("semantic-ui-react");class S extends D.Component{constructor(){super(),this.state={showLoading:!1},this.checkLoadingTime=this.checkLoadingTime.bind(this),this.loadingTimeout=null,this.fallbackTimeout=null,this.initialFilterTimeout=null}componentDidMount(){const{app:t,csv:i,store:e,params:a,source:l,group:n,editing:s,waitForFilters:r=!1}=this.props;console.log("Group & Store ",e,this.props.mySelf),t==="csv"?this.props.onSetData({app:t,csv:i,store:e,params:a,group:n}):(this.setState({showLoading:!1}),(!r||s)&&(console.log("📥 [D3 Map DataProvider] Initial data load triggered",{app:t,editing:s,waitForFilters:r}),this.loadData({app:t,source:l,store:e,params:a,group:n})),!s&&r&&(this.fallbackTimeout=setTimeout(()=>{!this.props.data&&!this.props.loading&&(console.warn("⚠️ [D3 Map DataProvider] Fallback loading triggered"),this.loadData({app:t,source:l,store:e,params:a,group:n}))},2e3)))}componentWillUnmount(){clearTimeout(this.fallbackTimeout),clearTimeout(this.loadingTimeout),clearTimeout(this.initialFilterTimeout)}componentDidUpdate(t){const{app:i,filters:e,apply:a,source:l,store:n,params:s,csv:r,group:d,autoApply:c,lastInitialFilterChange:u,lastUserFilterChange:h,waitForFilters:p}=this.props;if(a!=null&&a!==t.apply){console.log("🔄 [DataProvider] Manual reload (apply button)"),this.loadData({app:i,source:l,store:n,params:s,group:d});return}if(c!==!1&&(e!==t.filters||JSON.stringify(s)!==JSON.stringify(t.params)||i!==t.app||JSON.stringify(t.source)!==JSON.stringify(l)||r!==t.csv))if(i==="csv")this.props.onSetData({app:i,csv:r,store:n,params:s,group:d});else{const m=u!==t.lastInitialFilterChange,f=h!==t.lastUserFilterChange;m&&p?(console.log("ℹ️ [DataProvider] Initial filters changing, debouncing..."),this.initialFilterTimeout&&clearTimeout(this.initialFilterTimeout),this.initialFilterTimeout=setTimeout(()=>{console.log("✅ [DataProvider] Initial filters settled, loading data"),this.loadData({app:i,source:l,store:n,params:s,group:d})},500)):f&&(console.log("ℹ️ [DataProvider] User filters changed, loading data"),this.loadData({app:i,source:l,store:n,params:s,group:d}))}}loadData(t){console.log("Loading data for map",t),this.setState({showLoading:!1}),this.props.onLoadData(t),this.loadingTimeout&&clearTimeout(this.loadingTimeout),this.loadingTimeout=setTimeout(this.checkLoadingTime,200)}checkLoadingTime(){const{loading:t,time:i}=this.props;t&&i&&(Date.now()-i>1e3?this.setState({showLoading:!0}):this.loadingTimeout=setTimeout(this.checkLoadingTime,200))}render(){const{data:t}=this.props;return T.jsx(C.DataContext.Provider,{value:t,children:this.props.children})}}const y=(o,t)=>{const{store:i,group:e,app:a}=t;return{lastUserFilterChange:o.getIn(["data","filters-settings",a,e,"lastUserFilterChange"]),lastInitialFilterChange:o.getIn(["data","filters-settings",a,e,"lastInitialFilterChange"]),data:o.getIn(["data",...i,"data"]),filters:o.getIn(["data","filters",a,e]),autoApply:o.getIn(["data","filters-settings",a,e,"autoApply"]),apply:o.getIn(["data","filters-settings",a,e,"apply"]),error:o.getIn(["data",...i,"error"]),loading:o.getIn(["data",...i,"loading"]),time:o.getIn(["data",...i,"time"])}},L={onSetData:g.setData,onLoadData:g.getData},v=F.connect(y,L)(I.injectIntl(S));exports.default=v;
