"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.QuickFilterDataSet = exports.ConditionDataSet = void 0;

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _interface = require("../../../data-set/interface");

var _localeContext = require("../../../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((0, _objectSpread2["default"])({}, 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
  });
}

var ConditionDataSet = function ConditionDataSet() {
  return {
    paging: false,
    fields: [{
      name: 'fieldName',
      type: _interface.FieldType.string
    }, {
      name: 'value',
      transformRequest: function transformRequest(value) {
        if ((0, _typeof2["default"])(value) === 'object') {
          return JSON.stringify(value);
        }

        return value;
      },
      transformResponse: function transformResponse(value) {
        try {
          return JSON.parse(value);
        } catch (e) {
          return value;
        }
      }
    }],
    dataToJSON: _interface.DataToJSON.all,
    events: {
      update: function update() {}
    }
  };
};

exports.ConditionDataSet = ConditionDataSet;

var QuickFilterDataSet = function QuickFilterDataSet(_ref) {
  var queryDataSet = _ref.queryDataSet,
      tableFilterAdapter = _ref.tableFilterAdapter;
  return {
    paging: false,
    autoQuery: false,
    primaryKey: 'searchId',
    dataToJSON: _interface.DataToJSON.all,
    transport: {
      adapter: function adapter(config, type) {
        return getTransportConfig({
          config: config,
          type: type,
          queryDataSet: queryDataSet,
          tableFilterAdapter: tableFilterAdapter
        });
      }
    },
    fields: [{
      name: 'searchName',
      label: (0, _localeContext.$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'
    }]
  };
};

exports.QuickFilterDataSet = QuickFilterDataSet;
//# sourceMappingURL=QuickFilterDataSet.js.map
