"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Canary = Canary;
exports.TristateLabels = exports.TristateLabelStandalone = exports.MultiSelectLabelsDropdownStandalone = exports.HidePassingToggle = exports.LabelFilterList = void 0;

var _react = _interopRequireWildcard(require("react"));

var _lodash = require("lodash");

var _browser = _interopRequireDefault(require("history/browser"));

var _url = require("./url");

var _CanarySearchBar = require("./CanarySearchBar");

var _utils = require("./utils");

var _minimal = require("../CanaryInterface/minimal");

var _GroupByDropdown = require("../Dropdown/GroupByDropdown");

var _StandaloneWrapper = require("../Dropdown/StandaloneWrapper");

var _TimeRange = require("../Dropdown/TimeRange");

var _lists = require("../Dropdown/lib/lists");

var _TabByDropdown = require("../Dropdown/TabByDropdown");

var _Toggle = require("../Toggle");

var _FilterForm = require("./FilterForm");

var _labels = require("./labels");

var _TristateToggle = require("../TristateToggle");

var _mixinsModule = _interopRequireDefault(require("../../utils/mixins.module.css"));

var _jsxRuntime = require("react/jsx-runtime");

var _excluded = ["label", "className", "labelClass"],
    _excluded2 = ["className", "children"],
    _excluded3 = ["className", "style", "children", "topHeight"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var getSearchParams = function getSearchParams() {
  return (0, _utils.getParamsFromURL)(window.location.search);
};

function Canary(_ref) {
  var _getSearchParams;

  var _ref$url = _ref.url,
      url = _ref$url === void 0 ? "/canary/api" : _ref$url,
      _ref$refreshInterval = _ref.refreshInterval,
      refreshInterval = _ref$refreshInterval === void 0 ? 15 * 1000 : _ref$refreshInterval,
      _ref$topLayoutOffset = _ref.topLayoutOffset,
      topLayoutOffset = _ref$topLayoutOffset === void 0 ? 0 : _ref$topLayoutOffset,
      hideSearch = _ref.hideSearch,
      hideTimeRange = _ref.hideTimeRange;
  // force-set layout to table
  (0, _react.useEffect)(function () {
    (0, _url.updateParams)({
      layout: "table"
    });
  }, []);

  var _useState = (0, _react.useState)([]),
      _useState2 = _slicedToArray(_useState, 2),
      checks = _useState2[0],
      setChecks = _useState2[1]; // eslint-disable-next-line no-unused-vars


  var _useState3 = (0, _react.useState)(true),
      _useState4 = _slicedToArray(_useState3, 2),
      isLoading = _useState4[0],
      setIsLoading = _useState4[1]; // eslint-disable-next-line no-unused-vars


  var _useState5 = (0, _react.useState)(""),
      _useState6 = _slicedToArray(_useState5, 2),
      lastUpdated = _useState6[0],
      setLastUpdated = _useState6[1];

  var _useState7 = (0, _react.useState)(),
      _useState8 = _slicedToArray(_useState7, 2),
      filteredLabels = _useState8[0],
      setFilteredLabels = _useState8[1];

  var labelUpdateCallback = (0, _react.useCallback)(function (newLabels) {
    setFilteredLabels(newLabels);
  }, []);
  var handleFetch = (0, _lodash.throttle)(function () {
    var _getParamsFromURL;

    if (url == null) {
      return;
    }

    var timeRange = (_getParamsFromURL = (0, _utils.getParamsFromURL)(window.location.search)) === null || _getParamsFromURL === void 0 ? void 0 : _getParamsFromURL.timeRange;
    var params = (0, _url.encodeObjectToUrlSearchParams)({
      start: (0, _lodash.isEmpty)(timeRange) || timeRange === "undefined" ? "1h" : timeRange
    });
    setIsLoading(true);
    fetch("".concat(url, "?").concat(params)).then(function (result) {
      return result.json();
    }).then(function (e) {
      if (!(0, _lodash.isEmpty)(e.error)) {
        // eslint-disable-next-line no-console
        console.error(e.error);
      } else {
        setChecks(e.checks);
        setLastUpdated(new Date());
      }
    }).finally(function () {
      setIsLoading(false);
    });
  }, 1000);
  (0, _react.useMemo)(function () {
    handleFetch();
    var interval = setInterval(handleFetch, refreshInterval);
    return function () {
      return clearInterval(interval);
    }; // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [refreshInterval]); // listen to URL params change

  var _useState9 = (0, _react.useState)(window.location.search),
      _useState10 = _slicedToArray(_useState9, 2),
      searchParams = _useState10[0],
      setSearchParams = _useState10[1];

  (0, _react.useEffect)(function () {
    _browser.default.listen(function (_ref2) {
      var location = _ref2.location;
      setSearchParams(location.search);
      handleFetch();
    }); // eslint-disable-next-line react-hooks/exhaustive-deps

  }, []);
  var handleSearch = (0, _lodash.debounce)(function (value) {
    (0, _url.updateParams)({
      query: value
    });
  }, 400);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "flex flex-row place-content-center",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(SidebarSticky, {
      topHeight: topLayoutOffset,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SectionTitle, {
        className: "mb-4",
        children: "Filter by Health"
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "mb-6 flex items-center",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "h-9 flex items-center",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HidePassingToggle, {})
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "text-sm text-gray-800 mb-0",
          children: "Hide Passing"
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(SectionTitle, {
        className: "mb-5 flex justify-between items-center",
        children: ["Filter by Label", " "]
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "mb-4 mr-2 w-full",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(LabelFilterList, {
          labels: filteredLabels
        })
      })]
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "flex-grow p-6 max-w-7xl",
      children: [!hideSearch && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "flex flex-wrap mb-2",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CanarySearchBar.CanarySearchBar, {
          onChange: function onChange(e) {
            return handleSearch(e.target.value);
          },
          onSubmit: function onSubmit(value) {
            return handleSearch(value);
          },
          onClear: function onClear() {
            return handleSearch("");
          },
          style: {
            maxWidth: "480px",
            width: "100%"
          },
          inputClassName: "w-full py-2 mr-2 mb-px",
          inputOuterClassName: "w-full",
          placeholder: "Search by name, description, or endpoint",
          defaultValue: (_getSearchParams = getSearchParams()) === null || _getSearchParams === void 0 ? void 0 : _getSearchParams.query
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: "flex flex-wrap mb-2",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "mb-2 mr-2",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StandaloneWrapper.DropdownStandaloneWrapper, {
            dropdownElem: /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupByDropdown.GroupByDropdown, {}),
            checks: checks,
            defaultValue: "canaryName",
            paramKey: "groupBy",
            className: "w-64",
            prefix: /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
              children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
                className: "text-xs text-gray-500 mr-2 whitespace-nowrap",
                children: "Group By:"
              })
            })
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "mb-2 mr-2",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_StandaloneWrapper.DropdownStandaloneWrapper, {
            dropdownElem: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabByDropdown.TabByDropdown, {}),
            defaultValue: _lists.defaultTabSelections.namespace.value,
            paramKey: "tabBy",
            checks: checks,
            emptyable: true,
            className: "w-64",
            prefix: /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
              children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
                className: "text-xs text-gray-500 mr-2 whitespace-nowrap",
                children: "Tab By:"
              })
            })
          })
        }), !hideTimeRange && /*#__PURE__*/(0, _jsxRuntime.jsx)(_StandaloneWrapper.DropdownStandaloneWrapper, {
          dropdownElem: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TimeRange.TimeRange, {}),
          defaultValue: _TimeRange.timeRanges[0].value,
          paramKey: "timeRange",
          className: "w-56 mb-2 mr-2",
          prefix: /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
              className: "text-xs text-gray-500 mr-2 whitespace-nowrap",
              children: "Time Range:"
            })
          })
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_minimal.CanaryInterfaceMinimal, {
        checks: checks,
        searchParams: searchParams,
        onLabelFiltersCallback: labelUpdateCallback
      })]
    })]
  });
}

