{% import 'macro_functions.html.twig' as mf %}

{% set server = service.server %}
{% set hp = service.hosting_plan %}

<div class="card-body">
    <h3>{{ 'Details'|trans }}</h3>
</div>
<table class="table card-table table-vcenter table-striped text-nowrap">
    <tbody>
        <tr>
            <td class="w-50 text-end">{{ 'Status'|trans }}:</td>
            <td>{{ mf.status_name(order.status) }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Domain'|trans }}:</td>
            <td>
                <a target="_blank" href="https://{{ service.domain }}">{{ service.domain }}</a>
            </td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Server Name'|trans }}:</td>
            <td><a href="{{ 'servicehosting/server'|alink }}/{{ server.id }}">{{ server.name }}</a></td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Hosting plan'|trans }}:</td>
            <td><a href="{{ 'servicehosting/plan'|alink }}/{{ hp.id }}">{{ hp.name }}</a></td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Server IP'|trans }}:</td>
            <td>{{ server.ip }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Account IP'|trans }}:</td>
            <td>{{ service.ip }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Username'|trans }}:</td>
            <td>{{ service.username }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Nameserver 1'|trans }}:</td>
            <td>{{ server.ns1 }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Nameserver 2'|trans }}:</td>
            <td>{{ server.ns2 }}</td>
        </tr>
        {% if server.ns3 %}
        <tr>
            <td class="text-end">{{ 'Nameserver 3'|trans }}:</td>
            <td>{{ server.ns3 }}</td>
        </tr>
        {% endif %}
        {% if server.ns4 %}
        <tr>
            <td class="text-end">{{ 'Nameserver 4'|trans }}:</td>
            <td>{{ server.ns4 }}</td>
        </tr>
        {% endif %}
        <tr>
            <td class="text-end">{{ 'Bandwidth'|trans }}:</td>
            <td>{{ hp.bandwidth }} MB / {{ 'per month'|trans }}</td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Disk quota'|trans }}:</td>
            <td>{{ hp.quota }} MB</td>
        </tr>
    </tbody>
</table>

<div class="card-footer text-center">
    {{ order_actions }}
    <a class="btn btn-primary" href="{{ server.cpanel_url }}" target="_blank">
        <svg class="icon" width="24" height="24">
            <use xlink:href="#server" />
        </svg>
        <span>{{ 'Jump to control panel'|trans }}</span>
    </a>
    {% if service.reseller %}
    <a class="btn btn-primary" href="{{ server.reseller_cpanel_url }}" target="_blank">
        <svg class="icon" width="24" height="24">
            <use xlink:href="#server" />
        </svg>
        <span>{{ 'Reseller control panel'|trans }}</span>
    </a>
    {% endif %}

    <a class="btn btn-primary api-link"
        href="{{ 'api/admin/servicehosting/sync'|link({ 'order_id': order.id, 'CSRFToken': CSRFToken }) }}"
        data-api-confirm="{{ 'Are you sure?'|trans }}"
        data-api-msg="{{ 'Account was synced'|trans }}">
        <svg class="icon" width="24" height="24">
            <use xlink:href="#refresh" />
        </svg>
        <span>{{ 'Sync with server'|trans }}</span>
    </a>
</div>

<div class="card-body">
    <h3>{{ 'Change hosting plan'|trans }}</h3>

    <form action="{{ 'api/admin/servicehosting/change_plan'|link }}" method="post" class="api-form" data-api-msg="{{ 'Hosting plan changed'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'New hosting plan'|trans }}:</label>
            <div class="col">
                {{ mf.selectbox('plan_id', admin.servicehosting_hp_get_pairs, hp.id, 1) }}
            </div>
        </div>

        <input type="hidden" name="order_id" value="{{ order.id }}">
        <input type="submit" value="{{ 'Change'|trans }}" class="btn btn-primary w-100">
    </form>
    <hr>

    <h3>{{ 'Change account password'|trans }}</h3>
    <form action="{{ 'api/admin/servicehosting/change_password'|link }}" method="post" class="api-form" data-api-msg="{{ 'Account password changed'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Password'|trans }}:</label>
            <div class="col">
                <input class="form-control" type="password" name="password" required>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Password Confirm'|trans }}:</label>
            <div class="col">
                <input class="form-control" type="password" name="password_confirm" required>
            </div>
        </div>

        <input type="hidden" name="order_id" value="{{ order.id }}">
        <input type="submit" value="{{ 'Change'|trans }}" class="btn btn-primary w-100">
    </form>
    <hr>

    <h3>{{ 'Change IP'|trans }}</h3>
    <form method="post" action="{{ 'api/admin/servicehosting/change_ip'|link }}" class="api-form" data-api-msg="{{ 'Account IP changed'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'IP'|trans }}:</label>
            <div class="col">
                <input class="form-control" type="text" name="ip" value="{{ request.ip|default(service.ip) }}" required>
            </div>
        </div>

        <input type="hidden" name="order_id" value="{{ order.id }}">
        <button class="btn btn-primary w-100" type="submit">{{ 'Change'|trans }}</button>
    </form>
    <hr>

    <h3>{{ 'Change username'|trans }}</h3>
    <form method="post" action="{{ 'api/admin/servicehosting/change_username'|link }}" class="api-form" data-api-msg="{{ 'Account username changed'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Username'|trans }}:</label>
            <div class="col">
                <input class="form-control" type="text" name="username" value="{{ request.username|default(service.username) }}" required>
            </div>
        </div>

        <input type="hidden" name="order_id" value="{{ order.id }}">
        <button class="btn btn-primary w-100" type="submit">{{ 'Change'|trans }}</button>
    </form>
    <hr>

    <h3>{{ 'Change domain'|trans }}</h3>
    <form method="post" action="{{ 'api/admin/servicehosting/change_domain'|link }}" class="api-form" data-api-msg="{{ 'Account domain changed'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Domain'|trans }}:</label>
            <div class="col">
                <div class="input-group">
                    <input class="form-control" type="text" name="sld" value="{{ request.domain|default(service.sld) }}" required>
                    <input class="form-control" type="text" name="tld" value="{{ request.domain|default(service.tld) }}" required>
                </div>
            </div>
        </div>

        <input type="hidden" name="order_id" value="{{ order.id }}">
        <button class="btn btn-primary w-100" type="submit">{{ 'Change'|trans }}</button>
    </form>
</div>
