import React from 'react';
import Tips from "../../../../../components/new-tips";
export default (function (projectId, formatMessage, mergedRequestStore, appId, tabKey) {
  function changeCount(count) {
    mergedRequestStore.setCount(count);
  }

  return {
    selection: null,
    autoQuery: false,
    paging: true,
    transport: {
      read: {
        method: 'get',
        transformResponse: function transformResponse(response) {
          try {
            if (!response) {
              mergedRequestStore.setIsEmpty(true);
              return response;
            }

            mergedRequestStore.setIsEmpty(false);
            var data = JSON.parse(response);

            if (data && data.failed) {
              return data;
            } else {
              var closeCount = data.closeCount,
                  mergeCount = data.mergeCount,
                  openCount = data.openCount,
                  totalCount = data.totalCount,
                  auditCount = data.auditCount,
                  mergeRequestVOPageInfo = data.mergeRequestVOPageInfo;
              changeCount({
                closeCount: closeCount,
                mergeCount: mergeCount,
                openCount: openCount,
                totalCount: totalCount,
                auditCount: auditCount
              });
              return mergeRequestVOPageInfo;
            }
          } catch (e) {
            return response;
          }
        }
      }
    },
    fields: [{
      name: 'title',
      type: 'string',
      label: formatMessage({
        id: 'app.name'
      })
    }, {
      name: 'iid',
      type: 'string',
      label: /*#__PURE__*/React.createElement(Tips, {
        title: formatMessage({
          id: 'app.code'
        }),
        helpText: formatMessage({
          id: 'app.code.tip'
        })
      })
    }, {
      name: 'state',
      type: 'string',
      label: formatMessage({
        id: 'merge.state'
      })
    }, {
      name: 'targetBranch',
      type: 'string',
      label: /*#__PURE__*/React.createElement(Tips, {
        title: formatMessage({
          id: 'app.branch'
        }),
        helpText: formatMessage({
          id: 'app.branch.tip'
        })
      })
    }, {
      name: 'createdAt',
      type: 'string',
      label: /*#__PURE__*/React.createElement(Tips, {
        title: formatMessage({
          id: 'create'
        }),
        helpText: formatMessage({
          id: 'create.tip'
        })
      })
    }, {
      name: 'commits',
      type: 'string',
      label: /*#__PURE__*/React.createElement(Tips, {
        title: formatMessage({
          id: 'merge.commit'
        }),
        helpText: formatMessage({
          id: 'merge.commit.tip'
        })
      })
    }, {
      name: 'updatedAt',
      type: 'string',
      label: formatMessage({
        id: 'merge.upDate'
      })
    }, {
      name: 'assignee',
      type: 'string',
      label: formatMessage({
        id: 'merge.assignee'
      })
    }]
  };
});