<script>
import DynamicField from './DynamicField.vue';
import SourceExtended from '../../../source/SourceExtended';

export default {
    name: 'DynamicSubQueryArgumentField',

    extends: DynamicField,

    computed: {
        prop() {
            return SourceExtended.getSubQueryArgumentProp(this.$node, this.field.name) || {};
        },

        dynamicOptions() {
            return SourceExtended.getDynamicOptions({
                field: this.field,
            });
        },
    },

    methods: {
        migrateToComposable() {
            const composedOption = this.dynamicOptions.find(({ name }) => name === 'composable');

            const prop = composedOption.migrate(this.prop);

            SourceExtended.setSubQueryArgumentProp(this.$node, this.field.name, prop);

            composedOption.edit({ prop });
        },
        remove() {
            SourceExtended.removeSubQueryArgumentProp(this.$node, this.field.name);
        },
    },
};
</script>
