"use client";

import { useMemo } from "react";
import type { BrandProfile } from "@/types/workflow";
import { selectActiveBrand } from "./project-selectors";
import { useProjectsStore } from "./projects-store";

interface BrandStore {
  brand: BrandProfile;
  setBrand: (data: Partial<BrandProfile>) => void;
  saveBrand: () => void;
}

function useBrandStoreImpl(): BrandStore;
function useBrandStoreImpl<T>(selector: (state: BrandStore) => T): T;
function useBrandStoreImpl<T>(selector?: (state: BrandStore) => T): T | BrandStore {
  const brand = useProjectsStore(selectActiveBrand);
  const setBrand = useProjectsStore((s) => s.updateActiveBrand);

  const store = useMemo(
    (): BrandStore => ({
      brand,
      setBrand,
      saveBrand: () => {},
    }),
    [brand, setBrand],
  );

  return selector ? selector(store) : store;
}

export const useBrandStore = useBrandStoreImpl;
