import { shallowReactive, watch } from 'vue';
import { createComponent } from './createComponent.js';
import './Statistic.vue.js';
import script from './Statistic.vue2.js';

function useStatistic() {
  var props = shallowReactive({
    value: null,
    chart: null,
    visible: false,
    statistical: 0
  });
  var _createComponent = createComponent(script, props),
    close = _createComponent.close,
    open = _createComponent.open;
  var toggleStatistic = function toggleStatistic(visible) {
    if (visible !== undefined) {
      props.visible = visible;
    } else {
      props.visible = !props.visible;
    }
  };
  watch(function () {
    return props.visible;
  }, function (value, oldValue, onCleanup) {
    value ? open() : close();
  }, {
    immediate: true
  });
  return {
    close: close,
    open: open,
    props: props,
    toggleStatistic: toggleStatistic
  };
}

export { useStatistic };
