"use strict";

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

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

var _reactRedux = require("react-redux");

var _reselect = require("reselect");

var _redux = require("redux");

var actions = _interopRequireWildcard(require("../actions"));

var _documentation = _interopRequireDefault(require("../components/documentation"));

var _item = _interopRequireDefault(require("../selectors/item"));

var _pool = require("../selectors/pool");

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

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

var _default = (0, _reactRedux.connect)(mapState, mapDispatch)(_documentation.default);

exports.default = _default;
const selectNotFound = (0, _reselect.createSelector)(state => state.routing.locationBeforeTransitions.pathname, url => `
# Documentation not found

> Pretty sure these aren't the hypertext documents you are looking for.

We looked everywhere and could not find a single thing at \`${url}\`.

You might want to navigate back to [Home](/) or use the [Search](?search-enabled=true).

---

Help us to make this message more helpful on [GitHub](https://github.com/patternplate/patternplate)
`);

const selectNoDocs = () => `
# :construction: Add documentation

> Undocumented software could not exist just as well.
>
> – The Voice of Common Sense

Currently there is no readme data at \`./patterns/readme.md\`, so we left this
friendly reminder here to change that soon.

You could start right away:

\`\`\`sh
echo "# Docs\\n This patternplate contains ..." > patterns/readme.md
\`\`\`

Some ideas on what to write into your pattern readme

*  Why this Living Styleguide interface exists, e.g. what problems it should solve
*  What the components in are intended for, e.g. a brand, website or product
*  The component hierarchy you use, e.g. Atomic Design
*  Naming conventions
*  Rules for dependencies
*  Browser matrix

---

Help us to make this message more helpful on [GitHub](https://github.com/patternplate/patternplate).
`;

const selectDocItem = (0, _reselect.createSelector)(_item.default, _pool.flat, state => state.id, (item, pool, id) => {
  if (id === "/") {
    const first = pool.find(i => i.contentType === "doc");

    if (first) {
      return first;
    }
  }

  return item;
});
const selectDoc = (0, _reselect.createSelector)(selectDocItem, selectNoDocs, selectNotFound, (item, noDocs, notFound) => {
  if (item && item.contents) {
    return item.contents;
  }

  if (item && !item.contents) {
    return noDocs;
  }

  return notFound;
});
const selectDisplayName = (0, _reselect.createSelector)(selectDocItem, item => {
  if (!item) {
    return 'patternpalte';
  }

  return item.manifest.displayName;
});
const selectType = (0, _reselect.createSelector)(_item.default, match => {
  if (match && match.contents) {
    return "doc";
  }

  if (match && !match.contents) {
    return "fallback";
  }

  return "not-found";
});
const selectThemes = (0, _reselect.createSelector)(state => state.config.color, color => (0, _components.themes)(color));

function mapState(state) {
  return {
    displayName: selectDisplayName(state),
    doc: selectDoc(state),
    themes: selectThemes(state),
    type: selectType(state),
    isStatic: state.isStatic
  };
}

function mapDispatch(dispatch) {
  return (0, _redux.bindActionCreators)({
    requestScroll: actions.scrollTo
  }, dispatch);
}
//# sourceMappingURL=documentation.js.map