import { create } from "zustand";
import { persist } from "zustand/middleware";

interface HelpState {
  // État des tours guidés
  hasSeenWelcomeTour: boolean;
  hasSeenCorrelationTour: boolean;
  hasSeenRegressionTour: boolean;
  hasSeenOutlierTour: boolean;

  // État du panel d'aide
  isHelpPanelOpen: boolean;

  // Préférences utilisateur
  showTooltips: boolean;
  autoShowTours: boolean;

  // Actions
  setHelpPanelOpen: (open: boolean) => void;
  markTourAsSeen: (tour: "welcome" | "correlation" | "regression" | "outlier") => void;
  setShowTooltips: (show: boolean) => void;
  setAutoShowTours: (auto: boolean) => void;
  resetTours: () => void;
}

export const useHelpStore = create<HelpState>()(
  persist(
    (set) => ({
      // État initial
      hasSeenWelcomeTour: false,
      hasSeenCorrelationTour: false,
      hasSeenRegressionTour: false,
      hasSeenOutlierTour: false,

      isHelpPanelOpen: false,

      showTooltips: true,
      autoShowTours: true,

      // Actions
      setHelpPanelOpen: (open) => set({ isHelpPanelOpen: open }),

      markTourAsSeen: (tour) =>
        set((state) => {
          switch (tour) {
            case "welcome":
              return { hasSeenWelcomeTour: true };
            case "correlation":
              return { hasSeenCorrelationTour: true };
            case "regression":
              return { hasSeenRegressionTour: true };
            case "outlier":
              return { hasSeenOutlierTour: true };
          }
        }),

      setShowTooltips: (show) => set({ showTooltips: show }),

      setAutoShowTours: (auto) => set({ autoShowTours: auto }),

      resetTours: () =>
        set({
          hasSeenWelcomeTour: false,
          hasSeenCorrelationTour: false,
          hasSeenRegressionTour: false,
          hasSeenOutlierTour: false,
        }),
    }),
    {
      name: "data-analysis-help-storage", // Clé pour localStorage
    }
  )
);
