'use strict';

var slicedToArray = require('./slicedToArray-5d1bc3b3.js');
var React = require('react');
var Form = require('react-bootstrap/Form');
var FormControl = require('react-bootstrap/FormControl');
var Button = require('react-bootstrap/Button');
require('./_commonjsHelpers-06173234.js');
require('./web.dom.iterable-46657b5c.js');
require('./es6.string.iterator-c2573ffd.js');
require('./_to-object-6de10e57.js');
require('./core.get-iterator-method-f474eacc.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var Form__default = /*#__PURE__*/_interopDefaultLegacy(Form);
var FormControl__default = /*#__PURE__*/_interopDefaultLegacy(FormControl);
var Button__default = /*#__PURE__*/_interopDefaultLegacy(Button);

var Search = function Search(props) {
  var _props$placeholder = props.placeholder,
      placeholder = _props$placeholder === undefined ? 'Search' : _props$placeholder,
      _props$btnText = props.btnText,
      btnText = _props$btnText === undefined ? 'Search' : _props$btnText,
      _props$device = props.device,
      device = _props$device === undefined ? 'desktop' : _props$device;

  var _useState = React.useState(''),
      _useState2 = slicedToArray._slicedToArray(_useState, 2),
      searchKey = _useState2[0],
      setSearchKey = _useState2[1];

  var submitSearch = function submitSearch(e) {
    e.preventDefault();
    window.location.href = '/search?searchTerm=' + searchKey;
  };

  return React__default['default'].createElement(
    Form__default['default'],
    { inline: true, onSubmit: function onSubmit(e) {
        return submitSearch(e);
      } },
    React__default['default'].createElement(FormControl__default['default'], {
      className: device === 'mobile' ? 'mobile-search mr-sm-2' : 'mr-sm-2',
      type: 'text',
      placeholder: placeholder,
      value: searchKey,
      onChange: function onChange(e) {
        return setSearchKey(e.target.value);
      }
    }),
    React__default['default'].createElement(
      Button__default['default'],
      { variant: 'secondary', onClick: function onClick(e) {
          return submitSearch(e);
        } },
      btnText
    ),
    React__default['default'].createElement(
      'style',
      { jsx: 'true' },
      '\n        .mobile-search {\n          width: 75%;\n          margin-right: 15px;\n        }\n      '
    )
  );
};

module.exports = Search;
