"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SeriesChartTypes = SeriesChartTypes;
var _react = _interopRequireWildcard(require("react"));
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _public = require("@kbn/kibana-react-plugin/public");
var _public2 = require("@kbn/observability-shared-plugin/public");
var _chart_types = require("./chart_types");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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; }
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

function SeriesChartTypes({
  seriesId,
  series,
  seriesConfig
}) {
  var _series$seriesType, _find, _find2;
  const seriesType = (_series$seriesType = series === null || series === void 0 ? void 0 : series.seriesType) !== null && _series$seriesType !== void 0 ? _series$seriesType : seriesConfig.defaultSeriesType;
  const {
    services: {
      lens
    }
  } = (0, _public.useKibana)();
  const {
    data = []
  } = (0, _public2.useFetcher)(() => lens.getXyVisTypes(), [lens]);
  const icon = (_find = (data !== null && data !== void 0 ? data : []).find(({
    id
  }) => id === seriesType)) === null || _find === void 0 ? void 0 : _find.icon;
  const [isPopoverOpen, setIsPopoverOpen] = (0, _react.useState)(false);
  return /*#__PURE__*/_react.default.createElement(_eui.EuiPopover, {
    isOpen: isPopoverOpen,
    closePopover: () => setIsPopoverOpen(false),
    button: /*#__PURE__*/_react.default.createElement(_eui.EuiToolTip, {
      content: EDIT_CHART_TYPE_LABEL
    }, /*#__PURE__*/_react.default.createElement(_eui.EuiButtonEmpty, {
      "data-test-subj": "o11ySeriesChartTypesButton",
      size: "s",
      "aria-label": CHART_TYPE_LABEL,
      onClick: () => setIsPopoverOpen(prevState => !prevState),
      flush: "both"
    }, icon && /*#__PURE__*/_react.default.createElement(_eui.EuiIcon, {
      type: (_find2 = (data !== null && data !== void 0 ? data : []).find(({
        id
      }) => id === seriesType)) === null || _find2 === void 0 ? void 0 : _find2.icon,
      size: "l"
    })))
  }, /*#__PURE__*/_react.default.createElement(_chart_types.SeriesChartTypesSelect, {
    seriesId: seriesId,
    series: series,
    defaultChartType: seriesConfig.defaultSeriesType
  }));
}
const EDIT_CHART_TYPE_LABEL = _i18n.i18n.translate('xpack.exploratoryView.expView.seriesEditor.editChartSeriesLabel', {
  defaultMessage: 'Edit chart type for series'
});
const CHART_TYPE_LABEL = _i18n.i18n.translate('xpack.exploratoryView.expView.chartTypes.label', {
  defaultMessage: 'Chart type'
});