import React from "react";
import PropTypes from "prop-types";
import DataChecker from "./utils/DataChecker";
import CivicCardLayoutFull from "./CivicCardLayoutFull";
import ErrorBoundary from "../ErrorBoundary/ErrorBoundary";
import { cardMetaKeys, optionalCardMetaKeys } from "./cardMetaTypes";

var CivicCard = function CivicCard(_ref) {
  var cardMeta = _ref.cardMeta,
      data = _ref.data,
      isLoading = _ref.isLoading,
      Layout = _ref.Layout;
  return React.createElement(ErrorBoundary, {
    customMessage: "CivicCard: \"".concat(cardMeta(data).title, "\" failed to load")
  }, React.createElement(DataChecker, {
    data: cardMeta(data),
    dataAccessors: cardMetaKeys,
    optionalKeys: optionalCardMetaKeys,
    dataIsObject: true,
    message: "Invalid cardMeta"
  }, React.createElement(Layout, {
    cardMeta: cardMeta(data),
    isLoading: isLoading,
    data: data
  })));
};

CivicCard.propTypes = {
  cardMeta: PropTypes.func.isRequired,
  data: PropTypes.oneOfType([PropTypes.shape({}), PropTypes.array]),
  isLoading: PropTypes.bool,
  Layout: PropTypes.func
};
CivicCard.defaultProps = {
  Layout: CivicCardLayoutFull
};
export default CivicCard;