<script setup lang="ts">
import BackButton from '@/components/button/BackButton.vue';
import AdminLayout from '@/layouts/AdminLayout.vue';
import { Head } from '@inertiajs/vue3';
import RoleForm from './form/RoleForm.vue';
import { index, update } from '@/routes/admin/system/roles';

interface PermissionOption {
    value: string;
    label: string;
    group: string;
}

interface RoleData {
    id: number;
    name: string;
    permission_names: string[];
}

defineProps<{
    role: RoleData;
    permissions: PermissionOption[];
}>();
</script>

<template>
    <Head title="Ubah Role" />

    <AdminLayout>
        <div
            class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between"
        >
            <div class="space-y-1">
                <h2 class="text-2xl font-bold tracking-tight">Ubah Role</h2>
            </div>

            <BackButton :href="index.url()" />
        </div>

        <RoleForm
            :submit-url="update.url(role.id)"
            method="put"
            submit-label="Perbarui"
            :initial-data="role"
            :permissions="permissions"
        />
    </AdminLayout>
</template>
