"""People: initials avatars, person rows and the attendee grid. CSS: people.css."""
from .evidence import evidence
from .links import e
def avatar(name, small=False):
"""A 32px initials avatar, or 24px with small, from the first letters of the first two words of the name.
avatar('Priya Nair') # "PN"
"""
cls = 'avatar-initials avatar-initials--small' if small else 'avatar-initials'
return f'{e("".join(w[0] for w in name.split()[:2]).upper())}'
def person(p, first=False):
"""A person row for a list, with their evidence lines. first adds "Try first".
Data: {"name", "team"?, "role"?, "lastWorked"?, "evidence": [evidence items]}. role is a tag after the name.
person({"name": "Priya Nair", "team": "Team Ledger", "role": "Named contact", "evidence": [...]}, first=True)
"""
tag = f'{e(p["role"])}' if p.get('role') else ''
try_first = 'Try first' if first else ''
team = f'
{e(p["team"])}
' if p.get('team') else ''
last = f'Last worked on this {e(p["lastWorked"])}
' if p.get('lastWorked') else ''
return (f'{avatar(p["name"])}{e(p["name"])}{tag}{try_first}
'
f'{team}{last}{evidence(p["evidence"])}
')
def attendees(people, guests=''):
"""Attendees as initials avatars in a two-column grid (one column on phones), then the guests line.
Data: [{"name", "role"?, "response"?, "optional"?, "you"?, "organiser"?}]. response is "Accepted",
"Tentative", "Declined" or "Not responded", left out without a calendar. you and organiser add a tag after
the name. guests is plain text, such as "2 external guests".
attendees([{"name": "Marco Ruiz", "role": "Engineering manager", "response": "Accepted", "organiser": True}],
guests='1 external guest')
"""
items = []
for p in people:
tags = ''.join(f'{t}' for t, on in (('You', p.get('you')), ('Organiser', p.get('organiser'))) if on)
role = f'{e(p["role"])}
' if p.get('role') else ''
status = ' ยท '.join(x for x in (p.get('response'), 'Optional' if p.get('optional') else '') if x)
status = f'{e(status)}
' if status else ''
items.append(f'{avatar(p["name"])}{e(p["name"])}{tags}
{role}{status}
')
more = f'{e(guests)}
' if guests else ''
return f'{more}'