{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 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/>.
 #
 # ---------------------------------------------------------------------
 #}

{% set target       = params['target'] ?? item.getFormURL() %}
{% set withtemplate = params['withtemplate'] ?? '' %}
{% set rand         = random() %}
{% set nametype     = params['formtitle'] ?? item.getTypeName(1) %}
{% set no_id        = params['noid'] ?? false %}
{% set formoptions  = params['formoptions'] ?? '' %}

{% set entity_id = 0 %}
{% set entity_name = '' %}
{% if item.isEntityAssign() %}
   {% if item.getType() == 'Entity' and item.fields['id'] == 0 %}
      {% set entity_id = null %}
   {% else %}
      {% set entity_id = params['entities_id'] ?? item.getEntityID() ?? session('glpiactive_entity') %}
   {% endif %}

   {% if is_multi_entities_mode() %}
      {% set entity_name = get_item_name('Entity', entity_id is not empty ? entity_id : null) %}
   {% endif %}
{% endif %}

{% set no_header = no_header|default(false) %}
{% set open_form = no_header or item.isNewID(item.fields['id']) or in_twig is not defined %}
{# Include header content if one or more condition matches and no_header is not explicitly true: #}
{# - This template is called from another twig template (as opposed to from PHP and most likely a legacy form) OR is in a modal #}
{# - Not from a twig template and it is a new item #}
{% set include_header_content = no_header == false and ((in_twig is defined or _get._in_modal|default(false)) or (in_twig is not defined and item.isNewID(item.fields['id']))) %}

{% if open_form and item.canEdit(item.fields['id']) %}
<form name="asset_form" method="post" action="{{ target }}" {{ formoptions|raw }} enctype="multipart/form-data" data-submit-once>
   {% if item.isField("entities_id") %}
       <input type="hidden" name="entities_id" value="{{ entity_id }}" />
   {% endif %}
   {% if _request['_in_modal'] is defined and _request['_in_modal'] == "1" %}
      <input type="hidden" name="_in_modal" value="1"/>
   {% endif %}
{% endif %}
   <div id="mainformtable">
      {% if include_header_content %}
         {{ include('components/form/header_content.html.twig', {'inside_main': true}) }}
      {% else %}
         <input type="hidden" name="is_recursive" value="{{ item.fields['is_recursive']|default(1) }}" />
      {% endif %}

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

      {# todo modal message #}
      {% if app.request.request('in_modal') == true %}
      <input type="hidden" name="_no_message_link" value="1" />
      {% endif %}
