<template>
	<view class="yingbing-reader-footer">
		<view class="yingbing-reader-footer-left">
			<battery ref="battery"></battery>
			<text class="yingbing-reader-footer-text" :style="{color: color}">{{time}}</text>
		</view>
		<text class="yingbing-reader-footer-text" :style="{color: color}"> {{progress ? progress + '%' : current + ' / ' + total }}</text>
	</view>
</template>

<script>
	import Battery from '../battery/battery.vue'
	export default {
		inject: ['getColor'],
		components: {
			Battery
		},
		props: {
			total: {
				type: [Number, String],
				default: 0
			},
			current: {
				type: [Number, String],
				default: 0
			},
			progress: {
				type: [Number, String],
				default: 0
			}
		},
		computed: {
			color () {
				return this.getColor()
			}
		},
		data () {
			return {
				time: ''
			}
		},
		created() {
			this.getTime()
		},
		methods: {
			zeroize (value) {
				return value >= 10 ? value : '0' + value
			},
			getTime () {
				const d = new Date()
				this.time = this.zeroize(d.getHours()) + ':' + this.zeroize(d.getMinutes())
			},
			refresh () {
				this.$refs.battery.getBattery()
				this.getTime()
			}
		}
	}
</script>

<style scoped>
	.yingbing-reader-footer {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		height: 20px;
		margin-top: 10px;
	}
	.yingbing-reader-footer-left {
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.yingbing-reader-footer-text {
		font-size: 10px;
		opacity: 0.5;
		margin-left: 10px;
	}
</style>