@extends('layouts.app')

@section('title', 'Item Variations')

@section('content')
<div class="page-content">
    <div class="row">
        <div class="col-md-12">
            <div class="page-title-box">
                <div class="page-title-right">
                    <ol class="breadcrumb m-0">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}">Dashboard</a></li>
                        <li class="breadcrumb-item active">Item Variations</li>
                    </ol>
                </div>
                <h4 class="page-title">Item Variations</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h4 class="header-title">All Item Variations</h4>
                    <a href="{{ route('variations.create') }}" class="btn btn-primary">
                        <i class="fas fa-plus"></i> Add New Variation
                    </a>
                </div>
                <div class="card-body">
                    @if(session('success'))
                        <div class="alert alert-success">{{ session('success') }}</div>
                    @endif
                    @if(session('error'))
                        <div class="alert alert-danger">{{ session('error') }}</div>
                    @endif

                    <div class="table-responsive">
                        <table id="variations-table" class="table table-striped table-centered mb-0">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Item</th>
                                    <th>Variation Name</th>
                                    <th>Full SKU</th>
                                    <th>Size</th>
                                    <th>Color</th>
                                    <th>Dimensions</th>
                                    <th>Weight</th>
                                    <th>Cost Price</th>
                                    <th>Selling Price</th>
                                    <th>Stock Info</th>
                                    <th>Status</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('plugin-scripts')
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/dataTables.bootstrap5.min.js"></script>
@endpush

@push('plugin-styles')
<link href="https://cdn.datatables.net/1.11.5/css/dataTables.bootstrap5.min.css" rel="stylesheet">
@endpush

@push('scripts')
<script>
$(document).ready(function() {
    $('#variations-table').DataTable({
        processing: true,
        serverSide: false,
        ajax: '{{ route("variations.data") }}',
        columns: [
            {data: 'id', name: 'id'},
            {data: 'item_name', name: 'item_name'},
            {data: 'name', name: 'name'},
            {data: 'full_sku', name: 'full_sku'},
            {data: 'size', name: 'size'},
            {data: 'color', name: 'color'},
            {data: 'dimensions', name: 'dimensions'},
            {data: 'weight_display', name: 'weight'},
            {data: 'cost_price_display', name: 'cost_price'},
            {data: 'selling_price_display', name: 'selling_price'},
            {data: 'stock_info', name: 'stock_info'},
            {data: 'status_badge', name: 'status'},
            {data: 'actions', name: 'actions', orderable: false, searchable: false}
        ],
        order: [[0, 'desc']],
        pageLength: 25,
        language: {
            search: "Search:",
            lengthMenu: "Show _MENU_ entries per page",
            info: "Showing _START_ to _END_ of _TOTAL_ entries",
            infoEmpty: "Showing 0 to 0 of 0 entries",
            infoFiltered: "(filtered from _MAX_ total entries)",
            processing: "Processing...",
            emptyTable: "No variations found"
        }
    });
});
</script>
@endpush
