<template>
  <div class="RecordHeader">
    <div class="RecordHeader__Header">
      <div>
        <q-btn
          class="RecordHeader__ButtonBack"
          dense
          icon="pgs-arrow-left"
          size="sm"
          @click="goBackOrToParentView(defaultRoute)"
        />
      </div>
      <div class="RecordHeader__Details">
        <div class="RecordHeader__Source">Организация</div>
      </div>
      <div class="RecordHeader__Space" />
      <r-btn
        v-if="$AC.haveScope($AC.scopes.SECURITY_ADMINISTRATOR)"
        class="RecordHeader__Archive"
        action
        label="Архивировать"
        @click="editOrg = data"
      />
    </div>
    <p class="RecordHeader__Title">
      {{ organizationName }}
    </p>
    <DeleteModal
      :organization="editOrg"
      @close="editOrg = null"
      @finish="goBackOrToParentView(defaultRoute)"
    />
  </div>
</template>

<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator';
import ReturnToParentView from '@mixins/ReturnToParentView';
import { Organization } from '@openapi/idm';
import DeleteModal from './DeleteModal.vue';

@Component({
  components: { DeleteModal },
})
export default class RecordHeader extends Mixins(ReturnToParentView) {
  @Prop({ default: () => ({}) }) data: Organization;

  public editOrg: Organization | null = null;

  get organizationName(): string {
    return this.data?.fullname || 'Организация';
  }

  private defaultRoute = '/admin/organizations';
}
</script>

<style lang="scss" scoped>
.RecordHeader {
  background-color: rgb(237, 243, 247);
  display: flex;
  flex-flow: column;
  &__Title {
    font-family: 'Golos Text', sans-serif;
    font-style: normal;
    font-weight: 500;
    font-size: 28px;
    line-height: 32px;
    letter-spacing: -0.02em;
    color: rgba(2, 12, 18, 0.9);
    margin-top: 6px;
    margin-bottom: 8px;
    padding: 4px 16px;
  }
  &__ButtonBack {
    border: 1px solid rgba(1, 72, 116, 0.18) !important;
    border-radius: 24px !important;
    color: #1491cf !important;
    padding-left: 4px;
    padding-right: 4px;
    margin-right: 4px;
  }
  &__Details {
    gap: 8px;
    display: flex;
    flex-wrap: wrap;

    > div {
      overflow-x: hidden;
      font-family: 'Golos Text', sans-serif;
      font-style: normal;
      font-weight: 600;
      font-size: 12px;
      line-height: 16px;
      flex: 0 1 auto;

      &.RecordHeader__Source {
        display: inline-flex;
        text-align: center;
        padding-left: 4px;
        font-family: 'Golos Text', sans-serif;
        font-style: normal;
        font-weight: 600;
        font-size: 12px;
        line-height: 26px;
        color: rgba(2, 12, 18, 0.58);
      }
    }
  }
  &__Space {
    flex-grow: 1;
  }
  &__Loader {
    background-color: inherit;
  }
  &__Header {
    padding: 16px 16px 0 16px;
    display: flex;
    flex-wrap: wrap;
  }
  &__Archive {
    margin-left: 8px;
  }
}
</style>
