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); }
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) { _defineProperty(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; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useContext, useEffect } from 'react';
import { locales } from '@pisell/utils';
import ContactInfo from "../../../../../plus/contactInfo";
import { Context } from "../../../info/model";
var ContactInfoMode = function ContactInfoMode() {
  var _state$client$value6, _state$contacts_info3, _state$contacts_info4;
  var _useContext = useContext(Context),
    state = _useContext.state,
    dispatch = _useContext.dispatch;
  console.log('state>>>>>>>>>', state);
  useEffect(function () {
    var _state$contacts_info, _state$client$value, _state$client$value2, _state$contacts_info2;
    // 如果客户id发生变化，则获取客户信息中的ContactInfo，如果不存在，则使用客户信息填充ContactInfo
    console.log('state>>>>>>>>>111', state === null || state === void 0 || (_state$contacts_info = state.contacts_info) === null || _state$contacts_info === void 0 ? void 0 : _state$contacts_info.client_id);
    console.log('state>>>>>>>>>222', (_state$client$value = state.client.value) === null || _state$client$value === void 0 ? void 0 : _state$client$value.id);
    if (((_state$client$value2 = state.client.value) === null || _state$client$value2 === void 0 ? void 0 : _state$client$value2.id) != (state === null || state === void 0 || (_state$contacts_info2 = state.contacts_info) === null || _state$contacts_info2 === void 0 ? void 0 : _state$contacts_info2.client_id)) {
      var _state$client$value3;
      var contactInfo = (_state$client$value3 = state.client.value) === null || _state$client$value3 === void 0 || (_state$client$value3 = _state$client$value3.contacts_info) === null || _state$client$value3 === void 0 ? void 0 : _state$client$value3.value;
      if (!contactInfo) {
        var _state$client, _state$client$value4;
        var _ref = ((_state$client = state.client) === null || _state$client === void 0 ? void 0 : _state$client.value) || {},
          first_name = _ref.first_name,
          last_name = _ref.last_name,
          phone = _ref.phone,
          country_calling_code = _ref.country_calling_code,
          country_code = _ref.country_code,
          email = _ref.email;
        dispatch({
          type: 'setContactsInfo',
          payload: {
            value: {
              first_name: first_name || '',
              last_name: last_name || '',
              phone: {
                phone: phone || '',
                country_calling_code: country_calling_code || '',
                country_code: country_code || ''
              },
              email: email || ''
            },
            client_id: (_state$client$value4 = state.client.value) === null || _state$client$value4 === void 0 ? void 0 : _state$client$value4.id
          }
        });
      } else {
        var _state$client$value5;
        dispatch({
          type: 'setContactsInfo',
          payload: {
            value: _objectSpread({}, contactInfo || {}),
            client_id: (_state$client$value5 = state.client.value) === null || _state$client$value5 === void 0 ? void 0 : _state$client$value5.id
          }
        });
      }
    }
  }, [(_state$client$value6 = state.client.value) === null || _state$client$value6 === void 0 ? void 0 : _state$client$value6.id, state === null || state === void 0 || (_state$contacts_info3 = state.contacts_info) === null || _state$contacts_info3 === void 0 ? void 0 : _state$contacts_info3.client_id]);
  var handleSave = function handleSave(value) {
    dispatch({
      type: 'setContactsInfo',
      payload: {
        value: value,
        edit: true
      }
    });
  };
  return /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: '24px'
    }
  }, /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-contact-info-title",
    style: {
      fontSize: '16px',
      fontWeight: 500,
      marginBottom: '8px'
    }
  }, locales.getText('pisell2.booking.text.contact-info.title')), /*#__PURE__*/React.createElement(ContactInfo, {
    dataSource: ((_state$contacts_info4 = state.contacts_info) === null || _state$contacts_info4 === void 0 ? void 0 : _state$contacts_info4.value) || null,
    isShowDelete: false,
    isShowAvatar: false,
    isShowPhone: true,
    isShowEmail: true,
    style: {
      padding: '14px 0 14px 14px'
    },
    onSave: handleSave
  }));
};
export default ContactInfoMode;