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 { locales } from '@pisell/utils';
import React, { useContext, useEffect, useMemo } from 'react';
import Footer from "../components/footer";
import TabPane from "../components/tabPane";
import localeTexts from "../locales";
import Client from "./client";
import DateCom from "./date";
import Header from "./header";
import { Context, Provider } from "./model";
import Pet from "./pet";
import Service from "./service";
import { Skeleton } from 'antd';
import classNames from 'classnames';
import useEngineContext from "../../../hooks/useEngineContext";
import useCreateBookingPageHeader from "../hooks/useCreateBookingPageHeader";
import { findNextDuration, flexibleObj, formatResource, getErrorList, request, sliceDayIntoFiveMinutes } from "../utils";
import { updateServiceDate } from "./date";
import { getLocale } from "../../../utils/locales";
import "./index.less";
import Notes from "./notes";
import { Service2Cart } from "./service2";
import { isDayBooking, isEventBooking, isTerminalDayBooking } from "./service2/utils";
var defaultModules = {
  client: 1,
  date: 1,
  service: 1,
  holder: 1,
  note: 1,
  service2: 0
};
locales.init(localeTexts, getLocale());
var Info = Provider(function (props) {
  var _modal$state2, _modal$state3, _context$appHelper4, _modal$state4;
  var style = props.style,
    globalState = props.globalState,
    _props$modules = props.modules,
    modules = _props$modules === void 0 ? defaultModules : _props$modules,
    slot = props.slot;
  var modal = useContext(Context);
  var context = useEngineContext();
  request.setRequest(context.appHelper.utils.request);
  var params = useMemo(function () {
    var _modal$state;
    return ((_modal$state = modal.state) === null || _modal$state === void 0 || (_modal$state = _modal$state.bookingConfig) === null || _modal$state === void 0 || (_modal$state = _modal$state.config) === null || _modal$state === void 0 || (_modal$state = _modal$state.basic) === null || _modal$state === void 0 ? void 0 : _modal$state.appointment_subject) || {};
  }, [(_modal$state2 = modal.state) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.bookingConfig) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.config) === null || _modal$state2 === void 0 || (_modal$state2 = _modal$state2.basic) === null || _modal$state2 === void 0 ? void 0 : _modal$state2.appointment_subject]);
  var _useCreateBookingPage = useCreateBookingPageHeader(globalState),
    createHeader = _useCreateBookingPage.createHeader,
    isBookingCreatePage = _useCreateBookingPage.isBookingCreatePage,
    isBookingCreatePageCreateMode = _useCreateBookingPage.isBookingCreatePageCreateMode;
  useEffect(function () {
    document.body.id = 'body';
    // 注入函数到页面的state内
    if (props.setState) {
      props.setState({
        bookingFunctions: {
          formatResource: formatResource,
          getErrorList: getErrorList,
          sliceDayIntoFiveMinutes: sliceDayIntoFiveMinutes,
          findNextDuration: findNextDuration,
          flexibleObj: flexibleObj,
          updateServiceDate: updateServiceDate
        }
      });
    }
  }, []);
  useEffect(function () {
    var _context$appHelper, _context$appHelper$ge, _context$appHelper2, _context$appHelper2$i, _context$appHelper3;
    var isFranchisee = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.businessUtils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getAppByModal) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper, 'franchisee');
    modal.dispatch({
      type: 'setState',
      payload: _objectSpread(_objectSpread({
        setGlobalState: props.setGlobalState
      }, globalState), {}, {
        isTerminal: context === null || context === void 0 || (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$i = _context$appHelper2.isTerminal) === null || _context$appHelper2$i === void 0 ? void 0 : _context$appHelper2$i.call(_context$appHelper2),
        isFranchisee: isFranchisee,
        timezone: context === null || context === void 0 || (_context$appHelper3 = context.appHelper) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.utils) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.store) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.getState()) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.global) === null || _context$appHelper3 === void 0 || (_context$appHelper3 = _context$appHelper3.globalConfig) === null || _context$appHelper3 === void 0 ? void 0 : _context$appHelper3.timezone,
        isDayBooking: (globalState === null || globalState === void 0 ? void 0 : globalState.renderType) === 'dayBooking'
      })
    });
  }, [globalState]);
  var addNote = function addNote(e) {
    modal.dispatch({
      type: 'setNotes',
      payload: {
        orderNote: e,
        edit: true
      }
    });
  };
  var header = useMemo(function () {
    if ((globalState === null || globalState === void 0 ? void 0 : globalState.renderType) === 'eventBooking') {
      return locales.getText('pisell2.text.enroll.detail');
    }
    return globalState !== null && globalState !== void 0 && globalState.bookingId ? /*#__PURE__*/React.createElement(Header, {
      state: modal.state,
      dispatch: modal.dispatch
    }) : /*#__PURE__*/React.createElement("div", {
      className: "",
      style: {
        height: 0
      }
    });
  }, [globalState === null || globalState === void 0 ? void 0 : globalState.bookingId, modal.state, modal.dispatch, globalState === null || globalState === void 0 ? void 0 : globalState.renderType]);
  var notes = useMemo(function () {
    if (!modules.note) {
      return null;
    }
    if (isEventBooking(modal.state)) {
      return null;
    }

    // 跨日预约一直显示备注
    if (isDayBooking(globalState)) {
      return (
        // <AddNote value={modal.state?.notes?.orderNote} onChange={addNote} />
        null
      );
    }
    return globalState !== null && globalState !== void 0 && globalState.bookingId ? globalState.renderType === 'eventBooking' || globalState.isBookingCreatePage ? /*#__PURE__*/React.createElement(Notes, null) : null :
    // <AddNote value={modal.state?.notes?.orderNote} onChange={addNote} />
    null;
  }, [modules.note, globalState === null || globalState === void 0 ? void 0 : globalState.bookingId, globalState.render, (_modal$state3 = modal.state) === null || _modal$state3 === void 0 || (_modal$state3 = _modal$state3.notes) === null || _modal$state3 === void 0 ? void 0 : _modal$state3.orderNote]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, !!modal.state.setGlobalState ? /*#__PURE__*/React.createElement(TabPane, {
    style: _objectSpread(_objectSpread({}, style), {}, {
      height: context !== null && context !== void 0 && (_context$appHelper4 = context.appHelper) !== null && _context$appHelper4 !== void 0 && (_context$appHelper4 = _context$appHelper4.utils) !== null && _context$appHelper4 !== void 0 && _context$appHelper4.isMobile ? '100%' : '100vh'
    }),
    header: header,
    footer: /*#__PURE__*/React.createElement(Footer, {
      state: modal.state,
      dispatch: modal.dispatch,
      source: "info"
    }),
    bodyClassName: classNames('booking-info-warp', _defineProperty(_defineProperty({}, 'create-booking-page-info-wrap', isBookingCreatePage), 'create-booking-page-info-wrap-create', isBookingCreatePageCreateMode && !isTerminalDayBooking(modal.state))),
    state: modal.state,
    dispatch: modal.dispatch,
    source: "info"
  }, /*#__PURE__*/React.createElement("div", {
    className: "booking-info"
  }, createHeader, modules.client ? /*#__PURE__*/React.createElement(Client, null) : null, modules.holder && !((_modal$state4 = modal.state) !== null && _modal$state4 !== void 0 && _modal$state4.disabledEdit) ? /*#__PURE__*/React.createElement(React.Fragment, null, params.type === 'form' ? /*#__PURE__*/React.createElement(Pet, null) : null) : null, modules.date ? /*#__PURE__*/React.createElement(DateCom, null) : null, /*#__PURE__*/React.createElement(Skeleton, {
    loading: globalState.loading,
    round: true,
    active: true,
    avatar: false,
    style: {
      paddingTop: 20
    }
  }, modules.service ? /*#__PURE__*/React.createElement(React.Fragment, null, modal.state.date.value ? /*#__PURE__*/React.createElement(Service, null) : null) : null, modules.service2 ? /*#__PURE__*/React.createElement(React.Fragment, null, modal.state.date.value ? /*#__PURE__*/React.createElement(Service2Cart, null) : null) : null, notes, slot ? slot : null))) : null);
});
export default Info;