function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
import { defineSavedMetrics } from '@superset-ui/chart-controls';
import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core';
import { getQueryMode, isAggMode, validateAggControlValues } from './shared';
var percentMetrics = {
  type: 'MetricsControl',
  label: t('Percentage metrics'),
  description: t('Metrics for which percentage of total are to be displayed. Calculated from only data within the row limit.'),
  multi: true,
  visibility: isAggMode,
  resetOnHide: false,
  mapStateToProps: (_ref, controlState) => {
    var _controls$groupby, _controls$metrics;
    var {
      datasource,
      controls
    } = _ref;
    return {
      columns: (datasource == null ? void 0 : datasource.columns) || [],
      savedMetrics: defineSavedMetrics(datasource),
      datasource,
      datasourceType: datasource == null ? void 0 : datasource.type,
      queryMode: getQueryMode(controls),
      externalValidationErrors: validateAggControlValues(controls, [(_controls$groupby = controls.groupby) == null ? void 0 : _controls$groupby.value, (_controls$metrics = controls.metrics) == null ? void 0 : _controls$metrics.value, controlState == null ? void 0 : controlState.value])
    };
  },
  rerender: ['groupby', 'metrics'],
  default: [],
  validators: []
};
var dndPercentMetrics = _extends({}, percentMetrics, {
  type: 'DndMetricSelect'
});
export var percentMetricsControlSetItem = {
  name: 'percent_metrics',
  config: _extends({}, isFeatureEnabled(FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP) ? dndPercentMetrics : percentMetrics)
};
export var metricsControlSetItem = {
  name: 'metrics',
  override: {
    validators: [],
    visibility: isAggMode,
    mapStateToProps: (_ref2, controlState) => {
      var _datasource$columns$, _columns, _controls$groupby2, _controls$percent_met;
      var {
        controls,
        datasource,
        form_data
      } = _ref2;
      return {
        columns: datasource != null && (_datasource$columns$ = datasource.columns[0]) != null && _datasource$columns$.hasOwnProperty('filterable') ? datasource == null || (_columns = datasource.columns) == null ? void 0 : _columns.filter(c => c.filterable) : datasource == null ? void 0 : datasource.columns,
        savedMetrics: defineSavedMetrics(datasource),
        // current active adhoc metrics
        selectedMetrics: form_data.metrics || (form_data.metric ? [form_data.metric] : []),
        datasource,
        externalValidationErrors: validateAggControlValues(controls, [(_controls$groupby2 = controls.groupby) == null ? void 0 : _controls$groupby2.value, (_controls$percent_met = controls.percent_metrics) == null ? void 0 : _controls$percent_met.value, controlState.value])
      };
    },
    rerender: ['groupby', 'percent_metrics'],
    resetOnHide: false
  }
};
export var showTotalsControlSetItem = {
  name: 'show_totals',
  config: {
    type: 'CheckboxControl',
    label: t('Show totals'),
    default: false,
    description: t('Show total aggregations of selected metrics. Note that row limit does not apply to the result.'),
    visibility: isAggMode,
    resetOnHide: false
  }
};