import { getTestRequestParams, getTestRequestData } from '@teamix/utils';
import { initializeRequestExpression } from '../utils';

var initializeDataSource = function initializeDataSource(dataSource, suffix) {
  var _dataSource$extraConf;

  var _initializeRequestExp = initializeRequestExpression(dataSource, '$dataSource', suffix),
      expression = _initializeRequestExp.expression,
      scope = _initializeRequestExp.scope;

  return expression ? {
    reactions: [expression],
    scope: scope,
    data: {
      readOnlyOnLoading: (dataSource === null || dataSource === void 0 ? void 0 : (_dataSource$extraConf = dataSource.extraConfig) === null || _dataSource$extraConf === void 0 ? void 0 : _dataSource$extraConf.readOnly) !== false
    },
    props: {
      className: 'teamix-test-request',
      'data-teamix-test-request': "url=".concat(dataSource === null || dataSource === void 0 ? void 0 : dataSource.url, "&formatResult=").concat(!!(dataSource === null || dataSource === void 0 ? void 0 : dataSource.formatResult)),
      'data-teamix-test-params': getTestRequestParams(dataSource === null || dataSource === void 0 ? void 0 : dataSource.params),
      'data-teamix-test-data': getTestRequestData('dataSource')
    }
  } : {
    reactions: [],
    scope: {},
    dataSource: dataSource
  };
};

export default initializeDataSource;