{% import '_includes/forms' as forms %}
{% import 'verbb-base/_macros' as macros %}

{% set displayName = integration.displayName() %}

{% set instructions %}
### Step 1. Connect to the {name} API
1. Go to <a href="https://sugarcrm.com/" target="_blank">{name}</a> and login to your account.
1. Click on your profile dropdown on the top-right of the screen, and select **Admin**.
1. Find and click the **Configure API Platforms** link.
1. Below the table of API Platforms, enter `formie` in the add field, and click the **Add** button. This will add `formie` to the table of platforms.
1. Enter the username for your {name} account in the **Username** field below.
1. Enter the password for your {name} account in the **Password** field below.
1. Enter the full domain (including `https://`) for your {name} account in the **Domain** field below.

### Step 2. Test Connection
1. Save this integration.
1. Click on the **Connect** button in the right-hand sidebar.
{% endset %}

<div class="fui-settings-block">
    {{ instructions | t('formie', { name: displayName }) | md }}
</div>

{% if not craft.app.config.general.allowAdminChanges %}
    <span class="warning with-icon">
        {{ 'Integration settings can only be editable on an environment with `allowAdminChanges` enabled.' | t('formie') | md(inlineOnly=true) }}
    </span>
{% endif %}

{{ macros.proxyField(fieldVariables, 'autosuggestField', {
    label: 'Username' | t('formie'),
    instructions: 'Enter your {name} {label} here.' | t('formie'),
    name: 'username',
    required: true,
    suggestEnvVars: true,
    value: integration.settings.username ?? '',
    warning: macros.configWarning('username', 'formie'),
    errors: integration.getErrors('username'),
}) }}

{{ macros.proxyField(fieldVariables, 'autosuggestField', {
    label: 'Password' | t('formie'),
    instructions: 'Enter your {name} {label} here.' | t('formie'),
    name: 'password',
    required: true,
    suggestEnvVars: true,
    value: integration.settings.password ?? '',
    warning: macros.configWarning('password', 'formie'),
    errors: integration.getErrors('password'),
}) }}

{{ macros.proxyField(fieldVariables, 'autosuggestField', {
    label: 'Domain' | t('formie'),
    instructions: 'Enter your {name} {label} here. e.g. `{link}`' | t('formie', { link: 'https://example.sugarcrm.com' }),
    name: 'apiDomain',
    required: true,
    suggestEnvVars: true,
    value: integration.settings.apiDomain ?? '',
    warning: macros.configWarning('apiDomain', 'formie'),
    errors: integration.getErrors('apiDomain'),
}) }}