<template>
    <div class="row">
        <div class="col">
            <button class="btn btn-block btn-sm btn-success b-rad-none" @click="submitForm">
                Update Default Billing Address
            </button>
        </div>
    </div>
</template>

<script setup lang="ts">
import { useFormHandler } from '@/composables/useFormHandler';
import route from '@/general/functions/router';

interface Props {
    data: { id: number };
    section: string;
}

const props = defineProps<Props>();
const emit = defineEmits(['updateBillingAddress']);

const { submit } = useFormHandler({ section: props.section });

const submitForm = () => {
    submit(route('api.address.default', props.data.id), 'put', props.section, true, true, null, {
        successHandler: () => {
            emit('updateBillingAddress', props.data.id);
        }
    });
};
</script>