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

#define ANSI
//#define ISO
//#define ALL_1U
//#define HHKB

/ {
  chosen {
  #ifdef ANSI
    zmk,physical-layout = &layout_60_ansi;
  #elif defined(ISO)
    zmk,physical-layout = &layout_60_iso;
  #elif defined(ALL_1U)
    zmk,physical-layout = &layout_60_all1u;
  #elif defined(HHKB)
    zmk,physical-layout = &layout_60_hhkb;
  #else
  #error "Layout not defined, please define a layout by uncommenting the appropriate line in bt60.keymap"
  #endif
  };

  keymap {
    compatible = "zmk,keymap";
    #ifdef ANSI
    default_layer {
        // ------------------------------------------------------------------------------------------
        // | ESC |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  0  |  -  |  =  |   BSPC   |
        // | 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 CAPS  &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
      >;
      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  | HUI | HUD |  Y  |  U  | INS |  O  |PSCRN| SLCK| P_B |  RGB_TOG|
        // | CAPS  | LEFT| DOWN|RIGHT| BRI | BRD |  H  |  J  |  K  |  L  | HOME| PGUP|     BOOT     |
        // |  SHIFT   |VOLDN|VOLUP| MUTE|BLINC|BLDEC|  N  |  M  |  ,  | END | PGDN |      BL_TOG    |
        // | BT_PRV| BT_NXT|  ALT  |            SPACE               | ALT |   1  |  RESET  | 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 &rgb_ug RGB_HUI &rgb_ug RGB_HUD &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &rgb_ug RGB_TOG
        &trans    &kp LEFT &kp DOWN &kp RIGHT &rgb_ug RGB_BRI &rgb_ug RGB_BRD &trans &trans &trans &trans &kp HOME  &kp PG_UP   &bootloader
        &trans   &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &bl BL_INC &bl BL_DEC &trans &trans &trans &kp END &kp PG_DN  &bl BL_TOG
        &bt BT_PRV &bt BT_NXT  &trans              &trans                            &trans   &trans   &sys_reset &bt BT_CLR
      >;
      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  |  -  |  =  |    BSPC   |
        // |   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 CAPS  &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 {
        // ------------------------------------------------------------------------------------------
        // |GRAVE| F1  | F2  | F3  | F4  | F5  | F6  | F7  | F8  | F9  | F10 | F11 | F12 |    DEL    |
        // | TAB   |  Q  | UP  |  E  | HUI | HUD |  Y  |  U  | INS |  O  |PSCRN| SLCK| P_B |         |
        // | CAPS   | LEFT| DOWN|RIGHT| BRI | BRD |  H  |  J  |  K  |  L  | HOME| PGUP|RGB_TOG| BOOT |
        // | SHIFT |VOLDN|VOLUP| MUTE|BLINC|BLDEC|  B  |  N  |  M  |  ,  | END | PGDN |    BL_TOG    |
        // | BT_PRV| BT_NXT|  ALT  |            SPACE               |  ALT |  1    |  RESET  |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 &rgb_ug RGB_HUI &rgb_ug RGB_HUD &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK
        &trans    &kp LEFT &kp DOWN &kp RIGHT &rgb_ug RGB_BRI &rgb_ug RGB_BRD &trans &trans &trans &trans &kp HOME  &kp PG_UP &rgb_ug RGB_TOG &bootloader
        &trans &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &bl BL_INC &bl BL_DEC &trans &trans &trans &trans &kp END &kp PG_DN  &bl BL_TOG
        &bt BT_PRV &bt BT_NXT  &trans              &trans                            &trans   &trans   &sys_reset &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  |  -  |  =  |BSPC | DEL |
        // | TAB   |  Q  |  W  |  E  |  R  |  T  |  Y  |  U  |  I  |  O  |  P  |  [  |  ]  |    \    |
        // | CAPS   |  A  |  S  |  D  |  F  |  G  |  H  |  J  |  K  |  L  |  ;  |  '  |     ENTER    |
        // | SHFT  |NONE|  Z  |  X  |  C  |  V  |  B  |  N  |  M  |  ,  |  .  | /   | SHFT | UP |  1 |
        // |  CTL  |  WIN  |  ALT  |           SPACE              | RALT| 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 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 &none  &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 {
        // ------------------------------------------------------------------------------------------
        // |GRAVE| F1  | F2  | F3  | F4  | F5  | F6  | F7  | F8  | F9  | F10 | F11 | F12 |BSPC | DEL |
        // | TAB  |  Q  |  W  |  E  | HUI | HUD |  Y  |  U  | INS |  O  |PSCRN| SLCK| P_B | RGB_TOG  |
        // | CAPS  |  A  |  S  |  D  | BRI | BRD |  H  |  J  |  K  |  L  | HOME| PGUP|      BOOT     |
        // | SHFT |NONE|VOLDN|VOLUP|MUTE|BLINC|BLDEC|  N  |  M  |  ,  | END | PGDN | SHFT|BL_TOG| 1  |
        // | BT_PRV| BT_NXT|  ALT  |           SPACE              | RALT| CTRL | LEFT |RESET| 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   &trans &trans
        &trans &trans &trans &trans &rgb_ug RGB_HUI &rgb_ug RGB_HUD &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &rgb_ug RGB_TOG
        &trans    &trans &trans &trans &rgb_ug RGB_BRI &rgb_ug RGB_BRD &trans &trans &trans &trans &kp HOME  &kp PG_UP   &bootloader
        &trans &none &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &bl BL_INC &bl BL_DEC &trans &trans &trans &kp END &kp PG_DN &trans &bl BL_TOG &trans
        &bt BT_PRV &bt BT_NXT  &trans              &trans                            &trans  &trans &trans   &sys_reset &bt BT_CLR
      >;
      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  |  -  |  =  |   BSPC   |
        // | 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    |  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 CAPS  &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 RCTRL
      >;
      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  | HUI | HUD |  Y  |  U  | INS |  O  |PSCRN| SLCK| P_B |  RGB_TOG|
        // | CAPS  | LEFT| DOWN|RIGHT| BRI | BRD |  H  |  J  |  K  |  L  | HOME| PGUP|     BOOT     |
        // |  SHFT    |VOLDN|VOLUP| MUTE|BLINC|BLDEC|  N  |  M  |  ,  | END | PGDN |      BL_TOG    |
        // | BT_PRV | BT_NXT |   ALT  |             SPACE                | RESET |   1    |  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 &rgb_ug RGB_HUI &rgb_ug RGB_HUD &trans &trans &kp INS &trans &kp PSCRN &kp SLCK &kp PAUSE_BREAK &rgb_ug RGB_TOG
        &trans    &kp LEFT &kp DOWN &kp RIGHT &rgb_ug RGB_BRI &rgb_ug RGB_BRD &trans &trans &trans &trans &kp HOME  &kp PG_UP   &bootloader
        &trans &kp C_VOL_DN &kp C_VOL_UP &kp C_MUTE &bl BL_INC &bl BL_DEC &trans &trans &trans &kp END &kp PG_DN  &bl BL_TOG
        &bt BT_PRV &bt BT_NXT  &trans              &trans                            &sys_reset   &trans  &bt BT_CLR
      >;
      sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
    };
    #else
    #error "Layout not defined, please define a layout by uncommenting the appropriate line in bt60.keymap"
    #endif

  };
};
