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

{% extends 'components/itilobject/timeline/form_timeline_item.html.twig' %}
{% import 'components/form/fields_macros.html.twig' as fields %}

{% block timeline_card %}
    {% if form_mode == 'view' %}
        {{ include('components/itilobject/timeline/sub_documents.html.twig', {
            'entry': {
                'documents': [entry],
            },
            'item': item,
        }, with_context: false) }}
    {% else %}
        <div class="document_item">
            <form name="asset_form" style="width: 100%;" class="d-flex flex-column" method="post"
                  action="{{ "Document"|itemtype_form_path() }}" enctype="multipart/form-data" data-track-changes="true" data-submit-once>
                <input type="hidden" name="entities_id" value="{{ item.getEntityID() }}" />
                <input type="hidden" name="is_recursive" value="{{ item.isRecursive() ? 1 : 0 }}" />
                <input type="hidden" name="itemtype" value="{{ item.getType() }}" />
                <input type="hidden" name="items_id" value="{{ item.fields['id'] }}" />
                <input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}" />
                {{ call_plugin_hook(constant('Glpi\\Plugin\\Hooks::PRE_ITEM_FORM'), {"item": subitem, 'options': params}) }}

                {% set can_screenshot = call('Document::isValidDoc', ['.png']) is not empty %}
                {% set can_screenrecord = call('Document::isValidDoc', ['.webm']) is not empty %}

                {% if can_screenshot or can_screenrecord %}
                    <div class="upload-from-section d-none">
                        <label id="upload_source_label" class="form-label">{{ __("Upload from") }}</label>
                        <div class="d-inline" role="group" aria-labelledby="upload_source_label">
                            {% if can_screenshot %}
                                <button class="btn btn-sm btn-secondary me-2 d-none" type="button" name="add_screenshot">
                                    <i class="ti ti-photo"></i>
                                    <span>{{ __('Screenshot') }}</span>
                                </button>
                            {% endif %}
                            {% if can_screenrecord %}
                                <button class="btn btn-sm btn-secondary me-2 d-none" type="button" name="add_screenrecording">
                                    <i class="ti ti-camera"></i>
                                    <span>{{ __('Screen recording') }}</span>
                                </button>
                            {% endif %}
                        </div>
                        <div id="screen_capture_preview" class="w-100">
                            <div class="previews overflow-x-auto my-2 d-flex px-2"></div>
                            <button type="button" name="stop_recording" class="btn btn-secondary d-none">{{ __('Stop recording') }}</button>
                        </div>
                        <hr class="my-1">
                    </div>
                {% endif %}
                {% if get_current_interface() == 'central' %}
                    {{ fields.dropdownField(
                        'DocumentCategory',
                        'documentcategories_id',
                        null,
                        __("Heading"),
                        {
                            'full_width': true,
                            'is_horizontal': false
                        }
                    ) }}
                {% endif %}

                {{ fields.fileField(
                    'filename',
                    null,
                    __("File"),
                    {
                        'multiple': true,
                        'full_width': true,
                        'is_horizontal': false,
                    }
                ) }}

                {{ call_plugin_hook(constant('Glpi\\Plugin\\Hooks::POST_ITEM_FORM'), {"item": subitem, 'options': params}) }}

                <div class="d-flex card-footer mx-n3 mb-n3">
                    {% if (subitem.fields['id'] ?? 0) <= 0 %}
                        <div class="input-group">
                            <button class="btn btn-primary" type="submit" name="add">
                                <i class="ti ti-file-plus"></i>
                                <span>{{ _x('button', 'Add a new file') }}</span>
                            </button>
                        </div>
                    {% endif %}
                </div>
            </form>
        </div>
        <script type="module">
            import('/js/modules/ITIL/Timeline/DocumentForm.js');
        </script>
    {% endif %}
{% endblock %}
