export const CALENDAR_FILTER_VALUE = {
  any: {
    stringFrom: 'now/d',
  },
  yesterday: {
    stringFrom: 'now-1d/d',
    stringTo: 'now/d',
    value: 'days',
  },
  last7days: {
    stringFrom: 'now-7d/d',
    stringTo: 'now/d',
    value: 'week',
  },
  last30days: {
    stringFrom: 'now-30d/d',
    stringTo: 'now/d',
    value: 'month',
  },
  custom: 'Custom',
};

export const CALENDAR_FILTER = [
  { label: 'Any time', value: CALENDAR_FILTER_VALUE.any },
  { label: 'Past 24 hours', value: CALENDAR_FILTER_VALUE.yesterday },
  { label: 'Past week', value: CALENDAR_FILTER_VALUE.last7days },
  { label: 'Past month', value: CALENDAR_FILTER_VALUE.last30days },
  { label: 'Custom', value: CALENDAR_FILTER_VALUE.custom },
];

export const DEVICES_CONFIG = {
  desktop: {
    title: 'Desktop',
    items: [
      {
        title: 'X Large',
        key: 'xLarge',
      },
      {
        title: 'Large',
        key: 'large',
      },
      {
        title: 'Medium & Smaller',
        key: 'medium',
      },
    ],
  },
  mobile: {
    title: 'Mobile',
    items: [
      {
        title: 'Medium',
        key: 'medium',
      },
      {
        title: 'Small',
        key: 'small',
      },
      {
        title: 'X Small',
        key: 'xSmall',
      },
    ],
  },
};

const queryUsersGQL = `
  query livePerformanceUsers(
    $eventId: Int,
    $scheduleSessionIds: [Int],
    $inFocus: Boolean,
    $interval: AnalyticsIntervalInputType,
    $timezone: String
  ) {
    livePerformanceUsers(
      eventId: $eventId,
      scheduleSessionIds: $scheduleSessionIds,
      inFocus: $inFocus,
      interval: $interval,
      timezone: $timezone
    ) {
      rid
      data {
        id
        data {
          time
          users
          usersInFocus
        }
      }
    }
  }
`;

const queryMinutesTotalGQL = `
  query livePerformanceMinutesTotal(
    $eventId: Int,
    $scheduleSessionIds: [Int],
    $inFocus: Boolean,
    $interval: AnalyticsIntervalInputType,
    $timezone: String
  ) {
    livePerformanceMinutesTotal(
      eventId: $eventId,
      scheduleSessionIds: $scheduleSessionIds,
      inFocus: $inFocus,
      interval: $interval,
      timezone: $timezone
    ) {
      rid
      data {
        id
        data {
          time
          minutesTotal
          minutesTotalInFocus
        }
      }
    }
  }
`;

const queryMinutesAvgGQL = `
  query livePerformanceMinutesAvg(
    $eventId: Int,
    $scheduleSessionIds: [Int],
    $inFocus: Boolean,
    $interval: AnalyticsIntervalInputType,
    $timezone: String
  ) {
    livePerformanceMinutesAvg(
      eventId: $eventId,
      scheduleSessionIds: $scheduleSessionIds,
      inFocus: $inFocus,
      interval: $interval,
      timezone: $timezone
    ) {
      rid
      data {
        id
        data {
          time
          minutesAvg
          minutesAvgInFocus
        }
      }
    }
  }
`;

export const TABS = [
  {
    title: 'Users',
    id: 'USERS',
    key: 'users',
    tooltipTitle: 'Total quantity of unique viewing sessions within the selected duration',
    query: queryUsersGQL,
  },
  {
    title: 'Total viewed minutes',
    id: 'TOTAL',
    key: 'totalMinutes',
    tooltipTitle: 'Total number of minutes viewed in all sessions within the selected duration',
    query: queryMinutesTotalGQL,
  },
  {
    title: 'Average viewed minutes',
    id: 'AVERAGE',
    key: 'averageMinutes',
    tooltipTitle: 'The average quantity of minutes viewed in one session within the selected duration',
    additionalKey: 'averageMinutesPercent',
    query: queryMinutesAvgGQL,
    chartTooltipFormatter: (value) => Math.round(value * 100) / 100,
  },
];
