/**
 * 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 { ColumnOption } from '@superset-ui/chart-controls';
import { ensureIsArray, FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core';
import React from 'react';
import { getQueryMode, isRawMode } from './shared';
var allColumns = {
  type: 'SelectControl',
  label: t('Columns'),
  description: t('Columns to display'),
  multi: true,
  freeForm: true,
  allowAll: true,
  commaChoosesOption: false,
  default: [],
  optionRenderer: c => /*#__PURE__*/React.createElement(ColumnOption, {
    showType: true,
    column: c
  }),
  valueRenderer: c => /*#__PURE__*/React.createElement(ColumnOption, {
    column: c
  }),
  valueKey: 'column_name',
  mapStateToProps: (_ref, controlState) => {
    var {
      datasource,
      controls
    } = _ref;
    return {
      options: (datasource == null ? void 0 : datasource.columns) || [],
      queryMode: getQueryMode(controls),
      externalValidationErrors: isRawMode({
        controls
      }) && ensureIsArray(controlState == null ? void 0 : controlState.value).length === 0 ? [t('must have a value')] : []
    };
  },
  visibility: isRawMode,
  resetOnHide: false
};
var dndAllColumns = {
  type: 'DndColumnSelect',
  label: t('Columns'),
  description: t('Columns to display'),
  default: [],
  mapStateToProps(_ref2, controlState) {
    var {
      datasource,
      controls
    } = _ref2;
    var newState = {};
    if (datasource) {
      var _datasource$columns$;
      if (datasource != null && (_datasource$columns$ = datasource.columns[0]) != null && _datasource$columns$.hasOwnProperty('filterable')) {
        var _columns;
        newState.options = datasource == null || (_columns = datasource.columns) == null ? void 0 : _columns.filter(c => c.filterable);
      } else newState.options = datasource.columns;
    }
    newState.queryMode = getQueryMode(controls);
    newState.externalValidationErrors = isRawMode({
      controls
    }) && ensureIsArray(controlState == null ? void 0 : controlState.value).length === 0 ? [t('must have a value')] : [];
    return newState;
  },
  visibility: isRawMode,
  resetOnHide: false
};
export var allColumnsControlSetItem = {
  name: 'all_columns',
  config: isFeatureEnabled(FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP) ? dndAllColumns : allColumns
};