<template>
  <div>
    <WidgetsDropdown/>
    <CCard>
      <CCardBody>
        <CRow>
          <CCol sm="5">
            <h4 id="traffic" class="card-title mb-0">Traffic</h4>
            <div class="small text-muted">November 2017</div>
          </CCol>
          <CCol sm="7" class="d-none d-md-block">
            <CButton variant="primary" class="float-right">
              <i class="cui-cloud-download"></i>
            </CButton>
            <CButtonGroup class="float-right mr-3">
              <CButton
                variant="outline-secondary"
                v-for="(value, key) in ['Day', 'Month', 'Year']"
                :key="key"
                class="mx-0"
                :pressed="value === selected ? true : false"
                @click="selected = value"
              >
                {{value}}
              </CButton>
            </CButtonGroup>
          </CCol>
        </CRow>
        <MainChartExample style="height:300px;margin-top:40px;"/>
      </CCardBody>
      <CCardFooter>
        <CRow class="text-center">
          <CCol md sm="12" class="mb-sm-2 mb-0">
            <div class="text-muted">Visits</div>
            <strong>29.703 Users (40%)</strong>
            <CProgress
              class="progress-xs mt-2"
              :precision="1"
              variant="success"
              :value="40"
            />
          </CCol>
          <CCol md sm="12" class="mb-sm-2 mb-0 d-md-down-none">
            <div class="text-muted">Unique</div>
            <strong>24.093 Users (20%)</strong>
            <CProgress
              class="progress-xs mt-2"
              :precision="1"
              variant="info"
              :value="20"
            />
          </CCol>
          <CCol md sm="12" class="mb-sm-2 mb-0">
            <div class="text-muted">Pageviews</div>
            <strong>78.706 Views (60%)</strong>
            <CProgress
              class="progress-xs mt-2"
              :precision="1"
              variant="warning"
              :value="60"
            />
          </CCol>
          <CCol md sm="12" class="mb-sm-2 mb-0">
            <div class="text-muted">New Users</div>
            <strong>22.123 Users (80%)</strong>
            <CProgress
              class="progress-xs mt-2"
              :precision="1"
              variant="danger"
              :value="80"
            />
          </CCol>
          <CCol md sm="12" class="mb-sm-2 mb-0 d-md-down-none">
            <div class="text-muted">Bounce Rate</div>
            <strong>Average Rate (40.15%)</strong>
            <CProgress
              class="progress-xs mt-2"
              :precision="1"
              :value="40"
            />
          </CCol>
        </CRow>
      </CCardFooter>
    </CCard>
    <WidgetsBrand/>
    <CRow>
      <CCol md="12">
        <CCard header-html="Traffic &amp; Sales" body-wrapper>
          <CRow>
            <CCol sm="12" lg="6">
              <CRow>
                <CCol sm="6">
                  <CCallout variant="info">
                    <small class="text-muted">New Clients</small><br>
                    <strong class="h4">9,123</strong>
                  </CCallout>
                </CCol>
                <CCol sm="6">
                  <CCallout variant="danger">
                    <small class="text-muted">Recurring Clients</small><br>
                    <strong class="h4">22,643</strong>
                  </CCallout>
                </CCol>
              </CRow>
              <hr class="mt-0">
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Monday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    variant="info"
                    :value="34"
                  />
                  <CProgress
                    class="progress-xs"
                    variant="danger"
                    :value="78"
                  />
                </div>
              </div>
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Tuesday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    :value="56"
                    variant="info"
                  />
                  <CProgress
                    class="progress-xs"
                    :value="94"
                    variant="danger"
                  />
                </div>
              </div>
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Wednesday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    :value="12"
                    variant="info"
                  />
                  <CProgress
                    class="progress-xs"
                    :value="67"
                    variant="danger"
                  />
                </div>
              </div>
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Thursday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    :value="43"
                    variant="info"
                  />
                  <CProgress
                    class="progress-xs"
                    :value="91"
                    variant="danger"
                  />
                </div>
              </div>
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Friday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    :value="22"
                    variant="info"
                  />
                  <CProgress
                    class="progress-xs"
                    :value="73"
                    variant="danger"
                  />
                </div>
              </div>
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Saturday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    :value="53"
                    variant="info"
                  />
                  <CProgress
                    class="progress-xs"
                    :value="82"
                    variant="danger"
                  />
                </div>
              </div>
              <div class="progress-group mb-4">
                <div class="progress-group-prepend">
                  <span class="progress-group-text">
                    Sunday
                  </span>
                </div>
                <div class="progress-group-bars">
                  <CProgress
                    class="progress-xs"
                    :value="9"
                    variant="info"
                  />
                  <CProgress
                    class="progress-xs"
                    :value="69"
                    variant="danger"
                  />
                </div>
              </div>
              <div class="legend text-center">
                <small>
                  <sup><CBadge pill variant="info">&nbsp;</CBadge></sup>
                  New clients
                  &nbsp;&nbsp;
                  <sup><CBadge pill variant="danger">&nbsp;</CBadge></sup>
                  Recurring clients
                </small>
              </div>
            </CCol>
            <CCol sm="12" lg="6">
              <CRow>
                <CCol sm="6">
                  <CCallout variant="warning">
                    <small class="text-muted">Pageviews</small><br>
                    <strong class="h4">78,623</strong>
                  </CCallout>
                </CCol>
                <CCol sm="6">
                  <CCallout variant="success">
                    <small class="text-muted">Organic</small><br>
                    <strong class="h4">49,123</strong>
                  </CCallout>
                </CCol>
              </CRow>
              <hr class="mt-0">
              <ul class="horizontal-bars type-2">
                <div class="progress-group">
                  <div class="progress-group-header">
                    <i class="cui-user progress-group-icon"></i>
                    <span class="title">Male</span>
                    <span class="ml-auto font-weight-bold">43%</span>
                  </div>
                  <div class="progress-group-bars">
                    <CProgress
                      class="progress-xs"
                      :value="43"
                      variant="warning"
                    />
                  </div>
                </div>
                <div class="progress-group mb-5">
                  <div class="progress-group-header">
                    <i class="cui-user-female progress-group-icon"></i>
                    <span class="title">Female</span>
                    <span class="ml-auto font-weight-bold">37%</span>
                  </div>
                  <div class="progress-group-bars">
                    <CProgress
                      class="progress-xs"
                      :value="37"
                      variant="warning"
                    />
                  </div>
                </div>
                <div class="progress-group">
                  <div class="progress-group-header">
                    <i class="cui-globe progress-group-icon"></i>
                    <span class="title">Organic Search</span>
                    <span class="ml-auto font-weight-bold">
                      191,235<span class="text-muted small">(56%)</span>
                    </span>
                  </div>
                  <div class="progress-group-bars">
                    <CProgress
                      class="progress-xs"
                      :value="56"
                      variant="success"
                    />
                  </div>
                </div>
                <div class="progress-group">
                  <div class="progress-group-header">
                    <CIcon
                      name="socialFacebook"
                      height="17"
                      class="progress-group-icon"
                    />
                    <span class="title">Facebook</span>
                    <span class="ml-auto font-weight-bold">
                      51,223 <span class="text-muted small">(15%)</span>
                    </span>
                  </div>
                  <div class="progress-group-bars">
                    <CProgress
                      class="progress-xs"
                      :value="15"
                      variant="success"
                    />
                  </div>
                </div>
                <div class="progress-group">
                  <div class="progress-group-header">
                    <CIcon
                      name="socialTwitter"
                      height="17"
                      class="progress-group-icon"
                    />
                    <span class="title">Twitter</span>
                    <span class="ml-auto font-weight-bold">
                      37,564 <span class="text-muted small">(11%)</span>
                    </span>
                  </div>
                  <div class="progress-group-bars">
                    <CProgress
                      class="progress-xs"
                      :value="11"
                      variant="success"
                    />
                  </div>
                </div>
                <div class="progress-group">
                  <div class="progress-group-header">
                    <CIcon
                      name="socialLinkedin"
                      height="17"
                      class="progress-group-icon"
                    />
                    <span class="title">LinkedIn</span>
                    <span class="ml-auto font-weight-bold">
                      27,319 <span class="text-muted small">&nbsp;(8%)</span>
                    </span>
                  </div>
                  <div class="progress-group-bars">
                    <CProgress
                      class="progress-xs"
                      :value="8"
                      variant="success"
                    />
                  </div>
                </div>
                <div class="divider text-center">
                  <CButton variant="link" size="sm" class="text-muted">
                    <i class="cui-options"></i>
                  </CButton>
                </div>
              </ul>
            </CCol>
          </CRow>
          <br/>
          <CTable
            class="mb-0 table-outline"
            hover
            :items="tableItems"
            :fields="tableFields"
            head-variant="light"
            no-sorting
          >
            <td slot="avatar" class="text-center" slot-scope="{item}">
              <div class="avatar">
                <img :src="item.avatar.url" class="img-avatar" alt="">
                <span
                  class="avatar-status"
                  :class="`bg-${item.avatar.status || 'secondary'}`"
                ></span>
              </div>
            </td>
            <td slot="user" slot-scope="{item}">
              <div>{{item.user.name}}</div>
              <div class="small text-muted">
                <span>
                  <template v-if="item.user.new">New</template>
                  <template v-else>Recurring</template>
                </span> | Registered: {{item.user.registered}}
              </div>
            </td>
            <td
              slot="country"
              slot-scope="{item}"
              class="text-center"
            >
              <CIcon
                :name="item.country.flag"
                height="25"
              />
            </td>
            <td slot="usage" slot-scope="{item}">
              <div class="clearfix">
                <div class="float-left">
                  <strong>{{item.usage.value}}%</strong>
                </div>
                <div class="float-right">
                  <small class="text-muted">{{item.usage.period}}</small>
                </div>
              </div>
              <CProgress
                class="progress-xs"
                v-model="item.usage.value"
                :variant="variant(item.usage.value)"
              />
            </td>
            <td
              slot="payment"
              slot-scope="{item}"
              class="text-center"
            >
              <CIcon
                :name="item.payment.icon"
                height="25"
              />
            </td>
            <td slot="activity" slot-scope="{item}">
              <div class="small text-muted">Last login</div>
              <strong>{{item.activity}}</strong>
            </td>
          </CTable>
        </CCard>
      </CCol>
    </CRow>
  </div>
