using Microsoft.AspNetCore.Components;
using System.Drawing;
using EgwCoreLib.Razor.Data;
namespace EgwCoreLib.Razor
{
public partial class CalendarWeek
{
#region Public Properties
///
/// Evento x ritorno click
///
[Parameter]
public EventCallback backToCalendar { get; set; }
///
/// Periodo da mostrare (tipicamente 1 settimana)
///
[Parameter]
public List DateList { get; set; } = new List();
///
/// Evento selezione data valida (= entro il periodo selezionato)
///
[Parameter]
public EventCallback DateSelected { get; set; }
///
/// Evento selezione data singola giornata da header
///
[Parameter]
public EventCallback EC_HeadDateSel { get; set; }
///
/// Ora fine visualizzazione calendario
///
[Parameter]
public int EndHour { get; set; } = 20;
///
/// Eventi da inserire
///
[Parameter]
public List EventList { get; set; } = new List();
///
/// Css titolo
/// default: color: red
///
[Parameter]
public string HeadStyle { get; set; } = "color: #E67E22";
///
/// Altezza di ogni blocco ora da mostrare
///
[Parameter]
public int HeightHour { get; set; } = 20;
///
/// Larghezza calcolata delle etichette, minimo tra
///
[Parameter]
public int labelWidth { get; set; } = 15;
///
/// Fattore di shift in X, se 0 = nessuno shift, se > 0 è percentuale moltiplica il
/// gradino calcolato
/// Default: 100 (poi riportato a intero, quindi 100/100 = 1.0)
///
[Parameter]
public int PercX { get; set; } = 100;
///
/// Fattore di shift in Y, se 0 = nessuno shift, se > 0 è percentuale moltiplica il
/// gradino calcolato
/// Default: 90 (poi riportato a intero, quindi 90/100 = 0.9)
///
[Parameter]
public int PercY { get; set; } = 90;
[Parameter]
public int StartHour { get; set; } = 8;
///
/// Dimensioni viewbox GLOBALE
///
[Parameter]
public Size vBox { get; set; } = new Size(1200, 1600);
///
/// Evento richiesta modifica settimana
///
[Parameter]
public EventCallback WeekChanged { get; set; }
#endregion Public Properties
#region Protected Fields
protected List HourSlot = new List();
#endregion Protected Fields
#region Protected Properties
protected int calcColSpan
{
get => numDays + 1;
}
protected int contWidth
{
get => (vBox.Width * 2) / (2 * numDays + 1);
//get => numDays > 1 ? (vBox.Width * 2) / (2 * numDays + 1) : vBox.Width * 90 / 100;
}
protected DateTime DtRif
{
get
{
DateTime answ = DateTime.Today;
if (DateList != null && DateList.Count > 0)
{
answ = DateList[0];
}
return answ;
}
}
protected int numDays
{
get => DateList.Count;
}
protected Size vBoxCont
{
get
{
// label e' MENO di 1/tot columns
Size answ = new Size(contWidth, vBox.Height);
return answ;
}
}
protected Size vBoxLabel
{
get
{
// label e' MENO di 1/tot columns
Size answ = new Size(contWidth / 2, vBox.Height);
//Size answ = new Size(labelWidth, vBox.Height);
return answ;
}
}
#endregion Protected Properties
#region Protected Methods
///
/// Richiesta cambio sett di riferimento --> riporta evento
///
///
///
protected async Task changeWeek(int delta)
{
await WeekChanged.InvokeAsync(delta);
}
protected List DayEvent(DateTime DtReq)
{
List answ = new List();
if (EventList != null)
{
answ = EventList.Where(x => x.Inizio.Date == DtReq.Date).ToList();
}
return answ;
}
///
/// Genera etichette orarie (1 x ora)
///
///
protected List LabelList()
{
int idx = 0;
List answ = HourSlot.Select(x => new CalendarEvent()
{
id = idx++,
Inizio = DtRif.AddHours(x),
Fine = DtRif.AddHours(x),
CssClass = "text-light",
Title = $"{x:00}:00",
Description = $"{x:00}:00"
}).ToList();
return answ;
}
protected override async Task OnParametersSetAsync()
{
HourSlot = new List();
for (int i = StartHour; i <= EndHour; i++)
{
HourSlot.Add(i);
}
await InvokeAsync(StateHasChanged);
}
protected async Task OpenCalendarMonth()
{
await backToCalendar.InvokeAsync(true);
}
protected async Task SelectDate(DateTime selDate)
{
await EC_HeadDateSel.InvokeAsync(selDate);
}
///
/// GetIso8601WeekOfYear
///
///
///
protected int weekNum(DateTime DtReq)
{
int wNum = WeekData.GetIso8601WeekOfYear(DtReq);
return wNum;
}
#endregion Protected Methods
#region Private Properties
private string dataWidth
{
get => $"{(double)contWidth / vBox.Width:P2}".Replace(",", ".");
}
private string lblWidth
{
get => $"{(double)(vBox.Width - (contWidth * numDays)) / vBox.Width:P2}".Replace(",", ".");
}
#endregion Private Properties
}
}