<template>
    <view :class="'van-grid custom-class ' + (border && !gutter ? 'van-hairline--top' : '')" :style="viewStyle">
        <slot />
    </view>
</template>

<script>
import { VantComponent } from '../common/component';
import { addUnit } from '../common/utils';
export default {
    data() {
        return {
            viewStyle: ''
        };
    },
    '../grid-item/index': {
        name: 'grid-item',
        type: 'descendant',
        current: 'grid'
    },
    props: {
        square: {
            type: Boolean
        },
        gutter: {
            type: [Number, String],
            default: 0
        },
        clickable: {
            type: Boolean
        },
        columnNum: {
            type: Number,
            default: 4
        },
        center: {
            type: Boolean,
            default: true
        },
        border: {
            type: Boolean,
            default: true
        },
        direction: {
            type: String
        },
        iconSize: {
            type: String
        }
    },
    created() {
        const { gutter } = this;
        if (gutter) {
            this.setData({
                viewStyle: `padding-left: ${addUnit(gutter)}`
            });
        }
    },
    methods: {
        updateChildren() {
            this.children.forEach((child) => {
                child.updateStyle();
            });
        }
    },
    watch: {
        square: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        gutter: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        clickable: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        columnNum: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        center: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        border: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        direction: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        },

        iconSize: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateStyle();
                });
            },

            immediate: true
        }
    }
};
</script>
<style>
@import './index.css';
</style>
