import { VIDEO_ADMIN } from '@/modules/@common/acl/constants';

import { hasPermission } from '@/modules/@common/user/helpers';

const filterConfig = (filters, userPermissions) => {
  const time = filters?.time?.filters?.[0]?.value;
  const duration = filters?.duration?.filters?.[0]?.value;
  const videos = filters?.videos?.filters?.[0]?.value;
  const people = filters?.people?.filters?.[0]?.value;
  const brands = filters?.brands?.filters?.[0]?.value;
  const categories = filters?.categories?.filters?.[0]?.value;
  const filterLabels = filters?.labels?.filters?.[0]?.value;
  const languages = filters?.languages?.filters?.[0]?.value;
  const owner = filters?.owner?.filters?.[0]?.value;
  const source = filters?.source?.filters?.[0]?.value;
  const order = filters?.order?.filters?.[0]?.value;
  const isReversed = filters?.order?.isReversed;
  const timeFrame = filters?.timeFrame?.filters?.[0]?.value;
  const brandSafety = filters?.brandSafety?.filters?.[0]?.value;
  const keywords = filters?.keywords?.filters?.[0]?.value;
  const evergreen = filters?.evergreen?.filters?.[0]?.value?.[0]?.value;
  const publishPlatform = filters?.publishPlatform.filters?.[0]?.value?.[0]?.value;
  const publishStatus = filters?.publishStatus.filters?.[0]?.value?.[0]?.value;
  const status = filters.status?.filters?.[0]?.value?.[0]?.value;
  const verification = filters.verification?.filters?.[0]?.value?.[0]?.value;
  const feedType = filters.feedType?.filters?.[0]?.value?.[0]?.value;
  const videoTab = filters.videoTabs?.filters?.[0]?.value;
  const account = filters.account?.filters?.[0]?.value;
  const targetingStatus = filters?.targetingStatus.filters?.[0]?.value?.[0]?.value;
  const hubs = filters?.hubs?.filters?.[0]?.value;
  const mediaType = filters.mediaType?.filters?.[0]?.value?.[0]?.value;
  const sponsored = filters.sponsored?.filters?.[0]?.value?.[0]?.value;

  const internalUserType = hasPermission(VIDEO_ADMIN, userPermissions);

  return {
    time,
    videos,
    people,
    brands,
    categories,
    filterLabels,
    languages,
    owner,
    source,
    order,
    isReversed,
    timeFrame,
    brandSafety,
    keywords,
    duration,
    internalUserType,
    evergreen,
    publishPlatform,
    publishStatus,
    status,
    verification,
    feedType,
    videoTab,
    account,
    targetingStatus,
    hubs,
    mediaType,
    sponsored,
  };
};

export default filterConfig;
