{% import "_includes/forms" as forms %}

{% set readOnly = readOnly ?? false %}

{{ forms.autosuggestField({
    label: "Hostname"|t('app'),
    id: 'host',
    name: 'host',
    suggestEnvVars: true,
    value: adapter.host,
    required: true,
    errors: adapter.getErrors('host'),
    disabled: readOnly,
}) }}

{{ forms.autosuggestField({
    label: "Port"|t('app'),
    id: 'port',
    name: 'port',
    suggestEnvVars: true,
    value: adapter.port,
    size: 20,
    errors: adapter.getErrors('port'),
    disabled: readOnly,
}) }}

{{ forms.booleanMenuField({
    label: "Use authentication"|t('app'),
    id: 'useAuthentication',
    name: 'useAuthentication',
    includeEnvVars: true,
    value: adapter.useAuthentication,
    toggle: 'auth-credentials',
    disabled: readOnly,
}) }}

<div id="auth-credentials" class="nested-fields{% if not adapter.useAuthentication %} hidden{% endif %}">
    {{ forms.autosuggestField({
        label: "Username"|t('app'),
        id: 'username',
        name: 'username',
        suggestEnvVars: true,
        value: adapter.username,
        errors: adapter.getErrors('username'),
        disabled: readOnly,
    }) }}

    {{ forms.autosuggestField({
        label: "Password"|t('app'),
        id: 'password',
        name: 'password',
        suggestEnvVars: true,
        value: adapter.password,
        errors: adapter.getErrors('password'),
        disabled: readOnly,
    }) }}
</div>
