using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static WebWindowComplex.LayoutConst;
namespace WebWindowComplex.Compo
{
public partial class CardTree
{
///
/// Lista oggetti ItemTable
///
[Parameter]
public List ItemTableList { get; set; } = null!;
///
/// Numero massimo di colonne
///
[Parameter]
public int maxCol { get; set; } = 0;
///
/// Dizionario con elementi che possono collassare
///
[Parameter]
public Dictionary RowCollapsedDict { get; set; } = new Dictionary();
///
/// Dizionario con numero di figli per elementi che possono collassare
///
[Parameter]
public Dictionary ChildDict { get; set; } = new Dictionary();
///
/// Evento richiesta prossimo step
///
[Parameter]
public EventCallback EC_NextStep { get; set; }
///
/// Evento richiesta prossimo step
///
[Parameter]
public EventCallback EC_Remove { get; set; }
///
/// Evento aggiornamento dizionari per collasso righe
///
[Parameter]
public EventCallback> EC_Collapsed { get; set; }
///
/// Metodo per richiesta prossimo step
///
///
private Task RaiseNextStep(CompileStep cs, int indexStep)
{
var Args = new DataNextStep
{
currCompileStep = cs,
index = indexStep,
};
return EC_NextStep.InvokeAsync(Args);
}
///
/// Metodo per aprire/chiudere sottorighe
///
///
private Task ChangeCollapsed(int row)
{
RowCollapsedDict[row] = RowCollapsedDict[row] ? false : true;
return EC_Collapsed.InvokeAsync(RowCollapsedDict);
}
private string hwIcon(int row)
{
return RowCollapsedDict[row] ? "fa-solid fa-chevron-down" : "fa-solid fa-chevron-up";
}
///
/// Metodo per rimuovere area
///
///
///
///
private Task Remove(CompileStep cs, int indexStep)
{
var Args = new DataNextStep
{
currCompileStep = cs,
index = indexStep,
};
return EC_Remove.InvokeAsync(Args);
}
///
/// Metodo per riempire tabella con contenuto vuoto o con i simboli per rappresentare la struttura
///
/// riga della cella
/// colonna della cella
///
private string FillTable(int row, int col)
{
List itemSameCol = new List();
for (int k = 0; k < row; k++)
{
if (ItemTableList[k].Col == col + 1)
{
itemSameCol.Add(ItemTableList[k]);
}
continue;
}
int numItemNextCol = 0;
for (int k = 0; k < row; k++)
{
if (ItemTableList[k].Row <= row && ItemTableList[k].Col == col + 2)
{
numItemNextCol++;
}
continue;
}
if (itemSameCol.Count > 1)
{
for (int i = 0; i <= itemSameCol.Count - 2; i++)
{
if (itemSameCol[i].NumChild > 0)
numItemNextCol = numItemNextCol - itemSameCol[i].NumChild;
}
}
if (itemSameCol.Count > 0)
{
// Sono alla riga successiva di un elemento e nella stessa colonna
if (itemSameCol.Last().Row == row)
{
// se ha un solo figlio
if (itemSameCol.Last().NumChild == 1)
{
return "└";
}
else if (itemSameCol.Last().NumChild == 0)
{
return " ";
}
else
{
return "├";
}
}
// Non sono alla riga successiva
else
{
// se ha un solo figlio
if (itemSameCol.Last().NumChild == 1)
{
return " ";
}
else if (col + 2 <= maxCol && ItemTableList[row].Col == col + 2)
{
if (numItemNextCol < itemSameCol.Last().NumChild && numItemNextCol != (itemSameCol.Last().NumChild - 1))
{
return "├";
}
return "└";
}
else if (numItemNextCol < itemSameCol.Last().NumChild)
{
return "│";
}
else
{
return " ";
}
}
}
else
{
return " ";
}
}
private bool HideRow(int row, int col)
{
List itemSameCol = new List();
for (int k = 0; k < row; k++)
{
if (ItemTableList[k].Col == col + 1)
{
itemSameCol.Add(ItemTableList[k]);
}
continue;
}
if(itemSameCol.Count > 0)
{
ItemTable? firstItem = itemSameCol.FirstOrDefault();
if (firstItem != null)
return RowCollapsedDict.GetValueOrDefault(firstItem.Row - 1);
}
return false;
}
}
///
/// Classe per inserire dati per NextStep
///
public class DataNextStep
{
public CompileStep currCompileStep { get; set; }
public int index { get; set; }
}
}