from rich.table import Table
from rich.console import Console
from rich import box
from datetime import datetime




def print_device_list(device_list,highlighted_rows: list = []):
    console = Console()
    table = Table(
        title="Devices",
        box=box.ROUNDED,
        padding=(0, 1),
        show_lines=False,
    )

    table.add_column("Name", style="bold cyan", overflow="fold")
    table.add_column("Device id", justify="right", style="magenta")
    
    for device in device_list:
        
        name=device['name']
        id= device['id']
        table.add_row(name, id)
    console.print(table)

def print_device_config(ospf_data,highlighted_rows: list = []):
    console = Console()
    table = Table(
        title=f"OSPF networks for device: [bold cyan]{ospf_data["device_name"]}",
        box=box.ROUNDED,
        padding=(0, 1),
        show_lines=False,
    )
    
    table.add_column("Network", style="bold cyan", overflow="fold")
    table.add_column("Passive", justify="right", style="magenta")
    table.add_column("Interface type", justify="right", style="orange3")
    
    for name, data in ospf_data["networks"].items():
        passive = "[green]True[/green]" if data["passive"] else "[red]False[/red]"
        interface_type = data["interface_type"]

        table.add_row(name, passive, interface_type,)
    console.print(table)

def print_dhcp_scopes(scope_data):
    console = Console()
    table = Table(
        title=f"DHCP scopes for device: [bold cyan]{scope_data["device_name"]}",
        box=box.ROUNDED,
        padding=(0, 1),
        show_lines=False,
    )
    #print(scope_data)
    table.add_column("Network", style="bold cyan", overflow="fold")
    table.add_column("Start IP", justify="right", style="magenta")
    table.add_column("End IP", justify="right", style="orange3")
    table.add_column("Gateway", justify="right", style="green")
    table.add_column("DNS1", justify="right", style="deep_pink2")
    table.add_column("DNS2", justify="right", style="deep_pink2")

    for name, data in scope_data["networks"].items():
        ip_start = data["Start IP"]
        ip_end = data["End IP"]
        gateway = data["Gateway"]
        dns1= data["DNS"][0]
        dns2 = data["DNS"][1] if len(data["DNS"]) >= 2 else "-"
        

        table.add_row(name, ip_start, ip_end,gateway,dns1,dns2)
    console.print(table)
    
def print_vrrp_gropus(vrrp_data):
    console = Console()
    table = Table(
        title=f"VRRP Grops for: [bold cyan]{vrrp_data["device_name"]}",
        box=box.ROUNDED,
        padding=(0, 1),
        show_lines=False,
    )
    
    table.add_column("VRRP Group ID", style="bold cyan", overflow="fold")
    table.add_column("Network", justify="right", style="magenta")
    table.add_column("ip", justify="right", style="orange3")
    
    
    for vrrp in vrrp_data["vrrp_groups"]:
        table.add_row(
            vrrp["id"],
            vrrp["network"],
            vrrp["ip"]
        )
    console.print(table)
     
def print_access(access_data):
    console = Console()
    table = Table(
        title=f"Accessconfig for: [bold cyan]{access_data["device_name"]}",
        box=box.ROUNDED,
        padding=(0, 1),
        show_lines=False,
    )
    
    table.add_column("Port", style="bold cyan", overflow="fold")
    table.add_column("Usage", justify="right", style="magenta")
    
    
    
    for access in access_data["port_config"]:
        table.add_row(
            access["port"],
            access["usage"],
            
        )
        
    console.print(table)