{#
/**
 * @file
 * FlowDrop Playground Component Template
 *
 * An interactive playground for testing FlowDrop workflows with a
 * chat-like interface.
 *
 * Available variables:
 * - workflow: Workflow data object.
 * - endpoint_config: API endpoint configuration.
 * - container_id: Unique ID for the playground container.
 * - height: Container height (CSS value).
 * - width: Container width (CSS value).
 * - back_url: URL for back navigation.
 * - workflow_name: Display name of the workflow.
 * - show_header: Whether to display the header (default: true).
 * - initial_session_id: Session ID (UUID) to auto-select when playground loads.
 * - show_chat_input: Whether to show the text input (default: true).
 * - show_run_button: Whether to show the Run button (default: true).
 * - predefined_message: Custom message for Run button click.
 * - auto_run: Auto-execute workflow on load (default: false).
 * - attributes: Additional HTML attributes.
 */
#}
{% set show_header = show_header is not defined ? true : show_header %}
{% set header_height = show_header ? '56px' : '0px' %}
{%
  set classes = [
    'fd-playground',
    'fd-fullscreen-layout',
    show_header ? 'fd-playground--with-header' : '',
  ]
%}

<div{{ attributes.addClass(classes) }}
  id="{{ container_id|default('flowdrop-playground') }}"
  data-flowdrop-playground
  data-workflow="{{ workflow|json_encode|e('html_attr') }}"
  data-endpoint-config="{{ endpoint_config|json_encode|e('html_attr') }}"
  data-mode="{{ mode|default('standalone') }}"
  data-back-url="{{ back_url|default('/admin/flowdrop/workflows') }}"
  data-workflow-name="{{ workflow_name|default('Workflow') }}"
  {% if initial_session_id %}data-initial-session-id="{{ initial_session_id }}"{% endif %}
  {% if show_chat_input is defined %}data-show-chat-input="{{ show_chat_input ? 'true' : 'false' }}"{% endif %}
  {% if show_run_button is defined %}data-show-run-button="{{ show_run_button ? 'true' : 'false' }}"{% endif %}
  {% if predefined_message %}data-predefined-message="{{ predefined_message }}"{% endif %}
  {% if auto_run %}data-auto-run="true"{% endif %}
  style="height: {{ height|default('100%') }}; width: {{ width|default('100%') }};">

  {# Header with back navigation - shown for standalone mode by default #}
  {% if show_header and mode|default('standalone') != 'modal' %}
  <header class="fd-playground__header">
    <div class="fd-playground__header-start">
      {# Back button - links to workflow listing #}
      <a href="{{ back_url|default('/admin/flowdrop/workflows') }}" class="fd-playground__back-btn" title="Back to Workflows">
        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
          <path d="M19 12H5"/>
          <path d="M12 19l-7-7 7-7"/>
        </svg>
      </a>
      
      {# Divider #}
      <div class="fd-playground__header-divider"></div>
      
      {# Workflow name #}
      <div class="fd-playground__workflow-info">
        <span class="fd-playground__workflow-label">Playground</span>
        <h1 class="fd-playground__workflow-name">{{ workflow_name|default('Workflow') }}</h1>
      </div>
    </div>
    
    <div class="fd-playground__header-end">
      {# Edit workflow button - links to workflow editor #}
      <a href="{{ editor_url|default(back_url|default('/admin/flowdrop/workflows')) }}" class="fd-playground__action-btn" title="Edit Workflow">
        <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
          <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
          <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
        </svg>
        <span>Edit Workflow</span>
      </a>
    </div>
  </header>
  {% endif %}

  {# Main playground container #}
  <div class="fd-playground__content" style="height: calc(100% - {{ header_height }});">
    {# Loading State - Only shown for non-modal modes #}
    {% if mode|default('standalone') != 'modal' %}
    <div class="fd-playground__loading">
      <div class="fd-playground__loading-spinner">
        <svg class="fd-playground__spinner-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
          <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" stroke-dasharray="31.416" stroke-dashoffset="10" stroke-linecap="round"/>
        </svg>
      </div>
      <p class="fd-playground__loading-text">Loading Playground...</p>
    </div>
    {% endif %}
  </div>

</div>
