function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React from 'react';
import styled from 'styled-components';
import { Flexbox, Input, Typography, Icon, Button, Box } from '../..';
export var StyledButton = styled(Button).withConfig({
  displayName: "ControlsListItemSelectListItem__StyledButton",
  componentId: "sc-15u61xs-0"
})(["background:", ";"], function (t) {
  return t.theme.color.background;
});
export var StyledBox = styled(Box).withConfig({
  displayName: "ControlsListItemSelectListItem__StyledBox",
  componentId: "sc-15u61xs-1"
})(["cursor:", ";color:", ";background:", ";&:hover{background:", ";}"], function (p) {
  return p.disabled ? 'not-allowed' : 'pointer';
}, function (p) {
  return p.disabled ? p.theme.color.disabledText : 'inherit';
}, function (p) {
  return p.focused ? p.theme.color.background : p.theme.color.card;
}, function (p) {
  return !p.isKeyboardNavigation && !p.disabled ? p.theme.color.background : 'inherit';
});
var StyledFlexbox = styled(Flexbox).withConfig({
  displayName: "ControlsListItemSelectListItem__StyledFlexbox",
  componentId: "sc-15u61xs-2"
})(["width:100%;"]);
var ControlsListItemSelectListItem = function ControlsListItemSelectListItem(_ref) {
  var _selectedItem$2;
  var index = _ref.index,
    selectedItem = _ref.selectedItem,
    _ref$showCheckmark = _ref.showCheckmark,
    showCheckmark = _ref$showCheckmark === void 0 ? true : _ref$showCheckmark,
    _ref$justifyContent = _ref.justifyContent,
    justifyContent = _ref$justifyContent === void 0 ? 'space-between' : _ref$justifyContent;
  var _Input$Select$useSele = Input.Select.useSelectMachineFromContext(),
    _Input$Select$useSele2 = _slicedToArray(_Input$Select$useSele, 1),
    state = _Input$Select$useSele2[0];
  var option = state.context.visibleOptions[index];
  var isKeyboardNavigation = state.matches('interaction.enabled.active.navigation.keyboard');
  var disabled = state.context.options[index].disabled;
  var focused = isKeyboardNavigation && !disabled && state.context.itemFocusIdx === index;
  return React.createElement(StyledButton, {
    variant: "neutral",
    fullWidth: true,
    as: StyledBox
  }, React.createElement(StyledBox, {
    px: 3,
    py: 1,
    focused: focused,
    disabled: disabled,
    isKeyboardNavigation: isKeyboardNavigation
  }, React.createElement(Flexbox, {
    container: true,
    alignItems: "center"
  }, React.createElement(StyledFlexbox, {
    item: true,
    container: true,
    justifyContent: justifyContent,
    alignItems: "center"
  }, React.createElement(Flexbox, {
    item: true
  }, React.createElement(Typography, {
    whiteSpace: "nowrap",
    type: "secondary",
    color: function color(t) {
      var _selectedItem$;
      return option.value === (selectedItem === null || selectedItem === void 0 || (_selectedItem$ = selectedItem[0]) === null || _selectedItem$ === void 0 ? void 0 : _selectedItem$.value) ? t.color.quickFilterSelectedText : t.color.quickFilterText;
    }
  }, option.label)), showCheckmark && justifyContent !== 'flex-end' && React.createElement(Flexbox, {
    item: true
  }, option.value === (selectedItem === null || selectedItem === void 0 || (_selectedItem$2 = selectedItem[0]) === null || _selectedItem$2 === void 0 ? void 0 : _selectedItem$2.value) && React.createElement(Icon.Check16, {
    color: function color(t) {
      return t.color.quickFilterSelectedText;
    }
  }))))));
};
export default ControlsListItemSelectListItem;