<template>
    <view>
        <slot />
    </view>
</template>

<script>
import { VantComponent } from '../common/component';
export default {
    data() {
        return {
            valueClone: '',
            disabledClone: false
        };
    },
    field: true,
    '../radio/index': {
        name: 'radio',
        type: 'descendant',
        current: 'radio-group',

        linked(target) {
            this.updateChild(target);
        }
    },
    props: {
        value: {
            type: null
        },
        disabled: {
            type: Boolean
        }
    },
    methods: {
        updateChildren() {
            (this.children || []).forEach((child) => this.updateChild(child));
        },
        updateChild(child) {
            const { valueClone: value, disabledClone: disabled } = this;
            child.setData({
                valueClone: value,
                disabledClone: disabled || child.data.disabled
            });
        }
    },
    watch: {
        value: {
            handler: function () {
                this.valueClone = this.clone(this.value)(this.children || []).forEach((child) => this.updateChild(child));
            },

            immediate: true
        },

        disabled: {
            handler: function () {
                this.disabledClone = this.clone(this.disabled)(this.children || []).forEach((child) => this.updateChild(child));
            },

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