{#
Bengal OpenAPI Code Samples
===========================

Multi-language code sample panel with tab switching.
Displays request examples in curl, Python, JavaScript, Go, Ruby, PHP.

Context:
- method: HTTP method (GET, POST, etc.)
- path: Endpoint path
- base_url: Base API URL (optional)
- parameters: List of parameters (optional)
- request_body: Request body schema (optional)
- headers: Additional headers dict (optional)
- auth_scheme: Authentication scheme name (optional)

Kida Features:
- {% spaceless %} for compact tab output
- {% with %} for nil-safe optional sections
- Uses generate_code_sample() template function
- Optional chaining (?.) and null coalescing (??)
#}
{% let method_upper = method |> upper ?? 'GET' %}
{% let api_base = base_url ?? 'https://api.example.com' %}
{% let full_url = api_base ~ path %}
{% let auth = auth_scheme ?? 'Bearer' %}

{# Available languages for code samples #}
{% let languages = [
  {'id': 'curl', 'name': 'cURL', 'icon': 'terminal'},
  {'id': 'python', 'name': 'Python', 'icon': 'code'},
  {'id': 'javascript', 'name': 'JavaScript', 'icon': 'code'},
  {'id': 'go', 'name': 'Go', 'icon': 'code'},
  {'id': 'ruby', 'name': 'Ruby', 'icon': 'code'},
  {'id': 'php', 'name': 'PHP', 'icon': 'code'}
] %}

<div class="api-code-samples" data-endpoint="{{ path }}">
  {# Header with Language Tabs #}
  <header class="api-code-samples__header">
    <h3 class="api-code-samples__title">Request</h3>
    <div class="api-code-samples__tabs" role="tablist">
      {% for lang in languages %}
      {% spaceless %}
      <button
        class="api-code-samples__tab{% if loop.first %} api-code-samples__tab--active{% end %}"
        role="tab"
        aria-selected="{{ 'true' if loop.first else 'false' }}"
        aria-controls="code-panel-{{ lang.id }}"
        data-language="{{ lang.id }}"
      >
        {{ lang.name }}
      </button>
      {% end %}
      {% end %}
    </div>
  </header>

  {# Code Panels #}
  <div class="api-code-samples__panels">
    {# cURL Panel #}
    <div class="api-code-samples__panel api-code-samples__panel--active" id="code-panel-curl" role="tabpanel">
      <div class="api-code-samples__code">
        <button class="api-code-samples__copy" data-copy-target="code-curl-{{ path | slugify }}" aria-label="Copy code">
          {{ icon('copy', size=14) }}
        </button>
        <pre id="code-curl-{{ path | slugify }}"><code class="language-bash">{{ generate_code_sample('curl', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}</code></pre>
      </div>
    </div>

    {# Python Panel #}
    <div class="api-code-samples__panel" id="code-panel-python" role="tabpanel">
      <div class="api-code-samples__code">
        <button class="api-code-samples__copy" data-copy-target="code-python-{{ path | slugify }}" aria-label="Copy code">
          {{ icon('copy', size=14) }}
        </button>
        <pre id="code-python-{{ path | slugify }}"><code class="language-python">{{ generate_code_sample('python', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}</code></pre>
      </div>
    </div>

    {# JavaScript Panel #}
    <div class="api-code-samples__panel" id="code-panel-javascript" role="tabpanel">
      <div class="api-code-samples__code">
        <button class="api-code-samples__copy" data-copy-target="code-js-{{ path | slugify }}" aria-label="Copy code">
          {{ icon('copy', size=14) }}
        </button>
        <pre id="code-js-{{ path | slugify }}"><code class="language-javascript">{{ generate_code_sample('javascript', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}</code></pre>
      </div>
    </div>

    {# Go Panel #}
    <div class="api-code-samples__panel" id="code-panel-go" role="tabpanel">
      <div class="api-code-samples__code">
        <button class="api-code-samples__copy" data-copy-target="code-go-{{ path | slugify }}" aria-label="Copy code">
          {{ icon('copy', size=14) }}
        </button>
        <pre id="code-go-{{ path | slugify }}"><code class="language-go">{{ generate_code_sample('go', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}</code></pre>
      </div>
    </div>

    {# Ruby Panel #}
    <div class="api-code-samples__panel" id="code-panel-ruby" role="tabpanel">
      <div class="api-code-samples__code">
        <button class="api-code-samples__copy" data-copy-target="code-ruby-{{ path | slugify }}" aria-label="Copy code">
          {{ icon('copy', size=14) }}
        </button>
        <pre id="code-ruby-{{ path | slugify }}"><code class="language-ruby">{{ generate_code_sample('ruby', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}</code></pre>
      </div>
    </div>

    {# PHP Panel #}
    <div class="api-code-samples__panel" id="code-panel-php" role="tabpanel">
      <div class="api-code-samples__code">
        <button class="api-code-samples__copy" data-copy-target="code-php-{{ path | slugify }}" aria-label="Copy code">
          {{ icon('copy', size=14) }}
        </button>
        <pre id="code-php-{{ path | slugify }}"><code class="language-php">{{ generate_code_sample('php', method, path, base_url=api_base, request_body=request_body, parameters=parameters, auth_scheme=auth) }}</code></pre>
      </div>
    </div>
  </div>

  {# Response Preview (optional) #}
  {% with response_example as example %}
  <div class="api-code-samples__response">
    <header class="api-code-samples__response-header">
      <h4 class="api-code-samples__title">Response</h4>
      <span class="badge badge--success badge--sm">200 OK</span>
    </header>
    <div class="api-code-samples__code">
      <pre><code class="language-json">{{ example | tojson(indent=2) }}</code></pre>
    </div>
  </div>
  {% end %}
</div>
