@extends('admin.layout.app')
@section('content')
    <style>
        #diamond-pricing {
            background: #f4f7fb;
            min-height: 100vh;
            padding: 40px 0;
        }

        /* Header */
        #diamond-pricing .page-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: #6B53EC;
            color: #fff;
            padding: 25px 30px;
            border-radius: 18px;
            margin-bottom: 30px;
        }

        #diamond-pricing .page-header h2 {
            font-size: 30px;
            font-weight: 700;
            margin-bottom: 5px;
        }

        #diamond-pricing .page-header p {
            opacity: .85;
        }

        #diamond-pricing .btn-add {
            background: #fff;
            color: #0b6efd;
            font-weight: 600;
            border-radius: 50px;
            padding: 12px 22px;
            transition: .3s;
        }

        #diamond-pricing .btn-add:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 25px rgba(0, 0, 0, .15);
        }

        /* Card */
        #diamond-pricing .card {
            border-radius: 18px;
        }

        /* Table */
        #diamond-pricing table {
            width: 100% !important;
        }

        #diamond-pricing table thead {
            background: #0b6efd;
            color: #fff;
        }

        #diamond-pricing table thead th {
            border: none;
            padding: 18px;
            font-weight: 600;
        }

        #diamond-pricing table tbody td {
            padding: 18px;
            vertical-align: middle;
        }

        #diamond-pricing table tbody tr {
            transition: .3s;
        }

        #diamond-pricing table tbody tr:hover {
            background: #edf5ff;
        }

        /* DataTables */
        .dataTables_wrapper {
            padding-top: 15px;
        }

        .dataTables_filter input {
            border-radius: 10px !important;
            border: 1px solid #ddd !important;
            padding: 8px 15px !important;
        }

        .dataTables_length select {
            border-radius: 10px !important;
        }

        .dataTables_paginate .paginate_button.current {
            background: #0b6efd !important;
            color: #fff !important;
            border: none !important;
        }

        /* Modal */
        #addModal .modal-content {
            border: none;
            border-radius: 20px;
        }

        #addModal .modal-header {
            background: #6B53EC;
            color: #fff;
            border: none;
            padding: 20px 30px;
        }

        #addModal .btn-close {
            filter: invert(1);
        }

        #addModal .modal-body {
            padding: 30px;
        }

        #addModal label {
            font-weight: 600;
            margin-bottom: 8px;
        }

        #addModal .form-control,
        #addModal .form-select {
            height: 50px;
            border-radius: 12px;
            border: 1px solid #d9d9d9;
            transition: .3s;
        }

        #addModal .form-control:focus,
        #addModal .form-select:focus {
            border-color: #0b6efd;
            box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .15);
        }

        #addModal .modal-footer {
            border: none;
            padding: 20px 30px;
        }

        #addModal .btn-save {
            background: #6B53EC;
            color: #fff;
            border-radius: 50px;
            padding: 12px 30px;
        }

        #addModal .btn-save:hover {
            background: #0048c8;
        }

        @media(max-width:768px) {
            #diamond-pricing .page-header {
                flex-direction: column;
                gap: 20px;
                text-align: center;
            }

            #diamond-pricing .btn-add {
                width: 100%;
            }
        }

        /* Table Header */
        /* #diamond-pricing .table thead th{
            background: linear-gradient(135deg, #1f4b99 0%, #0b6efd 100%);
            color: #fff;
            border: none;
            padding: 16px 18px;
            font-weight: 600;
            font-size: 15px;
            white-space: nowrap;
            vertical-align: middle;
        } */
        div#diamondTable_filter {
            margin-bottom: 20px;
        }

        /* Remove DataTables default sorting background */
        table.dataTable thead th.sorting,
        table.dataTable thead th.sorting_asc,
        table.dataTable thead th.sorting_desc,
        table.dataTable thead td.sorting,
        table.dataTable thead td.sorting_asc,
        table.dataTable thead td.sorting_desc {
            background: #6B53EC !important;
            color: #fff !important;
        }

        /* Sorting Icons */
        /* table.dataTable thead .sorting:before,
        table.dataTable thead .sorting:after,
        table.dataTable thead .sorting_asc:before,
        table.dataTable thead .sorting_asc:after,
        table.dataTable thead .sorting_desc:before,
        table.dataTable thead .sorting_desc:after{
            color: #fff !important;
        } */
        /* Rounded top corners */
        #diamond-pricing .card {
            overflow: hidden;
        }

        #diamond-pricing .table {
            margin-bottom: 0;
        }

        #diamond-pricing .table thead th:first-child {
            border-top-left-radius: 12px;
        }

        #diamond-pricing .table thead th:last-child {
            border-top-right-radius: 12px;
        }
    </style>
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
    <section id="diamond-pricing">
        <div class="container-fluid">
            <!-- Header -->
            <div class="page-header shadow-sm">
                <div>
                    <h2>
                        <i class="fa-solid fa-gem"></i>
                        Diamond Pricing
                    </h2>
                    <p class="mb-0">
                        Manage all diamond pricing information.
                    </p>
                </div>
                <button class="btn btn-add" data-bs-toggle="modal" data-bs-target="#addModal">
                    <i class="fa-solid fa-plus"></i>
                    Add Pricing
                </button>
            </div>
            <!-- Card -->
            <div class="card border-0 shadow">
                <div class="card-body">
                    <table id="diamondTable" class="table align-middle table-hover">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Type</th>
                                <th>Shape</th>
                                <th>Size</th>
                                <th>PPC</th>
                                <th>Handling</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </section>
    <!-- Modal -->
    <div class="modal fade" id="addModal" tabindex="-1">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <form id="diamondForm">
                @csrf
                <div class="modal-content">
                    <div class="modal-header">
                        <h4>
                            <i class="fa-solid fa-gem me-2"></i>
                            Add Diamond Pricing
                        </h4>
                        <button class="btn-close" data-bs-dismiss="modal"></button>
                    </div>
                    <div class="modal-body">
                        <div class="row g-4">
                            <div class="col-md-6">
                                <label>Type</label>
                                <input type="text" class="form-control" name="type" placeholder="Natural / Lab">
                            </div>
                            <div class="col-md-6">
                                <label>Shape</label>
                                <input type="text" class="form-control" name="shape" placeholder="Round">
                            </div>
                            <div class="col-md-6">
                                <label>Size</label>
                                <input type="text" class="form-control" name="size" placeholder="0.50">
                            </div>
                            <div class="col-md-6">
                                <label>PPC</label>
                                <input type="number" class="form-control" name="ppc" placeholder="5000">
                            </div>
                            <div class="col-md-6">
                                <label>Handling</label>
                                <input type="number" class="form-control" name="handeling" placeholder="200">
                            </div>
                            <div class="col-md-6">
                                <label>Status</label>
                                <select class="form-select" name="status">
                                    <option value="1"> Active </option>
                                    <option value="0"> Inactive </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-light" data-bs-dismiss="modal" type="button">
                            Cancel
                        </button>
                        <button class="btn btn-save">
                            <i class="fa-solid fa-floppy-disk me-2"></i>
                            Save Pricing
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script>
        $(document).ready(function() {
            var table = $('#diamondTable').DataTable({
                processing: true,
                serverSide: true,
                destroy: true,
                ajax: {
                    url: "{{ route('diamond-pricing.list') }}",
                    type: "GET",
                    dataSrc: function(json) {
                        console.log(json);
                        return json.data;
                    },
                    error: function(xhr) {
                        console.log(xhr.responseText);
                    }
                },
                columns: [{
                        data: null,
                        orderable: false,
                        searchable: false,
                        render: function(data, type, row, meta) {
                            return meta.row + 1;
                        }
                    },
                    {
                        data: 'type'
                    },
                    {
                        data: 'shape'
                    },
                    {
                        data: 'size'
                    },
                    {
                        data: 'ppc'
                    },
                    {
                        data: 'handeling'
                    }
                    // {
                    // data: 'action',
                    // orderable: false,
                    // searchable: false
                    //}
                ]
            });
        });
        $('#diamondForm').submit(function(e) {
            e.preventDefault();
            $.ajax({
                url: "{{ route('diamond-pricing.store') }}",
                type: "POST",
                data: $(this).serialize(),
                success: function(res) {
                    $('#addModal').modal('hide');
                    $('#diamondForm')[0].reset();
                    $('#diamondTable').DataTable().ajax.reload(null, false);
                },
                error: function(xhr) {
                    console.log(xhr.responseText);
                }
            });
        });
    </script>
@endsection
