import { useMemo } from 'react';
import { isWalkIn } from "../../utils";
var useHolderConfig = function useHolderConfig(state) {
  var _state$bookingConfig2, _state$bookingConfig4, _state$bookingConfig6, _state$client2;
  // board设置, 获取预约主体
  var appointment_subject = useMemo(function () {
    var _state$bookingConfig;
    return (state === null || state === void 0 || (_state$bookingConfig = state.bookingConfig) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.config) === null || _state$bookingConfig === void 0 || (_state$bookingConfig = _state$bookingConfig.basic) === null || _state$bookingConfig === void 0 ? void 0 : _state$bookingConfig.appointment_subject) || {};
  }, [state === null || state === void 0 || (_state$bookingConfig2 = state.bookingConfig) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.config) === null || _state$bookingConfig2 === void 0 || (_state$bookingConfig2 = _state$bookingConfig2.basic) === null || _state$bookingConfig2 === void 0 ? void 0 : _state$bookingConfig2.appointment_subject]);
  var holder = useMemo(function () {
    var _state$bookingConfig3;
    return (state === null || state === void 0 || (_state$bookingConfig3 = state.bookingConfig) === null || _state$bookingConfig3 === void 0 ? void 0 : _state$bookingConfig3.holder) || {};
  }, [state === null || state === void 0 || (_state$bookingConfig4 = state.bookingConfig) === null || _state$bookingConfig4 === void 0 ? void 0 : _state$bookingConfig4.holder]);

  // 配置主体为特定表单时
  var isFormSubject = useMemo(function () {
    return appointment_subject.type === 'form';
  }, [appointment_subject.type]);

  // holder 类型
  var holderType = useMemo(function () {
    var _state$bookingConfig5;
    return (state === null || state === void 0 || (_state$bookingConfig5 = state.bookingConfig) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.holder) === null || _state$bookingConfig5 === void 0 || (_state$bookingConfig5 = _state$bookingConfig5.form) === null || _state$bookingConfig5 === void 0 ? void 0 : _state$bookingConfig5.formType) || 'minors';
  }, [state === null || state === void 0 || (_state$bookingConfig6 = state.bookingConfig) === null || _state$bookingConfig6 === void 0 ? void 0 : _state$bookingConfig6.holder]);
  var isWalkInBol = useMemo(function () {
    var _state$client;
    return isWalkIn(state === null || state === void 0 || (_state$client = state.client) === null || _state$client === void 0 || (_state$client = _state$client.value) === null || _state$client === void 0 ? void 0 : _state$client.id);
  }, [state === null || state === void 0 || (_state$client2 = state.client) === null || _state$client2 === void 0 || (_state$client2 = _state$client2.value) === null || _state$client2 === void 0 ? void 0 : _state$client2.id]);

  // 配置主体为特定表单时
  var isCustomerSubject = useMemo(function () {
    return appointment_subject.type === 'customer';
  }, [appointment_subject.type]);
  var isShowChangeHolder = useMemo(function () {
    return isFormSubject && !isWalkInBol;
  }, [isFormSubject, isWalkInBol]);
  return {
    appointment_subject: appointment_subject,
    holder: holder,
    isFormSubject: isFormSubject,
    isCustomerSubject: isCustomerSubject,
    isWalkInBol: isWalkInBol,
    isShowChangeHolder: isShowChangeHolder,
    holderType: holderType
  };
};
export default useHolderConfig;