'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.concat.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
var React = require('react');
var PropTypes = require('prop-types');
var classnames = require('classnames');
var react = require('@carbon/react');
var Button = require('../Button/Button.js');
var Settings = require('../../constants/Settings.js');
var deprecate = require('../../internal/deprecate.js');
var EmptyStateErrorIcon = require('../../icons/static/EmptyStateErrorIcon.js');
var EmptyState404Icon = require('../../icons/static/EmptyState404Icon.js');
var EmptyStateDefaultIcon = require('../../icons/static/EmptyStateDefaultIcon.js');
var EmptyStateNotAuthorizedIcon = require('../../icons/static/EmptyStateNotAuthorizedIcon.js');
var EmptyStateNoResultsIcon = require('../../icons/static/EmptyStateNoResultsIcon.js');
var EmptyStateSuccessIcon = require('../../icons/static/EmptyStateSuccessIcon.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _toConsumableArray__default = /*#__PURE__*/_interopDefault(_toConsumableArray);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var iotPrefix = Settings.settings.iotPrefix;
var icons = {
  error: EmptyStateErrorIcon,
  error404: EmptyState404Icon,
  empty: EmptyStateDefaultIcon,
  'not-authorized': EmptyStateNotAuthorizedIcon,
  'no-result': EmptyStateNoResultsIcon,
  success: EmptyStateSuccessIcon
};
var smallIconProps = {
  width: 64,
  height: 64,
  viewBox: '0 0 80 80'
};
var SMALL_SIZE = 'small';
var DEFAULT_SIZE = 'default';
var props = {
  /** Title of empty state */
  title: PropTypes__default.default.oneOfType([PropTypes__default.default.node, PropTypes__default.default.string]).isRequired,
  /** Description of empty state */
  body: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.node]).isRequired,
  /** Optional image of state */
  icon: PropTypes__default.default.oneOfType([PropTypes__default.default.func, PropTypes__default.default.oneOf(['error', 'error404', 'empty', 'not-authorized', 'no-result', 'success', ''])]),
  /** Optional action for container */
  action: PropTypes__default.default.shape({
    label: PropTypes__default.default.oneOfType([PropTypes__default.default.node, PropTypes__default.default.string]).isRequired,
    onClick: PropTypes__default.default.func.isRequired,
    /** primary, secondary, etc from carbon */
    kind: PropTypes__default.default.oneOf([].concat(_toConsumableArray__default.default(react.ButtonKinds), ['icon-selection']))
  }),
  /** Optional secondary action for container */
  secondaryAction: PropTypes__default.default.shape({
    label: PropTypes__default.default.string.isRequired,
    onClick: PropTypes__default.default.func.isRequired
  }),
  /** Specify an optional className to be applied to the container */
  className: PropTypes__default.default.string,
  // eslint-disable-next-line react/require-default-props
  testID: deprecate(PropTypes__default.default.string, "The 'testID' prop has been deprecated. Please use 'testId' instead."),
  /** Specify a testid for testing this component */
  testId: PropTypes__default.default.string,
  /** Size of the empty state */
  size: PropTypes__default.default.oneOf([DEFAULT_SIZE, SMALL_SIZE]),
  /** Arrangement of the empty state */
  arrangement: PropTypes__default.default.oneOf(['stacked', 'inline']),
  /** aria-labe to be passed to the empty state icon */
  iconAriaLabel: PropTypes__default.default.string,
  /** aria-hidden to be passed to the empty state icon */
  iconAriaHidden: PropTypes__default.default.bool
};

/**
 * Component to set empty states
 * For reference, visit https://pages.github.ibm.com/ai-applications/design/components/empty-states/usage/
 */
