"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MessagePageCrate = exports.PageCrate = exports.PageCrateHeading = exports.Page = exports.LogoCrate = void 0;

var _preact = require("preact");

var _classnames = _interopRequireDefault(require("classnames"));

var _getStyledComponent = _interopRequireDefault(require("./utils/get-styled-component"));

var _transitionIn = require("./transition-in");

var _object = require("./utils/object");

var _icon = require("./icon");

var _logo = require("./logo");

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const LogoCrate = ({
  wide = false
}) => (0, _preact.h)("div", {
  className: (0, _classnames.default)({
    mw6: !wide,
    mw7: wide
  }, 'mv3 ph3 center br2')
}, (0, _preact.h)("a", {
  href: "/"
}, (0, _preact.h)(_logo.XChart, {
  className: "h2"
})));
/** @type {import('preact').FunctionComponent} */


exports.LogoCrate = LogoCrate;
const Page = (0, _transitionIn.transitionIn)((0, _getStyledComponent.default)({
  baseClasses: 'transition',
  options: {
    transitions: ['firstRender']
  },
  fn: ({
    firstRender
  }) => firstRender ? 'o-0 translate-y' : 'o-100'
}));
exports.Page = Page;
const PageCrateHeading = (0, _getStyledComponent.default)({
  baseClasses: 'mt1 mb3',
  tagName: 'h3'
});
exports.PageCrateHeading = PageCrateHeading;
const PageCrate = (0, _getStyledComponent.default)({
  baseClasses: 'no-print-padding pa3 center br2',
  options: {
    title: '',
    backgroundColor: 'white',
    width: ['wide', 'noMaxWidth'],
    shadowExists: ['noShadow'],
    margins: ['noMargin']
  },
  fn: ({
    wide,
    noMaxWidth,
    backgroundColor,
    noShadow,
    noMargin
  }) => (0, _classnames.default)("bg-".concat(backgroundColor), {
    'shadow-1': !noShadow,
    mv3: !noMargin,
    mw7: wide,
    mw6: !wide && !noMaxWidth
  }),
  renderChildren: ({
    title,
    children
  }) => {
    const res = [children];

    if (title) {
      res.unshift((0, _preact.h)(PageCrateHeading, null, title));
    }

    return res;
  }
});
/**
 * @typedef MessagePageCrateProps
 * @property {boolean} [loading]
 * @property {boolean} [error]
 * @property {boolean} [success]
 * @property {boolean} [warning]
 * @property {boolean} [info]
 * @property {boolean} [noShadow]
 * @property {any} children
 */

/**
 * @type {import('preact').FunctionComponent}
 * @param {MessagePageCrateProps} props
 */

exports.PageCrate = PageCrate;

const MessagePageCrate = props => {
  const {
    loading,
    error,
    warning,
    success,
    info,
    children,
    noShadow,
    noMargin
  } = props;
  const rest = (0, _object.omit)(props, ['loading', 'error', 'warning', 'success', 'children']);
  let icon = null;
  let iconClasses = null;
  let backgroundColor = 'white';
  let colorClasses = null;

  if (loading) {
    icon = 'autorenew';
    iconClasses = 'load';
  }

  if (error) {
    icon = 'error';
    backgroundColor = 'red';
    colorClasses = 'black';
  }

  if (warning) {
    icon = 'warning';
    backgroundColor = 'orange';
    colorClasses = 'black';
  }

  if (success) {
    icon = 'check';
    backgroundColor = 'light-blue';
    colorClasses = 'black';
  }

  if (info) {
    icon = 'info';
    backgroundColor = 'lightest-blue';
    colorClasses = 'black';
  }

  let iconComp;

  if (loading) {
    iconComp = (0, _preact.h)(_logo.LoadingMark, {
      className: (0, _classnames.default)('f3 mr3 top-animation', iconClasses),
      style: {
        width: '50px'
      }
    });
  } else if (loading || error || warning || success || info) {
    iconComp = (0, _preact.h)(_icon.Icon, {
      className: (0, _classnames.default)('f3 mr3', iconClasses),
      size: "40",
      icon: icon
    });
  }

  return (0, _preact.h)(PageCrate, _extends({
    backgroundColor: backgroundColor,
    noShadow: !!noShadow,
    noMargin: !!noMargin
  }, rest), (0, _preact.h)("div", {
    className: (0, _classnames.default)('flex items-center min-h3 f4', colorClasses)
  }, iconComp, children));
};

exports.MessagePageCrate = MessagePageCrate;