@extends('layouts.frontend')

@section('title', $produk->nama_produk)

@section('content')
    <!-- Single Page Header -->
    <div class="container-fluid page-header py-5">
        <h1 class="text-center text-white display-6">{{ $produk->nama_produk }}</h1>
        <ol class="breadcrumb justify-content-center mb-0">
            <li class="breadcrumb-item"><a href="{{ url('/') }}">Home</a></li>
            <li class="breadcrumb-item"><a href="{{ route('shop') }}">Belanja</a></li>
            <li class="breadcrumb-item active text-white">Detail</li>
        </ol>
    </div>

    <!-- Single Product Start -->
    <div class="container-fluid py-5 mt-5">
        <div class="container py-5">
            <div class="row g-4 mb-5">
                <div class="col-lg-8 col-xl-9">
                    <div class="row g-4">
                        <div class="col-lg-6">
                            <div class="border rounded">
                                <a href="#">
                                    <img src="{{ $produk->foto_produk ? asset('storage/' . $produk->foto_produk) : asset('template/frontend/img/fruite-item-5.jpg') }}"
                                        class="img-fluid rounded" alt="Image">
                                </a>
                            </div>
                        </div>
                        <div class="col-lg-6">
                            <h4 class="fw-bold mb-3">{{ $produk->nama_produk }}</h4>
                            <p class="mb-3">Kategori: {{ $produk->kategori ?? 'Sayuran' }}</p>
                            <h5 class="fw-bold mb-3">Rp {{ number_format($produk->harga, 0, ',', '.') }} / kg</h5>
                            <div class="d-flex mb-4">
                                <i class="fa fa-star text-secondary"></i>
                                <i class="fa fa-star text-secondary"></i>
                                <i class="fa fa-star text-secondary"></i>
                                <i class="fa fa-star text-secondary"></i>
                                <i class="fa fa-star"></i>
                            </div>
                            <p class="mb-4">{{ $produk->deskripsi }}</p>

                            {{-- Form Add to Cart --}}
                            <form action="{{ route('cart.add') }}" method="POST">
                                @csrf
                                <input type="hidden" name="id" value="{{ $produk->id }}">
                                <div class="input-group quantity mb-5" style="width: 100px;">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-minus rounded-circle bg-light border"
                                            onclick="this.parentNode.querySelector('input[type=number]').stepDown()">
                                            <i class="fa fa-minus"></i>
                                        </button>
                                    </div>
                                    <input type="number" name="qty"
                                        class="form-control form-control-sm text-center border-0" value="1"
                                        min="1">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-plus rounded-circle bg-light border"
                                            onclick="this.parentNode.querySelector('input[type=number]').stepUp()">
                                            <i class="fa fa-plus"></i>
                                        </button>
                                    </div>
                                </div>
                                <button type="submit"
                                    class="btn border border-secondary rounded-pill px-4 py-2 mb-4 text-primary"><i
                                        class="fa fa-shopping-bag me-2 text-primary"></i> Masukkan Keranjang</button>
                                
                                <a href="{{ route('checkout', ['produk_id' => $produk->id]) }}" class="...">
                                    Beli Sekarang
                                </a>
                            </form>
                        </div>

                        <div class="col-lg-12">
                            <nav>
                                <div class="nav nav-tabs mb-3">
                                    <button class="nav-link active border-white border-bottom-0" type="button"
                                        role="tab" id="nav-about-tab" data-bs-toggle="tab" data-bs-target="#nav-about"
                                        aria-controls="nav-about" aria-selected="true">Deskripsi</button>
                                    <button class="nav-link border-white border-bottom-0" type="button" role="tab"
                                        id="nav-mission-tab" data-bs-toggle="tab" data-bs-target="#nav-mission"
                                        aria-controls="nav-mission" aria-selected="false">Info Petani</button>
                                </div>
                            </nav>
                            <div class="tab-content mb-5">
                                <div class="tab-pane active" id="nav-about" role="tabpanel" aria-labelledby="nav-about-tab">
                                    <p>{{ $produk->deskripsi }}</p>
                                </div>
                                <div class="tab-pane" id="nav-mission" role="tabpanel" aria-labelledby="nav-mission-tab">
                                    <div class="d-flex">
                                        <img src="{{ asset('template/frontend/img/avatar.jpg') }}"
                                            class="img-fluid rounded-circle p-3" style="width: 100px; height: 100px;"
                                            alt="">
                                        <div class="">
                                            <p class="mb-2" style="font-size: 14px;">Petani Lokal</p>
                                            <div class="d-flex justify-content-between">
                                                <h5>{{ $produk->petani->nama_lengkap ?? 'Petani Desa' }}</h5>
                                            </div>
                                            <p>Produk ini ditanam dan dipanen langsung oleh petani lokal terverifikasi.</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Sidebar -->
                <div class="col-lg-4 col-xl-3">
                    <div class="row g-4 fruite">
                        <div class="col-lg-12">
                            <div class="mb-3">
                                <h4>Produk Terkait</h4>
                                @foreach ($produk_terkait ?? [] as $related)
                                    <div class="d-flex align-items-center justify-content-start mt-3">
                                        <div class="rounded me-4" style="width: 100px; height: 100px;">
                                            <img src="{{ $related->foto_produk ? asset('storage/' . $related->foto_produk) : asset('template/frontend/img/fruite-item-5.jpg') }}"
                                                class="img-fluid rounded" alt="">
                                        </div>
                                        <div>
                                            <h6 class="mb-2">{{ $related->nama_produk }}</h6>
                                            <div class="d-flex mb-2">
                                                <i class="fa fa-star text-secondary"></i>
                                                <i class="fa fa-star text-secondary"></i>
                                                <i class="fa fa-star text-secondary"></i>
                                                <i class="fa fa-star text-secondary"></i>
                                                <i class="fa fa-star"></i>
                                            </div>
                                            <div class="d-flex mb-2">
                                                <h5 class="fw-bold me-2">Rp
                                                    {{ number_format($related->harga, 0, ',', '.') }}</h5>
                                            </div>
                                        </div>
                                    </div>
                                @endforeach

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
