<q-tab-panel name="security">
  <q-card-section class="q-pa-none">
    <h6 class="q-my-none">Server Management</h6>
    <div class="row">
      <div class="col-md-6">
        <p>Base URL</p>
        <q-input
          filled
          v-model.number="formData.lnbits_baseurl"
          label="Static/Base url for the server"
        ></q-input>
        <br />
      </div>
    </div>
    <h6 class="q-my-none q-mb-sm">Authentication</h6>
    <div class="row q-col-gutter-sm">
      <div class="col-12 col-sm-6">
        <q-input
          filled
          v-model="formData.auth_token_expire_minutes"
          type="number"
          label="Token expire minutes"
          hint="Time in minutes until the token expires"
        >
        </q-input>
      </div>
      <div class="col-12 col-sm-6">
        <q-select
          filled
          v-model="formData.auth_allowed_methods"
          multiple
          hint="Allowed authorization methods"
          label="Select authorization methods"
          :options="formData.auth_all_methods"
        ></q-select>
      </div>
    </div>
  </q-card-section>
  <q-card-section
    v-if="formData.auth_allowed_methods?.includes('nostr-auth-nip98')"
    class="q-pl-xl"
  >
    <strong class="q-my-none q-mb-sm">Nostr Auth</strong>

    <div class="row">
      <div class="col-12">
        <q-input
          class="q-mb-sm"
          filled
          v-model="nostrAcceptedUrl"
          @keydown.enter="addNostrUrl"
          type="text"
          label="Nostr Request URL"
          hint="Absolute URL that the clients will use to login."
        >
          <q-btn @click="addNostrUrl" dense flat icon="add"></q-btn>
        </q-input>
      </div>
      <div class="col-12">
        <q-chip
          v-for="url in formData.nostr_absolute_request_urls"
          :key="url"
          removable
          @remove="removeNostrUrl(url)"
          color="primary"
          text-color="white"
          :label="url"
          class="ellipsis"
        ></q-chip>
      </div>
    </div>
  </q-card-section>
  <q-card-section
    v-if="formData.auth_allowed_methods?.includes('google-auth')"
    class="q-pl-xl"
  >
    <strong class="q-my-none q-mb-sm">Google Auth</strong>

    <div class="row">
      <div class="col-md-6 col-sm-12 q-pr-sm">
        <q-input
          filled
          v-model="formData.google_client_id"
          label="Google Client ID"
          hint="Make sure thant the authorized redirect URIs contain https://{domain}/api/v1/auth/google/token"
        >
        </q-input>
      </div>
      <div class="col-md-6 col-sm-12">
        <q-input
          filled
          v-model="formData.google_client_secret"
          type="password"
          label="Google Client Secret"
        >
        </q-input>
      </div>
    </div>
  </q-card-section>
  <q-card-section
    v-if="formData.auth_allowed_methods?.includes('github-auth')"
    class="q-pl-xl"
  >
    <strong class="q-my-none q-mb-sm">GitHub Auth</strong>

    <div class="row">
      <div class="col-md-6 col-sm-12 q-pr-sm">
        <q-input
          filled
          v-model="formData.github_client_id"
          label="GitHub Client ID"
          hint="Make sure thant the authorization callback URL is set to https://{domain}/api/v1/auth/github/token"
        >
        </q-input>
      </div>
      <div class="col-md-6 col-sm-12">
        <q-input
          filled
          v-model="formData.github_client_secret"
          type="password"
          label="GitHub Client Secret"
        >
        </q-input>
      </div>
    </div>
  </q-card-section>
  <q-card-section
    v-if="formData.auth_allowed_methods?.includes('keycloak-auth')"
    class="q-pl-xl"
  >
    <strong class="q-my-none q-mb-sm">Keycloak Auth</strong>

    <div class="row">
      <div class="col-md-4 col-sm-12 q-pr-sm">
        <q-input
          filled
          v-model="formData.keycloak_discovery_url"
          label="Keycloak Discovey URL"
        >
        </q-input>
      </div>
      <div class="col-md-4 col-sm-12 q-pr-sm">
        <q-input
          filled
          v-model="formData.keycloak_client_id"
          label="Keycloak Client ID"
          hint="Make sure thant the authorization callback URL is set to https://{domain}/api/v1/auth/keycloak/token"
        >
        </q-input>
      </div>
      <div class="col-md-4 col-sm-12">
        <q-input
          filled
          v-model="formData.keycloak_client_secret"
          type="password"
          label="Keycloak Client Secret"
        >
        </q-input>
      </div>
    </div>
  </q-card-section>
  <q-separator></q-separator>
  <q-card-section class="q-pa-none">
    <br />
    <h6 class="q-my-none" v-text="$t('security_tools')"></h6>
    <div>
      <div class="row">
        <div v-if="serverlogEnabled" class="column" style="width: 100%">
          <div
            class="col bg-primary"
            style="padding-left: 5px; max-height: 20px; color: #fafafa"
            v-text="$t('server_logs')"
          ></div>
          <div class="col" style="background-color: #292929">
            <q-scroll-area
              ref="logScroll"
              style="padding: 10px; color: #fafafa; height: 320px"
            >
              <small v-for="log in logs"
                ><span v-text="log"></span><br
              /></small>
            </q-scroll-area>
          </div>
        </div>
        <q-btn
          @click="toggleServerLog"
          dense
          flat
          color="primary"
          :label="(serverlogEnabled) ? $t('disable_server_log') : $t('enable_server_log')"
        ></q-btn>
      </div>
      <br />
      <div class="row q-col-gutter-md">
        <div class="col-12 col-md-12">
          <p v-text="$t('ip_blocker')"></p>
          <div class="row q-col-gutter-md">
            <div class="col-6">
              <q-input
                filled
                v-model="formBlockedIPs"
                @keydown.enter="addBlockedIPs"
                type="text"
                :label="$t('enter_ip')"
                :hint="$t('block_access_hint')"
              >
                <q-btn
                  @click="addExtensionsManifest"
                  dense
                  flat
                  icon="add"
                ></q-btn>
              </q-input>
              <div>
                <q-chip
                  v-for="blocked_ip in formData.lnbits_blocked_ips"
                  :key="blocked_ip"
                  removable
                  @remove="removeBlockedIPs(blocked_ip)"
                  color="primary"
                  text-color="white"
                  :label="blocked_ip"
                  class="ellipsis"
                ></q-chip>
              </div>
              <br />
            </div>
            <div class="col-6">
              <q-input
                filled
                v-model="formAllowedIPs"
                @keydown.enter="addAllowedIPs"
                type="text"
                :label="$t('enter_ip')"
                :hint="$t('allow_access_hint')"
              >
                <q-btn
                  @click="addExtensionsManifest"
                  dense
                  flat
                  icon="add"
                ></q-btn>
              </q-input>
              <div>
                <q-chip
                  v-for="allowed_ip in formData.lnbits_allowed_ips"
                  :key="allowed_ip"
                  removable
                  @remove="removeAllowedIPs(allowed_ip)"
                  color="primary"
                  text-color="white"
                  :label="allowed_ip"
                  class="ellipsis"
                ></q-chip>
              </div>
              <br />
            </div>
          </div>
        </div>

        <div class="col-12 col-md-12">
          <p v-text="$t('rate_limiter')"></p>
          <div class="row q-col-gutter-md">
            <div class="col-6">
              <q-input
                filled
                type="number"
                v-model.number="formData.lnbits_rate_limit_no"
                :label="$t('number_of_requests')"
              ></q-input>
            </div>
            <div class="col-6">
              <q-select
                filled
                :options="[$t('second'),$t('minute'),$t('hour')]"
                v-model="formData.lnbits_rate_limit_unit"
                :label="$t('time_unit')"
              ></q-select>
            </div>
          </div>
        </div>

        <div class="col-12 col-md-12">
          <p v-text="$t('wallet_limiter')"></p>
          <div class="row q-col-gutter-md">
            <div class="col-4">
              <q-input
                filled
                type="number"
                v-model.number="formData.lnbits_wallet_limit_max_balance"
                :label="$t('wallet_max_ballance')"
              ></q-input>
            </div>
            <div class="col-4">
              <q-input
                filled
                type="number"
                v-model.number="formData.lnbits_wallet_limit_daily_max_withdraw"
                :label="$t('wallet_limit_max_withdraw_per_day')"
              ></q-input>
            </div>
            <div class="col-4">
              <q-input
                filled
                type="number"
                v-model.number="formData.lnbits_wallet_limit_secs_between_trans"
                :label="$t('wallet_limit_secs_between_trans')"
              ></q-input>
            </div>
          </div>
        </div>
      </div>
    </div>
  </q-card-section>
</q-tab-panel>
