import { useMemo } from 'react';
import { useAuth } from '@/features/auth/hooks/useAuth';
import type { Playlist } from '../types';

export function usePlaylistPermissions(playlist?: Playlist) {
  const { user } = useAuth();

  return useMemo(() => {
    if (!playlist || !user) {
      return {
        canEdit: false,
        canDelete: false,
        canAddTracks: false,
        canRemoveTracks: false,
        canManageCollaborators: false,
        canRead: false,
        isOwner: false,
      };
    }

    // FE-TYPE-001: IDs are already strings, no conversion needed
    const isOwner = playlist.user_id === user.id;
    // Add logic for collaborators if/when implemented

    return {
      canEdit: isOwner,
      canDelete: isOwner,
      canAddTracks: isOwner,
      canRemoveTracks: isOwner,
      canManageCollaborators: isOwner,
      canRead: true, // Anyone can read public playlists, owner can read private ones
      isOwner,
    };
  }, [playlist, user]);
}
