<script setup lang="ts">
import {
    Card,
    CardContent,
    CardHeader,
    CardTitle,
    CardDescription,
} from '@/components/ui/card';
import AdminLayout from '@/layouts/AdminLayout.vue';
import { Head } from '@inertiajs/vue3';
import { computed, ref, watch } from 'vue';
import admin from '@/routes/admin';
import DataTableToolbar from '@/components/data-table/DataTableToolbar.vue';
import type { DataTableFilterDef } from '@/types/data-table';
import {
    useDataTableQuery,
    useDataTableQuerySync,
} from '@/composables/useDataTableQuery';
import { Presentation } from '@lucide/vue';

const props = defineProps<{
    filters: {
        search: string;
        status?: string;
    };
}>();

const search = ref(props.filters.search ?? '');

const { query, setSearch, setFilter, resetFilters, syncFromServer } =
    useDataTableQuery({
        url: admin.analysis.url(),
        initial: { ...props.filters },
        filterKeys: ['status'],
    });

useDataTableQuerySync(() => props.filters, syncFromServer);

const filterDefs = computed<DataTableFilterDef[]>(() => [
    {
        key: 'status',
        label: 'Status',
        type: 'select',
        options: [
            { value: 'active', label: 'Aktif' },
            { value: 'inactive', label: 'Nonaktif' },
        ],
    },
]);

const filterValues = computed(() => ({
    status: query.value.status ?? '',
}));

watch(search, (value) => {
    setSearch(value);
});

watch(
    () => props.filters.search,
    (value) => {
        search.value = value ?? '';
    },
);
</script>

<template>
    <Head title="Analisa" />

    <AdminLayout>
        <div class="flex flex-col gap-6">
            <!-- Header -->
            <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">Analisa</h2>
                    <p class="text-sm text-muted-foreground">
                        Halaman analisa data dan performa toko.
                    </p>
                </div>
            </div>
        </div>
    </AdminLayout>
</template>
