"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SyncJobFlyout = void 0;
var _react = _interopRequireDefault(require("react"));
var _eui = require("@elastic/eui");
var _i18n = require("@kbn/i18n");
var _documents_panel = require("./documents_panel");
var _events_panel = require("./events_panel");
var _filtering_panel = require("./filtering_panel");
var _flyout_panel = require("./flyout_panel");
var _pipeline_panel = require("./pipeline_panel");
var _sync_callouts = require("./sync_callouts");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

const SyncJobFlyout = ({
  onClose,
  syncJob
}) => {
  var _syncJob$connector$fi, _syncJob$total_docume, _syncJob$indexed_docu, _syncJob$canceled_at, _syncJob$cancelation_, _syncJob$started_at, _syncJob$completed_at, _syncJob$last_seen, _filtering$rules, _syncJob$connector;
  const filtering = syncJob !== null && syncJob !== void 0 && syncJob.connector.filtering ? Array.isArray(syncJob === null || syncJob === void 0 ? void 0 : syncJob.connector.filtering) ? syncJob === null || syncJob === void 0 ? void 0 : (_syncJob$connector$fi = syncJob.connector.filtering) === null || _syncJob$connector$fi === void 0 ? void 0 : _syncJob$connector$fi[0] : syncJob === null || syncJob === void 0 ? void 0 : syncJob.connector.filtering : null;
  const visible = !!syncJob;
  return visible ? /*#__PURE__*/_react.default.createElement(_eui.EuiFlyout, {
    onClose: onClose
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiFlyoutHeader, {
    hasBorder: true
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiTitle, {
    size: "m"
  }, /*#__PURE__*/_react.default.createElement("h2", null, _i18n.i18n.translate('xpack.enterpriseSearch.content.syncJobs.flyout.title', {
    defaultMessage: 'Event log'
  })))), /*#__PURE__*/_react.default.createElement(_eui.EuiFlyoutBody, null, /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, {
    direction: "column"
  }, /*#__PURE__*/_react.default.createElement(_sync_callouts.SyncJobCallouts, {
    syncJob: syncJob
  }), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_flyout_panel.FlyoutPanel, {
    title: _i18n.i18n.translate('xpack.enterpriseSearch.content.syncJobs.flyout.sync', {
      defaultMessage: 'Sync'
    })
  }, /*#__PURE__*/_react.default.createElement(_eui.EuiBasicTable, {
    columns: [{
      field: 'id',
      name: _i18n.i18n.translate('xpack.enterpriseSearch.content.syncJobs.flyout.sync.id', {
        defaultMessage: 'ID'
      })
    }],
    items: [{
      id: syncJob.id
    }]
  }))), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_documents_panel.SyncJobDocumentsPanel, {
    added: syncJob.indexed_document_count,
    total: (_syncJob$total_docume = syncJob.total_document_count) !== null && _syncJob$total_docume !== void 0 ? _syncJob$total_docume : 0,
    removed: syncJob.deleted_document_count,
    volume: (_syncJob$indexed_docu = syncJob.indexed_document_volume) !== null && _syncJob$indexed_docu !== void 0 ? _syncJob$indexed_docu : 0
  })), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_events_panel.SyncJobEventsPanel, {
    canceledAt: (_syncJob$canceled_at = syncJob.canceled_at) !== null && _syncJob$canceled_at !== void 0 ? _syncJob$canceled_at : '',
    cancelationRequestedAt: (_syncJob$cancelation_ = syncJob.cancelation_requested_at) !== null && _syncJob$cancelation_ !== void 0 ? _syncJob$cancelation_ : '',
    syncRequestedAt: syncJob.created_at,
    syncStarted: (_syncJob$started_at = syncJob.started_at) !== null && _syncJob$started_at !== void 0 ? _syncJob$started_at : '',
    completed: (_syncJob$completed_at = syncJob.completed_at) !== null && _syncJob$completed_at !== void 0 ? _syncJob$completed_at : '',
    lastUpdated: (_syncJob$last_seen = syncJob.last_seen) !== null && _syncJob$last_seen !== void 0 ? _syncJob$last_seen : '',
    triggerMethod: syncJob.trigger_method
  })), /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_filtering_panel.FilteringPanel, {
    advancedSnippet: filtering === null || filtering === void 0 ? void 0 : filtering.advanced_snippet,
    filteringRules: (_filtering$rules = filtering === null || filtering === void 0 ? void 0 : filtering.rules) !== null && _filtering$rules !== void 0 ? _filtering$rules : []
  })), ((_syncJob$connector = syncJob.connector) === null || _syncJob$connector === void 0 ? void 0 : _syncJob$connector.pipeline) && /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, null, /*#__PURE__*/_react.default.createElement(_pipeline_panel.PipelinePanel, {
    pipeline: syncJob.connector.pipeline
  }))))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
};
exports.SyncJobFlyout = SyncJobFlyout;