import { _ as _slicedToArray } from './slicedToArray-6ebcbfea.js';
import Breadcrumb from 'react-bootstrap/Breadcrumb';
import React__default, { useState, useEffect } from 'react';
import './_commonjsHelpers-0c4b6f40.js';
import './web.dom.iterable-ab4dea5c.js';
import './core.get-iterator-method-ea258bb1.js';

var Breadcrumbs = function Breadcrumbs(_ref) {
  var _ref$data = _ref.data,
      data = _ref$data === undefined ? [] : _ref$data,
      _ref$separator = _ref.separator,
      separator = _ref$separator === undefined ? '/' : _ref$separator;

  // To be used on landing pages eg. /news/[url]
  var _useState = useState(''),
      _useState2 = _slicedToArray(_useState, 2),
      parentPath = _useState2[0],
      setParentPath = _useState2[1];

  var _useState3 = useState(''),
      _useState4 = _slicedToArray(_useState3, 2),
      currentPath = _useState4[0],
      setCurrentPath = _useState4[1];

  var _useState5 = useState(''),
      _useState6 = _slicedToArray(_useState5, 2),
      parentPathName = _useState6[0],
      setParentPathName = _useState6[1];

  var get_parent_path = function get_parent_path(parsedUrl) {
    var parent_path = '';
    for (var i = 1; i < parsedUrl.length - 3; i++) {
      if (parsedUrl.length > i + 1) {
        parent_path = '' + parsedUrl[parsedUrl.length - (i + 1)] + (parent_path ? '/' + parent_path : '');
      }
    }

    return parent_path;
  };

  useEffect(function () {
    var parsedUrl = window.location.href.split('/');
    setCurrentPath(parsedUrl[parsedUrl.length - 1].split('?')[0]);
    setParentPathName(parsedUrl[parsedUrl.length - 2].split('?')[0]);
    setParentPath(get_parent_path(parsedUrl));
  }, []);

  if (data && data.length > 0) {
    return React__default.createElement(
      Breadcrumb,
      null,
      data.map(function (item, index) {
        return React__default.createElement(
          Breadcrumb.Item,
          { key: index, href: item.url, active: item.isActive || false },
          item.name
        );
      }),
      React__default.createElement(
        'style',
        { jsx: 'true' },
        '\n          .breadcrumb {\n            background: transparent;\n            padding-left: 0.25rem;\n          }\n          .breadcrumb .breadcrumb-item + .breadcrumb-item::before {\n            content: \'' + separator + '\';\n          }\n          .breadcrumb-item.active {\n            white-space: nowrap;\n            overflow: hidden;\n            text-overflow: ellipsis;\n            max-width: 40ch;\n          }\n          @media screen and (max-width: 1400px) {\n            .breadcrumb-item.active {\n              max-width: 20ch;\n            }\n          }\n          @media screen and (max-width: 768px) {\n            .breadcrumb-item.active {\n              max-width: 40ch;\n            }\n          }\n        '
      )
    );
  }

  return React__default.createElement(
    Breadcrumb,
    null,
    React__default.createElement(
      Breadcrumb.Item,
      { href: '/' },
      'home'
    ),
    parentPath.split('/').length > 1 && React__default.createElement(
      Breadcrumb.Item,
      { active: true },
      '...'
    ),
    React__default.createElement(
      Breadcrumb.Item,
      { href: '/' + parentPath },
      parentPathName
    ),
    React__default.createElement(
      Breadcrumb.Item,
      { active: true },
      currentPath
    ),
    React__default.createElement(
      'style',
      { jsx: 'true' },
      '\n        ol.breadcrumb {\n          background: transparent;\n          padding-left: 0.25rem;\n        }\n        .breadcrumb-item.active {\n          white-space: nowrap;\n          overflow: hidden;\n          text-overflow: ellipsis;\n          max-width: 40ch;\n        }\n        @media screen and (max-width: 1400px) {\n          .breadcrumb-item.active {\n            max-width: 20ch;\n          }\n        }\n        @media screen and (max-width: 768px) {\n          .breadcrumb-item.active {\n            max-width: 40ch;\n          }\n        }\n      '
    )
  );
};

var Breadcrumbs$1 = React__default.memo(Breadcrumbs);

export { Breadcrumbs$1 as default };
