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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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, { useCallback, useMemo } from 'react';
import { getServiceTime } from "../../utils";
import Divider from "../Divider";
import Like from "./components/Like";
import SelectResource from "./components/SelectResource";
import SelectHolder from "./components/SelectHolder";
import "./index.less";
import SelectHolderMultiple from "./components/SelectHolderMultiple";
var prefix = 'pisell-lowcode-';
var Time = function Time(_ref) {
  var item = _ref.item,
    isShowHolder = _ref.isShowHolder,
    _onLike = _ref.onLike,
    isShowChangeResource = _ref.isShowChangeResource,
    changeResource = _ref.changeResource,
    changeHolder = _ref.changeHolder,
    isShowChangeHolder = _ref.isShowChangeHolder,
    holderMode = _ref.holderMode,
    onAddHolder = _ref.onAddHolder,
    isShowAddHolderButton = _ref.isShowAddHolderButton,
    onClearHolder = _ref.onClearHolder,
    onClearResource = _ref.onClearResource;
  var start_date = item.start_date,
    end_date = item.end_date,
    holder_title = item.holder_title,
    resource_id = item.resource_id,
    relation_form_name = item.relation_form_name,
    like_status = item.like_status,
    resources = item.resources,
    is_hide_like = item.is_hide_like,
    holder_id = item.holder_id,
    holders = item.holders,
    multiResources = item.multiResources,
    addHolderButtonText = item.addHolderButtonText,
    isErrorHolder = item.isErrorHolder,
    allowClearHolder = item.allowClearHolder,
    allowClearResource = item.allowClearResource,
    isErrorResource = item.isErrorResource,
    resourceErrorText = item.resourceErrorText,
    isMultipleResource = item.isMultipleResource,
    _item$isShowChangeHol = item.isShowChangeHolder,
    itemIsShowChangeHolder = _item$isShowChangeHol === void 0 ? true : _item$isShowChangeHol,
    itemHolderMode = item.holderMode,
    holderMaxCount = item.holderMaxCount;
  var holderCom = useMemo(function () {
    if (!isShowHolder) return null;

    // 可以控制选择holder
    if (isShowChangeHolder && itemIsShowChangeHolder) {
      var Cpt = (itemHolderMode || holderMode) === 'multiple' ? SelectHolderMultiple : SelectHolder;
      return /*#__PURE__*/React.createElement(Cpt, {
        holderMaxCount: holderMaxCount,
        lists: holders,
        value: holder_id,
        onChange: changeHolder,
        holderMode: itemHolderMode || holderMode,
        isShowAddHolderButton: isShowAddHolderButton,
        onAddHolder: onAddHolder,
        addHolderButtonText: addHolderButtonText,
        onClearHolder: onClearHolder,
        isErrorHolder: isErrorHolder,
        allowClear: allowClearHolder
      });
    }
    if (holder_title) {
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefix, "product-holder-wrap")
      }, holder_title);
    }
  }, [isShowHolder, holder_id, holder_title, holderMode, holders, isShowAddHolderButton, isShowChangeHolder, isErrorHolder, addHolderButtonText, allowClearHolder, itemIsShowChangeHolder, itemHolderMode, holderMaxCount]);
  var likeCom = useCallback(function (status, item) {
    return /*#__PURE__*/React.createElement(Like, {
      isShowChangeResource: isShowChangeResource,
      style: {
        marginRight: 4
      },
      status: status,
      onLike: function onLike(e) {
        _onLike(_objectSpread(_objectSpread({}, item), {}, {
          like_status: e
        }));
      }
    });
  }, [isShowChangeResource]);
  var resourceCom = useCallback(function (item) {
    if (item !== null && item !== void 0 && item.hasOwnProperty('isShowChangeResource') && !item.isShowChangeResource || !isShowChangeResource) {
      return item === null || item === void 0 ? void 0 : item.name;
    }
    return /*#__PURE__*/React.createElement(SelectResource, _extends({}, item, {
      lists: item === null || item === void 0 ? void 0 : item.lists,
      value: item === null || item === void 0 ? void 0 : item.id,
      onChange: changeResource,
      onClearResource: onClearResource,
      allowClear: item === null || item === void 0 ? void 0 : item.allowClearResource,
      isErrorResource: item === null || item === void 0 ? void 0 : item.isErrorResource,
      resourceErrorText: item === null || item === void 0 ? void 0 : item.resourceErrorText,
      resourceMode: item.resourceMode,
      maxLength: item.maxLength
    }));
  }, [isShowChangeResource]);
  var likeAndResourceCom = useMemo(function () {
    if (isMultipleResource) {
      if ((multiResources === null || multiResources === void 0 ? void 0 : multiResources.length) > 0) {
        return multiResources.map(function (resourceItem) {
          return /*#__PURE__*/React.createElement("div", {
            key: (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.id) + (resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem._id)
          }, resourceItem !== null && resourceItem !== void 0 && resourceItem.id && !is_hide_like && !resourceItem.is_hide_like ? likeCom(resourceItem === null || resourceItem === void 0 ? void 0 : resourceItem.status, resourceItem) : null, resourceCom(resourceItem));
        });
      }
      return null;
    }
    var _resourceCom = resourceCom({
      name: relation_form_name,
      id: resource_id,
      lists: resources,
      allowClearResource: allowClearResource,
      isErrorResource: isErrorResource,
      resourceErrorText: resourceErrorText
    });
    return resource_id && !is_hide_like || _resourceCom ? /*#__PURE__*/React.createElement(React.Fragment, null, resource_id && !is_hide_like ? likeCom(like_status, item) : null, _resourceCom) : null;
  }, [multiResources, resource_id, resources, relation_form_name, is_hide_like, resourceErrorText, allowClearResource, isErrorResource, isShowChangeResource]);
  var isShow = useMemo(function () {
    return start_date && end_date || holderCom || likeAndResourceCom;
  }, [start_date, holderCom, likeAndResourceCom]);
  return isShow ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "product-time-wrap")
  }, start_date && end_date ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "product-date")
  }, getServiceTime(item, start_date)) : null, holderCom, likeAndResourceCom ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefix, "product-technician ").concat(isShowChangeResource ? 'pisell-lowcode-change-resource' : '', " ").concat((multiResources === null || multiResources === void 0 ? void 0 : multiResources.length) > 0 ? 'pisell-lowcode-multi-resources' : '')
  }, likeAndResourceCom) : null)) : null;
};
export default Time;