﻿<template>
  <div class="ui-header-bar">
    <div class="ui-header-bar-inner">
      <div class="ui-header-bar-main">
        <ui-icon-button v-if="backButton" type="white" @click="onBack" />
        <div>
          <h2 class="ui-header-bar-title" :class="{'is-empty': !title && titleEmpty}">
            <span v-if="prefix" class="-minor" v-localize:html="prefix"></span>
            <span v-localize="title || titleEmpty"></span>
            <span v-if="suffix" class="-minor" v-localize:html="suffix"></span>
          </h2>
          <p v-if="description" class="ui-header-bar-description" v-localize="description"></p>
        </div>
      </div>
      <div class="ui-header-bar-aside">
        <slot></slot>
        <ui-icon-button v-if="closeButton" @click="onClose" icon="fth-x" title="@ui.close" />
      </div>
    </div>
  </div>
</template>


<script>
  import Overlay from 'zero/services/overlay';

  export default {
    name: 'uiHeaderBar',

    props: {
      title: {
        type: String
      },
      titleEmpty: {
        type: String
      },
      prefix: {
        type: String
      },
      suffix: {
        type: String
      },
      description: {
        type: String
      },
      backButton: {
        type: Boolean,
        default: false
      },
      closeButton: {
        type: Boolean,
        default: false
      }
    },

    methods: {
      onBack()
      {
        this.$router.go(-1);
      },
      onClose()
      {
        Overlay.close();
      }
    }
  }
</script>

<style lang="scss">
  .ui-header-bar
  {
    width: 100%;
    height: 100px;
    padding: 0 var(--padding) 10px;
    /*background: var(--color-bg-light);*/
    //border-bottom: 1px solid var(--color-line);

    & + .ui-blank-box, & + .ui-box, & + .ui-view-box
    {
      margin-top: 0;
    }

    & + .ui-view-box
    {
      padding-top: 0;
    }
  }

  .ui-header-bar-inner
  {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    /*max-width: 1104px;*/
  }

  .ui-header-bar-main
  {
    display: flex;
    align-items: center;
    height: 100%;

    .ui-icon-button
    {
      margin-right: var(--padding);
    }
  }

  .ui-header-bar-aside
  {
    display: flex;
    align-items: center;
    height: 100%;

    > * + *
    {
      margin-left: 15px;
    }
  }

  .ui-header-bar-title
  {
    font-family: var(--font);
    color: var(--color-fg);
    margin: 0;
    font-size: var(--font-size-l);
    font-weight: 700;

    &.is-empty, .-minor
    {
      color: var(--color-fg-light);
      font-weight: 400;
    }
  }

  .ui-header-bar-description
  {
    font-size: var(--font-size-s);
    color: var(--color-fg-light);
    margin: 2px 0 0;
  }
</style>