<template>
  <transition name="modal" v-if="showModal" @close="showModal = false">
    <div @click="$emit('close')">
      <div :class="$style.modalMask">
        <div :class="$style.modalWrapper">
          <div
            @click.stop=""
            :class="$style.modalContainer"
            :style="{
              width: width + 'px',
            }"
          >
            <div
              :class="$style.modalHeader"
              :style="{
                'background-color': bgHeader,
              }"
            >
              <div
                :class="$style.iconTitle"
                :style="{
                  'text-transform': uppercase,
                }"
              >
                <i
                  :class="'saglan-icon-' + iconNameHeader"
                  v-if="iconHeader"
                ></i>
                <slot name="header"> default header </slot>
              </div>
              <div :class="$style.close">
                <button @click="$emit('close')">
                  <i class="saglan-icon-close"></i>
                </button>
              </div>
            </div>

            <div :class="$style.modalBody" @click.stop="">
              <slot name="body"> default body </slot>
            </div>

            <div :class="$style.modalFooter">
              <slot name="footer">
                default footer
                <button
                  :class="$style.modalDefaultButton"
                  @click="$emit('close')"
                >
                  OK
                </button>
              </slot>
            </div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  name: "modal-saglan",
  data() {
    return {
      showModal: true,
    };
  },
  props: {
    width: {
      type: Number,
      default: 600,
    },
    iconHeader: { type: Boolean, default: true },
    iconNameHeader: { type: String, default: "document-list" },
    bgHeader: {
      type: String,
      default: "rgb(251, 140, 0)",
    },
    uppercase: {
      type: String,
      default: "uppercase",
    },
  },
};
</script>

<style lang="scss" module>
.modalMask {
  position: fixed;
  z-index: 9998;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: table;
  transition: opacity 0.3s ease;

  .modalWrapper {
    display: table-cell;
    vertical-align: middle;
  }

  .modalContainer {
    margin: 0px auto;
    background-color: #fff;
    border-radius: 3px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
    transition: all 0.3s ease;
    /*font-family: Helvetica, Arial, sans-serif;*/
  }

  .modalHeader {
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    flex-direction: row;
    justify-content: space-between;

    .iconTitle {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      flex-direction: row;
      i {
        margin-right: 10px;
        color: #ffffff;
      }
      h3 {
        margin: 0;
        color: #ffffff;
        font-weight: bold;
        font-size: 12px;
      }
    }

    .close {
      button {
        background-color: transparent;
        border: 0;
        padding: 0;
        margin: 0;
        color: #fff;
        outline: none;
        &:hover {
          cursor: pointer;
        }
      }
    }
  }

  .modalBody {
    padding: 20px;
  }

  .modalDefaultButton {
    float: right;
  }

  .modalFooter {
    padding: 10px 20px;
  }
}
</style>

<style lang="css" scoped>
.modal-enter {
  opacity: 0;
}

.modal-leave-active {
  opacity: 0;
}

.modal-enter,
.modal-leave-active {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}
</style>