{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2026 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{# @var form                   Glpi\Form #}
{# @var comment                Glpi\Form\Comment|null #}
{# @var section                Glpi\Form\Section|null #}
{# @var can_update             bool #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{% set base_field_options = {
    'is_horizontal': false,
    'full_width'   : true,
    'no_label'     : true,
} %}
{% set comment = comment|default(null) %}

<section
    role="option"
    class="d-flex"
    data-glpi-form-editor-block
    data-glpi-form-editor-comment
    data-glpi-form-editor-condition-type="{{ enum('Glpi\\Form\\Condition\\Type').COMMENT.value }}"
    data-glpi-draggable-item
    aria-label="{{ comment is not null ? comment.fields.name : __('New comment') }}"
>
    <section
        data-glpi-form-editor-on-click="set-active"
        data-glpi-form-editor-comment-details
        class="card flex-grow-1"
        aria-label="{{ __("Comment details") }}"
    >
        <div
            class="card-status-start bg-primary"
            data-glpi-form-editor-active-comment-status-indicator
        ></div>
        <div class="card-body">
            <div class="d-flex">
                <i
                    class="glpi-form-editor-question-handle ti ti-grip-horizontal cursor-grab ms-auto me-auto mt-n3 mb-n2"
                    data-glpi-form-editor-question-handle
                    draggable="true"
                    data-glpi-form-editor-state-action
                ></i>
            </div>
            {# Display comment's title #}
            <div class="d-flex mt-n1 mb-3 align-items-center">
                <input
                    class="form-control content-editable-h2 mb-0"
                    type="text"
                    name="name"
                    value="{{ comment is not null ? comment.fields.name : '' }}"
                    placeholder="{{ __("New comment") }}"
                    aria-label="{{ __("Comment title") }}"
                    data-glpi-form-editor-dynamic-input
                    data-glpi-form-editor-comment-details-name
                    maxlength="255"
                />

                <div class="ms-auto"></div>

                {# Visibility dropdown #}
                {{ include('pages/admin/form/conditional_visibility_dropdown.html.twig', {
                    'item': comment,
                    'type': "Glpi\\Form\\Comment",
                }, with_context = false) }}

                {# Duplicate comment #}
                <i
                    role="button"
                    class="ti ti-copy ms-3 cursor-pointer"
                    data-bs-toggle="tooltip"
                    data-bs-placement="top"
                    title="{{ __("Duplicate comment") }}"
                    data-glpi-form-editor-on-click="duplicate-comment"
                    data-glpi-form-editor-comment-extra-details
                    data-glpi-form-editor-state-action
                ></i>

                {# Delete comment #}
                <i
                    role="button"
                    class="ti ti-trash ms-3 cursor-pointer"
                    data-bs-toggle="tooltip"
                    data-bs-placement="top"
                    title="{{ __("Delete") }}"
                    aria-label="{{ __("Delete") }}"
                    data-glpi-form-editor-on-click="delete-comment"
                    data-glpi-form-editor-comment-extra-details
                    data-glpi-form-editor-state-action
                ></i>

                {# Extra actions #}
                <div class="dropdown ms-3 cursor-pointer d-flex align-items-center">
                    <i
                        class="ti ti-dots-vertical show"
                        data-bs-toggle="dropdown"
                        aria-expanded="false"
                        role="button"
                        title="{{ __('More actions') }}"
                        aria-label="{{ __('More actions') }}"
                        data-glpi-form-editor-state-action
                    ></i>
                    <ul class="dropdown-menu" data-bs-popper="none">
                        <li>
                            <button
                                type="button"
                                class="dropdown-item"
                                aria-label="{{ __('Configure visibility') }}"
                                data-glpi-form-editor-on-click="show-visibility-dropdown"
                            >
                                <i class="ti ti-eye-cog me-2"></i>
                                <span>{{ __("Configure visibility") }}</span>
                            </button>
                        </li>
                    </ul>
                </div>
            </div>

            {# Display common fields #}
            <div
                class="content-editable-tinymce"
                data-glpi-form-editor-comment-description
                {# Mark as secondary if empty #}
                {{ comment is null or comment.fields.description|length == 0 ? "data-glpi-form-editor-active-comment-extra-details" : "" }}
            >
                {{ fields.textareaField(
                    'description',
                    comment is not null ? comment.fields.description : '',
                    __('Description'),
                    base_field_options|merge({
                        'placeholder': __('Add a description'),
                        'aria_label': __("Comment description"),
                        'enable_richtext': true,
                        'add_body_classes': ['content-editable-tinymce-editor', 'text-muted'],
                        'editor_height': "0",
                        'rows' : 1,
                        'toolbar_location': 'bottom',
                        'init': false,
                        'init_on_demand': section is not null ? true : false,
                        'mb': 'mb-0',
                    })
                ) }}
            </div>
        </div>

        {# Common hidden data #}
        <input
            type="hidden"
            name="uuid"
            value="{{ comment is not null ? comment.fields.uuid : '' }}"
        />
        <input
            type="hidden"
            name="forms_sections_uuid"
            value="{{ section is not null ? section.fields.uuid : '' }}"
        />
        <input
            type="hidden"
            name="vertical_rank"
            value="{{ comment is not null ? comment.fields.vertical_rank : 0 }}"
        />
        <input
            type="hidden"
            name="horizontal_rank"
            value="{{ comment is not null ? comment.fields.horizontal_rank : 0 }}"
        />
    </section>

    <div data-glpi-form-editor-comment-extra-details>
        {{ include('pages/admin/form/form_toolbar.html.twig', {
            'can_update'     : can_update,
            'form'           : form,
            'vertical_layout': true
        }, with_context = false) }}
    </div>
    <div data-glpi-form-editor-question-drag-merge></div>
</section>
