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

#define ANSI true
//#define HHKB true
//#define ISO true
//#define ALL_1U true
//#define SPLIT_BKSP_RSHFT true



/ {
	chosen {
	#ifdef ANSI
		zmk,matrix_transform = &ansi_transform;
	#elif defined(HHKB)
		zmk,matrix_transform = &hhkb_transform;
	#elif defined(ISO)
		zmk,matrix_transform = &iso_transform;
	#elif defined(ALL_1U)
		zmk,matrix_transform = &all_1u_transform;
	#else
		zmk,matrix_transform = &split_transform;
	#endif
	};


	keymap {
		compatible = "zmk,keymap";
		#ifdef ANSI
		default_layer {
				// ------------------------------------------------------------------------------------------
				// | ESC |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  |   BKSP   |
				// |  TAB  |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |   |    |
				// |  CAPS  |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  |    ENTER    |
				// |  SHIFT    |  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  | /   |      SHIFT     |
				// |  CTL  |  WIN  |  ALT  |            SPACE              | ALT | 1    |  MENU    |  CTRL  |
				// ------------------------------------------------------------------------------------------
			bindings = <
				&kp ESC &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp  N8   &kp  N9 &kp  N0  &kp MINUS &kp EQUAL &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 LBKT &kp RBKT  &kp BSLH
				&kp CLCK  &kp A  &kp S  &kp D  &kp F  &kp G  &kp H  &kp J  &kp  K    &kp  L  &kp SEMI &kp SQT           &kp RET
				&kp LSHFT  &kp Z  &kp X  &kp C  &kp V  &kp B  &kp N  &kp M  &kp COMMA &kp DOT &kp FSLH             &kp RSHFT
				&kp LCTRL &kp LGUI &kp LALT            &kp SPACE                          &kp RALT  &mo 1 &kp K_CMENU &kp RCTRL &bt BT_CLR
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		raise {
				// ------------------------------------------------------------------------------------------
				// |GRAVE| F1  | F2  | F3  | F4  | F5  | F6  | F7  | F8  | F9  | F10 | F11 | F12 |   DEL   |
				// | TAB  |  Q  | UP  |  E  |  R  |  T  |  Y  |  U  | INS |  O  |PSCRN|SLCK |PSEBRK| RESET |
				// | CAPS  |LEFT |DOWN |RIGHT|  F  |  G  |  H  |  J  |  K  |  L  |HOME |PGUP |  BOOTLOADER |
				// |   PREV  |VOLUP |VOLDN|MUTE |  V  |  B  |  N  |  M  |  ,  | END | PGDN |      NEXT     |
				// |  CTL  |  WIN  |  ALT  |            SPACE               | ALT | 1    |  MENU  | BT_CLR |
				// ------------------------------------------------------------------------------------------
			bindings = <
				&kp GRAVE &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp  F8   &kp  F9 &kp  F10  &kp F11 &kp F12   &kp DEL
				&trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &reset
				&trans    &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME  &kp PG_UP   &bootloader
				&kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &kp END &kp PG_DN  &kp C_NEXT
				&bt BT_PRV &bt BT_NXT  &trans              &trans                            &trans   &trans   &trans &bt BT_CLR &trans
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		#elif defined(HHKB)
		default_layer {
				// ------------------------------------------------------------------------------------------
				// | ESC |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  |  \  | `  |
				// | TAB  |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |  BSPC   |
				// | CTRL  |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  |      ENTER   |
				// |  SHIFT    |  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  | /   | SHIFT |   1    |
				// |  CAPS  |  ALT  |  WIN |                     SPACE               |   WIN   | ALT | CTRL |
				// ------------------------------------------------------------------------------------------
			bindings = <
				&kp ESC       &kp N1          &kp N2          &kp N3        &kp N4    &kp N5    &kp N6    &kp N7    &kp  N8      &kp  N9     &kp  N0       &kp MINUS     &kp EQUAL          &kp BSLH    &kp GRAVE
				&kp TAB       &kp Q           &kp W           &kp E         &kp R     &kp T     &kp Y     &kp U     &kp  I       &kp  O      &kp  P        &kp LBKT      &kp RBKT           &kp BSPC
				&kp LCTRL     &kp A           &kp S           &kp D         &kp F     &kp G     &kp H     &kp J     &kp  K       &kp  L      &kp SEMI      &kp SQT       &kp RET
				&kp LSHFT     &kp Z           &kp X           &kp C         &kp V     &kp B     &kp N     &kp M     &kp COMMA    &kp DOT     &kp FSLH      &kp RSHFT     &mo 1
				&kp LCTRL     &kp LALT        &kp LGUI                                                    &kp SPACE                                        &kp RGUI      &kp RALT           &kp RCTRL
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		raise {
			bindings = <
				&trans        &kp F1          &kp F2          &kp F3        &kp F4    &kp F5    &kp F6    &kp F7    &kp F8       &kp F9      &kp F10       &kp F11       &kp F12            &kp INS      &kp DEL
				&kp CLCK      &bt BT_PRV      &bt BT_NXT      &bt BT_CLR    &trans    &trans    &trans    &trans    &trans       &trans      &trans        &kp UP        &trans             &reset
				&trans        &kp C_VOL_DN    &kp C_VOL_UP    &kp C_MUTE    &trans    &trans    &trans    &trans    &trans       &trans      &kp LEFT      &kp RIGHT     &trans
				&trans        &trans          &trans          &trans        &trans    &trans    &trans    &trans    &trans       &trans      &kp DOWN      &trans        &trans
				&trans        &trans          &trans                                                      &bootloader                                      &trans        &trans             &trans
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		#elif defined(ISO)
		default_layer {
				// ------------------------------------------------------------------------------------------
				// | ESC |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  |   BKSP   |
				// | TAB  |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |         |
				// | CAPS  |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  |  #   | ENTER |
				// |  SHIFT | |  |  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  | /   |     SHIFT    |
				// |  CTL  |  WIN  |  ALT  |                     SPACE        |   ALT   |  1  | MENU | CTRL |
				// ------------------------------------------------------------------------------------------
			bindings = <
				&kp ESC &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp  N8   &kp  N9 &kp  N0  &kp MINUS &kp EQUAL &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 LBKT &kp RBKT
				&kp CLCK  &kp A  &kp S  &kp D  &kp F  &kp G  &kp H  &kp J  &kp  K    &kp  L  &kp SEMI &kp SQT  &kp NON_US_HASH  &kp RET
				&kp LSHFT &kp NON_US_BSLH &kp Z  &kp X  &kp C  &kp V  &kp B  &kp N  &kp M  &kp COMMA &kp DOT &kp FSLH             &kp RSHFT
				&kp LCTRL &kp LGUI &kp LALT            &kp SPACE                          &kp RALT  &mo 1 &kp K_CMENU &kp RCTRL
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		raise {
			bindings = <
				&kp GRAVE &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp  F8   &kp  F9 &kp  F10  &kp F11 &kp F12   &kp DEL
				&reset &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK
				&trans    &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME  &kp PG_UP  &trans &bootloader
				&kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &trans &kp END &kp PG_DN  &kp C_NEXT
				&bt BT_PRV &bt BT_NXT  &trans              &trans                            &trans   &trans   &trans &bt BT_CLR
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		#elif defined(ALL_1U)
		default_layer {
				// ------------------------------------------------------------------------------------------
				// | ESC |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  |   BKSP   |
				// | TAB  |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |   "|"   |
				// | CAPS  |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  |     ENTER    |
				// |  SHIFT    |  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  | /   | SHFT | UP | 1  |
				// |  CTL  |  WIN  |  ALT  |            SPACE              | ALT | CTRL | LEFT | DOWN | RIGHT |
				// ------------------------------------------------------------------------------------------
			bindings = <
				&kp ESC &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp  N8   &kp  N9 &kp  N0  &kp MINUS &kp EQUAL &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 LBKT &kp RBKT  &kp BSLH
				&kp CLCK  &kp A  &kp S  &kp D  &kp F  &kp G  &kp H  &kp J  &kp  K    &kp  L  &kp SEMI &kp SQT           &kp RET
				&kp LSHFT  &kp Z  &kp X  &kp C  &kp V  &kp B  &kp N  &kp M  &kp COMMA &kp DOT &kp FSLH    &kp RSHFT &kp UP   &mo 1
				&kp LCTRL &kp LGUI &kp LALT            &kp SPACE                          &kp RALT  &kp RCTRL &kp LEFT &kp DOWN &kp RIGHT
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		raise {
			bindings = <
				&kp GRAVE &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp  F8   &kp  F9 &kp  F10  &kp F11 &kp F12   &kp F1
				&trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &reset
				&trans    &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME  &kp PG_UP   &bootloader
				&kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &trans &trans &kp END &kp PG_DN  &kp C_NEXT
				&bt BT_PRV &bt BT_NXT  &trans              &trans                            &trans  &trans &trans   &trans &bt BT_CLR
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		#else
		default_layer {
				// ------------------------------------------------------------------------------------------
				// | ESC |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  |BKSP| DEL |
				// | TAB  |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |    \    |
				// | CAPS  |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  |     ENTER    |
				// |  SHIFT    |  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  | /   |   SHIFT  |  1  |
				// |  CTL  |  WIN  |  ALT  |                     SPACE               |   ALT   |  1  | CTRL |
				// ------------------------------------------------------------------------------------------
			bindings = <
				&kp ESC &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp  N8   &kp  N9 &kp  N0  &kp MINUS &kp EQUAL &kp BSPC &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 LBKT &kp RBKT  &kp BSLH
				&kp CLCK  &kp A  &kp S  &kp D  &kp F  &kp G  &kp H  &kp J  &kp  K    &kp  L  &kp SEMI &kp SQT           &kp RET
				&kp LSHFT  &kp Z  &kp X  &kp C  &kp V  &kp B  &kp N  &kp M  &kp COMMA &kp DOT &kp FSLH    &kp RSHFT    &mo 1
				&kp LCTRL &kp LGUI &kp LALT            &kp SPACE                          &kp RALT &kp RGUI &kp C_MENU &kp RCTRL
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		raise {
			bindings = <
				&kp GRAVE &kp F1 &kp F2 &kp F3 &kp F4 &kp F5 &kp F6 &kp F7 &kp  F8   &kp  F9 &kp  F10  &kp F11 &kp F12   &kp DEL &trans
				&trans &trans &kp UP &trans &trans &trans &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &reset
				&trans    &kp LEFT &kp DOWN &kp RIGHT &trans &trans &trans &trans &trans &trans &kp HOME  &kp PG_UP   &bootloader
				&kp C_PREV &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &trans &trans &trans &trans &trans &kp END &kp PG_DN  &kp C_NEXT &trans
				&bt BT_PRV &bt BT_NXT  &trans                       &trans                            &trans  &trans &trans &bt BT_CLR
			>;
			sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
		};
		#endif
	};
};
