"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 _behaviors = require("../../behaviors");

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

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

var StyledFieldLabel = (0, _styledComponents["default"])(_typography.FieldLabel).withConfig({
  displayName: "StyledFieldLabel",
  componentId: "l6qcsg-0"
})(["&&{padding-bottom:14px;}"]);
var ListItemButton = (0, _styledComponents["default"])(_behaviors.UnstyledButton).withConfig({
  displayName: "ListItemButton",
  componentId: "l6qcsg-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: "l6qcsg-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;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 _react["default"].createElement(ListItemButton, {
    insetFocus: true,
    type: "submit",
    onClick: handleClick,
    disabled: disabled
  }, _react["default"].createElement(_primitives.Box, {
    spacing: ['pr1', 'pl3'],
    stacked: "row",
    align: "center",
    justify: "space-between"
  }, icon ? _react["default"].createElement(_primitives.Box, {
    align: "center",
    stacked: "row",
    justify: "space-between"
  }, _react["default"].createElement(ClickableListItemIcon, {
    backgroundColor: icon.backgroundColor
  }, typeof icon.imgSrc === 'string' ? _react["default"].createElement("img", {
    src: icon.imgSrc,
    alt: icon.altText
  }) : icon.imgSrc), _react["default"].createElement(_typography.Span, {
    fontSize: "f2",
    fontFace: "sans",
    bold: true
  }, text)) : _react["default"].createElement(_typography.Span, {
    fontSize: "f2",
    fontFace: "sans",
    bold: true
  }, text), _react["default"].createElement(_icon.ChevronRight, {
    justify: "end"
  })));
};

var ClickableList = function ClickableList(_ref2) {
  var label = _ref2.label,
      options = _ref2.options,
      onClick = _ref2.onClick,
      disabled = _ref2.disabled;
  return _react["default"].createElement(_primitives.Box, null, _react["default"].createElement(StyledFieldLabel, null, label), _react["default"].createElement(_formList.FormList, {
    items: options.map(function (option) {
      return _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';