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

export default {
    name: 'DynamicQueryArgumentField',

    extends: DynamicField,

    computed: {
        prop() {
            return SourceExtended.getQueryArgumentProp(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.setQueryArgumentProp(this.$node, this.field.name, prop);

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