"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ComplexResponsiveForm = exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _textInput = require("./text-input");

var _datepicker = require("../../one-off/datepicker");

var _select = require("./select");

var _option = require("./select/option");

var _searchInput = require("./search-input");

var _fieldSet = require("./field-set");

var _primitives = require("../../primitives");

var _text = require("../typography/text");

var _formRecipes = _interopRequireDefault(require("./form-recipes.mdx"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var _default = {
  title: 'Recipes/Forms',
  parameters: {
    docs: {
      page: _formRecipes["default"]
    }
  }
};
exports["default"] = _default;
var allSearchResults = [{
  id: 'ca',
  text: 'Canada'
}, {
  id: 'fr',
  text: 'France'
}, {
  id: 'de',
  text: 'Germany'
}, {
  id: 'it',
  text: 'Italy'
}, {
  id: 'jp',
  text: 'Japan'
}, {
  id: 'cn',
  text: "People's Republic of China"
}, {
  id: 'ir',
  text: 'Republic of Ireland'
}, {
  id: 'uae',
  text: 'United Arab Emirates'
}, {
  id: 'uk',
  text: 'United Kingdom'
}, {
  id: 'us',
  text: 'United States of America'
}];

var getSearchResults = function getSearchResults(searchText) {
  if (searchText == null) return [];
  var regex = new RegExp(searchText, 'i');
  return allSearchResults.filter(function (result) {
    return result.text.match(regex);
  });
};

var FormSection = function FormSection(_ref) {
  var label = _ref.label,
      children = _ref.children;
  return /*#__PURE__*/_react["default"].createElement(_fieldSet.FieldSet, {
    label: label,
    spacing: "mb1"
  }, children);
};

var FormRow = function FormRow(_ref2) {
  var children = _ref2.children;
  return /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    stacked: {
      sm: 'column',
      md: 'row'
    },
    align: {
      sm: 'stretch',
      md: 'center'
    },
    spacing: "mb1"
  }, children);
};

