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

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

<div class="card-body">
    <div class="mb-3">
        <h3 class="card-title mb-1">{{ 'Details'|trans }}</h3>
        <p class="text-secondary mb-0">{{ 'Review the current hosting account, jump to the server control panel, and make targeted changes to the provisioned account.'|trans }}</p>
    </div>
</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_badge(order.status, 'order') }}</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/#{server.id}"|url }}'>{{ server.name }}</a></td>
        </tr>
        <tr>
            <td class="text-end">{{ 'Hosting Plan'|trans }}:</td>
            <td><a href='{{ "servicehosting/plan/#{hp.id}"|url }}'>{{ 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 d-flex flex-wrap gap-2 justify-content-end">
    {{ order_actions }}
    <a class="btn btn-primary" href="{{ server.cpanel_url }}" target="_blank">
        <svg class="icon">
            <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">
                <use xlink:href="#server" />
            </svg>
            <span>{{ 'Reseller control panel'|trans }}</span>
        </a>
    {% endif %}
    <a class="btn btn-primary" href="{{ 'servicehosting/sync'|api_url(query: { 'order_id': order.id }) }}"
        {{ fb_api_link({modal: {type: 'confirm', title: 'Are you sure?'|trans}, message: 'Account Synced'|trans}) }}>
        <svg class="icon">
            <use xlink:href="#refresh" />
        </svg>
        <span>{{ 'Sync with server'|trans }}</span>
    </a>
</div>

<div class="card-body">
    <div class="mb-5">
        <div class="mb-3">
            <h3 class="card-title mb-1">{{ 'Change Hosting Plan'|trans }}</h3>
            <p class="text-secondary mb-0">{{ 'Move this account onto a different hosting plan available on the current server.'|trans }}</p>
        </div>

        <form method="post" action="{{ 'servicehosting/change_plan'|api_url }}" {{ fb_api_form({message: 'Hosting Plan Changed'|trans}) }}>
            <div class="row g-3">
                <div class="col-lg-6">
                    <label class="form-label">{{ 'New Hosting Plan'|trans }}</label>
                    {{ mf.selectbox('plan_id', admin.servicehosting_hp_get_pairs, hp.id, 1) }}
                </div>
            </div>

            <input type="hidden" name="order_id" value="{{ order.id }}">
            <div class="d-flex justify-content-end mt-3">
                <button class="btn btn-primary" type="submit">{{ 'Change'|trans }}</button>
            </div>
        </form>
    </div>

    <hr class="my-4" />

    <div class="mb-5">
        <div class="mb-3">
            <h3 class="card-title mb-1">{{ 'Change Account Password'|trans }}</h3>
            <p class="text-secondary mb-0">{{ 'Set a new password for the hosting account on the remote server.'|trans }}</p>
        </div>

        <form method="post" action="{{ 'servicehosting/change_password'|api_url }}" {{ fb_api_form({message: 'Account Password Changed'|trans}) }}>
            <div class="row g-3">
                <div class="col-lg-6">
                    <label class="form-label">{{ 'Password'|trans }}</label>
                    <input class="form-control" type="password" name="password" required>
                </div>
                <div class="col-lg-6">
                    <label class="form-label">{{ 'Password Confirm'|trans }}</label>
                    <input class="form-control" type="password" name="password_confirm" required>
                </div>
            </div>

            <input type="hidden" name="order_id" value="{{ order.id }}">
            <div class="d-flex justify-content-end mt-3">
                <button class="btn btn-primary" type="submit">{{ 'Change'|trans }}</button>
            </div>
        </form>
    </div>

    <hr class="my-4" />

    <div class="mb-5">
        <div class="mb-3">
            <h3 class="card-title mb-1">{{ 'Change IP'|trans }}</h3>
            <p class="text-secondary mb-0">{{ 'Update the primary IP address assigned to the hosting account.'|trans }}</p>
        </div>

        <form method="post" action="{{ 'servicehosting/change_ip'|api_url }}" {{ fb_api_form({message: 'Account IP Changed'|trans}) }}>
            <div class="row g-3">
                <div class="col-lg-6">
                    <label class="form-label">{{ 'IP'|trans }}</label>
                    <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 }}">
            <div class="d-flex justify-content-end mt-3">
                <button class="btn btn-primary" type="submit">{{ 'Change'|trans }}</button>
            </div>
        </form>
    </div>

    <hr class="my-4" />

    <div class="mb-5">
        <div class="mb-3">
            <h3 class="card-title mb-1">{{ 'Change Username'|trans }}</h3>
            <p class="text-secondary mb-0">{{ 'Rename the hosting account username on the remote server.'|trans }}</p>
        </div>

        <form method="post" action="{{ 'servicehosting/change_username'|api_url }}" {{ fb_api_form({message: 'Account Username Changed'|trans}) }}>
            <div class="row g-3">
                <div class="col-lg-6">
                    <label class="form-label">{{ 'Username'|trans }}</label>
                    <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 }}">
            <div class="d-flex justify-content-end mt-3">
                <button class="btn btn-primary" type="submit">{{ 'Change'|trans }}</button>
            </div>
        </form>
    </div>

    <hr class="my-4" />

    <div>
        <div class="mb-3">
            <h3 class="card-title mb-1">{{ 'Change Domain'|trans }}</h3>
            <p class="text-secondary mb-0">{{ 'Update the domain assigned to the hosting account.'|trans }}</p>
        </div>

        <form method="post" action="{{ 'servicehosting/change_domain'|api_url }}" {{ fb_api_form({message: 'Account Domain Changed'|trans}) }}>
            <div class="row g-3">
                <div class="col-lg-8">
                    <label class="form-label">{{ 'Domain'|trans }}</label>
                    <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 }}">
            <div class="d-flex justify-content-end mt-3">
                <button class="btn btn-primary" type="submit">{{ 'Change'|trans }}</button>
            </div>
        </form>
    </div>
</div>
