var _excluded = ["initialIsOpen", "onSelect", "options", "label"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }
import React from 'react';
import Select from 'react-select';
import { selectors } from '@defencedigital/design-tokens';
import styled from 'styled-components';
import { DropdownIndicator } from './DropdownIndicator';
import { DropdownLabel } from './DropdownLabel';
import { DropdownPlaceholder } from './DropdownPlaceholder';
var color = selectors.color,
  spacing = selectors.spacing;
var StyledSelect = styled(Select).withConfig({
  displayName: "Dropdown__StyledSelect",
  componentId: "sc-1vsx7iv-0"
})([".rn-dropdown__control{border-color:", ";}.rn-dropdown__control:after{content:'';min-height:inherit;font-size:0;}.rn-dropdown__placeholder{color:", ";}.rn-dropdown__control--is-focused{border-color:", ";box-shadow:0 0 0 1px ", ";}.rn-dropdown__control--menu-is-open{.rn-arrow{transform:rotate(180deg) translateY(1px);}.rn-arrow__fill{fill:", ";}}.rn-dropdown__dropdown-indicator{padding-left:(40px - 11px)/2;padding-right:(40px - 11px)/2;}.rn-dropdown__indicator-separator{display:none;}.rn-dropdown__menu{box-shadow:0 4px 16px rgba(0,0,0,0.1),0 1px 2px rgba(0,0,0,0.1);top:102%;margin:", " 0 0 5%;width:95%;}.rn-dropdown__menu-list{border:2px solid ", ";border-radius:4px;padding:", ";}.rn-dropdown__menu:before{display:block;border-style:solid;border-width:0 7px 7px;border-color:", " transparent;position:absolute;top:-7px;right:0.9rem;width:0;z-index:0;content:'';}.rn-dropdown__menu:after{display:block;border-style:solid;border-width:0 6px 6px;border-color:", " transparent;position:absolute;top:-3px;right:0.9rem;width:0;z-index:1;content:'';transform:translateX(-1px);}.rn-dropdown__option,.rn-dropdown__option--is-selected,.rn-dropdown__option--is-focused{color:", ";}.rn-dropdown__option{border-radius:4px;padding:", " ", ";}.rn-dropdown__option--is-selected{background-color:", ";}.rn-dropdown__option--is-focused,.rn-dropdown__option--is-focused.rn-dropdown__option--is-selected{background-color:", ";}.rn-dropdown__single-value .rn-dropdownlabel .rn-dropdownlabel__end-adornment{display:none;}"], color('neutral', '200'), color('neutral', '500'), color('action', '600'), color('action', '600'), color('action', '600'), spacing('6'), color('action', '600'), spacing('2'), color('action', '600'), color('neutral', 'white'), color('neutral', '500'), spacing('6'), spacing('4'), color('neutral', 'white'), color('neutral', '100'));
export var Dropdown = function Dropdown(_ref) {
  var initialIsOpen = _ref.initialIsOpen,
    onSelect = _ref.onSelect,
    options = _ref.options,
    label = _ref.label,
    rest = _objectWithoutProperties(_ref, _excluded);
  var onChange = function onChange(option) {
    var dropdownOption = option;
    onSelect === null || onSelect === void 0 ? void 0 : onSelect(dropdownOption.value);
  };
  return /*#__PURE__*/React.createElement(StyledSelect, _extends({
    "aria-label": label,
    classNamePrefix: "rn-dropdown",
    components: {
      DropdownIndicator: DropdownIndicator,
      Placeholder: DropdownPlaceholder
    },
    controlShouldRenderValue: false,
    defaultMenuIsOpen: initialIsOpen,
    formatOptionLabel: DropdownLabel,
    isSearchable: false,
    options: options,
    onChange: onChange,
    placeholder: label
  }, rest));
};