<div class="fl-content fl-content-min-height">
  <app-fl-backdrop *ngIf="defaultsLoading" overlayParent></app-fl-backdrop>
  <!--suppress JSUnusedGlobalSymbols -->
  <app-form-errors #formErrors [formGroup]="defaultsForm"></app-form-errors>
  <div layoutDirection="row" appLayoutGap="10px">
    <form appFormSubmit (ngSubmit)="save()" *ngIf="defaults" [formGroup]="defaultsForm" layoutDirection="column" appFlex="40"
          xsFlex="100">
      <mat-form-field>
        <mat-label i18n>API timeout</mat-label>
        <input matInput type="number" formControlName="timeout" min="1" step="1" required
               placeholder="API timeout" i18n-placeholder>
        <mat-error>{{fieldErrors['timeout']}}</mat-error>
      </mat-form-field>
      <mat-form-field>
        <mat-label i18n>Gnocchi resource types timeout</mat-label>
        <input matInput type="number" formControlName="gnocchi_resource_types_timeout" min="1" step="1" required
               placeholder="Gnocchi resource types timeout" i18n-placeholder>
        <mat-error>{{fieldErrors['gnocchi_resource_types_timeout']}}</mat-error>
      </mat-form-field>

      <mat-form-field>
        <mat-label i18n>Default role names for admin user</mat-label>
        <mat-select formControlName="default_roles" multiple
                    placeholder="Default role names for admin user" i18n-placeholder>
          <mat-option *ngFor="let role of defaults.available_role_options" [value]="role.name">
            {{ role.name }}
          </mat-option>
        </mat-select>
      </mat-form-field>

      <mat-form-field>
        <mat-label i18n>Default role names for standard users</mat-label>
        <mat-select formControlName="default_roles_standard_user" multiple
                    placeholder="Default role names for standard users" i18n-placeholder>
          <mat-option *ngFor="let role of defaults.available_role_options" [value]="role.name">
            {{ role.name }}
          </mat-option>
        </mat-select>
      </mat-form-field>

      <mat-form-field>
        <mat-label i18n>Default region name</mat-label>
        <mat-select formControlName="default_region" placeholder="Default region name" i18n-placeholder>
          <mat-option *ngFor="let region of defaults.available_region_options" [value]="region.id">
            {{ region.id }}
          </mat-option>
        </mat-select>
      </mat-form-field>

      <mat-form-field>
        <mat-label i18n>Projects default domain</mat-label>
        <input matInput type="text" formControlName="project_domain_id" required
               placeholder="Projects default domain" i18n-placeholder>
        <mat-error>{{fieldErrors['project_domain_id']}}</mat-error>
      </mat-form-field>

      <mat-form-field>
        <mat-label i18n>New projects name template</mat-label>
        <input matInput type="text" formControlName="default_project_name" required
               placeholder="New projects name template" i18n-placeholder>
        <mat-error>{{fieldErrors['default_project_name']}}</mat-error>
      </mat-form-field>

      <mat-form-field>
        <mat-label i18n>New projects description template</mat-label>
        <input matInput type="text" formControlName="default_project_description" required
               placeholder="New projects description template" i18n-placeholder>
        <mat-error>{{fieldErrors['default_project_description']}}</mat-error>
      </mat-form-field>

      <mat-checkbox formControlName="force_config_drive_for_instance_creation" [color]="'primary'"
                    i18n>Force config drive for instance creation
      </mat-checkbox>

      <mat-checkbox formControlName="hide_projects_and_api_users" [color]="'primary'" i18n>Hide projects and API users
      </mat-checkbox>

      <mat-form-field>
        <mat-label i18n>Project IDs</mat-label>
        <input matInput type="text" formControlName="hide_project_ids"
               placeholder="Project ids" i18n-placeholder>
        <mat-error>{{fieldErrors['hide_project_ids']}}</mat-error>
      </mat-form-field>

      <mat-checkbox formControlName="use_api_username_template" [color]="'primary'"
                    i18n>Use API username template
      </mat-checkbox>

      <mat-form-field *ngIf="defaultsForm.controls.use_api_username_template.value">
        <mat-label i18n>API username template</mat-label>
        <input matInput type="text" formControlName="api_username_template"
               placeholder="API username template" i18n-placeholder>
        <mat-error>{{fieldErrors['api_username_template']}}</mat-error>
      </mat-form-field>

      <mat-checkbox formControlName="hide_images_in_other_flavor_scope" [color]="'primary'"
                    i18n>Hide images in other flavors' scope on instance create
      </mat-checkbox>

      <mat-checkbox formControlName="hide_unassigned_images" [color]="'primary'"
                    i18n>Hide unassigned images on instance create
      </mat-checkbox>

      <mat-checkbox formControlName="use_instance_az_for_volume_on_instance_create" [color]="'primary'"
                    i18n>Use instance availability zone for volume on instance create
      </mat-checkbox>

      <ng-container *ngIf="authSvc.feature('openstack.lbaas')">
        <mat-form-field class="fl-margin-top">
          <mat-label i18n>Default load balancers region name</mat-label>
          <mat-select formControlName="default_lbaas_region" placeholder="Default load balancers region name"
                      i18n-placeholder>
            <mat-option *ngFor="let region of defaults.available_region_options" [value]="region.id">
              {{ region.id }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </ng-container>

      <mat-checkbox formControlName="retrieve_gnocchi_metadata" [color]="'primary'"
                    i18n>Retrieve gnocchi metadata
      </mat-checkbox>

      <ng-container>
        <mat-form-field>
          <mat-label i18n>Default Gnocchi region name</mat-label>
          <mat-select formControlName="default_gnocchi_region" placeholder="Default gnocchi region name"
                      i18n-placeholder>
            <mat-option *ngFor="let region of defaults.available_region_options" [value]="region.id">
              {{ region.id }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </ng-container>

      <h2 class="fl-heading-md">Default PTR settings</h2>
      <mat-form-field>
        <mat-label i18n>PTR default format</mat-label>
        <input matInput type="text" formControlName="ptr_default_format"
               placeholder="PTR default format" i18n-placeholder>
        <mat-error>{{fieldErrors['ptr_default_format']}}</mat-error>
      </mat-form-field>
      <mat-form-field>
        <mat-label i18n>PTR default format for IPv6</mat-label>
        <input matInput type="text" formControlName="ptr_default_format_ipv6"
               placeholder="PTR default format for IPv6" i18n-placeholder>
        <mat-error>{{fieldErrors['ptr_default_format_ipv6']}}</mat-error>
      </mat-form-field>
      <mat-form-field>
        <mat-label i18n>Inverse address zone email</mat-label>
        <input matInput type="text" formControlName="inverse_address_zone_default_format"
               placeholder="Inverse address zone email" i18n-placeholder>
        <mat-error>{{fieldErrors['inverse_address_zone_default_format']}}</mat-error>
      </mat-form-field>
      <mat-checkbox formControlName="ptr_records_force_lowercase" [color]="'primary'"
                    i18n>Force lowercase for PTR records</mat-checkbox>

    </form>
    <div layoutDirection="column" appFlex="60" class="fl-help-text hide-xs" appLayoutGap="10px">
      <h3 i18n>API timeout</h3>
      <p class="fl-detail" i18n>
        How many seconds to wait for OpenStack API to reply.
      </p>
      <h3 i18n>Gnocchi resource types timeout</h3>
      <p class="fl-detail" i18n>
        How many seconds to wait for Gnocchi resource types API to reply.
      </p>
      <h3 i18n>Default role names for admin user</h3>
      <p class="fl-detail" i18n>
        The default roles Fleio assigns for admin user for each created Project.
        Fleio tries to set these roles automatically when the credentials are saved.
      </p>
      <h3 i18n>Default role names for standard users</h3>
      <p class="fl-detail" i18n>
        The default roles Fleio assigns for regular API users created for any Project.
        Fleio tries to set these roles automatically when API users are saved.
        Unprivileged roles should be used (defaults to [ '_member_', 'member'] if it exists).
        When a normal Fleio user asks Fleio to execute a command, for
        example an instance reboot, Fleio will authenticate using these roles.
      </p>
      <h3 i18n>Default region name</h3>
      <p class="fl-detail" i18n>
        The default region to use for various actions if no region is specified in a multi region cloud.
      </p>
      <h3 i18n>Projects default domain</h3>
      <p class="fl-detail" i18n>
        The OpenStack domain where all projects will be automatically created.
        <strong>default</strong> is usually present in all OpenStack installations.
        Do note that this is the domain ID, not it's name.
      </p>
      <h3 i18n>New project name and description templates</h3>
      <p class="fl-detail" i18n>
        Fleio automatically creates OpenStack Projects for clients and gives them names and descriptions.
        You can customize the default name and description using a template with access to
        <strong>client</strong> attributes. It's <strong>IMPORTANT</strong> to keep in mind that the project
        name needs to be unique/different from all the other projects already present in OpenStack.
        You can make sure of that by using the "client.id" template attribute or any attribute you know it
        will be unique. The <strong>client</strong> object has many attributes, some of them include:
        id, first_name, last_name, company, country, phone, email, date_created and
        <strong>id</strong> is always unique.
      </p>
      <h3 i18n>Force config drive for instance creation</h3>
      <p class="fl-detail" i18n>
        When an instance gets created from fleio, config_drive param is always sent as True to nova.
      </p>
      <h3 i18n>Hide projects and API users</h3>
      <p class="fl-detail" i18n>
        Checking this will hide all projects specified by IDs.
        The administrator project ID specified in credentials tabs will be automatically included in this list.
        API users for these projects will be also hidden
      </p>
      <h3 i18n>Use API username template</h3>
      <p class="fl-detail" i18n>
        Checking this will show a text field where a template for OpenStack API users' username can be configured.
        This will affect API users created from end-user panel and will override their username when saving.
      </p>
      <h3 i18n>API username template</h3>
      <p class="fl-detail">
        {{apiUsernameTemplateHelpTxt}}
      </p>
      <h3 i18n>Hide images in other flavors' scope on instance create</h3>
      <p class="fl-detail" i18n>
        Checking this will not show images that are assigned to other flavors and are unavailable
        to be used with the selected flavor. Unchecking this, they would show as disabled with an explanation tooltip.
        This setting is obsolete if the "Hide unassigned images on instance create" setting is used.
      </p>
      <h3 i18n>Hide unassigned images on instance create</h3>
      <p class="fl-detail" i18n>
        Checking this will not show unassigned images for a flavor on instance create.
        Flavors without any assignments will still display all images.
        Unchecking this, other images would show up on boot source selection if they are not
        assigned to another flavor than the selected one.
      </p>
      <h3 i18n>Use instance availability zone for volume on instance create</h3>
      <p class="fl-detail" i18n>
        Checking this will hide the volume availability zone selector on instance deploy form and will use the same
        AZ name as chosen for instance if found in cinder. If the names do not match and AZ name is not found
        in cinder, it will be automatically chosen by OpenStack.
      </p>
      <ng-container *ngIf="authSvc.feature('openstack.lbaas')">
        <h3 i18n>Default load balancers region name</h3>
        <p class="fl-detail" i18n>
          The default region to use for load balancers in a multi region cloud.
        </p>
      </ng-container>
      <ng-container>
        <h3 i18n>Retrieve gnocchi metadata</h3>
        <p class="fl-detail" i18n>
          Unchecking this will disable gnocchi metadata retrieval. Gnocchi metadata is used in filter configuration for
          metric rules. If you do not use metric rules you should uncheck this.
        </p>
      </ng-container>
      <ng-container>
        <h3 i18n>Default gnocchi region name</h3>
        <p class="fl-detail" i18n>
          The default region used to retrieve gnocchi metadata.
        </p>
      </ng-container>
      <ng-container>
        <h3 i18n>PTR default format</h3>
        <p class="fl-detail" i18n>
          PTR default format will be set on IPv4s allocation/de-allocation. Leave empty so it won't change PTR record on
          mentioned actions. You can use the following template examples:
          "{{ '{' }}dashed_ip{{ '}' }}.static.yourclouddomain.com",
          "{{ '{' }}dashed_ip{{ '}' }}.{{ '{' }}region{{ '}' }}.static.yourclouddomain.com".
        </p>
      </ng-container>
      <ng-container>
        <h3 i18n>PTR default format IPv6</h3>
        <p class="fl-detail" i18n>
          PTR default format IPv6 will be set on IPv6s allocation/de-allocation. Leave empty so it won't change PTR
          record on mentioned actions. You can use the following template examples:
          "{{ '{' }}dashed_ip{{ '}' }}.static.yourclouddomain.com",
          "{{ '{' }}dashed_ip{{ '}' }}.{{ '{' }}region{{ '}' }}.static.yourclouddomain.com".
        </p>
      </ng-container>
      <ng-container>
        <h3 i18n>Inverse address zone email</h3>
        <p class="fl-detail" i18n>
          If you are using "PTR default format" settings, you also need to set "Inverse address zone email", which
          will be used when creating the DNS zone.
        </p>
      </ng-container>
    </div>
  </div>
  <div layoutDirection="row" layoutAlign="end" layoutDirection-xs="column">
    <a mat-button class="fl-margin-top" [color]="'primary'" (click)="save()" i18n>Save</a>
  </div>
</div>
