@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]))
                    <div class="list-product-header">
                        <div>
                            <a class="btn btn-primary" href="{{ route('master.barbershop.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>Nama</th>
                                        <th>Kontak</th>
                                        <th>Patokan</th>
                                        <th>Alamat</th>
                                        <th>Dibuka</th>
                                        <th>Tutup</th>
                                        <th>Kas</th>
                                        <th>Gambar</th>
                                        <th>Tanggal</th>
                                        @if (in_array(auth()->user()->role_id, [1, 3]))
                                            <th>Aksi</th>
                                        @endif
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach ($barbershop as $item)
                                        <tr>
                                            <td>{{ $loop->iteration }}</td>
                                            <td>{{ $item->name }}</td>
                                            <td>{{ $item->contact_number }}</td>
                                            <td>{{ $item->landmark }}</td>
                                            <td>{{ $item->address }}</td>
                                            <td>{{ formatDateIndo($item->opened) }}</td>
                                            <td>{{ $item->closed ? formatDateIndo($item->closed) : 'Masih Beroperasi' }}
                                            </td>
                                            <td>{{ formatToRupiah($item->cash) }}</td>
                                            <td>
                                                @if ($item->attachment && $item->attachment->formatted_attachment)
                                                    <a
                                                        href="{{ Storage::url("barbershop/{$item->attachment->formatted_attachment}") }}">
                                                        <img src="{{ Storage::url("barbershop/{$item->attachment->formatted_attachment}") }}"
                                                            alt="{{ $item->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($item->created_at) }}</td>
                                            @if (in_array(auth()->user()->role_id, [1, 3]))
                                                <td>
                                                    <ul class="action">
                                                        <li class="edit">
                                                            <a href="{{ route('master.barbershop.edit', encryptId($item->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('master.barbershop.delete', encryptId($item->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
