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

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

{% set instructions %}
### Connect to the {name} API
1. Login to your <a href="https://portal.addressfinder.net/sessions/login" target="_blank">{name}</a> account.
1. Click the account dropdown in the top-right corner of the screen, and select **Settings**.
1. Under the **Account** section, copy the key into the **API Key** field below.
{% endset %}

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

{{ macros.proxyField(fieldVariables, 'autosuggestField', {
    label: 'API Key' | t('formie'),
    name: 'apiKey',
    required: true,
    suggestEnvVars: true,
    value: integration.settings.apiKey ?? '',
    warning: macros.configWarning('apiKey', 'formie'),
    errors: integration.getErrors('apiKey'),
}) }}

{{ macros.proxyField(fieldVariables, 'selectField', {
    label: 'Country Code' | t('formie'),
    name: 'countryCode',
    required: true,
    value: integration.settings.countryCode ?? '',
    warning: macros.configWarning('countryCode', 'formie'),
    errors: integration.getErrors('countryCode'),
    options: [
        { label: 'Select an option' | t('formie'), value: '' },
        { label: 'Australia' | t('formie'), value: 'AU' },
        { label: 'New Zealand' | t('formie'), value: 'NZ' },
    ],
}) }}

{{ macros.proxyField(fieldVariables, 'editableTableField', {
    label: 'Widget Options' | t('formie'),
    instructions: 'Provide any additional options, as per the {link}.' | t('formie', { link: '[Address Finder docs](https://addressfinder.com.au/docs/widget_docs)' }),
    id: 'widgetOptions',
    name: 'widgetOptions',
    cols: [
        {
            type: 'singleline',
            heading: 'Option' | t('formie'),
            width: '25%',
        },
        {
            type: 'singleline',
            heading: 'Value' | t('formie'),
        },
    ],
    rows: integration.settings.widgetOptions ?? [],
    addRowLabel: 'Add an option' | t('formie'),
    warning: macros.configWarning('widgetOptions', 'formie'),
    errors: integration.getErrors('widgetOptions'),
    allowAdd: true,
    allowDelete: true,
    allowReorder: true,
}) }}