<template>
  <div class="l-flex--col">
    <tabs
      v-if="useTabs"
      :items="tabs"
      :active.sync="active"
    />
    <div class="l-flex__fill u-overflow-y--auto">
      <component
        :is="activeComponent"
        v-bind="$attrs"
      />
    </div>
  </div>
</template>

<script>
import {
  startSensor,
  stopSensor
} from '../monitor'
import Tabs from './Tabs'
import DeviceRuntime from './DeviceRuntime'
import DeviceSensor from './DeviceSensor'

export default {
  name: 'DeviceStatus',
  components: {
    Tabs,
    DeviceRuntime,
    DeviceSensor
  },
  data () {
    const tabs = [
      { key: 'runtime', name: '播控器状态' },
      __SENSOR__ ? { key: 'sensor', name: '传感器状态' } : null
    ].filter(val => val)
    return {
      tabs,
      active: tabs[0].key
    }
  },
  computed: {
    useTabs () {
      return this.tabs.length > 1
    },
    activeComponent () {
      switch (this.active) {
        case 'runtime':
          return 'DeviceRuntime'
        case 'sensor':
          return 'DeviceSensor'
        default:
          return null
      }
    }
  },
  activated () {
    startSensor()
  },
  deactivated () {
    stopSensor()
  }
}
</script>

<style lang="scss">
.c-runtime {
  padding: 12px 16px 16px;
  color: $info;
  font-size: 14px;
  line-height: 1;

  .medium {
    font-size: 18px;
  }

  .large {
    font-size: 32px;
  }

  &__icon {
    display: inline-block;
    width: 32px;
    height: 32px;
    margin-right: 8px;
    background-position: 0 0;
    background-size: 100% 100%;
    background-repeat: no-repeat;

    &.running {
      background-image: url("~@/assets/icon_condition.png");
    }

    &.screenshot {
      background-image: url("~@/assets/icon_image.png");
    }

    &.download {
      background-image: url("~@/assets/icon_download.png");
    }

    &.temperature {
      background-image: url("~@/assets/icon_temperature.png");
    }

    &.smoke {
      background-image: url("~@/assets/icon_smoke.png");
    }

    &.flooding {
      background-image: url("~@/assets/icon_flooding.png");
    }

    &.light {
      background-image: url("~@/assets/icon_light.png");
    }
  }

  &__title {
    color: $info--dark;
  }

  &__list {
    color: $blue;
    font-size: 18px;
  }
}
</style>
