<template>
    <view :class="'custom-class van-collapse ' + (border ? 'van-hairline--top-bottom' : '')">
        <slot />
    </view>
</template>

<script>
import { VantComponent } from '../common/component';
export default {
    data() {
        return {};
    },
    '../collapse-item/index': {
        name: 'collapse-item',
        type: 'descendant',
        current: 'collapse'
    },
    props: {
        value: {
            type: null
        },
        accordion: {
            type: Boolean
        },
        border: {
            type: Boolean,
            default: true
        }
    },
    methods: {
        updateExpanded() {
            this.children.forEach((child) => {
                child.updateExpanded();
            });
        },
        switchFun(name, expanded) {
            const { accordion, value } = this;
            const changeItem = name;
            if (!accordion) {
                name = expanded ? (value || []).concat(name) : (value || []).filter((activeName) => activeName !== name);
            } else {
                name = expanded ? name : '';
            }
            if (expanded) {
                this.$emit('open', changeItem);
            } else {
                this.$emit('close', changeItem);
            }
            this.$emit('change', name);
            this.$emit('input', name);
        }
    },
    watch: {
        value: {
            handler: function () {
                this.children.forEach((child) => {
                    child.updateExpanded();
                });
            },

            immediate: true
        },

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

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