<template>
    <div class="report_header">
        <div>
            <div v-if="type_logo==2"></div>
            <div v-else>
                <div class="logo" style="position: absolute; left: 0; top: 0px" v-if="company.logo!=''">
                    <img :src="company.logo" alt="" width="110px" />
                </div>
                <div class="title text-center mb-3">
                    <p class="title_km h5 text_moul">{{ company.name_kh }}</p>
                    <p class="title_en h5">{{ company.name_en }}</p>
                </div>
            </div>
            <div class="title text-center">
                <p class="h5 text_moul"> 
                    {{ title }}  
                </p>
                <p v-if="date" class="mb-1">
                    <strong v-if="date_title">{{ date_title }}:</strong> 
                    <span v-if="type==1">
                        <strong>{{ funDate(date)}}</strong>
                    </span>
                    <span v-else-if="date[0]!=date[1]">
                        <strong>{{ $t("From") }}{{funDate(date[0])}} {{ $t("To") }} {{funDate(date[1])}}</strong>
                    </span>
                    <span v-else>
                        <strong>ត្រឹម{{funDate(date[0])}}</strong>
                    </span>
                </p>
                <p v-else></p>
            </div>
        </div>
    </div>
</template>

<script>
    var moment = require("moment"); 
    export default {
        props:{
            type      : '',
            type_logo : '',
            date      : '',
            title     : '',
            date_title: '',
        },
        data(){
            return{
                company:"",
                print_date:'',
                com_info:'',
            }
        },
        created() {
            this.funGetCompany();
        },
        methods: {
            funGetCompany(){
                axios.get('admin-api/company').then((res) => {
                    this.company = res.data;
                });
            },
            currentDateTime() {
                const current = new Date();
                const date = current.getDate() + '-' + (current.getMonth() + 1) + '-' + current.getFullYear();
                const time = current.getHours() + ":" + current.getMinutes() + ":" + current.getSeconds();
                const dateTime = date + ' ' + time;
                return dateTime;
            },
            // funDate(date) {
            //     return "ថ្ងៃទី" + moment(date).format("DD") + " ខែ" + this.funMonth(moment(date).format("MMM")) + " ឆ្នាំ" + moment(date).format("YYYY");
            // },
            funDay(day) {
                if (day == "Mo") {
                    return "ចន្ទ";
                } else if (day == "Tu") {
                    return "អង្គារ";
                } else if (day == "We") {
                    return "ពុធ";
                } else if (day == "Th") {
                    return "ព្រហស្បតិ៍";
                } else if (day == "Fr") {
                    return "សុក្រ";
                } else if (day == "Sa") {
                    return "សៅរ៍";
                } else {
                    return "អាទិត្យ";
                }
            },
            funDate(date) {
                return "ថ្ងៃ" + this.funDay(moment(date).format("dd")) + " ទី" + moment(date).format("DD") + " ខែ" + this.funMonth(moment(date).format("MMM")) + " ឆ្នាំ" + moment(date).format("YYYY");
            },
            funMonth(mon) {
                if (mon == "Jan") {
                    return "មករា";
                } else if (mon == "Feb") {
                    return "កុម្ភៈ";
                } else if (mon == "Mar") {
                    return "មីនា";
                } else if (mon == "Apr") {
                    return "មេសា";
                } else if (mon == "May") {
                    return "ឧសភា";
                } else if (mon == "Jun") {
                    return "មិថុនា";
                } else if (mon == "Jul") {
                    return "កក្កដា";
                } else if (mon == "Aug") {
                    return "សីហា";
                } else if (mon == "Sep") {
                    return "កញ្ញា";
                } else if (mon == "Oct") {
                    return "តុលា";
                } else if (mon == "Nov") {
                    return "វិច្ឆិកា";
                } else if (mon == "Dec") {
                    return "ធ្នូ";
                }
            },
        }
    }
</script>