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

{% block meta_title %}{{ 'Hosting Management'|trans }}{% endblock %}

{% set active_menu = 'system' %}

{% 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="{{ 'servicehosting'|url }}">{{ 'Hosting Plans and Servers'|trans }}</a>
        </li>
        <li class="breadcrumb-item active" aria-current="page">{{ hp.name }}</li>
    </ol>
{% endblock %}

{% block content %}
<div class="p-3 d-flex flex-column gap-3">
    <form method="post" action="{{ 'servicehosting/hp_update'|api_url }}" {{ fb_api_form({message: 'Hosting Plan Updated'|trans}) }}>
        {% embed 'partial_admin_form_card.html.twig' with {
            title: hp.name,
            subtitle: 'Configure resource limits, manager-specific parameters, and extra provisioning fields for this hosting plan.'|trans,
            card_class: 'mb-0'
        } %}
            {% block form_content %}
                <div class="row g-3">
                    <div class="col-lg-6">
                        <label class="form-label" for="plan-name">{{ 'Name'|trans }}</label>
                        <input class="form-control" id="plan-name" type="text" name="name" value="{{ hp.name }}" required placeholder="{{ 'Unique name to identify this hosting plan'|trans }}">
                    </div>
                    <div class="col-lg-3">
                        <label class="form-label" for="plan-disk">{{ 'Disk Quota'|trans }}</label>
                        <div class="input-group">
                            <input class="form-control" id="plan-disk" type="text" name="quota" value="{{ hp.quota }}" aria-describedby="quota">
                            <span class="input-group-text" id="quota">MB</span>
                        </div>
                    </div>
                    <div class="col-lg-3">
                        <label class="form-label" for="plan-bandwidth">{{ 'Bandwidth'|trans }}</label>
                        <div class="input-group">
                            <input class="form-control" id="plan-bandwidth" type="text" name="bandwidth" value="{{ hp.bandwidth }}" aria-describedby="bandwidth">
                            <span class="input-group-text" id="bandwidth">MB</span>
                        </div>
                    </div>
                    <div class="col-lg-4">
                        <label class="form-label" for="plan-addon">{{ 'Maximum Addon Domains'|trans }}</label>
                        <input class="form-control" id="plan-addon" type="text" name="max_addon" value="{{ hp.max_addon }}">
                    </div>
                    <div class="col-lg-4">
                        <label class="form-label" for="plan-ftp">{{ 'Maximum FTP Accounts'|trans }}</label>
                        <input class="form-control" id="plan-ftp" type="text" name="max_ftp" value="{{ hp.max_ftp }}">
                    </div>
                    <div class="col-lg-4">
                        <label class="form-label" for="plan-sql">{{ 'Maximum Databases'|trans }}</label>
                        <input class="form-control" id="plan-sql" type="text" name="max_sql" value="{{ hp.max_sql }}">
                    </div>
                    <div class="col-lg-4">
                        <label class="form-label" for="plan-email">{{ 'Maximum Email Accounts'|trans }}</label>
                        <input class="form-control" id="plan-email" type="text" name="max_pop" value="{{ hp.max_pop }}">
                    </div>
                    <div class="col-lg-4">
                        <label class="form-label" for="plan-subdomains">{{ 'Maximum Subdomains'|trans }}</label>
                        <input class="form-control" id="plan-subdomains" type="text" name="max_sub" value="{{ hp.max_sub }}">
                    </div>
                    <div class="col-lg-4">
                        <label class="form-label" for="plan-parked">{{ 'Maximum Parked Domains'|trans }}</label>
                        <input class="form-control" id="plan-parked" type="text" name="max_park" value="{{ hp.max_park }}">
                    </div>
                </div>

                {% if hp.config|length > 0 %}
                    <div class="d-flex flex-column gap-1 mt-4 mb-4">
                        <h6 class="card-title mb-0">{{ 'Server Manager Specific Parameters'|trans }}</h6>
                        <p class="text-secondary mb-0">{{ 'Review adapter-specific values that are sent to the active hosting server manager for this plan.'|trans }}</p>
                    </div>
                    <div class="row g-3">
                        {% for name, value in hp.config %}
                        <div class="col-lg-6">
                            <label class="form-label" for="plan-special-{{ name }}">{{ name }}</label>
                            <textarea class="form-control" id="plan-special-{{ name }}" name="config[{{ name }}]" rows="1">{{ value }}</textarea>
                        </div>
                        {% endfor %}
                    </div>
                {% endif %}

                <input type="hidden" name="id" value="{{ hp.id }}">
            {% endblock %}

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

    <form method="post" action="{{ 'servicehosting/hp_update'|api_url }}" {{ fb_api_form({message: 'Additional Parameter Added'|trans, reload: true}) }}>
        {% embed 'partial_admin_form_card.html.twig' with {
            title: 'Hosting Plan Additional Parameters'|trans,
            subtitle: 'Add extra provisioning parameters required by the active server manager for this hosting plan.'|trans,
            card_class: 'mb-0'
        } %}
            {% block form_content %}
                <div class="row g-3">
                    <div class="col-lg-6">
                        <label class="form-label">{{ 'Parameter Name'|trans }}</label>
                        <input class="form-control" type="text" name="new_config_name" required>
                    </div>
                    <div class="col-lg-6">
                        <label class="form-label">{{ 'Parameter Value'|trans }}</label>
                        <textarea class="form-control" name="new_config_value" rows="1" required></textarea>
                    </div>
                </div>
                <input type="hidden" name="id" value="{{ hp.id }}">
            {% endblock %}

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