{% extends 'layout_default.html.twig' %}

{% set active_menu = 'client' %}
{% set can_manage_groups = has_permission('client', 'manage_groups') %}

{% block meta_title %}{{ group.title }}{% endblock %}

{% block breadcrumbs %}
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ '/'|url }}">
                <svg class="icon">
                    <use xlink:href="#home" />
                </svg>
            </a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'client'|url }}#tab-groups">{{ 'Client Groups'|trans }}</a>
        </li>
        <li class="breadcrumb-item active" aria-current="page">{{ group.title}}</li>
    </ol>
{% endblock %}

{% block content %}
<div class="card">
    <div class="card-header">
        <div>
            <h3 class="card-title">{{ group.title }}</h3>
            <p class="card-subtitle">{{ 'Update the client group name or remove the group entirely.'|trans }}</p>
        </div>
    </div>
    {% if can_manage_groups %}
    <form method="post" action="{{ 'client/group_update'|api_url }}" {{ fb_api_form({redirect: 'client'|url ~ '#tab-groups'}) }}>
        <div class="card-body">
            <div class="row g-3">
                <div class="col-lg-6">
                    <label class="form-label">{{ 'Title'|trans }}</label>
                    <input class="form-control" type="text" name="title" value="{{ group.title }}" required>
                </div>
            </div>
        </div>

        <input type="hidden" name="id" value="{{ group.id }}">

        <div class="card-footer d-flex flex-wrap gap-2 justify-content-between">
            <a href="{{ 'client'|url }}#tab-groups" class="btn btn-secondary">
                <svg class="icon">
                    <use xlink:href="#arrow-sm-left" />
                </svg>
                {{ 'Go Back'|trans }}
            </a>
            <div class="d-flex flex-wrap gap-2">
                <a class="btn btn-danger" href="{{ 'client/group_delete'|api_url(query: { 'id': group.id }) }}"
                    {{ fb_api_link({modal: {type: 'confirm', title: 'Are you sure?'|trans}, redirect: 'client'|url ~ '#tab-groups'}) }}>
                    <svg class="icon">
                        <use xlink:href="#delete" />
                    </svg>
                    {{ 'Delete'|trans }}
                </a>
                <button class="btn btn-primary" type="submit">{{ 'Update'|trans }}</button>
            </div>
        </div>
    </form>
    {% else %}
    <div class="card-body">
        <p class="text-muted mb-0">{{ 'You do not have permission to manage client groups.'|trans }}</p>
    </div>
    {% endif %}
</div>
{% endblock %}
