{{!
    @template local_kid/admin_capp

    * addurl - string
    * hassessions - bool
    * sessions - array of { id, code, libelle, statuslabel, statusclass,
      editurl, toggleurl, deleteurl, openurl }
    * hasrattachable - bool
    * rattachrows - array of { sourcetype, sourceid, label, typelabel,
      options: [{ id, label, selected }] }
    * rattachurl, sesskey - string
    * hassessionsforrule - bool
}}
<div class="fr-scope">
<p class="fr-mb-4w">
    <a class="fr-btn" href="{{addurl}}">{{#str}}capp_add, local_kid{{/str}}</a>
</p>

{{^hassessions}}
    {{> local_kid/empty_state}}
{{/hassessions}}

{{#hassessions}}
<div class="fr-table">
    <table>
        <caption>{{#str}}capp_libelle, local_kid{{/str}}</caption>
        <thead>
            <tr>
                <th scope="col">{{#str}}capp_col_code, local_kid{{/str}}</th>
                <th scope="col">{{#str}}capp_libelle, local_kid{{/str}}</th>
                <th scope="col">{{#str}}promotion_col_status, local_kid{{/str}}</th>
                <th scope="col">{{#str}}promotion_col_actions, local_kid{{/str}}</th>
            </tr>
        </thead>
        <tbody>
            {{#sessions}}
            <tr>
                <td><a class="fr-link" href="{{openurl}}">{{code}}</a></td>
                <td>{{libelle}}</td>
                <td><span class="{{statusclass}}">{{statuslabel}}</span></td>
                <td>
                    <a class="fr-link" href="{{editurl}}">{{#str}}action_edit, local_kid{{/str}}</a>
                    · <a class="fr-link" href="{{toggleurl}}">{{#str}}action_toggle_active, local_kid{{/str}}</a>
                    · <form class="kid-inline-form" method="post" action="{{deleteurl}}" onsubmit="return confirm('{{#str}}capp_session_delete_confirm, local_kid{{/str}}');">
                        <input type="hidden" name="sesskey" value="{{sesskey}}">
                        <button type="submit" class="fr-link">{{#str}}action_delete, local_kid{{/str}}</button>
                    </form>
                </td>
            </tr>
            {{/sessions}}
        </tbody>
    </table>
</div>
{{/hassessions}}

{{#hassessionsforrule}}
<div class="fr-card fr-my-4w">
    <div class="fr-card__body">
        <div class="fr-card__content">
            <h3 class="fr-card__title">{{#str}}capp_rattachement_heading, local_kid{{/str}}</h3>
            <p class="fr-text--sm">{{#str}}capp_rattachement_help, local_kid{{/str}}</p>

            {{^hasrattachable}}
                <p>{{#str}}capp_no_rattachable, local_kid{{/str}}</p>
            {{/hasrattachable}}

            {{#hasrattachable}}
            <div class="fr-table fr-table--no-caption fr-mt-2w">
                <table>
                    <caption>{{#str}}capp_rattachement_heading, local_kid{{/str}}</caption>
                    <thead>
                        <tr>
                            <th scope="col">{{#str}}capp_col_type, local_kid{{/str}}</th>
                            <th scope="col">{{#str}}capp_col_source, local_kid{{/str}}</th>
                            <th scope="col">{{#str}}capp_col_session, local_kid{{/str}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {{#rattachrows}}
                        <tr>
                            <td>{{typelabel}}</td>
                            <td>{{label}}</td>
                            <td>
                                <form method="post" action="{{{rattachurl}}}" class="kid-inline-form">
                                    <input type="hidden" name="sesskey" value="{{sesskey}}">
                                    <input type="hidden" name="sourcetype" value="{{sourcetype}}">
                                    <input type="hidden" name="sourceid" value="{{sourceid}}">
                                    <select name="sessionid" class="fr-select" onchange="this.form.submit()">
                                        {{#options}}
                                        <option value="{{id}}" {{#selected}}selected{{/selected}}>{{label}}</option>
                                        {{/options}}
                                    </select>
                                    <noscript><button type="submit" class="fr-btn fr-btn--sm">{{#str}}promotion_switch_go, local_kid{{/str}}</button></noscript>
                                </form>
                            </td>
                        </tr>
                        {{/rattachrows}}
                    </tbody>
                </table>
            </div>
            {{/hasrattachable}}
        </div>
    </div>
</div>
{{/hassessionsforrule}}
</div>
