extends /layout

block pageSpecificScipts
  script(nonce=cspNonce src="/javascripts/admin.js")

block body
  section#fixed-top-section
    include /common/main-navigation
    +main-navigation(false)
  include /common/side-menu-mixin-dictionaries
  - const d = { activeLvl1: 'attributes', activeLvl2: 'users' }
  +sideNavigation(d)

  include /utilities/dictionaries-main-panel-header
  - const c = { sideMenu: true, h2: dictionary.name, h1: t('Uporabniki'), description: t('Registrirani uporabniki lahko dobijo različne vloge na portalu. Kot administrator jim lahko dodelite tudi vlogo skrbnika slovarjev in/ali skrbnika svetovalnice.'), buttons: [{ type: 'disabled', content: t('Shrani'), form: 'admin-dictionary-users' }] }
  +mainHeader(c)
  .content-hold-prerequisites
    #offset-main.main-container.mt-1
      form#admin-dictionary-users.container-xxl.ms-0.ps-0(method="post")
        span.users-subtitle-txt.ms-0= t('Faze urejanja')
        .row.align-items-center.mt-2
          .col-sm-6
            .switch-forms-and-key-word.d-md-flex.mt-2
              .switch-forms
                .form-check.form-switch.d-flex
                  input#preposition.form-check-input(
                    type="checkbox"
                    disabled
                    checked
                  )
                  label.form-check-label(for="preposition")= t('Predlog')

          .col-sm
            span.name-info-txt= t('V slovarju so samo terminološki kandidati. Slovarja ne morete objaviti.')

        .row.align-items-center
          .col-sm-6
            .switch-forms-and-key-word.d-md-flex
              .switch-forms
                .form-check.form-switch.d-flex
                  input#editing.form-check-input(
                    type="checkbox"
                    disabled
                    checked
                  )
                  label.form-check-label(for="editing")= t('V urejanju')

          .col-sm
            span.name-info-txt= t('Slovarski sestavek je v fazi, ko se dodajajo in oblikujejo elementi, ki ste jih izbrali v strukturi slovarskega sestavka.')
            a.ms-1.name-info-txt(href="/pomoc#help-users-dict" target="_blank")= t('Več...')

        .row.align-items-center
          .col-sm-6
            .switch-forms-and-key-word.d-md-flex
              .switch-forms
                .form-check.form-switch.d-flex
                  input#edited.form-check-input(
                    type="checkbox"
                    disabled
                    checked
                  )
                  label.form-check-label(for="edited")= t('Urejeno')
          .col-sm
            span.name-info-txt= t('Slovarski sestavek je pregledan in dokončan.')

        .row.align-items-center.mt-2
          .col-sm-6
            .switch-forms-and-key-word.d-md-flex
              .switch-forms
                if dictionary.terminologyReviewFlag
                  .form-check.form-switch.d-flex
                    input#terminology_review.form-check-input(
                      type="checkbox"
                      name="hasTerminologyReview"
                      checked
                    )
                    label.form-check-label(for="terminology_review")= t('Strokovno pregledano')
                else
                  .form-check.form-switch.d-flex
                    input#terminology_review.form-check-input(
                      type="checkbox"
                      name="hasTerminologyReview"
                    )
                    label.form-check-label(for="terminology_review")= t('Strokovno pregledano')
          .col-sm
            span.name-info-txt= t('Slovar je pregledal področni strokovnjak.')

        .row.align-items-center.mt-2
          .col-sm-6
            .switch-forms-and-key-word.d-md-flex
              .switch-forms
                if dictionary.languageReviewFlag
                  .form-check.form-switch.d-flex
                    input#language_review.form-check-input(
                      type="checkbox"
                      name="hasLanguageReview"
                      checked
                    )
                    label.form-check-label(for="language_review")= t('Jezikovno pregledano')
                else
                  .form-check.form-switch.d-flex
                    input#language_review.form-check-input(
                      type="checkbox"
                      name="hasLanguageReview"
                    )
                    label.form-check-label(for="language_review")= t('Jezikovno pregledano')

          .col-sm
            span.name-info-txt= t('Slovar je pregledal jezikoslovec.')

        .container-xl.mt-4.ms-0.ps-0
          span.users-subtitle-txt.ms-0.mt-3= t('Uporabniške pravice/vloge')
            table#user-roles-table.table-users.table-borderless.align-middle.mt-3
              thead
                tr
                  th.col-2
                    span.user-rights-column-title= t('Uporabnik')
                  th.col-2
                    span.user-rights-column-title= t('Administracija')
                  th.col-2.text-center
                    span.user-rights-column-title= t('Urejanje')
                  th.col-2
                    span#txt-term-rev.user-rights-column-title= t('Strokovni pregled')
                  th.col-2
                    span#txt-lang-rev.user-rights-column-title= t('Jezikovni pregled')
                  th.col-1.justify-content-center
                    span.hidden-text= t('Izbriši polje')

              if userRights
                each el in userRights
                  tbody.user-data.pb-xl-2
                    tr
                      input.hidden-user-id(type="hidden" value=el.id)
                      td.d-grid.justify-content-left.justify-content-xl-center.mb-0.align-items-center(
                        scope="row"
                        data-label=""
                      ) 
                        span.user-name-last-name= el.userName
                        span.user-email= el.email

                      td.pt-1.pb-1(data-label="Administrator")
                        .form-check.d-flex.justify-content-left.justify-content-xl-center.mb-0.align-items-center
                          if el.hasAdministration
                            input.administration-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isAdministration]`
                              checked
                            )
                          else
                            input.administration-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isAdministration]`
                            )

                      td.pt-1.pb-1(data-label="Urejanje")
                        .form-check.d-flex.justify-content-left.justify-content-xl-center.mb-0.align-items-center
                          if el.hasEditing
                            input.edit-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isEditing]`
                              checked
                            )
                          else
                            input.edit-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isEditing]`
                            )

                      td.pt-1.pb-1(data-label="Strokovni pregled")
                        .form-check.d-flex.justify-content-left.justify-content-xl-center.mb-0.align-items-center
                          if el.hasTerminologyReview
                            input.terminology-review-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isTerminologyReview]`
                              checked
                            )
                          else
                            input.terminology-review-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isTerminologyReview]`
                            )

                      td.pt-1.pb-1(data-label="Jezikovni pregled")
                        .form-check.d-flex.justify-content-left.justify-content-xl-center.mb-0.align-items-center
                          if el.hasLanguageReview
                            input.language-review-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isLanguageReview]`
                              checked
                            )
                          else
                            input.language-review-cb.form-check-input(
                              type="checkbox"
                              name=`rightsPerUser['${el.id}'][isLanguageReview]`
                            )

                      td.delete-user-btn.pt-3.delete-row(
                        value=`${el.id}`
                        data-bs-target="#alert-modal"
                        data-bs-toggle="modal"
                      )
                        img.icon-trash-delete(
                          src="/images/red-trash-icon.svg"
                          alt="Delete"
                        )

      form#form-add-user.container-xl.new-user-input.mt-4.ps-0.ms-0(
        action="/api/v1/users/addUser"
      )
        span.new-user-info= t('NOV UPORABNIK')
        .row.d-flex.justify-content-lg-start.align-items-center.mt-2.ms-0.ps-0
          .col-lg-6.ms-0.ps-0.me-2
            input.name-input.d-inline.form-control.ms-0.ps-0(
              type="text"
              name="userNameEmail"
              autocomplete="off"
            )
          .col.ms-xl-4.ms-0.ps-0.d-flex.justify-content-start.mt-2.mt-lg-0
            button.btn.btn-primary= t('Dodaj')

      - const minEntriesNum = parseInt(minEntries)
      - const countEntries = parseInt(entriesCount)
      .container-xxl.ms-0.ps-0
        .row.align-items-center.mt-4
          .col-sm-6
            .switch-forms-and-key-word.d-md-flex
              .form-check.form-switch.d-flex
                if publishApproval === 'F'
                  if dictionary.status === 'closed'
                    input#publish-switch.form-check-input(
                      type="checkbox"
                      name="isPublished"
                      form="admin-dictionary-users"
                      disabled=countEntries < minEntriesNum ? true : false
                    )
                  if dictionary.status === 'published'
                    input#publish-switch.form-check-input(
                      type="checkbox"
                      name="isPublished"
                      form="admin-dictionary-users"
                      checked
                    )
                else
                  if dictionary.status === 'closed'
                    input#publish-switch.form-check-input(
                      type="checkbox"
                      name="isPublished"
                      form="admin-dictionary-users"
                      disabled=countEntries < minEntriesNum ? true : false
                    )
                  if dictionary.status === 'reviewed'
                    input#publish-switch.form-check-input(
                      type="checkbox"
                      name="isPublished"
                      form="admin-dictionary-users"
                      checked
                      disabled
                    )
                  if dictionary.status === 'published'
                    input#publish-switch.form-check-input(
                      type="checkbox"
                      name="isPublished"
                      form="admin-dictionary-users"
                      checked
                    )
                label.form-check-label(for="publish-switch")= t('Slovar odprt')

          .col-sm
            span.name-info-txt= t('Slovar je odprt.')
        if dictionary.status === 'published' && countEntries < minEntriesNum
          .col-sm-6
            span.mt-3.d-md-inline.d-block.normal-red-note= t('Število slovarskih sestavkov je manjše od zahtevanega števila - povečajte število slovarskih sestavkov, sicer ga skrbnik slovarjev lahko zapre')
        if publishApproval === 'T' && dictionary.status === 'reviewed'
          .col-sm-6
            span.mt-3.d-md-inline.d-block.normal-red-note= t('Slovar je v odpiranju - čaka na potrditev skrbnika slovarjev')

      include /common/footer
    include /utilities/modal-alert
    include /utilities/modal-response
    +responseModal
  include /utilities/modal-alert-mixin
  +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?'))
