"use strict";

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

var _react = _interopRequireDefault(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 _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 getBorderRadius = function getBorderRadius(_ref) {
  var theme = _ref.theme,
      isFirst = _ref.isFirst,
      isLast = _ref.isLast;
  if (isFirst) return "".concat(theme.cardBorderRadius, " ").concat(theme.cardBorderRadius, " 0 0");
  return isLast ? "0 0 ".concat(theme.cardBorderRadius, " ").concat(theme.cardBorderRadius) : undefined;
};

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"
})(["border-radius:", ";&&{width:100%;outline:none;min-height:60px;}&:disabled{color:", ";}&:hover:not(:disabled):not(:active){background:", ";}"], getBorderRadius, (0, _branding.getPaletteColor)('greyscale-dark'), (0, _branding.getPaletteColor)('background'));

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 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,
      props = _objectWithoutProperties(_ref2, ["label", "options", "onClick", "disabled", "spacing", "className", "data-qa", "data-cy", "id"]);

  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, _extends({
    spacing: spacing
  }, props, {
    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, i) {
      return /*#__PURE__*/_react["default"].createElement(ListItemButton, {
        insetFocus: true,
        type: "submit",
        onClick: function onClick() {
          return _onClick(option.id);
        },
        disabled: disabled || option.disabled,
        spacing: ['pr1', 'pl3'],
        stacked: "row",
        align: "center",
        justify: "space-between",
        isFirst: i === 0,
        isLast: i === options.length - 1
      }, option.icon ? /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
        align: "center",
        stacked: "row",
        justify: "space-between",
        grow: 1
      }, /*#__PURE__*/_react["default"].createElement(ClickableListItemIcon, {
        backgroundColor: option.icon.backgroundColor
      }, typeof option.icon.imgSrc === 'string' ? /*#__PURE__*/_react["default"].createElement("img", {
        src: option.icon.imgSrc,
        alt: option.icon.altText
      }) : option.icon.imgSrc), /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
        grow: 1
      }, /*#__PURE__*/_react["default"].createElement(_typography.Span, {
        fontSize: "f2",
        bold: true
      }, option.text))) : /*#__PURE__*/_react["default"].createElement(_typography.Span, {
        fontSize: "f2",
        bold: true
      }, option.text), /*#__PURE__*/_react["default"].createElement(_icon.ChevronRight, null));
    })
  }));
};

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