<template>
  <div class="drawer-container">
    <div>
      <h3 class="drawer-title">{{ $t("settings.title") }}</h3>

      <div class="drawer-item">
        <span>{{ $t("settings.layout") }}</span>
        <div class="nav-type-box clearfix">
          <div
            :class="['nav-type-item', 'left-right', { navStyle: navStyle }]"
            @click="leftRight"
          />
          <div
            :class="['nav-type-item', 'top-bottom', { navStyle: !navStyle }]"
            @click="topBottom"
          />
        </div>
      </div>

      <div class="drawer-item">
        <span>{{ $t("settings.theme") }}</span>
        <theme-picker
          style="float: right; height: 26px; margin: -3px 8px 0 0"
          @change="themeChange"
        />
      </div>

      <div class="drawer-item">
        <span>{{ $t("settings.tagsView") }}</span>
        <el-switch v-model="tagsView" class="drawer-switch" />
      </div>

      <div class="drawer-item">
        <span>{{ $t("settings.fixedHeader") }}</span>
        <el-switch v-model="fixedHeader" class="drawer-switch" />
      </div>

      <div class="drawer-item">
        <span>{{ $t("settings.sidebarLogo") }}</span>
        <el-switch v-model="sidebarLogo" class="drawer-switch" />
      </div>
    </div>
  </div>
</template>

<script>
import ThemePicker from '@/components/ThemePicker'

export default {
  components: { ThemePicker },
  data() {
    return {
      navStyle: this.$store.state.settings.layoutWay === 'leftRight'
    }
  },
  computed: {
    isShowJob() {
      return this.$store.getters.language === 'en'
    },
    fixedHeader: {
      get() {
        return this.$store.state.settings.fixedHeader
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'fixedHeader',
          value: val
        })
      }
    },
    tagsView: {
      get() {
        return this.$store.state.settings.tagsView
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'tagsView',
          value: val
        })
      }
    },
    sidebarLogo: {
      get() {
        return this.$store.state.settings.sidebarLogo
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'sidebarLogo',
          value: val
        })
      }
    },
    supportPinyinSearch: {
      get() {
        return this.$store.state.settings.supportPinyinSearch
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'supportPinyinSearch',
          value: val
        })
      }
    },
    lang() {
      return this.$store.getters.language
    }
  },
  methods: {
    themeChange(val) {
      this.$store.dispatch('settings/changeSetting', {
        key: 'theme',
        value: val
      })
    },
    leftRight() {
      this.$store.dispatch('settings/changeSetting', {
        key: 'layoutWay',
        value: 'leftRight'
      })
      this.navStyle = true
    },
    topBottom() {
      this.$store.dispatch('settings/changeSetting', {
        key: 'layoutWay',
        value: 'topBottom'
      })
      this.navStyle = false
    }
  }
}
</script>

<style lang="scss" scoped>
.drawer-container {
  padding: 24px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;

  .navStyle {
    box-shadow: 0 1px 5.5px 0 #1890ff !important;
  }

  .drawer-title {
    margin-bottom: 12px;
    color: rgba(0, 0, 0, 0.85);
    font-size: 14px;
    line-height: 22px;
  }

  .drawer-item {
    color: rgba(0, 0, 0, 0.65);
    font-size: 14px;
    padding: 12px 0;
  }

  .nav-type-item {
    position: relative;
    width: 44px;
    height: 36px;
    margin-right: 16px;
    overflow: hidden;
    background-color: #f0f2f5;
    border-radius: 4px;
    box-shadow: 0 1px 2.5px 0 #333;
    cursor: pointer;
    float: left;
    margin-right: 20px;
  }
  .nav-type-item:before {
    z-index: 1;
    background-color: #001529;
    content: "";
  }
  .left-right:before {
    position: absolute;
    top: 0;
    left: 0;
    width: 33%;
    height: 100%;
  }
  .left-right:after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 25%;
    background-color: #fff;
    content: "";
  }
  .top-bottom:before {
    position: absolute;
    top: 0;
    left: 0;
    width: 33%;
    height: 100%;
    content: "";
  }
  .top-bottom:after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 25%;
    background-color: #fff;
    content: "";
    z-index: 999;
  }
  .nav-type-box {
    margin-top: 10px;
  }

  .drawer-switch {
    float: right;
  }

  .job-link {
    display: block;
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
  }
}
</style>
