import React, { Component } from "react";
import popupPropTypes, { defaultProps, propsDescription } from "./Popup.propTypes";
import SkeletonThemeWrapper from "../../customization-cornor/skeletonCustomization";
import { default as GeneralPopup } from "./__popupfunctionality";
import childrenWithProps from "./Popup.ComputeProps";
import { toggle } from "./Popup.actions";
import popupReducer, { initialState } from "./Popup.reducers";
import useCommonReducer from "../../libraries/reducerHandler";

let SkeletonWrapper = props => {
  let {
    children,
    renderComponent,
    reducer,
    ...basicProps
  } = props;
  let {
    state,
    dispatch
  } = useCommonReducer(popupReducer, reducer, initialState);

  function handleToggle(e) {
    dispatch(toggle());
    props.togglePopup && props.togglePopup(e);
    props.removeClose && props.removeClose(e);
  }

  let childrenWithPropsData = childrenWithProps(props, {
    handleToggle
  });
  let renderProps = {
    childrenWithPropsData
  };
  return /*#__PURE__*/React.createElement(SkeletonThemeWrapper, {
    basicProps: basicProps,
    renderProps: renderProps,
    component: renderComponent
  });
};

export function PopupBehaviour(props) {
  return /*#__PURE__*/React.createElement(SkeletonWrapper, props);
}
export function PopupTargetBehaviour(props) {
  let renderProps = {};
  let {
    renderComponent,
    ...basicProps
  } = props;
  return /*#__PURE__*/React.createElement(SkeletonThemeWrapper, {
    basicProps: basicProps,
    renderProps: renderProps,
    component: renderComponent
  });
}
export function PopupContentBehaviour(props) {
  let renderProps = {};
  let {
    renderComponent,
    ...basicProps
  } = props;
  return /*#__PURE__*/React.createElement(SkeletonThemeWrapper, {
    basicProps: basicProps,
    renderProps: renderProps,
    component: renderComponent
  });
}
export default GeneralPopup(PopupBehaviour);
PopupBehaviour.propTypes = popupPropTypes;
PopupBehaviour.defaultProps = defaultProps;
PopupBehaviour.propsDescription = propsDescription;