"use strict";

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

var _components = require("@looker/components");

var _react = _interopRequireWildcard(require("react"));

var _DiffItem = require("./DiffItem");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var DocDiff = _ref => {
  var {
    delta,
    leftKey,
    leftSpec,
    rightKey,
    rightSpec,
    pageSize = 15
  } = _ref;
  var [page, setPage] = (0, _react.useState)(1);
  if (delta.length === 0) return _react.default.createElement(_components.Text, null, 'No differences found');
  var pageCount = Math.round((delta.length - 1) / pageSize);
  var pageItemData = delta.slice((page - 1) * pageSize + 1, page * pageSize + 1);
  return _react.default.createElement(_react.default.Fragment, null, delta.length === 0 ? _react.default.createElement(_components.Text, null, 'No differences found') : _react.default.createElement(_components.Flex, {
    flexDirection: "column",
    alignItems: "center"
  }, _react.default.createElement(_components.Space, null, _react.default.createElement(_components.Heading, {
    as: "h2"
  }, "".concat(delta.length, " differences between ").concat(leftKey, " and ").concat(rightKey))), _react.default.createElement(_components.SpaceVertical, {
    mt: "large",
    gap: "xxsmall"
  }, pageItemData.map((item, index) => _react.default.createElement(_DiffItem.DiffItem, {
    key: index,
    item: item,
    leftKey: leftKey,
    leftSpec: leftSpec,
    rightKey: rightKey,
    rightSpec: rightSpec
  }))), _react.default.createElement(_components.Pagination, {
    current: page,
    pages: pageCount,
    onChange: nextPage => {
      setPage(nextPage);
    }
  })));
};

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