@extends('admin.layouts.app')

@section('content')
<div class="container-fluid px-4">
    <x-admin.page-header title="Workflows" subtitle="Automation rules" icon="fas fa-project-diagram"
        :buttons="[
            ['label' => 'New Workflow', 'route' => route('admin.workflows.builder.create'), 'icon' => 'fas fa-plus', 'color' => 'primary', 'permission' => 'manage workflows'],
        ]" />

    <x-admin.card>
        <x-admin.data-table id="workflowsTable" :records-url="route('api.admin.workflows.records')">
            <th>ID</th>
            <th>Name</th>
            <th>Trigger</th>
            <th>Status</th>
            <th>Executions</th>
            <th>Last Run</th>
            <th class="text-end pe-4">{{ __('admin/common.actions') }}</th>
        </x-admin.data-table>
    </x-admin.card>
</div>
@endsection

@push('scripts')
<script>
window.permissions = {
    workflows: {
        view: {{ json_encode(Auth::user()->can('view workflows')) }},
        update: {{ json_encode(Auth::user()->can('manage workflows')) }},
        delete: {{ json_encode(Auth::user()->can('manage workflows')) }}
    }
};
window.workflowsConfig = {
    routes: {
        edit: '{{ route("admin.workflows.builder.edit", ":id") }}',
        destroy: '{{ route("api.admin.workflows.destroy", ":id") }}'
    },
    translations: { confirm_delete: '{{ __("admin/common.confirm_delete") }}' }
};
</script>
@vite('resources/js/admin/workflows/index.js')
@endpush
