{% 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://www.salesforce.com" target="_blank">{name}</a> and login to your account.
1. In the main menu, on the top-right, click the **Settings** icon and select **Setup**.
1. In the left-hand sidebar, click on **Apps** → **App Manager**.
1. Click the **New Connected App** button.
1. Fill out all required fields.
1. In the **API (Enable OAuth Settings)** section, tick the **Enable OAuth Settings** checkbox.
    - In the **Callback URL** field, enter the value from the **Redirect URI** field below.
    - In the **Selected OAuth Scopes** field, select the following permissions from the list and click **Add** arrow button:
        - **Manage Pardot services (pardot_api)**.
        - **Perform requests on your behalf at any time (refresh_token, offline_access)**.
1. Click the **Save** button.
1. Copy the **Consumer Key** from {name} and paste in the **Consumer Key** field below.
1. Copy the **Consumer Secret** from {name} and paste in the **Consumer Secret** field below.
1. Click on the **Manage** button.
1. Click on the **Edit Policies** button.
1. In the **OAuth policies** section:
    - In the **Permitted Users** field, select **All users may self-authorize**.
    - In the **IP Relaxation** field, select **Relax IP restrictions**.
1. Click the **Save** button.
1. In the main menu, on the top-right, click the **Settings** icon and select **Setup**.
1. Enter **Business Unit** in the Quick Find box, and click on **Business Unit Setup**.
1. Copy the **Business Unit ID** from {name} and paste in the **Business Unit ID** field below.

### Step 2. Test Connection
1. Save this integration.
1. Click on the **Connect** button in the right-hand sidebar.
1. You‘ll be redirected to {name}, where you must approve Formie to access your {name} account.
{% endset %}

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

{{ macros.proxyField(fieldVariables, 'textField', {
    readonly: true,
    label: 'Redirect URI' | t('formie'),
    instructions: 'Use this URI when setting up your {name} app.' | t('formie'),
    value: integration.getRedirectUri(),
}) }}

{% 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: 'Consumer Key' | t('formie'),
    instructions: 'Enter your {name} {label} here.' | t('formie'),
    name: 'clientId',
    required: true,
    suggestEnvVars: true,
    value: integration.settings.clientId ?? '',
    warning: macros.configWarning('clientId', 'formie'),
    errors: integration.getErrors('clientId'),
}) }}

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

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

{{ macros.proxyField(fieldVariables, 'booleanMenuField', {
    label: 'Use Sandbox' | t('formie'),
    instructions: 'Whether to use the {name} sandbox.' | t('formie', { name: displayName }),
    name: 'useSandbox',
    includeEnvVars: true,
    value: integration.settings.useSandbox ?? false,
    warning: macros.configWarning('useSandbox', 'formie'),
    errors: integration.getErrors('useSandbox'),
}) }}