#!/usr/bin/env python
# Copyright (c) 2022 Clément Martin <twisla@twis.la. All rights reserved.
# Unauthorized copying of this file, via any medium is strictly prohibited

from diagrams import Edge, Node

# Dict defining our custom edges styles.
EDGES = {
    'adsl':      { 'color': 'purple4',       'style': 'dotted'  },
    'audio':     { 'color': 'khaki4',        'style': 'solid'   },
    'bluetooth': { 'color': 'royalblue1',    'style': 'dashed'  },
    'cable':     { 'color': 'rebeccapurple', 'style': 'dotted'  },
    'electric':  { 'color': 'turquoise',     'style': 'tapered' },
    'ethernet':  { 'color': 'navy',          'style': 'solid'   },
    'hdmi':      { 'color': 'palegreen4',    'style': 'solid'   },
    'wifi':      { 'color': 'firebrick',     'style': 'dashed'  },
    'zigbee':    { 'color': 'orange',        'style': 'dashed'  }
}

# Common method to instanciate a styled edge
def MyEdge(edge):
    return Edge(color=EDGES[edge]['color'], style=EDGES[edge]['style'])

# Generate a legend for the colors and styles
def Legend():
    _html = '<<TABLE>'
    for edge in EDGES.keys():
        _html += f"""<TR><TD BGCOLOR="{EDGES[edge]['color']}">{edge} ({EDGES[edge]['style']})</TD></TR>"""
    _html += '</TABLE>>'
    return Node(label=_html, shape='plaintext')
