<?php
$values = is_array($values ?? null) ? $values : [];
$formId = $formId ?? 'software-product-form';
$handoverSchemaFields = is_array($handoverSchemaFields ?? null) ? $handoverSchemaFields : [];
?>
<form id="<?php e($formId); ?>" method="post" data-standard-detail-form="1">
  <div class="app-tabs" data-tabs data-app-component="tabs" data-tabs-param="tab" data-tabs-storage-key="helpdesk-software-product-form">
    <div class="app-tabs-nav">
      <button type="button" data-tab="basic" data-tab-default><?php e(t('Master data')); ?></button>
      <button type="button" data-tab="handover-protocol"><?php e(t('Handover protocol')); ?></button>
    </div>

    <div data-tab-panel="basic">
      <label for="software-product-name"><?php e(t('Product name')); ?></label>
      <input
        type="text"
        id="software-product-name"
        name="name"
        value="<?php e($values['name'] ?? ''); ?>"
        maxlength="255"
        placeholder="<?php e(t('Enter product name...')); ?>"
      >
    </div>

    <div data-tab-panel="handover-protocol" data-tab-panel-wide>
      <div class="handover-schema-split">
        <div class="handover-schema-split-editor">
          <div
            id="handover-schema-editor"
            data-app-component="helpdesk-handover-schema-editor"
            data-initial-fields="<?php e(json_encode($handoverSchemaFields, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); ?>"
            data-translations="<?php e(json_encode([
              'add_field' => t('Add field'),
              'remove_field' => t('Remove field'),
              'duplicate_field' => t('Duplicate field'),
              'move_up' => t('Move up'),
              'move_down' => t('Move down'),
              'field_key' => t('Field key'),
              'field_label' => t('Field label'),
              'field_type' => t('Field type'),
              'required' => t('Required'),
              'options' => t('Options'),
              'add_option' => t('Add option'),
              'remove_option' => t('Remove option'),
              'option_value' => t('Option value'),
              'option_label' => t('Option label'),
              'no_fields' => t('No fields defined yet. Click "Add field" to get started.'),
              'type_heading' => t('Heading'),
              'type_paragraph' => t('Paragraph'),
              'type_text' => t('Text'),
              'type_textarea' => t('Textarea'),
              'type_number' => t('Number'),
              'type_date' => t('Date'),
              'type_checkbox' => t('Checkbox'),
              'type_select' => t('Select'),
              'text_content' => t('Text content'),
              'field' => t('Field'),
              'preview' => t('Preview'),
              'preview_empty' => t('Add fields to see a live preview.'),
            ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); ?>"
          ></div>
          <input type="hidden" name="handover_schema_json" id="handover-schema-json" value="">
        </div>
        <div class="handover-schema-split-preview">
          <div class="handover-schema-preview-header"><?php e(t('Preview')); ?></div>
          <div id="handover-schema-preview" class="handover-schema-preview"></div>
        </div>
      </div>
    </div>
  </div>

  <?php \MintyPHP\Session::getCsrfInput(); ?>
</form>
