@extends('layouts.admin')
@section('styles')
    <link rel="stylesheet" type="text/css" href="{{ asset('assets/admin/css/vendors/datatables.css') }}">
@endsection
@section('app')
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                @if (in_array(auth()->user()->role_id, [1, 3, 4]))
                    <div class="list-product-header">
                        <div>
                            <a class="btn btn-primary" href="{{ route('manage.transaction.create') }}">Tambah</a>
                        </div>
                    </div>
                @endif
                <div class="card">
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="display" id="datatable">
                                <thead>
                                    <tr>
                                        <th>No</th>
                                        <th>Barber</th>
                                        <th>Pelanggan</th>
                                        <th>Layanan</th>
                                        <th>Harga</th>
                                        <th>Diskon</th>
                                        <th>Total</th>
                                        <th>Metode Pembayaran</th>
                                        <th>Gambar</th>
                                        <th>Tanggal</th>
                                        @if (in_array(auth()->user()->role_id, [1, 3, 4]))
                                            <th>Aksi</th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($transactions as $transaction)
                                        <tr>
                                            <td>{{ $loop->iteration }}</td>
                                            <td>{{ $transaction->user->biography->full_name ?? '-deleted-' }}</td>
                                            <td>{{ $transaction->customer->name }}</td>
                                            <td>{{ $transaction->service->name }}</td>
                                            <td>{{ formatToRupiah($transaction->price) }}</td>
                                            <td>{{ formatToRupiah($transaction->discount) }}</td>
                                            <td>{{ formatToRupiah($transaction->total) }}</td>
                                            <td>
                                                @if ($transaction->payment_method === '1')
                                                    <span class="badge badge-primary">Tunai</span>
                                                @elseif($transaction->payment_method === '2')
                                                    <span class="badge badge-info">Qris</span>
                                                @elseif($transaction->payment_method === '3')
                                                    <span class="badge badge-success">Lainnya</span>
                                                @else
                                                    <span class="badge badge-danger">Tidak Diketahui</span>
                                                @endif
                                            </td>
                                            <td>
                                                @if ($transaction->attachment && $transaction->attachment->formatted_attachment)
                                                    <a
                                                        href="{{ Storage::url("transactions/{$transaction->attachment->formatted_attachment}") }}">
                                                        <img src="{{ Storage::url("transactions/{$transaction->attachment->formatted_attachment}") }}"
                                                            alt="{{ $transaction->name }}" width="77" height="77">
                                                    </a>
                                                @else
                                                    <a href="{{ asset('assets/images/no-imge.png') }}">
                                                        <img src="{{ asset('assets/images/no-imge.png') }}"
                                                            alt="Default Image" style="width: 77px; height: 77px">
                                                    </a>
                                                @endif
                                            </td>
                                            <td>{{ formatDateIndo($transaction->created_at) }}</td>
                                            @if (in_array(auth()->user()->role_id, [1, 3, 4]))
                                                <td>
                                                    <ul class="action">
                                                        <li class="edit">
                                                            <a href="{{ route('manage.transaction.edit', encryptId($transaction->id)) }}"
                                                                data-bs-toggle="tooltip" data-bs-placement="left"
                                                                data-bs-title="Edit">
                                                                <i data-feather="edit"></i>
                                                            </a>
                                                        </li>
                                                        @if (auth()->user()->role_id === 1)
                                                            <li class="delete">
                                                                <form
                                                                    action="{{ route('manage.transaction.delete', encryptId($transaction->id)) }}"
                                                                    method="post">
                                                                    @csrf
                                                                    @method('delete')
                                                                    <a href="javascript:void(0)" class="delete-data"
                                                                        data-bs-toggle="tooltip" data-bs-placement="left"
                                                                        data-bs-title="Hapus">
                                                                        <i data-feather="trash-2"></i>
                                                                    </a>
                                                                </form>
                                                            </li>
                                                        @endif
                                                    </ul>
                                                </td>
                                            @endif
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('afterScripts')
    <script src="{{ asset('assets/admin/js/datatable/jquery.dataTables.min.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/admin/js/datatable/client-side.js?ver=1.0.0') }}"></script>
    <script src="{{ asset('assets/js/interactions/confirmation.js?ver=1.0.0') }}"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
@endsection
