<!--
 * @Description:
 * @Author: chd
 * @Date: 2020-10-19 15:44:02
 * @LastEditors: chd
 * @LastEditTime: 2021-04-28 13:57:48
-->

<script>
import { isMobile } from '../../utils/commonUtil'

export default {
  name: 'layout',
  inheritAttrs: false,
  props: {
    isleftshow: {
      default: true,
      type: Boolean,
    },
  },
  data() {
    return {
      isLeft: true,
    }
  },
  methods: {
    leftChange() {
      this.isLeft = !this.isLeft
    },
  },
  render() {
    const {
      $scopedSlots,
      $attrs,
      isLeft,
      isleftshow,
      $vnode,
    } = this
    const leftStyle = $attrs?.leftStyle || {}
    let { width, ...attrs } = leftStyle
    if (!width) width = '200px'
    return (
      <div class={`page_main ${isMobile ? 'mobile' : ''}`}>
        {$scopedSlots.header && (
          <div class="page_header">
            {$scopedSlots.header()}
          </div>
        )}

        <div
          class="layout_wrap"
          style={$vnode.data.staticStyle}
        >
          {$scopedSlots.page_left && (
            <div
              class="page_left"
              style={{
                ...attrs,
                width: isLeft ? width : '1px',
              }}
            >
              {$scopedSlots.page_left()}
            </div>
          )}
          {isleftshow && (
            <div class="separation">
              <span
                class="left_toggle"
                title={isLeft ? '点击收起' : '点击展开'}
                onClick={this.leftChange}
              >
                <i
                  class={
                    isLeft
                      ? 'el-icon-caret-left'
                      : 'el-icon-caret-right'
                  }
                ></i>
              </span>
            </div>
          )}
          {$scopedSlots.page_right && (
            <div
              class="page_right"
              style={$attrs?.rightStyle || {}}
            >
              {$scopedSlots.page_right()}
            </div>
          )}
          {$scopedSlots.default && $scopedSlots.default()}
        </div>
      </div>
    )
  },
}
</script>
<style scoped>
.page_main {
  height: calc(100vh - 86px);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  margin: 0;
  overflow: hidden;
  position: relative;
}
.page_main .layout_wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.page_main:not(.mobile) {
  margin-right: 54px;
}
/* .page_main.home .tool_warper {
  display: none;
} */
.page_main.row .layout_wrap {
  flex-direction: row;
}
.page_main.wrap .layout_wrap {
  background: #fff;
  box-sizing: border-box;
  border-radius: 10px;
  padding-top: 10px;
}

.page_main.wrap .layout_wrap >>> form:nth-of-type(1) {
  margin-left: 10px;
}
.page_main.mobile {
  height: calc(100vh - 56px);
}
.page_header {
  background: #fff;
  padding-top: 10px;
  margin-bottom: 10px;
}
.page_left {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 200px;
  height: 100%;
  background: var(--background-color);
  box-sizing: border-box;
  border-radius: 5px 5px 0 0;
  overflow: auto;
}
.separation {
  display: none;
  position: relative;
  width: 1px;
}
.row .separation {
  display: block;
}
.separation .left_toggle {
  position: absolute;
  right: -16px;
  width: 17px;
  height: 24px;
  background: #dedede;
  z-index: 1000;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
}
.separation .left_toggle::before {
  position: absolute;
  width: 0px;
  height: 0px;
  content: '';
  top: 10px;
  left: -12px;
  pointer-events: none;
  transform: rotate(45deg);
  border-width: 12px;
  border-style: solid;
  border-color: rgba(0, 0, 0, 0) #dedede rgba(0, 0, 0, 0)
    rgba(0, 0, 0, 0);
  border-radius: 5px;
}
.separation .left_toggle::after {
  position: absolute;
  width: 0px;
  height: 0px;
  top: -10px;
  left: -12px;
  pointer-events: none;
  content: '';
  transform: rotate(-45deg);
  border-width: 12px;
  border-style: solid;
  border-color: rgba(0, 0, 0, 0) #dedede rgba(0, 0, 0, 0)
    rgba(0, 0, 0, 0);
  border-radius: 5px;
}
.separation .left_toggle i {
  display: block;
  margin-top: 3px;
  pointer-events: none;
}
.separation:hover .left_toggle {
  display: block;
}
.page_right {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-left: 10px;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
}
.page_main:not(.drag) .page_right {
  background: var(--background-color);
  border-radius: 5px 5px 0 0;
  padding-top: 10px;
  box-sizing: border-box;
}
.page_main .page_right >>> form:nth-of-type(1),
.page_main .page_left >>> form,
.page_main.drag >>> form {
  padding-left: 10px;
}
/* .page_right >>> .top {
  padding-top: 0;
} */
.page_main.drag .page_right {
  /* padding-top: 10px; */
  background: transparent;
}
</style>
