function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useEffect, useState } from 'react';
import { isMobile, locales } from '@pisell/utils';
import { Skeleton } from 'antd';
import { useEvent, useSales, useEventDetail, useStep, useCustomer } from "../../../../Sales";
import BookingServiceList from "../../bookingServiceList";
import BookingDetailModal from "../../bookingDetailModal";
import "./index.less";
import useLoginUser from "../../../../../hooks/useLoginUser";
var Event = function Event() {
  var _data$resourceData2;
  var _useEvent = useEvent(),
    eventData = _useEvent.eventData,
    selectEvent = _useEvent.selectEvent,
    getEventList = _useEvent.getEventList,
    getEventListByTitle = _useEvent.getEventListByTitle;
  var _useSales = useSales(),
    data = _useSales.data;
  var _useStep = useStep(),
    changeAutoOperate = _useStep.changeAutoOperate;
  var _useEventDetail = useEventDetail(),
    onOpenEventDetail = _useEventDetail.onOpenEventDetail,
    open = _useEventDetail.open;
  var _useState = useState(),
    _useState2 = _slicedToArray(_useState, 2),
    lists = _useState2[0],
    setLists = _useState2[1];
  var customer = useLoginUser();
  var _useCustomer = useCustomer(),
    appUtils = _useCustomer.appUtils;
  useEffect(function () {
    var _data$stepData;
    var eventList = (eventData === null || eventData === void 0 ? void 0 : eventData.eventList) || [];
    setLists(eventList);

    // 如果只有一个event，则直接选择并打开详情
    if ((eventList === null || eventList === void 0 ? void 0 : eventList.length) === 1 && data !== null && data !== void 0 && (_data$stepData = data.stepData) !== null && _data$stepData !== void 0 && _data$stepData.isAutoOperate) {
      selectEvent(eventList[0]);
      onOpenEventDetail(eventList[0]);
      // 自动操作结束，防止刷新再次弹出来
      changeAutoOperate(false);
    }
  }, [eventData === null || eventData === void 0 ? void 0 : eventData.eventList]);
  useEffect(function () {
    var _data$resourceData, _appUtils$getHistory, _history$location;
    var id = data === null || data === void 0 || (_data$resourceData = data.resourceData) === null || _data$resourceData === void 0 || (_data$resourceData = _data$resourceData.currentResourceItem) === null || _data$resourceData === void 0 ? void 0 : _data$resourceData.id;
    if (!id) return;
    var history = (appUtils === null || appUtils === void 0 || (_appUtils$getHistory = appUtils.getHistory) === null || _appUtils$getHistory === void 0 ? void 0 : _appUtils$getHistory.call(appUtils)) || {};
    var query = history === null || history === void 0 || (_history$location = history.location) === null || _history$location === void 0 ? void 0 : _history$location.query;
    var params = {
      event_item_resource_id: id,
      skip: 1,
      num: 100,
      customer_id: customer === null || customer === void 0 ? void 0 : customer.id,
      open_quotation: 1
    };
    if (query !== null && query !== void 0 && query.ids) {
      var _query$ids;
      params.ids = query === null || query === void 0 || (_query$ids = query.ids) === null || _query$ids === void 0 ? void 0 : _query$ids.split(',');
    }
    getEventList.run(params);
  }, [data === null || data === void 0 || (_data$resourceData2 = data.resourceData) === null || _data$resourceData2 === void 0 || (_data$resourceData2 = _data$resourceData2.currentResourceItem) === null || _data$resourceData2 === void 0 ? void 0 : _data$resourceData2.id, customer === null || customer === void 0 ? void 0 : customer.id]);

  /**
   * @title: 点击选择event
   * @description:
   * @param {any} item
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-15 22:06
   */
  var handleClick = function handleClick(item) {
    selectEvent(item);
    onOpenEventDetail(item);
  };

  /**
   * @title: 搜索
   * @description:
   * @param {string} value
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-01-16 10:25
   */
  var handleSearch = function handleSearch(e) {
    var _e$target;
    var value = (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value;
    var events = getEventListByTitle(value);
    setLists(events);
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: "event-interface-service-wrap ".concat(isMobile() ? 'event-interface-service-mobile-wrap' : '')
  }, /*#__PURE__*/React.createElement(Skeleton, {
    active: true,
    loading: getEventList.loading,
    style: {
      padding: '16px'
    }
  }, /*#__PURE__*/React.createElement(BookingServiceList, {
    dataSource: lists,
    showSearch: true,
    showCategory: false,
    showImage: true,
    onClick: handleClick,
    onSearch: handleSearch,
    placeholder: locales.getText('pisell2.event.search'),
    isShowEmpty: !getEventList.loading,
    description: locales.getText('pisell2.event.empty.event')
  }))), /*#__PURE__*/React.createElement(BookingDetailModal, {
    open: open
  }));
};
export default Event;