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, { useRef, useState } from 'react';
import { Typography, Flag, Flexbox, FormField, Button, Box } from '../..';
import { Display } from '../../common/Display';
import { Select } from '.';
var options = [{
  label: 'Red is the best color according to scientific research',
  value: '#Red is the best color according to scientific research'
}, {
  label: 'Green',
  value: '#4CAF50'
}, {
  label: 'Blue',
  value: '#2196F3'
}];
var otherOptions = [{
  label: 'First option',
  value: '1'
}, {
  label: 'second',
  value: '2'
}, {
  label: 'third',
  value: '3'
}];
var countryOptions = [{
  label: 'Sweden',
  value: 'se'
}, {
  label: 'Norway',
  value: 'no'
}, {
  label: 'Denmark',
  value: 'dk'
}, {
  label: 'Finland',
  value: 'fi'
}];
var meta = {
  component: Select,
  title: 'Molecules/Select'
};
export default meta;
export var Primary = function Primary() {
  return React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option..."
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  }));
};
export var DefaultValue = function DefaultValue() {
  return React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option...",
    defaultValue: options[0].value
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  }));
};
export var CustomOption = function CustomOption() {
  return React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a country..."
  }, countryOptions.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    }, React.createElement(Flexbox, {
      container: true,
      alignItems: "center",
      gap: 2
    }, React.createElement(Flexbox, {
      item: true
    }, React.createElement(Flag, {
      country: option.value,
      size: "m"
    })), React.createElement(Flexbox, {
      item: true
    }, React.createElement(Typography, {
      type: "primary"
    }, option.label))));
  }));
};
export var DifferentSizes = function DifferentSizes() {
  return React.createElement(Display, {
    items: [{
      title: 'Default (medium) size',
      component: React.createElement(Select, {
        name: "my-select",
        size: "m",
        placeholder: "Select a option..."
      }, options.map(function (option) {
        return React.createElement(Select.Option, {
          key: "".concat(option.value, "-m"),
          value: option.value,
          label: option.label
        });
      }))
    }, {
      title: 'Small size',
      component: React.createElement(Select, {
        name: "my-small-select",
        size: "s",
        placeholder: "Select a option..."
      }, options.map(function (option) {
        return React.createElement(Select.Option, {
          key: "".concat(option.value, "-s"),
          value: option.value,
          label: option.label
        });
      }))
    }]
  });
};
export var DifferentWidths = function DifferentWidths() {
  return React.createElement(Display, {
    items: [{
      title: '75 units wide',
      component: React.createElement(Select, {
        name: "my-select",
        placeholder: "Select a option...",
        width: 75
      }, options.map(function (option) {
        return React.createElement(Select.Option, {
          key: "".concat(option.value, "-m"),
          value: option.value,
          label: option.label
        });
      }))
    }, {
      title: 'Full width',
      component: React.createElement(Select, {
        name: "my-full-width-select",
        placeholder: "Select a option...",
        fullWidth: true
      }, options.map(function (option) {
        return React.createElement(Select.Option, {
          key: "".concat(option.value, "-s"),
          value: option.value,
          label: option.label
        });
      }))
    }]
  });
};
export var WithFormField = function WithFormField() {
  return React.createElement(FormField, {
    label: "Label",
    required: true,
    extraInfo: "Extra info"
  }, React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option..."
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  })));
};
export var WithError = function WithError() {
  return React.createElement(FormField, {
    error: "Error message",
    label: "Label"
  }, React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option...",
    hasError: true
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  })));
};
export var Disabled = function Disabled() {
  return React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option...",
    disabled: true
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  }));
};
export var GroupedOptions = function GroupedOptions() {
  return React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option..."
  }, React.createElement(Select.Group, {
    label: "First Group"
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  })), React.createElement(Select.Group, {
    label: "Second Group"
  }, otherOptions.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  })));
};
export var MultiSelectUnControlled = function MultiSelectUnControlled() {
  return React.createElement(Select, {
    name: "my-select",
    multiple: true
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label,
      multiple: true
    });
  }));
};
export var MultiSelect = function MultiSelect() {
  var _useState = useState(0),
    _useState2 = _slicedToArray(_useState, 2),
    selectedCount = _useState2[0],
    setSelectedCount = _useState2[1];
  return React.createElement(Select, {
    name: "my-select",
    multiple: true,
    onChange: function onChange(e, value) {
      return setSelectedCount(value ? value.length : 0);
    },
    valueDisplay: React.createElement(Select.ValueDisplayMultiSelect, {
      label: selectedCount > 1 ? 'Colors' : 'Color',
      placeholder: "Select a value...",
      selectedCount: selectedCount
    })
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label,
      multiple: true
    });
  }));
};
export var MultiSelectWithGroupedOptions = function MultiSelectWithGroupedOptions() {
  var _useState3 = useState(0),
    _useState4 = _slicedToArray(_useState3, 2),
    selectedCount = _useState4[0],
    setSelectedCount = _useState4[1];
  return React.createElement(Select, {
    name: "my-select",
    multiple: true,
    placeholder: "Select a option...",
    onChange: function onChange(e, value) {
      return setSelectedCount(value ? value.length : 0);
    },
    valueDisplay: React.createElement(Select.ValueDisplayMultiSelect, {
      label: selectedCount > 1 ? 'Colors' : 'Color',
      placeholder: "Select a value...",
      selectedCount: selectedCount
    })
  }, React.createElement(Select.Group, {
    label: "First Group"
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label,
      multiple: true
    });
  })), React.createElement(Select.Group, {
    label: "Second Group"
  }, otherOptions.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label,
      multiple: true
    });
  })));
};
export var WithForwardedRef = function WithForwardedRef() {
  var buttonRef = useRef(null);
  var focusButton = function focusButton() {
    var _buttonRef$current;
    (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 || _buttonRef$current.focus();
  };
  return React.createElement("div", null, React.createElement(Button, {
    onClick: focusButton
  }, "Focus"), React.createElement(Box, {
    mt: 2
  }, React.createElement(Select, {
    name: "my-select",
    placeholder: "Select a option...",
    ref: buttonRef
  }, options.map(function (option) {
    return React.createElement(Select.Option, {
      key: option.value,
      value: option.value,
      label: option.label
    });
  }))));
};