</template>

<script>
import MainChartExample from './charts/MainChartExample'
import WidgetsDropdown from './widgets/WidgetsDropdown'
import WidgetsBrand from './widgets/WidgetsBrand'

export default {
  name: 'Dashboard',
  components: {
    MainChartExample,
    WidgetsDropdown,
    WidgetsBrand
  },
  data () {
    return {
      selected: 'Month',
      tableItems: [
        {
          avatar: { url: 'img/avatars/1.jpg', status: 'success' },
          user: { name: 'Yiorgos Avraamu', new: true, registered: 'Jan 1, 2015' },
          country: { name: 'USA', flag: 'US' },
          usage: { value: 50, period: 'Jun 11, 2015 - Jul 10, 2015' },
          payment: { name: 'Mastercard', icon: 'cc-mastercard' },
          activity: '10 sec ago'
        },
        {
          avatar: { url: 'img/avatars/2.jpg', status: 'danger' },
          user: { name: 'Avram Tarasios', new: false, registered: 'Jan 1, 2015' },
          country: { name: 'Brazil', flag: 'BR' },
          usage: { value: 22, period: 'Jun 11, 2015 - Jul 10, 2015' },
          payment: { name: 'Visa', icon: 'cc-visa' },
          activity: '5 minutes ago'
        },
        {
          avatar: { url: 'img/avatars/3.jpg', status: 'warning' },
          user: { name: 'Quintin Ed', new: true, registered: 'Jan 1, 2015' },
          country: { name: 'India', flag: 'IN' },
          usage: { value: 74, period: 'Jun 11, 2015 - Jul 10, 2015' },
          payment: { name: 'Stripe', icon: 'stripe' },
          activity: '1 hour ago'
        },
        {
          avatar: { url: 'img/avatars/4.jpg', status: '' },
          user: { name: 'Enéas Kwadwo', new: true, registered: 'Jan 1, 2015' },
          country: { name: 'France', flag: 'FR' },
          usage: { value: 98, period: 'Jun 11, 2015 - Jul 10, 2015' },
          payment: { name: 'PayPal', icon: 'paypal' },
          activity: 'Last month'
        },
        {
          avatar: { url: 'img/avatars/5.jpg', status: 'success' },
          user: { name: 'Agapetus Tadeáš', new: true, registered: 'Jan 1, 2015' },
          country: { name: 'Spain', flag: 'ES' },
          usage: { value: 22, period: 'Jun 11, 2015 - Jul 10, 2015' },
          payment: { name: 'Google Wallet', icon: 'google-wallet' },
          activity: 'Last week'
        },
        {
          avatar: { url: 'img/avatars/6.jpg', status: 'danger' },
          user: { name: 'Friderik Dávid', new: true, registered: 'Jan 1, 2015' },
          country: { name: 'Poland', flag: 'PL' },
          usage: { value: 43, period: 'Jun 11, 2015 - Jul 10, 2015' },
          payment: { name: 'Amex', icon: 'cc-amex' },
          activity: 'Last week'
        }
      ],
      tableFields: [
        { key: 'avatar', label: '', _classes: 'text-center' },
        { key: 'user' },
        { key: 'country', _classes: 'text-center' },
        { key: 'usage' },
        { key: 'payment', label: 'Payment method', _classes: 'text-center' },
        { key: 'activity' },
      ]
    }
  },
  methods: {
    variant (value) {
      let $variant
      if (value <= 25) {
        $variant = 'info'
      } else if (value > 25 && value <= 50) {
        $variant = 'success'
      } else if (value > 50 && value <= 75) {
        $variant = 'warning'
      } else if (value > 75 && value <= 100) {
        $variant = 'danger'
      }
      return $variant
    }
  }
}
</script>

<style>
  /* IE fix */
  #card-chart-01, #card-chart-02 {
    width: 100% !important;
  }
</style>
