import { defineStore, storeToRefs } from 'pinia';
import { ref, computed, watch } from 'vue';
import { usePageStore } from './page';
import { useDialogStore } from './dialog';

export const useVirtualSampleStore = defineStore('virtual-sample', () => {
  const { page } = storeToRefs(usePageStore());
  const { openedFile } = storeToRefs(useDialogStore());
  const step = computed(() => {
    return page.value.steps.find((step) => step.id === 'virtualSample');
  });
  const isCompareModeEnabled = ref(false);

  const activeTab = ref(step.value.files.dynamic ? 'dynamic' : 'static');
  const currentFile = ref(null);
  const isLoopAnimationEnabled = ref(false);
  const isDownloadTriggered = ref(false);

  watch(activeTab, () => (currentFile.value = null));

  return {
    activeTab,
    currentFile,
    step,
    isLoopAnimationEnabled,
    isCompareModeEnabled,
    isDownloadTriggered,
  };
});
