"use strict";

exports.__esModule = true;
exports.allColumnsControlSetItem = void 0;
var _chartControls = require("@superset-ui/chart-controls");
var _core = require("@superset-ui/core");
var _react = _interopRequireDefault(require("react"));
var _shared = require("./shared");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
 * 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.
 */

var allColumns = {
  type: 'SelectControl',
  label: (0, _core.t)('Columns'),
  description: (0, _core.t)('Columns to display'),
  multi: true,
  freeForm: true,
  allowAll: true,
  commaChoosesOption: false,
  default: [],
  optionRenderer: c => /*#__PURE__*/_react.default.createElement(_chartControls.ColumnOption, {
    showType: true,
    column: c
  }),
  valueRenderer: c => /*#__PURE__*/_react.default.createElement(_chartControls.ColumnOption, {
    column: c
  }),
  valueKey: 'column_name',
  mapStateToProps: (_ref, controlState) => {
    var {
      datasource,
      controls
    } = _ref;
    return {
      options: (datasource == null ? void 0 : datasource.columns) || [],
      queryMode: (0, _shared.getQueryMode)(controls),
      externalValidationErrors: (0, _shared.isRawMode)({
        controls
      }) && (0, _core.ensureIsArray)(controlState == null ? void 0 : controlState.value).length === 0 ? [(0, _core.t)('must have a value')] : []
    };
  },
  visibility: _shared.isRawMode,
  resetOnHide: false
};
var dndAllColumns = {
  type: 'DndColumnSelect',
  label: (0, _core.t)('Columns'),
  description: (0, _core.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 = (0, _shared.getQueryMode)(controls);
    newState.externalValidationErrors = (0, _shared.isRawMode)({
      controls
    }) && (0, _core.ensureIsArray)(controlState == null ? void 0 : controlState.value).length === 0 ? [(0, _core.t)('must have a value')] : [];
    return newState;
  },
  visibility: _shared.isRawMode,
  resetOnHide: false
};
var allColumnsControlSetItem = {
  name: 'all_columns',
  config: (0, _core.isFeatureEnabled)(_core.FeatureFlag.ENABLE_EXPLORE_DRAG_AND_DROP) ? dndAllColumns : allColumns
};
exports.allColumnsControlSetItem = allColumnsControlSetItem;