"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.CheckoutAddressForm = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

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

var _lib = require("@sentecacommerce-theme/lib");

var _Common = require("../../../../../Common");

var _UI = require("../../../UI");

var _CheckoutDeliveryOptions = require("../CheckoutDeliveryOptions");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _templateObject;

var CheckoutAddressForm = function CheckoutAddressForm() {
  var _useCheckoutFormShipp = (0, _lib.useCheckoutFormShippingState)(),
      errors = _useCheckoutFormShipp.errors,
      onInputChange = _useCheckoutFormShipp.onInputChange,
      address = _useCheckoutFormShipp.data,
      isSavedAddressListEnabled = _useCheckoutFormShipp.isSavedAddressListEnabled,
      saveShippingAddress = _useCheckoutFormShipp.saveShippingAddress,
      updateIsAddingNew = _useCheckoutFormShipp.updateIsAddingNew,
      savedAddressList = _useCheckoutFormShipp.savedAddressList;

  var _useCheckoutErrorFiel = (0, _lib.useCheckoutErrorFields)(),
      errorRef = _useCheckoutErrorFiel.errorRef;

  var _useGlobalLabels = (0, _lib.useGlobalLabels)(),
      buttons = _useGlobalLabels.buttons;

  var labels = (0, _lib.useLocalLabels)();

  var onChange = function onChange(e) {
    onInputChange == null ? void 0 : onInputChange(e.target.name, e.target.value);
  };

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "d-flex mt-4 pt-2 justify-content-between align-items-center"
  }, /*#__PURE__*/_react["default"].createElement(_UI.CheckoutTitle, {
    className: "m-0 p-0",
    data: labels.chooseCourier
  }), Boolean(savedAddressList == null ? void 0 : savedAddressList.length) && isSavedAddressListEnabled && /*#__PURE__*/_react["default"].createElement(_Common.Button, {
    bordered: true,
    small: true,
    onClick: function onClick() {
      return updateIsAddingNew(false);
    }
  }, buttons.cancel))), /*#__PURE__*/_react["default"].createElement(_CheckoutDeliveryOptions.CheckoutSelectDeliveryOption, null), /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, /*#__PURE__*/_react["default"].createElement(_UI.CheckoutTitle, {
    className: "mb-0 mt-4 pt-2",
    data: labels.personalInfo
  })), /*#__PURE__*/_react["default"].createElement(DesktopHalf, null, /*#__PURE__*/_react["default"].createElement(_Common.TextInput, {
    value: (address == null ? void 0 : address.firstName) || '',
    onChange: onChange,
    id: "adbook-firstName",
    label: labels.firstNameLabel,
    name: "firstName",
    isRequired: true,
    errors: errors,
    inputSize: "normal",
    errorRef: errorRef
  })), /*#__PURE__*/_react["default"].createElement(DesktopHalf, null, /*#__PURE__*/_react["default"].createElement(_Common.TextInput, {
    value: (address == null ? void 0 : address.lastName) || '',
    onChange: onChange,
    id: "adbook-lastName",
    isRequired: true,
    label: labels.lastNameLabel,
    errors: errors,
    name: "lastName",
    inputSize: "normal",
    errorRef: errorRef
  })), /*#__PURE__*/_react["default"].createElement(DesktopHalf, null, /*#__PURE__*/_react["default"].createElement(_Common.TextInput, {
    value: (address == null ? void 0 : address.phoneNumber) || '',
    onChange: onChange,
    id: "adbook-phoneNumber",
    type: "number",
    isRequired: true,
    label: labels.phoneLabel,
    errors: errors,
    name: "phoneNumber",
    inputSize: "normal",
    errorRef: errorRef
  })), /*#__PURE__*/_react["default"].createElement(DesktopHalf, null, /*#__PURE__*/_react["default"].createElement(_Common.TextInput, {
    value: (address == null ? void 0 : address.email) || '',
    onChange: onChange,
    type: "email",
    id: "adbook-email",
    isRequired: true,
    label: labels.emailLabel,
    errors: errors,
    name: "email",
    inputSize: "normal",
    errorRef: errorRef
  })), isSavedAddressListEnabled && /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, /*#__PURE__*/_react["default"].createElement(_Common.Button, {
    type: "button",
    bordered: true,
    onClick: saveShippingAddress
  }, labels.saveAddress)));
};

exports.CheckoutAddressForm = CheckoutAddressForm;

var DesktopHalf = _styledComponents["default"].div.attrs({
  className: 'col-12'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])([""])));
//# sourceMappingURL=index.js.map