"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

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

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

var _primitives = require("../../../primitives");

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

var _behaviors = require("../../behaviors");

var _typography = require("../../typography");

var _formList = require("../form-list");

var _branding = require("../../../mixins/branding");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

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

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); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var StyledFieldLabel = (0, _styledComponents["default"])(_typography.FieldLabel).withConfig({
  displayName: "StyledFieldLabel",
  componentId: "sc-1ktk893-0"
})(["&&{padding-bottom:14px;}"]);
var ListItemButton = (0, _styledComponents["default"])(_behaviors.UnstyledButton).withConfig({
  displayName: "ListItemButton",
  componentId: "sc-1ktk893-1"
})(["&&{width:100%;outline:none;min-height:inherit;opacity:1;transition:opacity 300ms ease;}&:active,&:disabled{opacity:0.5;}"]);

var ClickableListItemIcon = _styledComponents["default"].span.withConfig({
  displayName: "ClickableListItemIcon",
  componentId: "sc-1ktk893-2"
})(["height:35px;margin:0 20px 0 0;text-align:center;width:35px;border-radius:50%;background-color:", ";display:flex;align-items:center;justify-content:center;flex-direction:row;flex:0 0 35px;img{border-radius:50%;max-width:100%;}"], function (props) {
  return (0, _branding.getPaletteColor)(props.backgroundColor);
});

var ListItem = function ListItem(_ref) {
  var onClick = _ref.onClick,
      id = _ref.id,
      disabled = _ref.disabled,
      text = _ref.text,
      icon = _ref.icon;
  var handleClick = (0, _react.useCallback)(function () {
    onClick(id);
  }, [id, onClick]);
  return /*#__PURE__*/_react["default"].createElement(ListItemButton, {
    insetFocus: true,
    type: "submit",
    onClick: handleClick,
    disabled: disabled
  }, /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    spacing: ['pr1', 'pl3'],
    stacked: "row",
    align: "center",
    justify: "space-between"
  }, icon ? /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    align: "center",
    stacked: "row",
    justify: "space-between",
    grow: 1
  }, /*#__PURE__*/_react["default"].createElement(ClickableListItemIcon, {
    backgroundColor: icon.backgroundColor
  }, typeof icon.imgSrc === 'string' ? /*#__PURE__*/_react["default"].createElement("img", {
    src: icon.imgSrc,
    alt: icon.altText
  }) : icon.imgSrc), /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    grow: 1
  }, /*#__PURE__*/_react["default"].createElement(_typography.Span, {
    fontSize: "f2",
    bold: true
  }, text))) : /*#__PURE__*/_react["default"].createElement(_typography.Span, {
    fontSize: "f2",
    bold: true
  }, text), /*#__PURE__*/_react["default"].createElement(_icon.ChevronRight, null)));
};

var ClickableList = function ClickableList(_ref2) {
  var label = _ref2.label,
      options = _ref2.options,
      onClick = _ref2.onClick,
      disabled = _ref2.disabled,
      spacing = _ref2.spacing,
      className = _ref2.className,
      dataQa = _ref2['data-qa'],
      dataCy = _ref2['data-cy'],
      id = _ref2.id,
      stackeeProps = _objectWithoutProperties(_ref2, ["label", "options", "onClick", "disabled", "spacing", "className", "data-qa", "data-cy", "id"]);

  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, _extends({
    spacing: spacing
  }, stackeeProps, {
    className: className,
    "data-cy": dataCy,
    "data-qa": dataQa,
    id: id
  }), label != null && /*#__PURE__*/_react["default"].createElement(StyledFieldLabel, null, label), /*#__PURE__*/_react["default"].createElement(_formList.FormList, {
    items: options.map(function (option) {
      return /*#__PURE__*/_react["default"].createElement(ListItem, {
        id: option.id,
        key: option.id,
        text: option.text,
        onClick: onClick,
        disabled: disabled || option.disabled,
        icon: option.icon
      });
    })
  }));
};

exports.ClickableList = ClickableList;
ClickableList.displayName = 'ClickableList';