"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

exports.__esModule = true;
exports.ActionsContainer = exports.CompanyPreview = void 0;

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

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

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

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

var _EditCompanyModal = require("../EditCompanyModal");

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

var _Element = require("../../../Profile/Components/Vouchers/Element");

var _templateObject, _templateObject2, _templateObject3, _templateObject4;

var CompanyPreview = function CompanyPreview(_ref) {
  var _data$company, _data$company2, _data$company3, _data$company4;

  var data = _ref.data,
      isSelectable = _ref.isSelectable,
      isSelected = _ref.isSelected,
      onChange = _ref.onChange;

  var _useState = (0, _react.useState)(false),
      showModal = _useState[0],
      setShowModal = _useState[1];

  var _companiesApi$useRemo = _lib.companiesApi.useRemove(function () {
    return setShowModal(false);
  }),
      handleDelete = _companiesApi$useRemo[0];

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

  var handleEditClick = function handleEditClick(e) {
    e.stopPropagation();
    setShowModal(true);
  };

  var handleDeleteClick = function handleDeleteClick(e) {
    e.stopPropagation();
    handleDelete({
      id: data._id
    });
  };

  return /*#__PURE__*/_react["default"].createElement(Container, {
    onClick: onChange ? function () {
      return onChange(data);
    } : undefined,
    isSelectable: isSelectable,
    isSelected: isSelected
  }, /*#__PURE__*/_react["default"].createElement(_Common.ProfileElementContainer, null, showModal && /*#__PURE__*/_react["default"].createElement(_EditCompanyModal.EditCompanyModal, {
    handleClose: function handleClose() {
      return setShowModal(false);
    },
    queryData: data
  }), /*#__PURE__*/_react["default"].createElement(_Common.ProfileElementWrapper, null, /*#__PURE__*/_react["default"].createElement(_Common.ProfileElementContentContainer, null, /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.companyName), " ", (_data$company = data.company) == null ? void 0 : _data$company.companyName), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.vatNumber), " ", (_data$company2 = data.company) == null ? void 0 : _data$company2.vatId), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.companyId), " ", (_data$company3 = data.company) == null ? void 0 : _data$company3.companyId), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.recipient), " ", (_data$company4 = data.company) == null ? void 0 : _data$company4.companyPerson), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.city), " ", data.city), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.street), " ", data.streetName, ' ', data.streetNumber), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement(_Element.Label, null, company.zipCode, " "), " ", data.postalCode)), !isSelectable && /*#__PURE__*/_react["default"].createElement(ActionsContainer, null, /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Element.CTALabel, {
    onClick: handleEditClick
  }, buttons.edit), /*#__PURE__*/_react["default"].createElement(_Element.CTALabel, {
    onClick: handleDeleteClick
  }, buttons["delete"]))))));
};

exports.CompanyPreview = CompanyPreview;
var ActionsContainer = (0, _styledComponents["default"])(_Common.ProfileElementActionsContainer)(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  transition: all 0.3s ease;\n  @media (max-width: ", ") {\n    width: 34% !important;\n    margin-bottom: 2rem;\n  }\n"])), function (_ref2) {
  var theme = _ref2.theme;
  return theme.breakpoints.sm.max;
});
exports.ActionsContainer = ActionsContainer;

var Container = _styledComponents["default"].div.attrs(function (props) {
  return {
    className: props.isSelectable ? 'pl-4 ml-2' : ''
  };
})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  ", "\n"])), function (props) {
  return props.isSelectable && (0, _styledComponents.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n      position: relative;\n      cursor: pointer;\n\n      &:after {\n        content: '';\n        display: block;\n        width: 1.8rem;\n        height: 1.8rem;\n        border: 0.2rem solid ", ";\n        border-radius: 50%;\n\n        position: absolute;\n        left: -0.4rem;\n        top: 0.6rem;\n      }\n\n      ", "\n    "])), function (_ref3) {
    var theme = _ref3.theme;
    return theme.palette.primary;
  }, props.isSelected && (0, _styledComponents.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2["default"])(["\n        &:before {\n          content: '';\n          display: block;\n          width: 0.8rem;\n          height: 0.8rem;\n          background-color: ", ";\n          border-radius: 50%;\n\n          position: absolute;\n          left: 0.1rem;\n          top: 1.1rem;\n        }\n      "])), function (_ref4) {
    var theme = _ref4.theme;
    return theme.palette.primary;
  }));
});
//# sourceMappingURL=index.js.map