var LabelFilterList = function LabelFilterList(_ref3) {
  var labels = _ref3.labels;

  var _useState11 = (0, _react.useState)({}),
      _useState12 = _slicedToArray(_useState11, 2),
      list = _useState12[0],
      setList = _useState12[1];

  (0, _react.useEffect)(function () {
    if (labels) {
      var _separateLabelsByBool = (0, _labels.separateLabelsByBooleanType)(Object.values(labels)),
          _separateLabelsByBool2 = _slicedToArray(_separateLabelsByBool, 2),
          bl = _separateLabelsByBool2[0],
          nbl = _separateLabelsByBool2[1];

      var groupedNbl = (0, _labels.groupLabelsByKey)(nbl);
      var keyedBl = bl.map(function (o) {
        return _objectSpread(_objectSpread({}, o), {}, {
          isBoolean: true
        });
      }).reduce(function (acc, current) {
        acc[current.key] = [current];
        return acc;
      }, {});

      var mergedLabels = _objectSpread(_objectSpread({}, keyedBl), groupedNbl);

      setList(mergedLabels);
    }
  }, [labels]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    children: Object.entries(list).sort(function (a, b) {
      return a[0] > b[0] ? 1 : -1;
    }).map(function (_ref4) {
      var _ref5 = _slicedToArray(_ref4, 2),
          labelKey = _ref5[0],
          labels = _ref5[1];

      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "mb-2",
        children: labels.length > 1 ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: "text-xs whitespace-nowrap overflow-ellipsis w-full overflow-hidden mb-1",
            children: labelKey
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(MultiSelectLabelsDropdownStandalone, {
            labels: labels,
            selectAllByDefault: true
          })]
        }) : labels.length === 1 ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
          className: "flex w-full mb-3",
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: "mr-3 w-full text-xs text-left text-gray-700 break-all overflow-ellipsis overflow-x-hidden flex items-center",
            children: labels[0].key
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(TristateLabelStandalone, {
            label: labels[0],
            className: "flex items-center",
            labelClass: "",
            hideLabel: true
          })]
        }) : null
      }, labelKey);
    })
  });
};

