{# @tailwind-safelist bg-primary/10 bg-cohorts/10 bg-warning/10 bg-error/10 bg-success/10 bg-info/10 bg-pink/10 #} {# # ============================================================================ # MOLECULE: CONTRACT ROW # ============================================================================ # # Affiche une ligne de contrat avec nom, dates, outils et statut. # Utilisé dans les listes de contrats admin. # # ============================================================================ # COMPOSITION (Atomes utilisés) # ============================================================================ # # - _atoms/icon/icon.html.twig # - _atoms/badge/badge.html.twig # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |---------------|-------------------|----------|--------------------------------------| # | name | string | (requis) | Nom du contrat | # | startDate | DateTimeInterface | (requis) | Date de début | # | endDate | DateTimeInterface | (requis) | Date de fin | # | contractTools | array | [] | Codes des outils du contrat | # | allTools | array | [] | Tous les outils [{code, name}] | # | tokens | int | 0 | Tokens mensuels alloués | # | maxUsers | int | 0 | Nombre max d'utilisateurs | # | status | string | 'active' | Statut: active, inactive, upcoming, | # | | | | expired, disabled | # | daysRemaining | int | null | Jours restants (pour badge warning) | # | isExpiringSoon| bool | false | Expire bientôt (< 30j) | # | isActive | bool | true | Contrat actif (rétrocompatibilité) | # | href | string | null | Lien vers le détail | # | hasSamAccess | bool | null | Affiche l'icône SAM colorée/grisée | # # ============================================================================ # EXEMPLES D'UTILISATION # ============================================================================ # # Basique: # {% include '_molecules/contract-row/contract-row.html.twig' with { # name: 'Contrat Premium', # startDate: contract.startDate, # endDate: contract.endDate, # contractTools: contract.tools|map(t => t.code), # allTools: allTools, # tokens: contract.monthlyTokens, # maxUsers: contract.maxUsers, # status: contract.status, # daysRemaining: contract.daysRemaining, # isExpiringSoon: contract.isExpiringSoon(30), # href: path('admin_contract_show', {companyUuid: company.uuid, contractUuid: contract.uuid}) # } only %} # # ============================================================================ #} {# ============================================================================ CONFIGURATION DES VALEURS PAR DÉFAUT ============================================================================ #} {% set name = name|default('Contrat') %} {% set tokens = tokens|default(0) %} {% set maxUsers = maxUsers|default(0) %} {% set status = status|default('active') %} {% set daysRemaining = daysRemaining|default(null) %} {% set isExpiringSoon = isExpiringSoon|default(false) %} {% set isActive = isActive ?? true %} {% set href = href|default(null) %} {% set hasSamAccess = hasSamAccess ?? null %} {# Déterminer si inactif pour le style général #} {% set isInactive = status == 'expired' or status == 'disabled' or not isActive %} {# ============================================================================ BADGE CONFIGURATION ============================================================================ #} {% if status == 'expired' or status == 'disabled' %} {% set badgeConfig = { label: 'Inactif', variant: 'neutral' } %} {% elseif status == 'upcoming' %} {% set badgeConfig = { label: 'À venir', variant: 'info', dot: true } %} {% elseif isExpiringSoon and daysRemaining is not null %} {% set badgeConfig = { label: daysRemaining ~ 'j', variant: 'warning', dot: true } %} {% else %} {% set badgeConfig = { label: 'Actif', variant: 'success', dot: true } %} {% endif %} {# ============================================================================ CLASSES TAILWIND ============================================================================ #} {% set tag = href ? 'a' : 'div' %} {% set rowClasses = [ 'group flex items-center gap-4 p-4 rounded-xl border transition-all duration-200', isInactive ? 'border-transparent bg-white/50 opacity-55' : 'border-transparent bg-white hover:bg-primary-muted hover:border-primary-subtle', href ? 'cursor-pointer no-underline' : '' ]|join(' ')|trim %} {# ============================================================================ RENDU HTML ============================================================================ #} <{{ tag }}{% if href %} href="{{ href }}"{% endif %} class="{{ rowClasses }}"> {# Infos principales #}
{{ name }} {% include '_atoms/badge/badge.html.twig' with { label: badgeConfig.label, variant: badgeConfig.variant, dot: badgeConfig.dot|default(false), size: 'xs' } only %}
{{ startDate|date('d/m/Y') }} → {{ endDate|date('d/m/Y') }} {{ maxUsers }} utilisateurs • {{ tokens|number_format(0, ',', ' ') }} tokens/mois
{# Icône SAM (si paramètre fourni) #} {% if hasSamAccess is not null %}
{% include '_atoms/logo/logo.html.twig' with { variant: 'simple', size: 'xs', tint: 'cohorts' } only %}
{% endif %} {# Chevron #} {% if href %}
{% include '_atoms/icon/icon.html.twig' with { name: 'chevron-right', size: 'sm', color: 'current' } only %}
{% endif %}