<template>
    <div class="panel panel-default">
        <div class="panel-heading">
            <!--@lang('entry.title', ['name' => 'Some Mod 2.0', 'user' => 'Someuser'])-->
            {{ title }} {{ version }} by <a :href="'/profile/' + uid"><span :style="name_colour">{{ showName }}</span></a>
        </div>

        <div class="panel-body">
            <div class="container">
                <div class="row">
                    <div class="col-md-2">
                        <button type="button" class="btn btn-primary btn-lg">
                            <!--@lang('entry.download')-->
                            Download
                        </button>
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-primary">
                            <!--@lang('entry.update')-->
                            Update
                        </button>
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-danger">
                            <!--@lang('entry.remove')-->
                            Remove
                        </button>
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-primary">
                            <!--@lang('entry.approve')-->
                            Disapprove
                        </button>
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-warning">
                            <!--@lang('entry.report')-->
                            Report
                        </button>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-2">
                        <!--@lang('entry.views', ['count' => '1000'])-->
                        Views: {{ views }}
                    </div>
                    <div class="col-md-2">
                        <!--@lang('entry.downloads', ['count' => '1000'])-->
                        Downloads: {{ downloads }}
                    </div>
                    <div class="col-md-2">
                        <!--@lang('entry.submitted', ['datetime' => '1945/05/05'])-->
                        Submitted: {{ submit_date }}
                    </div>
                    <div v-if="last_date !== 0"class="col-md-2">
                        <!--@lang('entry.updated', ['datetime' => '2050/12/01'])-->
                        Updated: {{ last_date }}
                    </div>
                    <div class="col-md-2">
                        <!--@lang('entry.filesize', ['size' => '1 TB'])-->
                        Filesize: 1 TB
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import moment from 'moment';

    export default {
        name: 'entry-title',
        props: ['fid'],
        data: function () {
            return {
                id: this.fid,
                uid: 0,
                title: '',
                version: '',
                username: '',
                avatar: '',
                gender: '',
                display_name: '',
                name_colour: '',
                views: 0,
                downloads: 0,
                submit_date: 0,
                last_date: 0,
                showName: '',
            }
        },
        created: function () {
            axios.get('/api/rpc/file/getfiletitle/' + this.id).then(data => {
                this.uid = data.data[0].user_id;
                this.title = data.data[0].title;
                this.version = data.data[0].version;
                this.views = data.data[0].views;
                this.downloads = data.data[0].downloads;
                this.submit_date = moment.unix(data.data[0].submit_date).format("YYYY/MM/DD");
                this.last_date = data.data[0].last_date;

                this.username = data.data[0].username;
                this.display_name = data.data[0].display_name;
                this.gender = data.data[0].gender;
                this.avatar = data.data[0].avatar;
                this.name_colour = data.data[0].name_colour;
            }).then(() => {
                if (this.last_date !== 0) {
                    this.last_date = moment.unix(this.last_date).format("YYYY/MM/DD");
                }
                if (this.display_name !== '') {
                    this.showName = this.display_name;
                }
                else {
                    this.showName = this.username;
                }
            })
            
        }
    }
</script>

<style>
    .col {
		text-align: center;
    }
</style>