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

#include <behaviors.dtsi>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/outputs.h>
#include <dt-bindings/zmk/ext_power.h>
#include <dt-bindings/led/led.h>
#include <dt-bindings/zmk/backlight.h>
#include <dt-bindings/zmk/rgb.h>
#include <dt-bindings/zmk/reset.h>

/ {
    keymap {
        compatible = "zmk,keymap";

        default_layer {
            display-name = "BAS";
            // ------------------------------------------------------------------------------------------------------------
            // |  `    |  1  |  2  |  3   |  4   |  5   |                   |  6   |  7    |  8    |  9   |   0   |       |
            // |  ESC  |  Q  |  W  |  E   |  R   |  T   |                   |  Y   |  U    |  I    |  O   |   P   | BKSPC |
            // |  TAB  |  A  |  S  |  D   |  F   |  G   |                   |  H   |  J    |  K    |  L   |   ;   |   '   |
            // | SHIFT |  Z  |  X  |  C   |  V   |  B   |  MUTE  |  |       |  N   |  M    |  ,    |  .   |   /   | SHIFT |
            //               | GUI | ALT  | CTRL | LOWER|  ENTER |  | SPACE | RAISE| CTRL  | ALT   | GUI  |

            bindings = <
&kp ESC     &kp N1  &kp N2      &kp N3      &kp N4          &kp N5                                  &kp N6      &kp N7          &kp N8     &kp N9    &kp N0    &kp DEL
&kp TAB     &kp Q   &kp W       &kp E       &kp R           &kp T                                   &kp Y       &kp U           &kp I      &kp O     &kp P     &kp SQT
&kp LSHFT   &kp A   &kp S       &kp D       &lt 2 F         &kp G                                   &kp H       &kp J           &kp K      &kp L     &kp SEMI  &kp RSHFT
&kp LALT    &kp Z   &kp X       &kp C       &kp V           &kp B       &kp C_MUTE      &kp C_MUTE  &kp N       &kp M           &kp COMMA  &kp DOT   &kp FSLH  &kp BSLH
            &trans  &trans      &kp LWIN    &mt LCTRL TAB   &lt 1 RET                               &lt 2 SPACE &mt RCTRL BSPC  &kp RWIN    &trans   &trans
            >;

            sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>;
        };

        lower_layer {
            display-name = "LOW";
            // ------------------------------------------------------------------------------------------------------------
            // |       |  F1 |  F2 |  F3  |  F4  |  F5  |                   |  F6  |  F7   |  F8   |  F9  |  F10  |  F11  |
            // | `     |   1 |   2 |   3  |   4  |   5  |                   |   6  |   7   |   8   |   9  |    0  |  F12  |
            // |       |BTCLR| BT1 | BT2  | BT3  | BT4  |                   | LEFT | DOWN  |  UP   | RIGHT |  INS  |PRINTSCREEN|
            // |       |     | HOME| PGUP | PGDN | END  |        |  |       | UNDO |  CUT  | COPY  | PASTE |  DEL  |    BKSP   |
            //               |     |      |      |      |        |  |       |      |       |       |      |

            bindings = <
&trans          &trans              &trans          &trans          &trans          &trans                                   &trans  &trans    &trans    &trans      &trans          &trans
&studio_unlock  &bt BT_CLR          &bt BT_SEL 0    &bt BT_SEL 1    &bt BT_SEL 2    &bt BT_SEL 3                            &trans  &kp HOME  &kp UP    &kp END     &kp LS(LBKT)    &trans
&sys_reset      &kp LCTRL           &kp LSHFT       &kp LALT        &kp LGUI        &trans                                  &trans  &kp LEFT  &kp DOWN  &kp RIGHT   &kp LS(RBKT)    &trans
&trans          &rgb_ug  RGB_TOG    &rgb_ug RGB_EFF &rgb_ug RGB_BRD &rgb_ug RGB_BRI &trans          &trans          &trans  &trans  &kp LPAR  &kp RPAR  &kp LBKT    &kp RBKT        &trans
                &trans              &trans          &trans          &trans          &trans                                  &trans  &trans    &trans    &trans      &trans
            >;

            sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>;
        };

        raise_layer {
            display-name = "RAI";
            // ------------------------------------------------------------------------------------------------------------
            // |     |       |       |       |       |       |                |      |      |       |      |       |       |
            // |     |   !   |   @   |   #   |   $   |   %   |                |   ^  |  &   |   *   |   (  |   )   |       |
            // |     |RGB_TOG|RGB_HUI|RGB_SAI|RGB_BRI|       |                |   -  |   =  |   [   |   ]  |   \   | GRAVE |
            // |     |RGB_EFF|RGB_HUD|RGB_SAD|RGB_BRD|QK_BOOT|      |  |      |   _  |   +  |   {   |   }  |   |   |   ~   |
            //              |      |       |       |      |      |  |      |      |      |       |      |

            bindings = <
&trans  &trans      &trans      &trans          &trans          &trans                              &trans  &trans  &trans  &trans  &trans  &trans
&trans  &kp GRAVE   &kp PRCNT   &kp PIPE        &kp AMPS        &kp EQUAL                           &trans  &kp N7  &kp N8  &kp N9  &kp F1  &kp F2
&trans  &kp EXCL    &kp AT      &kp HASH        &kp DLLR        &kp LS(DOT)                         &trans  &kp N4  &kp N5  &kp N6  &kp F3  &kp F4
&trans  &kp CARET   &kp ASTRK   &kp LS(MINUS)   &kp LS(EQUAL)   &kp MINUS       &trans      &trans  &trans  &kp N1  &kp N2  &kp N3  &kp F5  &kp F6
        &trans      &trans      &trans          &trans          &trans                              &kp RET &kp N0  &trans  &trans  &trans
            >;

            sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>;
        };
        extra_1 {
            status = "reserved";
        };

        extra_2 {
            status = "reserved";
        };

        extra_3 {
            status = "reserved";
        };
    };
};
