-# haml-lint:disable ViewLength
- @pagetitle = "Token - #{@token.description.presence || 'No Description'}"

.card
  .card-body
    %h3.mb-3
      = @pagetitle
      - unless @token.enabled
        .fas.fa-ban.text-danger
        %span.text-warning Disabled

    .row
      .col-12.col-md-10.col-lg-8
        - if session[:show_token]
          %p.fw-bold Your new OBS Personal Access Token

        .row
          .col-sm
            %label.fw-bold
              Id:
            %span
              = @token.id

        - if session[:show_token]
          - session[:show_token] = nil # Ensure we're only showing the token once
          .row
            .col-12.col-md-10.col-lg-9
              %fieldset.mb-3
                %label.col-form-label.fw-bold
                  Secret:
                .input-group
                  = render CopyToClipboardInputComponent.new(input_text: @token.string)
              %hr

        .row
          .col
            .mb-3
              %label.col-form-label.me-2.fw-bold
                Type:
              %span
                = @token.token_name

        .row
          .col-sm
            .mb-3.ui-front
              %label.fw-bold
                Runs as:
              %span
                = link_to(@token.executor.login, user_path(@token.executor))

        - if @token.type == 'Token::Workflow'
          - if (unique_repository = @token.workflow_runs.where.not(response_url: nil).first)
            .row
              .col
                .mb-3
                  %label.fw-bold
                    Workflow Repository:
                  %span
                    = link_to unique_repository.repository_full_name, unique_repository.repository_url

          .row
            .col
              .mb-3
                %label.fw-bold
                  Workflows Configuration File Path:
                %span
                  = @token.workflow_configuration_path

          .row
            .col
              .mb-3
                %label.fw-bold
                  Workflows Configuration File URL:
                %span
                  - if @token.workflow_configuration_url.present?
                    = link_to(@token.workflow_configuration_url, @token.workflow_configuration_url)
                    %small.form-text.fst-italic
                      %i.fa.fa-lg.fa-question-circle.text-info
                      The URL is set, the path will be ignored. The URL should be accessible for the OBS instance.
                  - else
                    %small.fst-italic.text-muted
                      Nothing

          .row
            .col
              .mb-3
                %label.col-form-label.me-2.fw-bold
                  Token trigger url:
                .input-group
                  = render CopyToClipboardInputComponent.new(input_text: trigger_workflow_url(id: @token.id))

        - if @token.package
          .row
            .col-sm
              .mb-3.ui-front
                %label.fw-bold
                  Project:
                %span
                  = link_to(@token.package.project.name, project_show_path(@token.package.project))

          .row
            .col-sm
              .mb-3.ui-front
                %label.fw-bold
                  Package:
                %span
                  = link_to(@token.package.name, package_show_path(@token.package.project, @token.package))

        .actions
          - if policy(@token).edit?
            = link_to(edit_token_path(@token), class: 'ps-2', title: 'Edit') do
              %i.fas.fa-edit
              %span.nav-item-name Edit
          - if @token.type == 'Token::Workflow'
            = link_to(token_users_path(@token.id), class: 'ps-2', title: 'Share') do
              %i.fas.fa-users
              %span.nav-item-name Share
            = link_to(token_workflow_runs_path(@token.id), class: 'ps-2', title: 'Workflow Runs') do
              %i.fas.fa-book-open
              %span.nav-item-name Workflow Runs
-# haml-lint:enable ViewLength
