<template>
  <div :class="containerClass">
    <slot />
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'

type LinearLayoutOrientation = 'horizontal' | 'vertical'
type LinearLayoutGravity = 'repulsive' | 'attractive'
type LinearLayoutSpace = 'wrap-content' | 'match-parent'

@Component({
  name: 'linear-layout'
})
export default class LinearLayout extends Vue {
  @Prop({ default: 'wrap-content' }) readonly lwidth!: LinearLayoutSpace
  @Prop({ default: 'wrap-content' }) readonly lheight!: LinearLayoutSpace
  @Prop({ default: 'horizontal' }) readonly orientation!: LinearLayoutOrientation
  @Prop({ default: 'attractive' }) readonly gravity!: LinearLayoutGravity

  get containerClass () {
    return {
      'is-linear': true,
      'is-horizontal': this.orientation === 'horizontal',
      'is-vertical': this.orientation === 'vertical',
      'is-repulsive': this.gravity === 'repulsive',
      'is-width-match': this.lwidth === 'match-parent',
      'is-height-match': this.lheight === 'match-parent'
    }
  }
}
</script>

<style lang="scss" scoped>
.is-linear {
  display: flex;
  flex-wrap: wrap;
}

.is-width-match {
  width: 100%;
}

.is-height-match {
  height: 100%;
}

.is-vertical {
  flex-direction: column;
}

.is-horizontal {
  align-items: center;
}

.is-repulsive {
  justify-content: space-between;
}

.is-horizontal > *:not(:first-child) {
  margin-left: 1em;
}

.is-vertical > *:not(:first-child) {
  margin-top: 1em;
}
</style>
