{% extends 'layout_default.html.twig' %}

{% set active_menu = 'products' %}

{% block meta_title %}Product Addon Management{% endblock %}

{% block breadcrumbs %}
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ '/'|url }}">
                <svg class="icon">
                    <use xlink:href="#home" />
                </svg>
            </a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'product'|url }}">{{ 'Products'|trans }}</a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'product/addons'|url }}">{{ 'Addons'|trans }}</a>
        </li>
        <li class="breadcrumb-item active" aria-current="page">{{ product.title }}</li>
    </ol>
{% endblock %}

{% block content %}
<div class="p-3">
    <form method="post" action="{{ 'product/addon_update'|api_url }}" {{ fb_api_form({message: 'Addon Updated'|trans}) }}>
        {% embed 'partial_admin_form_card.html.twig' with {
            title: 'Edit Product Addon'|trans,
            subtitle: 'Update the addon title, availability, activation timing, and pricing.'|trans,
            card_class: 'mb-0'
        } %}
            {% block form_content %}
                <div class="row g-3">
                    <div class="col-lg-6">
                        <label class="form-label">{{ 'Title'|trans }}</label>
                        <input class="form-control" type="text" name="title" value="{{ product.title }}" required>
                    </div>
                    <div class="col-lg-6">
                        <label class="form-label">{{ 'Icon'|trans }}</label>
                        <input class="form-control" type="text" name="icon_url" value="{{ product.icon_url }}">
                    </div>
                    <div class="col-lg-6">
                        <label class="form-label">{{ 'Status'|trans }}</label>
                        <select class="form-select" name="status">
                            <option value="enabled"{% if product.status == 'enabled' %} selected{% endif %}>{{ 'Enabled'|trans }}</option>
                            <option value="disabled"{% if product.status == 'disabled' %} selected{% endif %}>{{ 'Disabled'|trans }}</option>
                        </select>
                    </div>
                    <div class="col-lg-6">
                        <label class="form-label">{{ 'Activation'|trans }}</label>
                        <select class="form-select" name="setup">
                            <option value="after_order"{% if product.setup == 'after_order' %} selected{% endif %}>{{ 'After Order is Placed'|trans }}</option>
                            <option value="after_payment"{% if product.setup == 'after_payment' %} selected{% endif %}>{{ 'After Payment is Received'|trans }}</option>
                            <option value="manual"{% if product.setup == 'manual' %} selected{% endif %}>{{ 'Manual Activation'|trans }}</option>
                        </select>
                    </div>
                    <div class="col-12">
                        <label class="form-label">{{ 'Description'|trans }}</label>
                        <div class="form-text mb-2">{{ 'Describe what this addon provides on the order page and in client-facing product details.'|trans }}</div>
                        <textarea class="form-control" name="description" rows="5">{{ product.description }}</textarea>
                    </div>
                </div>

                <div class="mt-4">
                    {{ include('partial_pricing.html.twig', { 'product': product }) }}
                </div>
                <input type="hidden" name="id" value="{{ product.id }}">
            {% endblock %}

            {% block form_actions %}
                <button class="btn btn-primary" type="submit">{{ 'Update'|trans }}</button>
            {% endblock %}
        {% endembed %}
    </form>
</div>
{% endblock %}
