"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DeliveryInstructions = DeliveryInstructions;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _supportedCountries = require("../helpers/supportedCountries");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var spanMessageByCountry = {
  GBR: /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "For newspaper delivery, we can only deliver to the ground floor, so if you live in an apartment, we\u2019ll leave the newspaper at reception or by the entrance. We deliver in the early hours of the morning so our drivers won\u2019t be able to contact you or ring your doorbell."),
  USA: /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Please note we cannot guarantee delivery of the newspaper to a specific location on your property, which also includes delivery to a specific floor/suite in a building. US Federal Law prohibits delivery of newspapers into a mailbox, except via a USPS mail carrier. If you prefer delivery to a mailbox, please either select the \"PO Box\" delivery option from the top of this form, or contact \xA0", /*#__PURE__*/_react["default"].createElement("a", {
    href: "https://help.ft.com/contact/"
  }, "FT Customer Care"), "."),
  CAN: /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Please note we cannot guarantee delivery of the newspaper to a specific location on your property, which also includes delivery to a specific floor/suite in a building. If you prefer delivery by Canada Post, please either select the \"PO Box\" delivery option from the top of this form, or contact \xA0", /*#__PURE__*/_react["default"].createElement("a", {
    href: "https://help.ft.com/contact/"
  }, "FT Customer Care"), "."),
  CEMEA_V1: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Newspaper delivery is restricted to ground floor addresses. If you live in an apartment the newspaper will be left at reception or by the entrance. Delivery is made in the early hours making it sometimes difficult to identify the right delivery location or gaining access where letter boxes are inside a building."), /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Special characters including punctuation cannot be used in the delivery instructions."), /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "If you prefer delivery to a mailbox, please either select the \u201CPO Box\u201D delivery option from the top of this form, or contact\xA0", /*#__PURE__*/_react["default"].createElement("a", {
    href: "https://help.ft.com/contact/"
  }, "FT Customer Care"), ".")),
  CEMEA_V2: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Newspaper delivery is restricted to ground floor addresses. If you live in an apartment the newspaper will be left at reception or by the entrance. Delivery is made in the early hours making it sometimes difficult to identify the right delivery location or gaining access where letter boxes are inside a building."), /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Special characters including punctuation cannot be used in the delivery instructions."), /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "If you prefer delivery to a mailbox, please either select the \u201CPO Box\u201D delivery option from the top of this form, or contact\xA0", /*#__PURE__*/_react["default"].createElement("a", {
    href: "https://help.ft.com/contact/"
  }, "FT Customer Care"), ".")),
  APAC: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Newspaper delivery is restricted to ground floor addresses. If you live in an apartment the newspaper will be left at reception or by the entrance. Delivery is made in the early hours making it sometimes difficult to identify the right delivery location or gaining access where letter boxes are inside a building."), /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Special characters including punctuation cannot be used in the delivery instructions."), /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "If you prefer delivery to a mailbox, please either select the \u201CPO Box\u201D delivery option from the top of this form, or contact\xA0", /*#__PURE__*/_react["default"].createElement("a", {
    href: "https://help.ft.com/contact/"
  }, "FT Customer Care"), "."))
};
function DeliveryInstructions(_ref) {
  var _ref$fieldId = _ref.fieldId,
    fieldId = _ref$fieldId === void 0 ? 'deliveryInstructionsField' : _ref$fieldId,
    _ref$hasError = _ref.hasError,
    hasError = _ref$hasError === void 0 ? false : _ref$hasError,
    _ref$inputId = _ref.inputId,
    inputId = _ref$inputId === void 0 ? 'deliveryInstructions' : _ref$inputId,
    _ref$maxlength = _ref.maxlength,
    maxlength = _ref$maxlength === void 0 ? '' : _ref$maxlength,
    _ref$rows = _ref.rows,
    rows = _ref$rows === void 0 ? null : _ref$rows,
    _ref$isDisabled = _ref.isDisabled,
    isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
    _ref$placeholder = _ref.placeholder,
    placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? '' : _ref$value,
    country = _ref.country;
  var textAreaWrapperClassNames = (0, _classnames["default"])(['o-forms-input', 'o-forms-input--textarea', {
    'o-forms-input--invalid': hasError
  }]);
  var shippingZone = (0, _supportedCountries.identifyShippingZone)(country);
  var extraInstruction = country === 'GBR' ? '' : "\n- Special handling, e.g. place in plastic bag, 24/7 security on reception";
  var shippingZoneToPlaceholderMap = {
    CEMEA_V1: "Enter instructions ".concat(maxlength && "(Max. ".concat(maxlength, " characters)"), ":\n- Door colour, letterbox location\n- Door entry codes, etc."),
    CEMEA_V2: "Enter instructions ".concat(maxlength && "(Max. ".concat(maxlength, " characters)"), ":\n- Door colour, letterbox location\n- Door entry codes, etc."),
    GBR: "Enter instructions ".concat(maxlength && "(Max. ".concat(maxlength, " characters)"), ":\n- Door colour, letterbox location\n- Placement i.e. letterbox delivery").concat(extraInstruction),
    USA: "Enter instructions ".concat(maxlength && "(Max. ".concat(maxlength, " characters)"), ":\n- Door colour, driveway signage\n- Cross street").concat(extraInstruction),
    CAN: "Enter instructions ".concat(maxlength && "(Max. ".concat(maxlength, " characters)"), ":\n- Door colour, driveway signage\n- Cross street").concat(extraInstruction),
    DEFAULT: "Enter instructions ".concat(maxlength && "(Max. ".concat(maxlength, " characters)"), ":\n- Door colour, letterbox location\n- Door entry codes, etc.")
  };
  var textAreaProps = _objectSpread(_objectSpread(_objectSpread({
    id: inputId,
    name: inputId
  }, maxlength && {
    maxLength: maxlength
  }), rows && {
    rows: rows
  }), {}, {
    'data-trackable': 'field-deliveryInstructions',
    placeholder: placeholder || shippingZoneToPlaceholderMap[shippingZone],
    disabled: isDisabled,
    defaultValue: value
  });
  var deliveryInstructionsMessage = /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__prompt"
  }, "Special characters including punctuation cannot be used in the delivery instructions.");
  return /*#__PURE__*/_react["default"].createElement("label", {
    id: fieldId,
    className: "o-forms-field o-forms-field--optional",
    "data-validate": "required",
    htmlFor: inputId
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "o-forms-title__main"
  }, "Delivery instructions"), spanMessageByCountry[shippingZone], country === 'GBR' && deliveryInstructionsMessage), /*#__PURE__*/_react["default"].createElement("span", {
    className: textAreaWrapperClassNames
  }, /*#__PURE__*/_react["default"].createElement("textarea", textAreaProps)));
}
DeliveryInstructions.propTypes = {
  hasError: _propTypes["default"].bool,
  maxlength: _propTypes["default"].number,
  rows: _propTypes["default"].number,
  isDisabled: _propTypes["default"].bool,
  value: _propTypes["default"].string,
  country: _propTypes["default"].string.isRequired
};