"use strict";

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

exports.__esModule = true;
exports.CheckoutInvoice = 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 _styledComponents = _interopRequireDefault(require("styled-components"));

var _Components = require("./Components");

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

var _templateObject;

var CheckoutInvoice = function CheckoutInvoice() {
  var _useCheckoutFormBilli = (0, _lib.useCheckoutFormBillingState)(),
      billingAddressList = _useCheckoutFormBilli.billingAddressList,
      updateIsWithBillingAddress = _useCheckoutFormBilli.updateIsWithBillingAddress,
      isWithBillingAddress = _useCheckoutFormBilli.isWithBillingAddress,
      canSaveBillingAddress = _useCheckoutFormBilli.canSaveBillingAddress,
      saveBillingAddress = _useCheckoutFormBilli.saveBillingAddress,
      isAddingNew = _useCheckoutFormBilli.isAddingNew,
      updateIsAddingNew = _useCheckoutFormBilli.updateIsAddingNew;

  var _useLocalLabels = (0, _lib.useLocalLabels)(),
      withInvoiceLabel = _useLocalLabels.withInvoiceLabel,
      cancelLabel = _useLocalLabels.cancelLabel,
      addNewCompanyLabel = _useLocalLabels.addNewCompanyLabel,
      chooseCompany = _useLocalLabels.chooseCompany,
      saveCompany = _useLocalLabels.saveCompany;

  var showForm = Boolean(isAddingNew || !(billingAddressList != null && billingAddressList.length));
  return /*#__PURE__*/_react["default"].createElement(InputsWrapper, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12",
    style: {}
  }, /*#__PURE__*/_react["default"].createElement(_Common.Checkbox, {
    size: "tiny",
    label: withInvoiceLabel,
    isChecked: Boolean(isWithBillingAddress),
    onChange: function onChange() {
      return updateIsWithBillingAddress(!isWithBillingAddress);
    }
  })), isWithBillingAddress && showForm && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Components.CheckoutCompanyForm, null), canSaveBillingAddress && /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "d-flex align-items-center"
  }, Boolean(billingAddressList == null ? void 0 : billingAddressList.length) && /*#__PURE__*/_react["default"].createElement("div", {
    className: "mr-2"
  }, /*#__PURE__*/_react["default"].createElement(_Common.Button, {
    variant: "light",
    bordered: true,
    small: true,
    type: "button",
    onClick: function onClick() {
      return updateIsAddingNew(false);
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "d-flex align-items-center"
  }, /*#__PURE__*/_react["default"].createElement("span", null, cancelLabel)))), /*#__PURE__*/_react["default"].createElement(_Common.Button, {
    small: true,
    type: "button",
    onClick: saveBillingAddress
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "d-flex align-items-center"
  }, /*#__PURE__*/_react["default"].createElement("span", null, saveCompany)))))), isWithBillingAddress && !showForm && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, /*#__PURE__*/_react["default"].createElement(_UI.CheckoutTitle, {
    className: "mb-3",
    data: chooseCompany
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, billingAddressList == null ? void 0 : billingAddressList.map(function (address) {
    return /*#__PURE__*/_react["default"].createElement(_Common.CompanyPreview, {
      data: address,
      isSelectable: true,
      onChange: address.select,
      isSelected: address.isSelected,
      key: address._id
    });
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12"
  }, /*#__PURE__*/_react["default"].createElement(_Common.Button, {
    variant: "primary",
    bordered: true,
    small: true,
    type: "button",
    onClick: function onClick() {
      return updateIsAddingNew(true);
    }
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "d-flex align-items-center"
  }, /*#__PURE__*/_react["default"].createElement(_Common.IconPlus, {
    width: "1.5rem",
    className: "mr-2"
  }), /*#__PURE__*/_react["default"].createElement("span", null, addNewCompanyLabel))))));
};

exports.CheckoutInvoice = CheckoutInvoice;

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