/*
 * Copyright (c) 2022 The ZMK Contributors
 *
 * SPDX-License-Identifier: MIT
 */

#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/bt.h>

#define DEFAULT 0
#define LOWER   1
#define RAISE   2

/ {
    chosen { zmk,matrix_transform = &layout_grid_transform; };
    keymap {
        compatible = "zmk,keymap";
        default_layer {
            //  -------------------------------------------------------------------------------------------------
            // |  GRAV |  1   |  2   |  3   |  4    |  5     |   6     |  7     |  8   |  9    |   0   | BSPC   |
            // |  TAB  |  Q   |  W   |  E   |  R    |  T     |   Y     |  U     |  I   |  O    |   P   | DEL    |
            // |  ESC  |  A   |  S   |  D   |  F    |  G     |   H     |  J     |  K   |  L    |   ;   |  '     |
            // | SHIFT |  Z   |  X   |  C   |  V    |  B     |   N     |  M     |  ,   |  .    |   /   | RET    |
            // |       | LGUI | LALT | LCTL | LOWER | SPACE  |  SPACE  |  RAISE | LEFT |  DOWN |   UP  | RIGHT  |
            bindings = <
                &kp GRAVE   &kp N1     &kp N2    &kp N3    &kp N4     &kp N5     &kp N6     &kp N7     &kp N8     &kp N9    &kp N0     &kp BSPC
                &kp TAB     &kp Q      &kp W     &kp E     &kp R      &kp T      &kp Y      &kp U      &kp I      &kp O     &kp P      &kp DEL
                &kp ESC     &kp A      &kp S     &kp D     &kp F      &kp G      &kp H      &kp J      &kp K      &kp L     &kp SEMI   &kp SQT
                &kp LSHIFT  &kp Z      &kp X     &kp C     &kp V      &kp B      &kp N      &kp M      &kp COMMA  &kp DOT   &kp SLASH  &kp RET
                &none       &kp LCTRL  &kp LALT  &kp LGUI  &mo LOWER  &kp SPACE  &kp SPACE  &mo RAISE  &kp LEFT   &kp DOWN  &kp UP     &kp RIGHT
                >;
        };
        lower {
            // ------------------------------------------------------------------------------------------
            // |   ~   |  !   |  @   |  #   |  $   |  %   |   ^   |   &   |   *  |  (   |   )   | BSPC  |
            // |   ~   |  !   |  @   |  #   |  $   |  %   |   ^   |   &   |   *  |  (   |   )   | DEL   |
            // |  DEL  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6   |   -   |   +  |  [   |   ]   |  |    |
            // |       |  F7  |  F8  |  F9  |  F10 |  F11 |  F12  |       | LCTL | HOME |  END  |       |
            // | LALT  |      |      |      |      |      |       |       | NEXT | VOL- | VOL+  | PLAY  |
            bindings = <
                &kp LS(GRAVE)  &kp LS(N1)  &kp LS(N2)  &kp LS(N3)  &kp LS(N4)  &kp LS(N5)  &kp LS(N6)  &kp LS(N7)  &kp LS(N8)  &kp LS(N9)        &kp LS(N0)         &kp BSPC
                &kp LS(GRAVE)  &kp LS(N1)  &kp LS(N2)  &kp LS(N3)  &kp LS(N4)  &kp LS(N5)  &kp LS(N6)  &kp LS(N7)  &kp LS(N8)  &kp LS(N9)        &kp LS(N0)         &kp DEL
                &kp DEL        &kp F1      &kp F2      &kp F3      &kp F4      &kp F5      &kp F6      &kp MINUS   &kp PLUS    &kp LEFT_BRACKET  &kp RIGHT_BRACKET  &kp PIPE
                &none          &kp F7      &kp F8      &kp F9      &kp F10     &kp F11     &kp F12     &none       &kp LCTRL   &kp HOME          &kp END            &none
                &kp LALT       &none       &none       &none       &trans      &none       &none       &none       &kp C_NEXT  &kp C_VOL_UP      &kp C_VOL_UP       &kp C_PLAY
                >;
        };
        raise {
            // -------------------------------------------------------------------------------------------
            // |   `   |  1   |  2   |  3   |  4   |   5   |   6   |   7   |   8  |  9   |   0   | BSPC  |
            // |   `   |  1   |  2   |  3   |  4   |   5   |   6   |   7   |   8  |  9   |   0   | DEL   |
            // |  DEL  |  F1  |  F2  |  F3  |  F4  |  F5   |  F6   |   -   |   =  |  [   |   ]   |  \    |
            // |       |  F7  |  F8  |  F9  |  F10 |  F11  |  F12  |   #   |   \  | PGUP |  PGDN |       |
            // |       |      |      |      |      | SHIFT |       |       | NEXT | VOL- |  VOL+ | PLAY  |
            bindings = <
                &kp GRAVE  &kp N1  &kp N2  &kp N3  &kp N4   &kp N5      &kp N6   &kp N7     &kp N8        &kp N9            &kp N0             &kp BSPC
                &kp GRAVE  &kp N1  &kp N2  &kp N3  &kp N4   &kp N5      &kp N6   &kp N7     &kp N8        &kp N9            &kp N0             &kp DEL
                &kp DEL    &kp F1  &kp F2  &kp F3  &kp F4   &kp F5      &kp F6   &kp MINUS  &kp KP_EQUAL  &kp LEFT_BRACKET  &kp RIGHT_BRACKET  &kp BSLH
                &none      &kp F7  &kp F8  &kp F9  &kp F10  &kp F11     &kp F12  &kp HASH   &kp BSLH      &kp PG_UP         &kp PG_DN          &none
                &none      &none   &none   &none   &none    &kp LSHIFT  &none    &trans     &kp C_NEXT    &kp C_VOL_DN      &kp C_VOL_UP       &kp C_PLAY
                >;
        };
    };
};