var ComplexResponsiveForm = function ComplexResponsiveForm() {
  var _useState = (0, _react.useState)(),
      _useState2 = _slicedToArray(_useState, 2),
      givenName = _useState2[0],
      setGivenName = _useState2[1];

  var _useState3 = (0, _react.useState)(),
      _useState4 = _slicedToArray(_useState3, 2),
      middleNames = _useState4[0],
      setMiddleNames = _useState4[1];

  var _useState5 = (0, _react.useState)(),
      _useState6 = _slicedToArray(_useState5, 2),
      familyName = _useState6[0],
      setFamilyName = _useState6[1];

  var _useState7 = (0, _react.useState)(),
      _useState8 = _slicedToArray(_useState7, 2),
      streetNameAndNumber = _useState8[0],
      setStreetNameAndNumber = _useState8[1];

  var _useState9 = (0, _react.useState)(),
      _useState10 = _slicedToArray(_useState9, 2),
      unit = _useState10[0],
      setUnit = _useState10[1];

  var _useState11 = (0, _react.useState)(),
      _useState12 = _slicedToArray(_useState11, 2),
      city = _useState12[0],
      setCity = _useState12[1];

  var _useState13 = (0, _react.useState)(),
      _useState14 = _slicedToArray(_useState13, 2),
      postalCode = _useState14[0],
      setPostalCode = _useState14[1];

  var _useState15 = (0, _react.useState)(),
      _useState16 = _slicedToArray(_useState15, 2),
      province = _useState16[0],
      setProvince = _useState16[1];

  var _useState17 = (0, _react.useState)(),
      _useState18 = _slicedToArray(_useState17, 2),
      countrySearchInput = _useState18[0],
      setCountrySearchInput = _useState18[1];

  var _useState19 = (0, _react.useState)(),
      _useState20 = _slicedToArray(_useState19, 2),
      country = _useState20[0],
      setCountry = _useState20[1];

  var _useState21 = (0, _react.useState)(),
      _useState22 = _slicedToArray(_useState21, 2),
      someMoney = _useState22[0],
      setSomeMoney = _useState22[1];

  var _useState23 = (0, _react.useState)(),
      _useState24 = _slicedToArray(_useState23, 2),
      birthdate = _useState24[0],
      setBirthdate = _useState24[1];

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(FormSection, {
    label: "Full Legal Name"
  }, /*#__PURE__*/_react["default"].createElement(FormRow, null, /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 1
    },
    spacing: {
      sm: 'mb1',
      md: 'mr1'
    },
    name: "givenName",
    placeholder: "Given name",
    label: "Given name",
    value: givenName,
    onChange: setGivenName
  }), /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 8
    },
    spacing: {
      sm: 'mb1',
      md: 'mr1'
    },
    name: "middleNames",
    placeholder: "Middle names",
    label: "Middle names",
    value: middleNames,
    onChange: setMiddleNames
  }), /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 1
    },
    name: "familyName",
    placeholder: "Family name",
    label: "Family name",
    value: familyName,
    onChange: setFamilyName
  }))), /*#__PURE__*/_react["default"].createElement(FormSection, {
    label: "Residential Address"
  }, /*#__PURE__*/_react["default"].createElement(FormRow, null, /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 9
    },
    spacing: {
      sm: 'mb1',
      md: 'mr1'
    },
    name: "streetNameAndNumber",
    placeholder: "Street name and number",
    label: "Street name and number",
    value: streetNameAndNumber,
    onChange: setStreetNameAndNumber
  }), /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 1
    },
    name: "unit",
    placeholder: "Unit",
    label: "Unit",
    value: unit,
    onChange: setUnit
  })), /*#__PURE__*/_react["default"].createElement(FormRow, null, /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 9
    },
    spacing: {
      sm: 'mb1',
      md: 'mr1'
    },
    name: "city",
    placeholder: "City",
    label: "City",
    value: city,
    onChange: setCity
  }), /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 1
    },
    spacing: {
      sm: 'mb1'
    },
    name: "postalCode",
    placeholder: "Postal code",
    label: "Postal code",
    value: postalCode,
    onChange: setPostalCode
  })), /*#__PURE__*/_react["default"].createElement(FormRow, null, /*#__PURE__*/_react["default"].createElement(_select.Select, {
    grow: {
      md: 1
    },
    basis: {
      md: 0
    },
    spacing: {
      sm: 'mb1',
      md: 'mr1'
    },
    placeholder: "Province",
    label: "Province",
    value: province,
    onChange: setProvince
  }, /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "on"
  }, "Ontario"), /*#__PURE__*/_react["default"].createElement(_option.Option, {
    value: "nl"
  }, "Newfoundland and Labrador")), /*#__PURE__*/_react["default"].createElement(_searchInput.SearchInput, {
    grow: {
      md: 1
    },
    basis: {
      md: 0
    },
    placeholder: "Country",
    label: "Country",
    value: country,
    searchInput: countrySearchInput,
    onChange: setCountrySearchInput,
    onSearchResultClicked: function onSearchResultClicked(id, value) {
      setCountry(value);
      setCountrySearchInput();
    },
    searchResults: getSearchResults(countrySearchInput)
  }))), /*#__PURE__*/_react["default"].createElement(FormSection, {
    label: "Other Stuff"
  }, /*#__PURE__*/_react["default"].createElement(FormRow, null, /*#__PURE__*/_react["default"].createElement(_textInput.TextInput, {
    grow: {
      md: 1
    },
    shrink: {
      md: 0
    },
    spacing: {
      sm: 'mb1',
      md: 'mr1'
    },
    name: "someMoney",
    placeholder: "200",
    type: "currency",
    label: "Some money",
    value: someMoney,
    onChange: setSomeMoney
  }), /*#__PURE__*/_react["default"].createElement(_datepicker.Datepicker, {
    grow: {
      md: 1
    },
    shrink: {
      md: 0
    },
    name: "birthdate",
    label: "Birthdate",
    value: birthdate,
    onChange: setBirthdate
  }))), /*#__PURE__*/_react["default"].createElement(_primitives.Box, {
    spacing: "p2"
  }, /*#__PURE__*/_react["default"].createElement(_text.Text, {
    bold: true
  }, "You entered:"), /*#__PURE__*/_react["default"].createElement(_text.Text, null, givenName, " ", middleNames, " ", familyName), /*#__PURE__*/_react["default"].createElement(_text.Text, null, streetNameAndNumber, " ", unit), /*#__PURE__*/_react["default"].createElement(_text.Text, null, city, " ", province, " ", postalCode), /*#__PURE__*/_react["default"].createElement(_text.Text, null, country), /*#__PURE__*/_react["default"].createElement(_text.Text, null, someMoney), /*#__PURE__*/_react["default"].createElement(_text.Text, null, birthdate ? birthdate.toString() : null)));
};

exports.ComplexResponsiveForm = ComplexResponsiveForm;