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, { createContext, useContext, useEffect, useRef } from 'react';
import AddService from "../service/addService";
import EditService from "../service/editService";
import { Context } from "../model";
import Lists from "./Lists";
import useQuotation from "../../hooks/useQuotation";
export var Service2Context = /*#__PURE__*/createContext({});
export var Service2Cart = function Service2Cart(_ref) {
  var hideAdd = _ref.hideAdd,
    hideEdit = _ref.hideEdit;
  var detailRef = useRef();
  var _useContext = useContext(Context),
    state = _useContext.state,
    dispatch = _useContext.dispatch;
  useEffect(function () {
    document.body.id = 'body';
  }, []);

  /**
   * @title: 更新服务
   * @description:
   * @param {string} type
   * @param {any} payload
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-12-09 16:02
   */
  var dispatchService = function dispatchService(type, payload) {
    dispatch({
      type: type,
      payload: _objectSpread({}, payload)
    });
  };
  var handleEdit = function handleEdit(cacheItem, type) {
    setTimeout(function () {
      var _detailRef$current, _detailRef$current$in;
      (_detailRef$current = detailRef.current) === null || _detailRef$current === void 0 || (_detailRef$current$in = _detailRef$current.init) === null || _detailRef$current$in === void 0 || _detailRef$current$in.call(_detailRef$current, cacheItem, false, type === 'edit_product');
    }, 100);
  };
  var _useQuotation = useQuotation(state, dispatch),
    dom = _useQuotation.dom;
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "pisell-lowcode__booking-service-wrap"
  }, /*#__PURE__*/React.createElement(Lists, {
    onEdit: handleEdit,
    onChange: function onChange(e, type) {
      return dispatchService(type || 'setService', e);
    }
  }), !hideAdd && /*#__PURE__*/React.createElement(AddService, {
    onEdit: handleEdit
  })), !hideEdit && /*#__PURE__*/React.createElement(EditService, {
    ref: detailRef
  }), dom);
};