import {
  WorkshopVisitedTimes,
  UserDailyVisitTimes,
  CameraVisitedTimeItem,
} from '@/api/datamanagement/dataplatform';

/**
 * @description 日期格式化
 * @param date
 * @returns yyyy-MM-dd-hh-mm-ss-SSS
 */
export function formatDate(date: Date) {
  const year = date.getFullYear();
  const month = ('0' + (date.getMonth() + 1)).slice(-2);
  const day = ('0' + date.getDate()).slice(-2);
  const hours = ('0' + date.getHours()).slice(-2);
  const minutes = ('0' + date.getMinutes()).slice(-2);
  const seconds = ('0' + date.getSeconds()).slice(-2);
  const milliseconds = ('00' + date.getMilliseconds()).slice(-3);
  // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

export function formatWorkshopChart(data: WorkshopVisitedTimes[]) {
  const label = data.map((i) => i.workshopName);
  const val = data.map((i) => i.count);
  return { label, val };
}

export function formatTimeChart(data: UserDailyVisitTimes) {
  //   const label = data.map((i) => i.time.match(/^.*?(\s|$)/)![0]);
  //   const val = data.map((i) => i.count);

  const label = data.time;
  const val = data.data;
  return { label, val };
}

export function formatCameraChart(data: CameraVisitedTimeItem[]) {
  // const label = data.map((i) => i.cameraName);
  // const val = data.map((i) => i.count);

  const label = [] as string[];
  const val = [] as number[];

  for (let i = 0; i < data.length; i++) {
    const workshopInfo = data[i];
    const workshopName = workshopInfo.workshopName;
    const cameras = workshopInfo.cameraCounts;
    for (let j = 0; j < cameras.length; j++) {
      const cameraInfo = cameras[j];
      label.push(`${cameraInfo.cameraName}（${workshopName}）`);
      val.push(cameraInfo.count);
    }
  }
  return { label, val };
}
