// 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>
#include <dt-bindings/zmk/pointing.h>

/ {
    behaviors {
        ht: hold_tap {
            compatible = "zmk,behavior-hold-tap";
            #binding-cells = <2>;
            flavor = "tap-preferred";
            tapping-term-ms = <220>;
            quick-tap-ms = <150>;
            require-prior-idle-ms = <100>;
            bindings = <&kp>, <&kp>;
        };
        
        esc_shct: escape_shortcut {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&mt LSHIFT ESC>, <&kp LCTRL>;
        };

        eq_dot: equal_dot {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp EQUAL>, <&kp DOT>;
        };
        
        dash_slsh: dash_slash {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp MINUS>, <&kp SLASH>;
        };

        tab_ret: tab_return {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp TAB>, <&kp RET>;
        };

        f1_f7: function1 {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp F1>, <&kp F7>;
        };

        f2_f8: function2 {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp F2>, <&kp F8>;
        };

        f3_f9: function3 {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp F3>, <&kp F9>;
        };

        f4_f10: function4 {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp F4>, <&kp F10>;
        };

        f5_f11: function5 {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp F5>, <&kp F11>;
        };
        f6_f12: function6 {
            compatible = "zmk,behavior-tap-dance";
            #binding-cells = <0>;
            tapping-term-ms = <200>;
            bindings = <&kp F6>, <&kp F12>;
        };
    };

    combos {
        compatible = "zmk,combos";
        combo_act {
            timeout-ms = <50>;
            key-positions = <14 31>;
            bindings = <&tog 3>;
            layers = <0>;
        };
    };

    keymap {
        compatible = "zmk,keymap";
        base {
            bindings = <
            &lt 1 Q    &kp W      &kp F      &kp P      &kp G          &kp J      &kp L      &kp U      &kp Y      &kp SEMI
            &kp A      &kp R      &kp S      &kp T      &kp D          &kp H      &kp N      &kp E      &kp I      &kp O
            &kp Z      &kp X      &kp C      &kp V      &kp B          &kp K      &kp M      &kp COMMA  &kp DOT    &kp FSLH
                                             &esc_shct  &kp SPACE      &kp BSPC   &kp ENTER
            >;
        };

        sym {
            bindings = <
            &none      &kp N7     &kp N8     &kp N9         &kp N0         &kp BSLH     &kp GRAVE    &kp LBKT   &kp RBKT   &kp APOS
            &none      &kp N4     &kp N5     &kp N6         &eq_dot        &kp HOME     &kp LEFT     &kp DOWN   &kp UP     &kp RIGHT
            &none      &kp N1     &kp N2     &kp N3         &dash_slsh     &kp END      &kp LC(LEFT) &kp PG_DN  &kp PG_UP  &kp LC(RIGHT)
                                             &mt LSHIFT ESC &tab_ret       &lt 2 DEL    &none
            >;
        };

        mnav {
            bindings = <
            &trans     &trans     &msc SCRL_UP   &trans     &trans         &trans     &mkp LCLK      &msc SCRL_DOWN &msc SCRL_UP &mkp RCLK
            &trans     &mkp LCLK  &mkp MCLK      &mkp RCLK  &trans         &trans     &mmv MOVE_LEFT &mmv MOVE_DOWN &mmv MOVE_UP &mmv MOVE_RIGHT
            &trans     &trans     &msc SCRL_DOWN &trans     &trans         &trans     &trans         &trans         &trans       &trans
                                                 &trans     &trans         &trans     &trans
            >;
        };

        act {
            bindings = <
            &f1_f7     &f2_f8     &f3_f9     &kp TAB     &trans            &studio_unlock  &trans       &trans         &trans         &trans
            &f4_f10    &f5_f11    &f6_f12    &kp LS(TAB) &tog 3            &bootloader     &kp C_PREV   &kp C_PP       &kp C_STOP     &kp C_NEXT
            &sk LCTRL  &sk LSHIFT &sk LALT   &sk LGUI    &kp PSCRN         &trans          &kp C_MUTE   &kp C_VOL_DN   &kp C_VOL_UP   &trans
                                             &trans      &tog 3            &trans     &trans
            >;
        };
    };
};