package templates

import (
	. "primesys_email/src/models/report"
	. "primesys_email/src/templates/utils"
)

// CreateKeyManTripWiseReportExcel is used for "Morning Keyman Report" (8) and "Summer Patrolman Report" (9)
func CreateKeyManTripWiseReportExcel(reports []DivisionTripReportModel, divisionName string, reportName string, reportDate string) ([]byte, error) {
	t := tableReport{
		sheet:        reportName + " TripWise",
		title:        reportName + " TRIPWISE",
		widths:       []float64{10, 24, 20, 20, 20, 20, 16, 16, 16, 14, 26, 24},
		headers:      []string{"Sr.No", "Name", "Expected Location", "Actual Location", "Expected Time", "OnTrack Time", "Expected KM", "Actual KM", "Expected Trip", "Actual Trip", "Start% - End% Battery", "Remarks"},
		headerHeight: 30,
	}

	return writeTableReport(t, reports, divisionName, reportDate, func(r DivisionTripReportModel, s tableStyles) []tableCell {
		// expected and actual location both use the actual km, same as the java report
		location := kmRange(r.TripActualStartKm, r.TripActualEndKm, 2)

		return []tableCell{
			{DefaultString(r.DeviceName), s.name},
			{location, s.cell},
			{location, s.cell},
			{timeRange(r.TripStartTime, r.TripEndTime), s.cell},
			{timeRange(r.ActualStartTime, r.ActualEndTime), s.cell},
			{DefaultFloat(r.TripDistanceTobeCoverKm), s.cell},
			{DefaultFloat(r.DistanceCoverTrip), s.cell},
			{intText(r.AllocatedTrips, "-"), s.cell},
			{intText(r.ActualTrips, "-"), s.cell},
			{batteryText(r.TripList, "- - -"), s.cell},
			{remarkText(r.Remark), s.cell},
		}
	})
}
