import { useMemo } from "react";
import { FLAGS, useFeatureIsOn } from "@komi-app/flags-sdk";
import { selectTalentProfileModules } from "redux/User/selector";
import { useTypedSelector } from "redux/rootReducer";

export const useHasTemplates = () => {
  const modules = useTypedSelector(selectTalentProfileModules);
  const isTemplatesV2Enabled = useFeatureIsOn(
    FLAGS.FEAT_SB_447_MODULE_TEMPLATES
  );

  return useMemo(() => {
    if (!isTemplatesV2Enabled) return false;

    return (modules || []).some((module) => module.template && module.visible);
  }, [modules, isTemplatesV2Enabled]);
};
