import { getScrollParent } from '@/utils';

export default {
  data() {
    return {
      originalScrollTop: 0,
      scrollContainer: null,
    };
  },
  methods: {
    toggleFullscreen() {
      const fullscreenClassName = 'dc-chart-fullscreen';
      const el = this.$refs.chartWrap;
      if (el.classList.contains(fullscreenClassName)) {
        el.classList.remove(fullscreenClassName);
        if (this.scrollContainer) {
          this.scrollContainer.scrollTop = this.originalScrollTop;
        }
      } else {
        this.scrollContainer = getScrollParent(el);
        if (this.scrollContainer) {
          this.originalScrollTop = this.scrollContainer.scrollTop;
        }
        el.classList.add(fullscreenClassName);
      }
    },
  },
};
