import _typeof from "@babel/runtime/helpers/typeof";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import { DataToJSON, FieldType } from '../../../data-set/interface';
import { $l } from '../../../locale-context';

function processAxiosConfig() {
  var axiosConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var args = arguments.length > 1 ? arguments[1] : undefined;

  if (typeof axiosConfig === 'function') {
    return axiosConfig(_objectSpread({}, args));
  }

  return axiosConfig;
}

function getTransportConfig(props) {
  var config = props.config,
      type = props.type,
      searchCode = props.searchCode,
      queryDataSet = props.queryDataSet,
      tableFilterAdapter = props.tableFilterAdapter;
  return processAxiosConfig(tableFilterAdapter, {
    type: type,
    config: config,
    searchCode: searchCode,
    queryDataSet: queryDataSet
  });
}

export var ConditionDataSet = function ConditionDataSet() {
  return {
    paging: false,
    fields: [{
      name: 'fieldName',
      type: FieldType.string
    }, {
      name: 'value',
      transformRequest: function transformRequest(value) {
        if (_typeof(value) === 'object') {
          return JSON.stringify(value);
        }

        return value;
      },
      transformResponse: function transformResponse(value) {
        try {
          return JSON.parse(value);
        } catch (e) {
          return value;
        }
      }
    }],
    dataToJSON: DataToJSON.all,
    events: {
      update: function update() {}
    }
  };
};
export var QuickFilterDataSet = function QuickFilterDataSet(_ref) {
  var queryDataSet = _ref.queryDataSet,
      tableFilterAdapter = _ref.tableFilterAdapter;
  return {
    paging: false,
    autoQuery: false,
    primaryKey: 'searchId',
    dataToJSON: DataToJSON.all,
    transport: {
      adapter: function adapter(config, type) {
        return getTransportConfig({
          config: config,
          type: type,
          queryDataSet: queryDataSet,
          tableFilterAdapter: tableFilterAdapter
        });
      }
    },
    fields: [{
      name: 'searchName',
      label: $l('Table', 'filter_name'),
      type: 'string',
      maxLength: 20,
      required: true
    }, {
      name: 'searchId',
      type: 'string'
    }, {
      name: 'searchIcon',
      type: 'string'
    }, {
      name: 'personalFilter',
      type: 'string'
    }, {
      name: 'personalColumn',
      type: 'string'
    }]
  };
};
//# sourceMappingURL=QuickFilterDataSet.js.map
