<template>
  <CRow>
    <CCol col="12" md="6">
      <CCard>
        <CCardHeader>
          <i class="fa fa-align-justify"></i>
          <strong> Bootstrap Alert</strong>
          <div class="card-header-actions">
            <a 
              href="https://coreui.io/vue/docs/3.0/components/Alert" 
              class="card-header-action" 
              rel="noreferrer noopener" 
              target="_blank"
            >
              <small class="text-muted">docs</small>
            </a>
          </div>
        </CCardHeader>
        <CCardBody>
          <div>
            <p></p>
            <CAlert show color="primary">Primary Alert</CAlert>
            <CAlert show color="secondary">Secondary Alert</CAlert>
            <CAlert show color="success">Success Alert</CAlert>
            <CAlert show color="danger">Danger Alert</CAlert>
            <CAlert show color="warning">Warning Alert</CAlert>
            <CAlert show color="info">Info Alert</CAlert>
            <CAlert show color="light">Light Alert</CAlert>
            <CAlert show color="dark">Dark Alert</CAlert>
          </div>
        </CCardBody>
      </CCard>
    </CCol>
    <CCol col="12" md="6">
      <CCard>
        <CCardHeader>
          <i class="fa fa-align-justify"></i> Alert
          <small> use <code>.alert-link</code> to provide links</small>
        </CCardHeader>
        <CCardBody>
          <div>
            <CAlert show color="primary">
              Primary Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="secondary">
              Secondary Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="success">
              Success Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="danger">
              Danger Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="warning">
              Warning Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="info">
              Info Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="light">
              Light Alert with <a href="#" class="alert-link">an example link</a>.
            </CAlert>
            <CAlert show color="dark">
              Dark Alert with
              <CLink href="#" class="alert-link">an example link</CLink>
              .
            </CAlert>
          </div>
        </CCardBody>
      </CCard>
    </CCol>
    <CCol col="12" md="6">
      <CCard>
        <CCardHeader>
          <i class="fa fa-align-justify"></i> Alerts <small>with additional content</small>
        </CCardHeader>
        <CCardBody>
          <CAlert show color="success">
            <h4 class="alert-heading">Well done!</h4>
            <p>
              Aww yeah, you successfully read this important alert message.
              This example text is going to run a bit longer so that you can see
              how spacing within an alert works with this kind of content.
            </p>
            <hr>
            <p class="mb-0">
              Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
            </p>
          </CAlert>
        </CCardBody>
      </CCard>
    </CCol>
    <CCol col="12" md="6">
      <CCard>
        <CCardHeader>
          <i class="fa fa-align-justify"></i> Alerts
          <small>dismissible</small>
        </CCardHeader>
        <CCardBody>
          <CAlert
            color="secondary"
            closeButton
            :show.sync="dismissibleAlerts[0]"
          >
            Dismissible Alert!
          </CAlert>

          <CAlert
            color="secondary"
            closeButton
            fade
            :show.sync="dismissibleAlerts[1]"
          >
            Dismissible Alert with fade effect!
          </CAlert>

          <CAlert
            color="secondary"
            :show.sync="dismissibleAlerts[2]"
            v-slot="{dismiss}"
            class="alert-dismissible"
          >
            Dismissible Alert with custom button!
            <CButton
              class="position-absolute"
              color="secondary"
              style="right:10px;top: 50%;transform: translateY(-50%);"
              @click="dismiss"
            >
              <i>Close</i>
            </CButton>
          </CAlert>
          <CButton
            @click="showDismissibleAlerts"
            color="info"
            class="m-1"
          >
            Show dismissible alerts
          </CButton>
        </CCardBody>
      </CCard>
      <CCard>
        <CCardHeader>
          <i class="fa fa-align-justify"></i> Alerts
          <small>auto dismissible</small>
        </CCardHeader>
        <CCardBody>
          <div>
            <CAlert
              :show.sync="dismissCountDown"
              closeButton
              color="warning"
              fade
            >
              Alert will dismiss after
              <strong>{{dismissCountDown}}</strong> seconds...
            </CAlert>

            <CAlert
              :show.sync="dismissCountDown"
              closeButton
              color="info"
            >
              Alert will dismiss after {{dismissCountDown}} seconds...
              <CProgress
                color="info"
                :max="dismissSecs"
                :value="dismissCountDown"
                height="4px"
              />
            </CAlert>
            <CButton @click="showAlert" color="info" class="m-1">
              Show alert with timer
            </CButton>
          </div>
        </CCardBody>
      </CCard>
    </CCol>
  </CRow>
</template>

<script>
export default {
  name: 'Alerts',
  data () {
    return {
      dismissSecs: 10,
      dismissCountDown: 10,
      dismissibleAlerts: [true, true, true],
    }
  },
  methods: {
    countDownChanged (dismissCountDown) {
      this.dismissCountDown = dismissCountDown
    },
    showAlert () {
      this.dismissCountDown = this.dismissSecs
    },
    showDismissibleAlerts () {
      this.dismissibleAlerts = this.dismissibleAlerts.map(el => el = true)
    }
  }
}
</script>
