{"ast":null,"code":"import { jsxs as _jsxs } from \"react/jsx-runtime\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport React from 'react';\nimport axios from 'axios';\nimport MakeTable from '../components/table.js';\nimport BuildSortFilter from '../components/playerSortFilter.js';\n\nasync function fetchStats(parameters) {\n  //console.log(parameters)  \n  let arrayData = await axios.get(parameters);\n  const DataTableContent = arrayData.data;\n  return DataTableContent;\n}\n\nexport default class TableBuilder extends React.Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n      options: {\n        sort: null,\n        group: null,\n        goalie: null,\n        page: null,\n        subseasonid: null,\n        subgoalie: null\n      },\n      baseURL: this.props.baseURL,\n      displayTable: null,\n      displayFilters: null,\n      initialized: false\n    };\n    this.updateTable = this.updateTable.bind(this);\n  }\n\n  async updateTable(sortset, text) {\n    this.setState(prevState => ({\n      displayTable: undefined\n    }));\n    var updateText = sortset + '=' + text;\n    var currentState = this.state.options;\n\n    if (sortset == 'sort') {\n      currentState.sort = updateText;\n      this.setState(state => ({\n        options: currentState\n      }));\n    } else if (sortset == 'group') {\n      currentState.group = updateText;\n    } else if (sortset == 'page') {\n      currentState.page = updateText;\n    } else if (sortset == 'subseasonid') {\n      currentState.subseasonid = updateText;\n    } else if (sortset == 'subgoalie') {\n      currentState.subgoalie = updateText;\n    } else if (sortset == 'goalie') {\n      currentState.goalie = updateText;\n      currentState.sort = null;\n      currentState.group = null;\n      currentState.page = null;\n      currentState.subseasonid = null;\n      currentState.subgoalie = null;\n    }\n\n    this.setState(state => ({\n      options: currentState\n    }));\n    var startParameters = this.state.baseURL; //console.log(this.state.options)\n\n    var currentOptions = '';\n\n    for (var index in this.state.options) {\n      if (this.state.options[index] != null) {\n        currentOptions += '&' + this.state.options[index];\n      }\n    }\n\n    var requestURL = startParameters + currentOptions;\n    const refreshTable = await fetchStats(requestURL);\n    this.setState(state => ({\n      displayFilters: refreshTable,\n      displayTable: /*#__PURE__*/_jsx(MakeTable, {\n        currentset: refreshTable\n      })\n    }));\n  }\n\n  static getDerivedStateFromProps(props, state) {\n    if (state.initialized == false) {\n      return {\n        initialized: true,\n        displayFilters: props.props,\n        displayTable: /*#__PURE__*/_jsx(MakeTable, {\n          currentset: props.props\n        })\n      };\n    } else {\n      return null;\n    }\n  }\n\n  render() {\n    return /*#__PURE__*/_jsxs(\"div\", {\n      children: [/*#__PURE__*/_jsx(BuildSortFilter, {\n        props: this.state.displayFilters,\n        updateTable: this.updateTable\n      }), this.state.displayTable]\n    });\n  }\n\n}","map":null,"metadata":{},"sourceType":"module"}