"use strict";

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

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

var _reactRouterDom = require("react-router-dom");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _designSystem = require("../design-system");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const BreadcrumbLink = (0, _styledComponents.default)(_reactRouterDom.Link).withConfig({
  displayName: "breadcrumbs__BreadcrumbLink",
  componentId: "yjyesi-0"
})(["color:", ";font-family:", ";line-height:", ";font-size:", ";text-decoration:none;&:hover{color:", ";}&:after{content:'/';padding:0 ", ";}&:last-child{&:after{content:'';}}"], ({
  theme
}) => theme.colors.greyLight, ({
  theme
}) => theme.font, ({
  theme
}) => theme.lineHeights.default, ({
  theme
}) => theme.fontSizes.default, ({
  theme
}) => theme.colors.bluePrimary, ({
  theme
}) => theme.space.default);
/**
 * @memberof Breadcrumbs
 */

/**
 * @component
 * @private
 */
class Breadcrumbs extends _react.default.PureComponent {
  renderResource() {
    const {
      resource,
      record
    } = this.props;
    return _react.default.createElement(BreadcrumbLink, {
      to: resource.href,
      className: record ? 'is-active' : ''
    }, resource.name);
  }

  renderAction() {
    const {
      actionName,
      resource,
      record
    } = this.props;
    const action = resource.resourceActions.find(a => a.name === actionName) || record && record.recordActions.find(a => a.name === actionName);

    if (action) {
      return _react.default.createElement(BreadcrumbLink, {
        to: "#"
      }, action.label);
    }

    return null;
  }

  render() {
    return _react.default.createElement(_designSystem.Box, {
      flexGrow: 1
    }, this.renderResource(), this.renderAction());
  }

}

var _default = Breadcrumbs;
exports.default = _default;