<template>
	<div :class="['x_dialog', this.cssClass]">
		<div class="x_dialog-main">
      <div :class="[{'x_dialog-bar' : kind === 'bar'}, 'x_dialog-title']">{{ title }}</div>
      <div class="x_dialog-body">
        <div class="x_dialog-message" v-if="message">{{ message }}</div>
      </div>
      <div class="x_dialog-ctrl">
        <wl-button @click="handlerCancel" v-if="type === 'confirm'" type="default" style="margin-right:14px;">{{ btnCancel }}</wl-button>
        <wl-button @click="handlerConfirm">{{ btnConfirm }}</wl-button>
      </div>
    </div>
		<div v-if="this.mask" @click="handlerClickMask" class="x_dialog-mask"></div>
	</div>
</template>

<script>
import mixin from "../mixin"
import wbutton from '../wbutton'
export default {
	name: mixin.prefix + "dialog",
	components: {
    'wl-button':wbutton
  },
  methods: {
    closeAction(){
      this.remove && this.remove()
    },
    handlerCancel() {
      this.cancel()
      this.closeAction()
    },
    handlerConfirm() {
      this.action()
      this.closeAction()
    },
    handlerClickMask() {
      this.touchclose ? this.handlerClickMask ? this.handlerCancel() : this.closeAction() : ''
    }
  }
};
</script>

<style lang="less" scoped>
.x_dialog {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	top: 0;
	transition: opacity 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
  z-index: 1000;
  &-main {
    backface-visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1001;
    background-color: #fff;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    box-sizing: border-box;
    color: #333;
    max-width: 400px;
    min-height: 144px;
    min-width: 246px;
    outline: 0;
    padding-bottom: 30px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  &-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
    padding: 30px 30px 0;
  }
  &-bar {
    align-self: stretch;
    border-bottom: 1px solid #f9f9f9;
    padding: 0;
    padding: 12px 20px;
  }
  &-body {
    padding: 0 30px;
  }
  &-message {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
  }
  &-ctrl {
    margin-top: auto;
    padding: 0 30px;
    display:flex;
  }
	&-mask {
		background-color: #000;
		bottom: 0;
		left: 0;
		opacity: 0.5;
		position: fixed;
		right: 0;
		top: 0;
		transition: opacity 0.2s ease;
		z-index: 1000;
  }
}
</style>