var EmptyState = function EmptyState(_ref) {
  var title = _ref.title,
    _ref$icon = _ref.icon,
    icon = _ref$icon === void 0 ? '' : _ref$icon,
    body = _ref.body,
    _ref$action = _ref.action,
    action = _ref$action === void 0 ? null : _ref$action,
    _ref$secondaryAction = _ref.secondaryAction,
    secondaryAction = _ref$secondaryAction === void 0 ? null : _ref$secondaryAction,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'EmptyState' : _ref$testId,
    testID = _ref.testID,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'default' : _ref$size,
    _ref$arrangement = _ref.arrangement,
    arrangement = _ref$arrangement === void 0 ? 'stacked' : _ref$arrangement,
    iconAriaLabel = _ref.iconAriaLabel,
    iconAriaHidden = _ref.iconAriaHidden;
  var isSmall = size === SMALL_SIZE;
  return /*#__PURE__*/React__default.default.createElement("div", {
    className: classnames__default.default("".concat(iotPrefix, "--empty-state"), className, _defineProperty__default.default({}, "".concat(iotPrefix, "--empty-state--inline"), arrangement === 'inline'))
    // TODO: remove deprecated testID in v3.
    ,
    "data-testid": testID || testId
  }, /*#__PURE__*/React__default.default.createElement("div", {
    className: classnames__default.default("".concat(iotPrefix, "--empty-state--content"), _defineProperty__default.default({}, "".concat(iotPrefix, "--empty-state--content--with-gap"), arrangement === 'inline' && !!icon))
  }, icon && /*#__PURE__*/React__default.default.createElement(typeof icon === 'string' ? icons[icon] : icon, _objectSpread({
    className: classnames__default.default("".concat(iotPrefix, "--empty-state--icon"), _defineProperty__default.default({}, "".concat(iotPrefix, "--empty-state--icon--sm"), isSmall)),
    alt: '',
    'data-testid': "".concat(testID || testId, "-icon"),
    'aria-label': iconAriaLabel,
    'aria-hidden': iconAriaHidden
  }, isSmall && smallIconProps)), /*#__PURE__*/React__default.default.createElement("h3", {
    className: classnames__default.default("".concat(iotPrefix, "--empty-state--title"), _defineProperty__default.default({}, "".concat(iotPrefix, "--empty-state--title--sm"), isSmall))
    // TODO: remove deprecated testID in v3.
    ,
    "data-testid": "".concat(testID || testId, "-title")
  }, title), typeof body === 'string' ? /*#__PURE__*/React__default.default.createElement("p", {
    className: "".concat(iotPrefix, "--empty-state--text")
    // TODO: remove deprecated testID in v3.
    ,
    "data-testid": "".concat(testID || testId, "-body")
  }, body) : body, action && /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(iotPrefix, "--empty-state--action")
    // TODO: remove deprecated testID in v3.
    ,
    "data-testid": "".concat(testID || testId, "-action")
  }, /*#__PURE__*/React__default.default.createElement(Button, {
    kind: action.kind,
    onClick: action.onClick,
    size: isSmall ? 'sm' : 'md'
  }, action.label)), secondaryAction && /*#__PURE__*/React__default.default.createElement("div", {
    className: "".concat(iotPrefix, "--empty-state--link")
    // TODO: remove deprecated testID in v3.
    ,
    "data-testid": "".concat(testID || testId, "-secondaryAction")
  }, secondaryAction.label &&
  /*#__PURE__*/
  // eslint-disable-next-line jsx-a11y/anchor-is-valid
  React__default.default.createElement(react.Link, {
    onClick: secondaryAction.onClick
  }, secondaryAction.label))));
};
EmptyState.propTypes = props;
EmptyState.__docgenInfo = {
  "description": "Component to set empty states\nFor reference, visit https://pages.github.ibm.com/ai-applications/design/components/empty-states/usage/",
  "methods": [],
  "displayName": "EmptyState",
  "props": {
    "icon": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Optional image of state",
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "enum",
          "value": [{
            "value": "'error'",
            "computed": false
          }, {
            "value": "'error404'",
            "computed": false
          }, {
            "value": "'empty'",
            "computed": false
          }, {
            "value": "'not-authorized'",
            "computed": false
          }, {
            "value": "'no-result'",
            "computed": false
          }, {
            "value": "'success'",
            "computed": false
          }, {
            "value": "''",
            "computed": false
          }]
        }]
      },
      "required": false
    },
    "action": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Optional action for container",
      "type": {
        "name": "shape",
        "value": {
          "label": {
            "name": "union",
            "value": [{
              "name": "node"
            }, {
              "name": "string"
            }],
            "required": true
          },
          "onClick": {
            "name": "func",
            "required": true
          },
          "kind": {
            "name": "enum",
            "value": [{
              "value": "...ButtonKinds",
              "computed": true
            }, {
              "value": "'icon-selection'",
              "computed": false
            }],
            "description": "primary, secondary, etc from carbon",
            "required": false
          }
        }
      },
      "required": false
    },
    "secondaryAction": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Optional secondary action for container",
      "type": {
        "name": "shape",
        "value": {
          "label": {
            "name": "string",
            "required": true
          },
          "onClick": {
            "name": "func",
            "required": true
          }
        }
      },
      "required": false
    },
    "className": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "Specify an optional className to be applied to the container",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'EmptyState'",
        "computed": false
      },
      "description": "Specify a testid for testing this component",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "'default'",
        "computed": false
      },
      "description": "Size of the empty state",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'default'",
          "computed": false
        }, {
          "value": "'small'",
          "computed": false
        }]
      },
      "required": false
    },
    "arrangement": {
      "defaultValue": {
        "value": "'stacked'",
        "computed": false
      },
      "description": "Arrangement of the empty state",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'stacked'",
          "computed": false
        }, {
          "value": "'inline'",
          "computed": false
        }]
      },
      "required": false
    },
    "title": {
      "description": "Title of empty state",
      "type": {
        "name": "union",
        "value": [{
          "name": "node"
        }, {
          "name": "string"
        }]
      },
      "required": true
    },
    "body": {
      "description": "Description of empty state",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "node"
        }]
      },
      "required": true
    },
    "testID": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "deprecate(\n  PropTypes.string,\n  `The 'testID' prop has been deprecated. Please use 'testId' instead.`\n)"
      },
      "required": false
    },
    "iconAriaLabel": {
      "description": "aria-labe to be passed to the empty state icon",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "iconAriaHidden": {
      "description": "aria-hidden to be passed to the empty state icon",
      "type": {
        "name": "bool"
      },
      "required": false
    }
  }
};
var EmptyState$1 = EmptyState;

module.exports = EmptyState$1;
