<template>
    <td :style="containerStyle" :class="containerClass">
        <component v-if="column.children && column.children.footer" :is="column.children.footer" :column="column" />
        {{ columnProp('footer') }}
    </td>
</template>

<script>
import { DomHandler, ObjectUtils } from 'primevue/utils';

export default {
    name: 'FooterCell',
    props: {
        column: {
            type: Object,
            default: null
        }
    },
    data() {
        return {
            styleObject: {}
        };
    },
    mounted() {
        if (this.columnProp('frozen')) {
            this.updateStickyPosition();
        }
    },
    updated() {
        if (this.columnProp('frozen')) {
            this.updateStickyPosition();
        }
    },
    methods: {
        columnProp(prop) {
            return ObjectUtils.getVNodeProp(this.column, prop);
        },
        updateStickyPosition() {
            if (this.columnProp('frozen')) {
                let align = this.columnProp('alignFrozen');

                if (align === 'right') {
                    let right = 0;
                    let next = this.$el.nextElementSibling;

                    if (next) {
                        right = DomHandler.getOuterWidth(next) + parseFloat(next.style.right || 0);
                    }

                    this.styleObject.right = right + 'px';
                } else {
                    let left = 0;
                    let prev = this.$el.previousElementSibling;

                    if (prev) {
                        left = DomHandler.getOuterWidth(prev) + parseFloat(prev.style.left || 0);
                    }

                    this.styleObject.left = left + 'px';
                }
            }
        }
    },
    computed: {
        containerClass() {
            const align= (this.columnProp('align') || '' ).toLowerCase();
            const alignClass= (align==='')? null : 'text-'+align;

            return [
                this.columnProp('footerClass'),
                alignClass,
                /*this.columnProp('class'),*/
                {
                    'p-frozen-column': this.columnProp('frozen')
                },
               
            ];
        },
        containerStyle() {
            
            //增加列宽度的设置
            let width =  this.columnProp('width') || '';
            let widthStyle =(width==='') ? null : { width }  ;

            let bodyStyle = this.columnProp('footerStyle');
            /*let columnStyle = this.columnProp('style');*/

            return this.columnProp('frozen') ? [widthStyle, bodyStyle, this.styleObject] : [widthStyle, bodyStyle];  //columnStyle, 
        }
    }
};
</script>
