/**
 * Handsontable 0.9.18
 * Handsontable is a simple jQuery plugin for editable tables with basic copy-paste compatibility with Excel and Google Docs
 *
 * Copyright 2012, Marcin Warpechowski
 * Licensed under the MIT license.
 * http://handsontable.com/
 *
 * Date: Thu Sep 19 2013 01:45:41 GMT+0200 (Central European Daylight Time)
 *
 * Forked from: https://github.com/warpech/jquery-handsontable/tree/7bd83de5ca32858735fb01ae3b9c1287246a83cb
 *
 * - Customized for OctoberCMS
 *
 */

@import "../../../../../assets/less/core/boot.less";

@color-handsontable-header: #808c8d;
@color-handsontable-active-cell: #4da7e8;
@color-handsontable-border: #e2e2e2;

@handsontable-cell-height: 28px;
@handsontable-font-size: 13px;

.handsontable {
    position: relative;

    .relative {
        position: relative;
    }

    &.htAutoColumnSize {
        visibility: hidden;
        left: 0;
        position: absolute;
        top: 0;
    }

    table, tbody, thead, td, th, div {
        box-sizing: content-box;
        -webkit-box-sizing: content-box;
        -moz-box-sizing: content-box;
    }

    table.htCore {
        // Must be separate, otherwise there are offset miscalculations in WebKit:
        // http://stackoverflow.com/questions/2655987/border-collapse-differences-in-ff-and-webkit
        border-collapse: separate;
        position: relative;
        border-spacing: 0;
        margin: 0;
        border-width: 0;
        table-layout: fixed;
        width: 0;
        outline-width: 0;
        max-width: none;
        max-height: none;
    }

    col {
        width: 50px;
    }
    col.rowHeader {
        width: 50px;
    }

    th,
    td {
        border-right: 1px solid @color-handsontable-border;
        border-bottom: 1px solid @color-handsontable-border;
        height: @handsontable-cell-height;
        empty-cells: show;
        line-height: @handsontable-cell-height - 1px;
        padding: 0 4px 0 4px;
        background-color: #FFF;
        font-size: @handsontable-font-size;
        vertical-align: top;
        overflow: hidden;
        outline-width: 0;
        white-space: pre-line;
    }

    th {
        font-size: @handsontable-font-size - 1px;
    }

    td.htInvalid {
        -webkit-transition: background 0.75s ease;
        transition: background 0.75s ease;
        background-color: #ff4c42;
    }
    th:last-child {
        // Foundation framework fix
        border-right: 1px solid @color-handsontable-border;
        border-bottom: 1px solid @color-handsontable-border;
    }
    tr:first-child th.htNoFrame,
    th:first-child.htNoFrame,
    th.htNoFrame {
        border-left-width: 0;
        background-color: transparent;
        border-color: transparent;
    }

    th:first-child,
    td:first-child,
    .htNoFrame + th,
    .htNoFrame + td {
        border-left: 1px solid @color-handsontable-border;
    }
    tr:first-child th,
    tr:first-child td {
        border-top: 1px solid @color-handsontable-border;
    }

    thead {
        tr:last-child {
            th { border-bottom-width: 0; }
        }
        tr.lastChild {
            th { border-bottom-width: 0; }
        }
        th {
            padding: 0;
            .relative {
                padding: 2px 4px;
            }
        }
    }

    th {
        background-color: transparent;
        color: @color-handsontable-header;
        text-align: center;
        font-weight: normal;
        white-space: nowrap;

        border: none !important;
        text-transform: uppercase;

        .small { font-size: 12px; }
    }

    tbody {
        th:last-of-type {
            border-right: 1px solid @color-handsontable-border !important;
        }

        //td:first-of-type {
        //    border-left: 3px solid transparent;
        //}

        // td:first-of-type.currentRow {
        //     border-left: 3px solid @color-list-stripe-active;
        // }
    }

    th.active {
        /*background-color: #CCC;*/
        color: #666;
    }

    //
    // Plugins
    //

    .manualColumnMover {
        position: absolute;
        left: 0;
        top: 0;
        background-color: transparent;
        width: 5px;
        height: 25px;
        z-index: 999;
        cursor: move;
    }

    .manualRowMover {
        position: absolute;
        left: -4px;
        top: 0;
        background-color: transparent;
        height: 5px;
        width: 50px;
        z-index: 999;
        cursor: move;
    }

    th .manualColumnMover,
    th .manualRowMover {
        &:hover,
        &.active {
            background-color: #88F;
        }
    }

    .manualColumnResizer {
        position: absolute;
        top: 0;
        cursor: col-resize;
        &:hover, &.active {
            .manualColumnResizerHandle { background-color: #AAB !important; }
        }

        &.active {
            .manualColumnResizerLine { display: block; }
        }
    }
    .manualColumnResizerHandle {
        background-color: transparent;
        width: 5px;
        height: 25px;
    }

    .manualColumnResizerLine {
        position: absolute;
        right: 0;
        top: 0;
        background-color: #AAB;
        display: none;
        width: 0;
        border-right: 1px dashed #777;
    }

    .columnSorting:hover {
        text-decoration: underline;
        cursor: pointer;
    }

    &.htRemoveRow {
        th.htRemoveRow {
            text-align: center;
            .btn {
                background-color: #BBB;
                border-radius: 9px;
                padding: 0 6px 0 6px;
                color: #FFF;
                cursor: pointer;
                font-size: 11px;
                font-weight: bold;
                display: none;
                margin: 0 auto;
                width: 10px;
                &:hover {
                    background-color: #777;
                }
            }
        }
    }

    //
    // Custom CP
    //

    &.htControlPanel {
        position: relative;
        width: auto;
        col:first-child {
            width: 1px;
        }
        th.htControlPanel {
            border: none !important;
            .close {
                background: transparent;
                line-height: @handsontable-cell-height;
                position: absolute;
                right: 7px;
            }
        }
    }

    //
    // Border line
    //

    .wtBorder {
        position: absolute;
        font-size: 0;
    }
    td.area {
        background-color: #EEF4FF;
    }

    //
    // Fill handle
    //

    .wtBorder.corner {
        font-size: 0;
        cursor: crosshair;
    }
    .htBorder.htFillBorder {
        background: red;
        width: 1px;
        height: 1px;
    }

    //
    // Read only cell
    //

    .htDimmed {
        font-style: italic;
        color: #777;
    }

    //
    // Checkbox
    //

    .htCheckboxRendererInput {
        //&.noValue { opacity: 0.5; }
        &.custom-checkbox {
            //text-align: center;
            label {
                margin: 0;

                &:before {
                    bottom: -4px;
                    left: -9px;
                }
            }
        }
    }

    //
    // Numeric
    //

    .htNumeric {
        text-align: right;
    }

    //
    // Auto complete
    //

    .htAutocomplete {
        position: relative;
        padding-right: 20px;
    }
    .htAutocompleteArrow {
        position: absolute;
        top: 0;
        right: 0;
        font-size: 10px;
        color: rgba(0,0,0,.07);
        cursor: default;
        width: 16px;
        text-align: center;
    }
    td {
        .htAutocompleteArrow:hover {
            color: #777;
        }
    }

    .autocomplete {
        position: absolute;
        line-height: 1.3em;
        font-size: 13px;
        z-index: 10;
        top: 100%;
        left: 0;
        float: left;
        display: none;
        min-width: 160px;
        padding: 4px 0;
        margin: 2px 0 0 0;
        list-style: none;
        background-color: white;
        border-color: rgba(0, 0, 0, 0.2);
        border-style: solid;
        border-width: 1px;
        -webkit-background-clip: padding-box;
        background-clip: padding-box;

        li {
            line-height: 18px;
            min-height: 18px;
            display: list-item;
            margin: 0;
        }
        a {
            display: block;
            padding: 3px 15px;
            clear: both;
            font-weight: normal;
            line-height: 18px;
            min-height: 18px;
            color: #666;
            white-space: nowrap;
            text-decoration: none;
        }

        li > a:hover,
        .active > a,
        .active > a:hover {
            color: white;
            text-decoration: none;
            background-color: @color-handsontable-active-cell;
        }
    }

    //
    // Drag dealer
    //

    .dragdealer {
        position: relative;
        width: 9px;
        height: 9px;
        background: #F8F8F8;
        border: 1px solid #DDD;
        .handle {
            position: absolute;
            width: 9px;
            height: 9px;
            background: #C5C5C5;
        }
        .disabled {
            background: #898989;
        }
    }
}

//
// Input cell
//

.handsontableInput {
    border: 2px solid @color-handsontable-active-cell;
    outline-width: 0;
    margin: 0;
    padding: 1px 4px 0 2px;
    line-height: 1.8em;
    font-size: @handsontable-font-size;
    resize: none;
    display: inline-block;
    color: @text-color;
    border-radius: 0;
    text-indent: 1px;
}

.handsontableInputHolder {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
}
