﻿@extends('layouts.admin')

@section('page-title', __('Budgets'))

@section('action-button')
    <a href="#" data-url="{{ route('budgets.create') }}" data-size="lg" data-ajax-popup="true"
        data-title="{{ __('Create New Budget') }}" class="btn btn-sm btn-primary">
        <i class="ti ti-plus"></i>
        {{ __('Add New Budget') }}
    </a>
@endsection

@section('content')
    <div class="row">
        {{-- HRM Navigation Tabs --}}
        <div class="col-12">
            @include('layouts.hrm_setup')
        </div>

        <div class="col-md-12">
            <div class="card">
                <div class="card-body table-border-style">
                    <div class="table-responsive">
                        <table class="table align-middle datatable">
                            <thead>
                                <tr>
                                    <th>{{ __('Name') }}</th>
                                    <th>{{ __('Amount') }}</th>
                                    <th>{{ __('Scope') }}</th>
                                    <th>{{ __('Department') }}</th>
                                    <th>{{ __('Period') }}</th>
                                    <th>{{ __('Notes') }}</th>
                                    <th width="200px">{{ __('Actions') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($budgets as $budget)
                                                            <tr>
                                                                <td>{{ $budget->name }}</td>
                                                                <td>{{ number_format($budget->amount, 2) }}</td>
                                                                <td>{{ ucfirst($budget->type) }}</td>
                                                                <td>{{ $budget->department?->name ?? '—' }}</td>
                                                                <td>
                                                                    {{ $budget->start_date ? \Carbon\Carbon::parse($budget->start_date)->format('M d, Y') : '—' }}
                                                                    -
                                                                    {{ $budget->end_date ? \Carbon\Carbon::parse($budget->end_date)->format('M d, Y') : '—' }}
                                                                </td>
                                                                <td>{{ Str::limit($budget->notes, 40) ?? '—' }}</td>
                                                                <td class="Action text-end">
                                                                    <div class="d-flex justify-content-end align-items-center">
                                                                        {{-- Edit Button --}}
                                                                        <div class="action-btn bg-info ms-2">
                                                                            <a href="#" data-url="{{ route('budgets.edit', $budget->id) }}"
                                                                                data-size="lg" data-ajax-popup="true"
                                                                                data-title="{{ __('Edit Budget') }}"
                                                                                class="btn btn-sm align-items-center" data-bs-toggle="tooltip"
                                                                                title="{{ __('Edit') }}">
                                                                                <i class="ti ti-pencil text-white"></i>
                                                                            </a>
                                                                        </div>

                                                                        {{-- Delete Button --}}
                                                                        <div class="action-btn bg-danger ms-2">
                                                                            {!! Form::open([
                                        'method' => 'DELETE',
                                        'route' => ['budgets.destroy', $budget->id],
                                        'id' => 'delete-form-' . $budget->id
                                    ]) !!}
                                                                            <a href="#" class="btn btn-sm align-items-center bs-pass-para"
                                                                                data-bs-toggle="tooltip" title="{{ __('Delete') }}"
                                                                                data-confirm="{{ __('Are You Sure?') }}"
                                                                                data-confirm-yes="document.getElementById('delete-form-{{ $budget->id }}').submit();">
                                                                                <i class="ti ti-trash text-white"></i>
                                                                            </a>
                                                                            {!! Form::close() !!}
                                                                        </div>
                                                                    </div>
                                                                </td>
                                                            </tr>
                                @empty
                                    <tr>
                                        <td colspan="7" class="text-center text-muted">
                                            {{ __('No budgets found.') }}
                                        </td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsect