import React, { useMemo, useEffect } from "react";
import { useCallLink } from "./CallLinks";
import { skipToken } from '@reduxjs/toolkit/query'
import { useGetSystemsQuery, useGetTalkgroupsQuery } from '../../features/api/apiSlice'
import { useParams } from 'react-router-dom';
import {
Header,
Divider,
List,
Statistic,
Icon,
Menu
} from "semantic-ui-react";
// ----------------------------------------------------
function CallInfoPane(props) {
let srcList = "";
let callLength = "-";
let callFreq = "-";
let callDate = "-";
let callTime = "-";
let talkgroupNum = "-";
let header = "Call Info"
let title = ""
const currentCall = props.call ? props.call : false;
const { callLink, callDownload, callTweet } = useCallLink(props.call)
const { data: allSystems, isSuccess } = useGetSystemsQuery();
let { shortName } = useParams();
if (!shortName && currentCall) {
shortName = currentCall.shortName;
}
const { data: talkgroupsData, isSuccess: isTalkgroupsSuccess } = useGetTalkgroupsQuery(shortName ? shortName : skipToken);
if (currentCall) {
if ((talkgroupsData) && talkgroupsData.talkgroups[currentCall.talkgroupNum]) {
header = talkgroupsData.talkgroups[currentCall.talkgroupNum].description;
title = talkgroupsData.talkgroups[currentCall.talkgroupNum].description;
} else {
title = `TG: ${currentCall.talkgroupNum}`;
}
const time = new Date(currentCall.time);
callTime = time.toLocaleTimeString();
callDate = time.toLocaleDateString();
if (currentCall.freq) {
const freq = currentCall.freq / 1000000;
callFreq = Math.round(freq * 1000) / 1000;
}
srcList = currentCall.srcList.map((source, index) =>
{srcList}