function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import classNames from 'classnames';
import React, { useMemo } from 'react';
import { locales } from '@pisell/utils';
import "./index.less";
var PREFIX = 'pisell-sale-detail-contact';
function normalizeContactInfo(value) {
  if (!value || Array.isArray(value) || _typeof(value) !== 'object') return null;
  if (!Object.keys(value).length) return null;
  return value;
}
export function Contact(_ref) {
  var _contact$phone;
  var dataSource = _ref.dataSource,
    className = _ref.className;
  var contact = useMemo(function () {
    return normalizeContactInfo(dataSource);
  }, [dataSource]);
  if (!contact) return null;
  var displayName = contact.display_name || [contact.first_name, contact.last_name].filter(Boolean).join(' ');
  var phone = (_contact$phone = contact.phone) !== null && _contact$phone !== void 0 && _contact$phone.phone ? "".concat(contact.phone.country_calling_code || '', " ").concat(contact.phone.phone).trim() : '';
  var isEmpty = !displayName && !phone && !contact.email;
  return /*#__PURE__*/React.createElement("section", {
    className: classNames('pisell-sale-detail-contact', className)
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__title")
  }, locales.getText('pisell2.sale-detail.contact-info')), /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__row")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__content-main")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__content")
  }, isEmpty ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__empty-description")
  }, locales.getText('pisell2.sale-detail.add-contact-info')) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__name-line")
  }, displayName ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__name")
  }, displayName) : null, phone ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__phone")
  }, "(", phone, ")") : null), contact.email ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__text")
  }, contact.email) : null))))));
}