exports.LabelFilterList = LabelFilterList;

var HidePassingToggle = function HidePassingToggle(_ref6) {
  var _ref6$defaultValue = _ref6.defaultValue,
      defaultValue = _ref6$defaultValue === void 0 ? true : _ref6$defaultValue;
  var searchParams = (0, _utils.getParamsFromURL)(window.location.search);
  var paramsValue = searchParams.hidePassing ? searchParams.hidePassing === "true" : null;

  var _useState13 = (0, _react.useState)(paramsValue !== null && paramsValue !== void 0 ? paramsValue : defaultValue),
      _useState14 = _slicedToArray(_useState13, 2),
      value = _useState14[0],
      setValue = _useState14[1];

  (0, _react.useEffect)(function () {
    (0, _url.updateParams)({
      hidePassing: value
    }); // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Toggle.Toggle, {
    value: value,
    onChange: function onChange(val) {
      setValue(val);
      (0, _url.updateParams)({
        hidePassing: val
      });
    }
  });
};

exports.HidePassingToggle = HidePassingToggle;

var MultiSelectLabelsDropdownStandalone = function MultiSelectLabelsDropdownStandalone(_ref7) {
  var _ref7$labels = _ref7.labels,
      labels = _ref7$labels === void 0 ? [] : _ref7$labels;

  var _useState15 = (0, _react.useState)(true),
      _useState16 = _slicedToArray(_useState15, 2),
      isFirstLoad = _useState16[0],
      setIsFirstLoad = _useState16[1];

  var _useState17 = (0, _react.useState)([]),
      _useState18 = _slicedToArray(_useState17, 2),
      dropdownValue = _useState18[0],
      setDropdownValue = _useState18[1];

  var handleChange = (0, _react.useCallback)(function (selected, all) {
    var _decodeUrlSearchParam = (0, _url.decodeUrlSearchParams)(window.location.search),
        urlLabelState = _decodeUrlSearchParam.labels;

    var labelState = _objectSpread({}, urlLabelState);

    if (!isFirstLoad) {
      all.forEach(function (selection) {
        // set unselected labels to 0
        labelState[selection.value] = 0;
      });
    }

    selected.forEach(function (selection) {
      // set selected labels to 1
      labelState[selection.value] = 1;
    });
    setDropdownValue(selected);
    var conciseLabelState = (0, _labels.getConciseLabelState)(labelState);
    (0, _url.updateParams)({
      labels: conciseLabelState
    });
    setIsFirstLoad(false);
  }, [isFirstLoad //  selectAllByDefault
  ]);
  (0, _react.useEffect)(function () {
    setIsFirstLoad(true);
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FilterForm.LabelFilterDropdown, {
    name: "HealthMultiLabelFilter",
    labels: labels,
    onChange: handleChange,
    loadFromURL: true,
    value: dropdownValue
  });
};

exports.MultiSelectLabelsDropdownStandalone = MultiSelectLabelsDropdownStandalone;

var TristateLabelStandalone = function TristateLabelStandalone(_ref8) {
  var label = _ref8.label,
      className = _ref8.className,
      labelClass = _ref8.labelClass,
      rest = _objectWithoutProperties(_ref8, _excluded);

  var _decodeUrlSearchParam2 = (0, _url.decodeUrlSearchParams)(window.location.search),
      _decodeUrlSearchParam3 = _decodeUrlSearchParam2.labels,
      urlLabelState = _decodeUrlSearchParam3 === void 0 ? {} : _decodeUrlSearchParam3;

  var _useState19 = (0, _react.useState)(true),
      _useState20 = _slicedToArray(_useState19, 2),
      isFirstLoad = _useState20[0],
      setIsFirstLoad = _useState20[1];

  var _useState21 = (0, _react.useState)(0),
      _useState22 = _slicedToArray(_useState21, 2),
      toggleState = _useState22[0],
      setToggleState = _useState22[1];

  var handleToggleChange = function handleToggleChange(v) {
    if (!isFirstLoad) {
      var _decodeUrlSearchParam4 = (0, _url.decodeUrlSearchParams)(window.location.search),
          _urlLabelState = _decodeUrlSearchParam4.labels;

      var newState = _objectSpread({}, _urlLabelState);

      newState[label.id] = v;
      var conciseLabelState = (0, _labels.getConciseLabelState)(newState);
      (0, _url.updateParams)({
        labels: conciseLabelState
      });
      setToggleState(v);
    }
  }; // get initial state from URL


  (0, _react.useEffect)(function () {
    var _decodeUrlSearchParam5 = (0, _url.decodeUrlSearchParams)(window.location.search),
        _decodeUrlSearchParam6 = _decodeUrlSearchParam5.labels,
        urlLabelState = _decodeUrlSearchParam6 === void 0 ? {} : _decodeUrlSearchParam6;

    if (Object.prototype.hasOwnProperty.call(urlLabelState, label.id)) {
      setToggleState(urlLabelState[label.id]);
    } else {
      setToggleState(0);
    }
  }, [label, urlLabelState]);
  (0, _react.useEffect)(function () {
    setIsFirstLoad(false);
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TristateToggle.TristateToggle, _objectSpread({
      value: toggleState,
      onChange: function onChange(v) {
        return handleToggleChange(v);
      },
      className: className,
      labelClass: labelClass,
      label: label
    }, rest))
  });
};

