<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
-->

<nz-spin [nzSpinning]="loading">
  <div class="main" *ngIf="config">
    <div class="left">
      <form nz-form nzLayout="vertical" #objectStoreForm="ngForm" (submit)="onSaveObjectStore()">
        <nz-form-item>
          <nz-form-label nzFor="config.type">{{ 'settings.object-store.type' | i18n }}</nz-form-label>
          <nz-form-control [nzErrorTip]="'validation.required' | i18n">
            <nz-select
              [(ngModel)]="config.type"
              [ngModelOptions]="{ standalone: true }"
              style="text-align: center; font-weight: bolder; margin-top: 4px"
              [nzDropdownStyle]="{ 'font-weight': 'bolder', 'font-size': 'larger' }"
              (ngModelChange)="onChange()"
            >
              <nz-option [nzValue]="ObjectStoreType.DATABASE" [nzLabel]="'settings.object-store.type.database' | i18n"></nz-option>
              <nz-option [nzValue]="ObjectStoreType.FILE" [nzLabel]="'settings.object-store.type.file' | i18n"></nz-option>
              <nz-option [nzValue]="ObjectStoreType.OBS" [nzLabel]="'settings.object-store.type.obs' | i18n"></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>
        <nz-form-item *ngIf="config.type == ObjectStoreType.OBS">
          <nz-form-label nzFor="obs.accessKey" nzRequired="true">{{ 'settings.object-store.obs.accessKey' | i18n }}</nz-form-label>
          <nz-form-control [nzErrorTip]="'validation.required' | i18n">
            <input
              [(ngModel)]="config.config.accessKey"
              placeholder="{{ 'settings.object-store.obs.accessKey.placeholder' | i18n }}"
              nz-input
              required
              name="accessKey"
              type="text"
              id="accessKey"
            />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item *ngIf="config.type == ObjectStoreType.OBS">
          <nz-form-label nzFor="obs.secretKey" nzRequired="true">{{ 'settings.object-store.obs.secretKey' | i18n }}</nz-form-label>
          <nz-form-control [nzErrorTip]="'validation.required' | i18n">
            <input
              [(ngModel)]="config.config.secretKey"
              placeholder="{{ 'settings.object-store.obs.secretKey.placeholder' | i18n }}"
              nz-input
              required
              name="secretKey"
              type="text"
              id="secretKey"
            />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item *ngIf="config.type == ObjectStoreType.OBS">
          <nz-form-label nzFor="obs.bucketName" nzRequired="true">{{ 'settings.object-store.obs.bucketName' | i18n }}</nz-form-label>
          <nz-form-control [nzErrorTip]="'validation.required' | i18n">
            <input
              [(ngModel)]="config.config.bucketName"
              placeholder="{{ 'settings.object-store.obs.bucketName.placeholder' | i18n }}"
              nz-input
              required
              name="bucketName"
              type="text"
              id="bucketName"
            />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item *ngIf="config.type == ObjectStoreType.OBS">
          <nz-form-label nzFor="obs.endpoint" nzRequired="true">{{ 'settings.object-store.obs.endpoint' | i18n }}</nz-form-label>
          <nz-form-control [nzErrorTip]="'validation.required' | i18n">
            <input
              [(ngModel)]="config.config.endpoint"
              placeholder="{{ 'settings.object-store.obs.endpoint.placeholder' | i18n }}"
              nz-input
              required
              name="endpoint"
              type="text"
              id="endpoint"
            />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item *ngIf="config.type == ObjectStoreType.OBS">
          <nz-form-label nzFor="obs.savePath" nzRequired="true">{{ 'settings.object-store.obs.savePath' | i18n }}</nz-form-label>
          <nz-form-control [nzErrorTip]="'validation.required' | i18n">
            <input
              [(ngModel)]="config.config.savePath"
              placeholder="{{ 'settings.object-store.obs.savePath.placeholder' | i18n }}"
              nz-input
              required
              name="savePath"
              type="text"
              id="savePath"
            />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
          <button nz-button nzType="primary">{{ 'settings.system-config.ok' | i18n }}</button>
        </nz-form-item>
      </form>
    </div>
  </div>
</nz-spin>
