<template>
    <div>
        <!-- More Ways To Share -->
        <div class="row m-0 mt-2">
            <div class="col-12 more-ways-text text-common-style">More ways to share</div>
        </div>
        <div class="row m-0 icon-container">
            <div class="col-12 d-flex align-items-center ml-3">
                <span class="icon-wrap">
                    <svg v-if="false" class="icon-checkmark">
                        <use xlink:href="/assets/img/mads-common-icons.svg#checkmark" />
                    </svg>
                    <svg
                        class="icon-social cursor-pointer"
                        @click="onShareByWhatsapp"
                        v-tooltip="'Comming Soon'"
                    >
                        <use xlink:href="/assets/img/mads-common-icons.svg#shareByWhatsapp" />
                    </svg>
                </span>
                <span class="icon-wrap">
                    <svg v-if="shareByEmail" class="icon-checkmark">
                        <use xlink:href="/assets/img/mads-common-icons.svg#checkmark" />
                    </svg>
                    <svg class="icon-social cursor-pointer ml-3" @click="onShareByEmails">
                        <use xlink:href="/assets/img/mads-common-icons.svg#shareByEmail" />
                    </svg>
                </span>
            </div>
        </div>
        <!-- Share By Email -->
        <div class="row m-0 mt-2" v-if="shareByEmail">
            <div class="col-12">
                <div class="form-group">
                    <label for class="label text-common-style mb-0">Add Email</label>
                    <multiselect
                        v-model="emailTag"
                        tag-placeholder="Add this as new tag"
                        placeholder="Search or add a email"
                        label="email"
                        track-by="email"
                        :options="emailOptions"
                        :multiple="true"
                        :taggable="true"
                        @tag="addTag"
                    ></multiselect>
                </div>
            </div>
        </div>
        <!-- Textarea -->
        <div class="row m-0 mt-2" v-if="shareByEmail && toggleTextArea()">
            <div class="col-12">
                <div class="form-group">
                    <label class="label text-common-style mb-0" for="textarea">Message</label>
                    <textarea
                        class="form-control email-textarea"
                        id="textarea"
                        v-model="textAreaComputed"
                    ></textarea>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
  props: ['selectedDashboard', 'dashboardUrl'],
  data () {
    return {
      shareByEmail: false,
      emailTag: [],
      emailOptions: []
    }
  },
  methods: {
    onShareByEmails () {
      this.shareByEmail = true
    //   this.shareByWhatsapp = false
    },
    onShareByWhatsapp () {
    //   this.shareByWhatsapp = true
      this.shareByEmail = false
    },
    addTag (newTag) {
      const tag = { email: newTag }
      this.emailOptions.push(tag)
      this.emailTag.push(tag)
    },
    toggleTextArea () {
      return this.emailTag.length > 0
    }
  },
  computed: {
    textAreaComputed () {
      const creator =
        this.selectedDashboard.creator.first_name +
        ' ' +
        this.selectedDashboard.creator.last_name
      const textAreaContent =
        'Hello! \n ' +
        creator +
        ' from Datakrew organization would like to share with you ' +
        this.selectedDashboard.name +
        ' You can access this dashboard by clicking the following link. \n\n Dashboard Link \n' +
        this.dashboardUrl +
        '\n\n PS. If this is a private dashboard, please contact ' +
        creator +
        ' for the dashboard password'
      return textAreaContent
    }
  }
}
</script>

<style lang="scss" scoped>
.more-ways-text {
    font-weight: 500;
    color: #212429;
}
.text-common-style {
    font-size: 12px;
    line-height: 24px;
}
.icon-container {
    .icon-wrap {
        position: relative;
        .icon-social {
            height: 75px;
            width: 60px;
        }
        .icon-checkmark {
            position: absolute;
            top: 30px;
            left: 50px;
        }
    }
}
.email-textarea {
    height: 259px;
    background: #ffffff;
    border: 1px solid #acb5bd;
    box-sizing: border-box;
    border-radius: 6px;
}
.text-area-visible {
    display: block;
}
.text-area-hidden {
    display: none;
}
</style>