exports.TristateLabelStandalone = TristateLabelStandalone;

var TristateLabels = function TristateLabels(_ref9) {
  var _ref9$labels = _ref9.labels,
      labels = _ref9$labels === void 0 ? [] : _ref9$labels;

  var _useState23 = (0, _react.useState)({}),
      _useState24 = _slicedToArray(_useState23, 2),
      labelStates = _useState24[0],
      setLabelStates = _useState24[1]; // first load or label change: set label states


  (0, _react.useEffect)(function () {
    var _decodeUrlSearchParam7 = (0, _url.decodeUrlSearchParams)(window.location.search),
        _decodeUrlSearchParam8 = _decodeUrlSearchParam7.labels,
        urlLabelState = _decodeUrlSearchParam8 === void 0 ? {} : _decodeUrlSearchParam8;

    var labelMap = labels.reduce(function (acc, current) {
      acc[current.id] = true;
      return acc;
    }, {});
    var newLabelStates = Object.entries(urlLabelState).reduce(function (acc, _ref10) {
      var _ref11 = _slicedToArray(_ref10, 2),
          k = _ref11[0],
          v = _ref11[1];

      if (Object.prototype.hasOwnProperty.call(labelMap, k)) {
        acc[k] = v;
      }

      return acc;
    }, {});
    setLabelStates(newLabelStates);
  }, [labels]);

  var handleToggleChange = function handleToggleChange(labelKey, value) {
    var _decodeUrlSearchParam9 = (0, _url.decodeUrlSearchParams)(window.location.search),
        urlLabelState = _decodeUrlSearchParam9.labels;

    var newState = _objectSpread({}, urlLabelState);

    newState[labelKey] = value;
    var conciseLabelState = (0, _labels.getConciseLabelState)(newState);
    (0, _url.updateParams)({
      labels: conciseLabelState
    });
  };

  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: "w-full break",
    children: labels.filter(function (o) {
      return o && o !== undefined;
    }).map(function (label) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TristateToggle.TristateToggle, {
          value: Object.prototype.hasOwnProperty.call(labelStates, label.id) ? labelStates[label.id] : 0,
          onChange: function onChange(v) {
            return handleToggleChange(label.id, v);
          },
          className: "mb-2 flex items-center",
          labelClass: "ml-3 text-xs text-left text-gray-700 break-all overflow-ellipsis overflow-x-hidden",
          label: label
        }, label.key)
      }, label.id);
    })
  });
};

exports.TristateLabels = TristateLabels;

var SectionTitle = function SectionTitle(_ref12) {
  var className = _ref12.className,
      children = _ref12.children,
      props = _objectWithoutProperties(_ref12, _excluded2);

  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({
    className: "uppercase font-semibold text-sm mb-3 text-indigo-700 ".concat(className)
  }, props), {}, {
    children: children
  }));
};

var SidebarSticky = function SidebarSticky(_ref13) {
  var className = _ref13.className,
      style = _ref13.style,
      children = _ref13.children,
      _ref13$topHeight = _ref13.topHeight,
      topHeight = _ref13$topHeight === void 0 ? 64 : _ref13$topHeight,
      props = _objectWithoutProperties(_ref13, _excluded3);

  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({
    className: className || "flex flex-col w-100 border-r",
    style: style || {
      minHeight: "calc(100vh - ".concat(topHeight, "px)")
    }
  }, props), {}, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "h-full overflow-y-auto overflow-x-hidden p-4 ".concat(_mixinsModule.default.appleScrollbar),
      style: {
        position: "sticky",
        top: "".concat(topHeight, "px"),
        maxHeight: "calc(100vh - ".concat(topHeight, "px)")
      },
      children: children
    })
  }));
};