@import '../bootstrap'
@import '../components/_ripples'
@import '../theme'

button($material)
  color: $material.text.primary

  &.vf-btn--disabled
    color: $material.buttons.disabled !important

    .vf-icon
      color: $material.buttons.disabled !important

    &:not(.vf-btn--icon):not(.vf-btn--flat)
      background-color: $material.buttons.focused !important

  &:not(.vf-btn--icon):not(.vf-btn--flat)
    background-color: $material.app-bar

theme(button, "vf-btn")

/** Base Spec */
.vf-btn
  align-items: center
  border-radius: $button-border-radius
  display: inline-flex
  height: $button-height
  flex: 0 1 auto
  font-size: $button-font-size
  font-weight: $button-font-weight
  justify-content: center
  margin: $button-margin
  min-width: $button-min-width
  outline: 0
  text-transform: $button-text-transform
  text-decoration: none
  transition: .3s $transition.swing, color 1ms
  position: relative
  vertical-align: middle
  user-select: none


/** Psuedo */
.vf-btn
  &__content:before
    border-radius: inherit
    color: inherit
    content: ''
    position: absolute
    left: 0
    top: 0
    height: 100%
    opacity: .12
    transition: $primary-transition
    width: 100%

/** Content */
.vf-btn
  &--active,
  &:hover,
  &:focus
    .vf-btn__content:before
      background-color: currentColor

  &__content
    align-items: center
    border-radius: inherit
    color: inherit
    display: flex
    height: 100%
    flex: 1 0 auto
    justify-content: center
    margin: 0 auto
    padding: $button-padding
    transition: $primary-transition
    white-space: nowrap

/** Icons */
.vf-btn .vf-btn__content .vf-icon
  color: inherit

/** Types */
.vf-btn
  &--flat
    background-color: transparent !important
    box-shadow: none !important

  &:not(.vf-btn--depressed)
    will-change: box-shadow
    elevation(2)

    &:active
      elevation(8)

  &--icon
    background: transparent
    box-shadow: none !important
    border-radius: 50%
    justify-content: center
    height: $button-height
    width: $button-height
    min-width: 0

    .vf-btn__content
      padding: 0

      &:before
        border-radius: 50%

    &.vf-btn--small
      width: $button-small-height

      .vf-btn__content
        height: $button-small-height

    &.vf-btn--large
      width: $button-large-height

      .vf-btn__content
        height: $button-large-height

  &--floating
    border-radius: 50%
    min-width: 0
    height: $button-floating-width
    width: $button-floating-width
    padding: 0
    elevation(6)

    &.vf-btn--fixed,
    &.vf-btn--absolute
      z-index: 4

    &:active
      elevation(12)

    .vf-btn__content
      flex: 1 1 auto
      margin: 0
      padding: 0

    &:after
      border-radius: 50%

    .vf-btn__content
      :not(:only-child)
        transition: $primary-transition

        &:last-child
          opacity: 0
          position: absolute
          transform: rotate(-45deg)
          left: calc(50% - 12px)
          top: calc(50% - 12px)

    &.vf-btn--active
      .vf-btn__content
        :not(:only-child)
          &:first-child
            opacity: 0
            transform: rotate(45deg)
            left: 'calc(50% - %s)' % (24 / 2)
            top: 'calc(50% - %s)' % (24 / 2)

          &:last-child
            opacity: 1
            transform: none

    .vf-icon
      height: $button-floating-icon-width
      width: $button-floating-icon-width

    &.vf-btn--small
      height: $button-floating-small-width
      width: $button-floating-small-width

      .vf-icon
        font-size: $button-floating-small-icon-width
        height: $button-floating-small-icon-width
        width: $button-floating-small-icon-width

      &.vf-btn--floating .vf-icon
        left: 'calc(50% - %s)' % ($button-floating-small-icon-width / 2)
        top: 'calc(50% - %s)' % ($button-floating-small-icon-width / 2)


    &.vf-btn--large
      height: $button-floating-large-width
      width: $button-floating-large-width

      .vf-icon
        font-size: $button-floating-large-icon-width
        height: $button-floating-large-icon-width
        width: $button-floating-large-icon-width

      &.vf-btn--floating .vf-icon
        left: 'calc(50% - %s)' % ($button-floating-large-icon-width / 2)
        top: 'calc(50% - %s)' % ($button-floating-large-icon-width / 2)

  &--reverse
    .vf-btn__content
      flex-direction: row-reverse

    &.vf-btn--column
      .vf-btn__content
        flex-direction: column-reverse

  &--fixed, &--absolute
    margin: 0

  // Position must have prepended .btn
  // to account for tooltip
  // TODO: Remove this once tooltips are
  // converted to elements
  &.vf-btn--absolute
    position: absolute

  &.vf-btn--fixed
    position: fixed

  &--top
    &:not(.vf-btn--absolute)
      top: $grid-gutters.lg

    &.vf-btn--absolute
      top: -($button-floating-width / 2)

      &.vf-btn--small
        top: -($button-floating-small-width / 2)

      &.vf-btn--large
        top: -($button-floating-large-width / 2)

  &--bottom
    &:not(.vf-btn--absolute)
      bottom: $grid-gutters.lg

    &.vf-btn--absolute
      bottom: -($button-floating-width / 2)

      &.vf-btn--small
        bottom: -($button-floating-small-width / 2)

      &.vf-btn--large
        bottom: -($button-floating-large-width / 2)

  &--left
    left: $grid-gutters.lg

  &--right
    right: $grid-gutters.lg

/** Disabled */
.vf-btn
  &.vf-btn--disabled
    box-shadow: none !important
    pointer-events: none

/** Sizes */
.vf-btn
  &--small
    font-size: $button-small-font-size
    height: $button-small-height

    .vf-btn__content
      padding: $button-small-padding

  &--large
    font-size: $button-large-font-size
    height: $button-large-height

    .vf-btn__content
      padding: $button-large-padding


/** Loader */
.vf-btn
  &--loader
    pointer-events: none

    .vf-btn__content
      opacity: 0

  &__loading
    align-items: center
    display: flex
    height: 100%
    justify-content: center
    left: 0
    position: absolute
    top: 0
    width: 100%

    .vf-icon
      &--left
        margin-right: 1rem
        line-height: inherit

      &--right
        margin-left: 1rem
        line-height: inherit


/** Custom Buttons */
.vf-btn
  &.btn--outline
    border: 1px solid currentColor
    background: transparent !important
    box-shadow: none

    &:hover
      box-shadow: none

  &--block
    display: flex
    flex: 1
    margin: $button-margin-y 0
    width: 100%

  &--round
    border-radius: 28px

    &:after
      border-radius: 28px


/** Button w/ directional Icon */
.vf-btn
  .vf-icon
    &--right
      margin-left: 16px

    &--left
      margin-right: 16px


/** Themes */
.vf-btn
  &.vf-primary,
  &.vf-secondary,
  &.vf-success,
  &.vf-error,
  &.vf-warning,
  &.vf-info
    color: $material-dark.text.primary
