//
// Component: Button
//
// ========================================================================


// Variables
// ========================================================================

@button-line-height:                            round(@global-control-height - (@button-border-width * 2) - 10px);
@button-small-line-height:                      round(@global-control-small-height - (@button-border-width * 2) - 5px);
@button-large-line-height:                      round(@global-control-large-height - (@button-border-width * 2) - 10px);

@button-font-size:                              @global-font-size;
@button-large-font-size:                        @global-font-size;

@button-padding-horizontal:                     round(@global-gutter / 1.3);
@button-small-padding-horizontal:               round(@global-small-gutter * 1.3);
@button-large-padding-horizontal:               round(@global-medium-gutter / 1.3);

@button-default-background:                     #eee;
@button-default-hover-background:               lighten(#eee, 2%);
@button-default-active-background:              darken(#eee, 4%);

@button-success-background:                     @global-success-background;
@button-success-hover-background:               darken(@global-success-background, 2%);
@button-success-active-background:              darken(@global-success-background, 5%);

@button-warning-background:                     @global-warning-background;
@button-warning-hover-background:               darken(@global-warning-background, 2%);
@button-warning-active-background:              darken(@global-warning-background, 5%);

@button-disabled-background:                    #eee;

@button-text-color:                             @global-emphasis-color;
@button-text-hover-color:                       @global-emphasis-color;

//
// New
//

@button-text-transform:                         none;

@button-border-width:                           @global-border-width;

@button-default-border:                         #d5d5d5;
@button-default-hover-border:                   darken(@global-border, 20%);
@button-default-active-border:                  darken(@global-border, 30%);

@button-disabled-border:                        @global-border;

@button-text-border-width:                      @global-border-width;
@button-text-border:                            @button-text-hover-color;

@button-border-radius:                          @global-border-radius;


// Component
// ========================================================================

.hook-button() {
    text-transform: @button-text-transform;
    -webkit-transition: 0.1s ease-in-out;
    transition: 0.1s ease-in-out;
    -webkit-transition-property: color, background-color, border-color;
    transition-property: color, background-color, border-color;
    background-color: @button-default-background;
    border-radius: @button-border-radius;
    border: @button-border-width solid @button-default-border;
    border-bottom-color: #bbbbbb;
}

.hook-button-hover() {
    color: @button-default-hover-color;
    background-color: @button-default-hover-background;
}

.hook-button-focus() {}

.hook-button-active() {
    color: @button-default-active-color;
    background-color: @button-default-active-background;
}


// Style modifiers
// ========================================================================

.hook-button-default() {}

.hook-button-default-hover() {}

.hook-button-default-active() {}

//
// Primary
//

.hook-button-primary() {
  border: @button-border-width solid darken(@global-primary-background, 20%);
}

.hook-button-primary-hover() {}

.hook-button-primary-active() {}

//
// Secondary
//

.hook-button-secondary() { border: @button-border-width solid transparent; }

.hook-button-secondary-hover() {}

.hook-button-secondary-active() {}

//
// Danger
//

.hook-button-danger() {
  border: @button-border-width solid darken(@global-danger-background, 20%);
}

.hook-button-danger-hover() {}

.hook-button-danger-active() {}


// Disabled
// ========================================================================

.hook-button-disabled() { border-color: @button-disabled-border; }


// Size modifiers
// ========================================================================

.hook-button-small() {}

.hook-button-large() {}


// Text modifier
// ========================================================================

.hook-button-text() {

    position: relative;
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
    border-bottom: @button-border-width solid transparent;

    &::before {
        content: "";
        position: absolute;
        bottom: 0;
        left: 0;
        right: 100%;
        border-top: none;
        border-left: none;
        border-right: none;
        border-bottom: @button-text-border-width solid @button-text-border;
        -webkit-transition: right 0.3s ease-out;
        transition: right 0.3s ease-out;
    }

}

.hook-button-text-hover() {

    background-color: transparent;

    &::before { right: 0; }

}

.hook-button-text-disabled() {

    &::before { display: none; }

}


// Link modifier
// ========================================================================

.hook-button-link() {
    border: none;
}


// Miscellaneous
// ========================================================================

.hook-button-misc() {

    //
    // Success
    //
    .uk-button-success {
        .hook-button-primary();

        background-color: @button-success-background;
        border: @button-border-width solid darken(@global-success-background, 10%);
        color: @button-primary-color;
    }

    .uk-button-success:hover,
    .uk-button-success:focus {
        background-color: @button-success-hover-background;
        color: @button-primary-color;
    }

    .uk-button-success:active {
        background-color: @button-success-active-background;
        color: @button-primary-color;
    }

    //
    // Warning
    //
    .uk-button-warning {
        .hook-button-primary();

        background-color: @button-warning-background;
        border: @button-border-width solid darken(@global-warning-background, 10%);
        color: @button-primary-color;
    }

    .uk-button-warning:hover,
    .uk-button-warning:focus {
        background-color: @button-warning-hover-background;
        color: @button-primary-color;
    }

    .uk-button-warning:active {
        background-color: @button-warning-active-background;
        color: @button-primary-color;
    }

    .uk-button-link:hover,
    .uk-button-link:focus {
      background-color: transparent;
    }

    /* Group
     ========================================================================== */

    /*
     * Collapse border
     */

    .uk-button-group > .uk-button:not(:first-child):not(:last-child),
    .uk-button-group > div:not(:first-child):not(:last-child) .uk-button { border-radius: 0; }

    .uk-button-group > .uk-button:first-child,
    .uk-button-group > div:first-child .uk-button {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
    }

    .uk-button-group > .uk-button:last-child,
    .uk-button-group > div:last-child .uk-button {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }

    .uk-button-group > .uk-button:nth-child(n+2),
    .uk-button-group > div:nth-child(n+2) .uk-button { margin-left: -@button-border-width; }

    /*
     * Create position context to superimpose the successor elements border
     * Known issue: If you use an `a` element as button and an icon inside,
     * the active state will not work if you click the icon inside the button
     * Workaround: Just use a `button` or `input` element as button
     */

    .uk-button-group .uk-button:hover,
    .uk-button-group .uk-button:focus,
    .uk-button-group .uk-button:active,
    .uk-button-group .uk-button.uk-active {
        position: relative;
        z-index: 1;
    }

}


// Inverse
// ========================================================================

@inverse-button-default-background:            transparent;
@inverse-button-default-color:                 @inverse-global-emphasis-color;
@inverse-button-default-hover-background:      transparent;
@inverse-button-default-hover-color:           @inverse-global-emphasis-color;
@inverse-button-default-active-background:     transparent;
@inverse-button-default-active-color:          @inverse-global-emphasis-color;

@inverse-button-text-color:                    @inverse-global-emphasis-color;
@inverse-button-text-hover-color:              @inverse-global-emphasis-color;

//
// Hooks
//

.hook-inverse-button-default() { border-color: @inverse-global-color; }
.hook-inverse-button-default-hover() { border-color: @inverse-global-emphasis-color; }
.hook-inverse-button-default-active() { border-color: @inverse-global-emphasis-color; }

.hook-inverse-button-primary() {}
.hook-inverse-button-primary-hover() {}
.hook-inverse-button-primary-active() {}

.hook-inverse-button-secondary() {}
.hook-inverse-button-secondary-hover() {}
.hook-inverse-button-secondary-active() {}

.hook-inverse-button-text() {
    &::before { border-bottom-color: @inverse-global-emphasis-color; }
}
.hook-inverse-button-text-hover() {}
.hook-inverse-button-text-disabled() {}
