{#
 # ---------------------------------------------------------------------
 #
 # 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/>.
 #
 # ---------------------------------------------------------------------
 #}

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

<div class="row g-3 mb-3">

    <div class="col-12 col-lg-6">
        <div class="card shadow-sm h-100">
            <div class="card-header fw-bold">
                {{ __('Add a document') }}
            </div>
            <div class="card-body">
                <form method="post" action="{{ 'Document'|itemtype_form_path }}" enctype="multipart/form-data" data-submit-once>
                    <div class="d-flex flex-column align-items-center">
                        {{ fields.dropdownField('DocumentCategory', 'documentcategories_id', item.fields['documentcategories_id'] ?? '', 'DocumentCategory'|itemtype_name, {
                            entity: entities,
                            'field_class': 'col-12 col-sm-10',
                        }) }}

                        {{ fields.fileField('filename', null, null, {
                            no_label: true,
                            multiple: true,
                            'field_class': 'col-12 col-sm-10',
                        }) }}

                        <div class="text-end">
                            {{ inputs.submit('add', _x('button', 'Add a new file'), 1) }}
                        </div>

                        {{ inputs.hidden('entities_id', entity) }}
                        {{ inputs.hidden('is_recursive', item.isRecursive() ? '1' : '0') }}
                        {{ inputs.hidden('itemtype', item.getType()) }}
                        {{ inputs.hidden('items_id', item.getID()) }}
                        {% if item.getType() == 'Ticket' %}
                            {{ inputs.hidden('tickets_id', item.getID()) }}
                        {% endif %}
                        {{ inputs.hidden('_glpi_csrf_token', csrf_token()) }}
                    </div>
                </form>
            </div>
        </div>
    </div>

    {% if canview %}
        <div class="col-12 col-lg-6">
            <div class="card shadow-sm h-100">
                <div class="card-header fw-bold">
                    {{ __('Associate an existing document') }}
                </div>
                <div class="card-body d-flex flex-column h-100">
                    <form method="post" action="{{ 'Document_Item'|itemtype_form_path }}" data-submit-once class="d-flex flex-column h-100">

                        <div class="d-flex flex-column align-items-center">
                            {{ fields.dropdownField('Document', 'documents_id', null, 'Document'|itemtype_name, {
                                entity: entities,
                                used: used,
                                'field_class': 'col-12 col-sm-12',
                                'label_class': 'col-xxl-2',
                                'input_class': 'col-xxl-10',
                            }) }}
                        </div>

                        <div class="d-flex flex-column align-items-center text-end mt-auto">
                            {{ inputs.submit('add', _x('button', 'Associate'), 1) }}
                        </div>

                        {{ inputs.hidden('itemtype', item.getType()) }}
                        {{ inputs.hidden('items_id', item.getID()) }}
                        {% if item.getType() == 'Ticket' %}
                            {{ inputs.hidden('tickets_id', item.getID()) }}
                            {{ inputs.hidden('documentcategories_id', config('documentcategories_id_forticket')) }}
                        {% endif %}
                        {{ inputs.hidden('_glpi_csrf_token', csrf_token()) }}
                    </form>
                </div>
            </div>
        </div>
    {% endif %}

</div>

