@extends('layouts.app')

@section('title', 'Prescription Items Management')

@section('content')
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
    <div class="mb-6 flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
        <h1 class="text-3xl font-bold text-gray-800">Prescription Items Management</h1>
        <div class="flex gap-2">
            <a href="{{ route('admin.dashboard') }}" class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded">
                <i class="fas fa-arrow-left mr-2"></i>Back to Dashboard
            </a>
            <a href="{{ route('admin.prescription-items.create', ['type' => $type]) }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded">
                <i class="fas fa-plus mr-2"></i>Add New Item
            </a>
        </div>
    </div>

    <!-- Type Filter Tabs -->
    <div class="mb-6 bg-white rounded-lg shadow p-4">
        <div class="flex gap-2 border-b">
            <a href="{{ route('admin.prescription-items.index', ['type' => 'quantity']) }}" 
               class="px-4 py-2 {{ $type === 'quantity' ? 'border-b-2 border-blue-600 text-blue-600 font-semibold' : 'text-gray-600' }}">
                Quantity
            </a>
            <a href="{{ route('admin.prescription-items.index', ['type' => 'frequency']) }}" 
               class="px-4 py-2 {{ $type === 'frequency' ? 'border-b-2 border-blue-600 text-blue-600 font-semibold' : 'text-gray-600' }}">
                Frequency
            </a>
            <a href="{{ route('admin.prescription-items.index', ['type' => 'instruction']) }}" 
               class="px-4 py-2 {{ $type === 'instruction' ? 'border-b-2 border-blue-600 text-blue-600 font-semibold' : 'text-gray-600' }}">
                Instruction
            </a>
            <a href="{{ route('admin.prescription-items.index', ['type' => 'duration']) }}" 
               class="px-4 py-2 {{ $type === 'duration' ? 'border-b-2 border-blue-600 text-blue-600 font-semibold' : 'text-gray-600' }}">
                Duration
            </a>
        </div>
    </div>

    @if(session('success'))
        <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
            {{ session('success') }}
        </div>
    @endif

    <div class="bg-white rounded-lg shadow overflow-hidden">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Sort Order</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                @forelse($items as $item)
                <tr>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">{{ $item->name }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $item->sort_order }}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full {{ $item->is_active ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' }}">
                            {{ $item->is_active ? 'Active' : 'Inactive' }}
                        </span>
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
                        <a href="{{ route('admin.prescription-items.edit', $item->id) }}" class="text-blue-600 hover:text-blue-900 mr-3">Edit</a>
                        <form action="{{ route('admin.prescription-items.destroy', $item->id) }}" method="POST" class="inline" onsubmit="return confirm('Are you sure you want to delete this item?');">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="text-red-600 hover:text-red-900">Delete</button>
                        </form>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="4" class="px-6 py-4 text-center text-sm text-gray-500">
                        No items found. <a href="{{ route('admin.prescription-items.create', ['type' => $type]) }}" class="text-blue-600 hover:underline">Create one now</a>.
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>
@endsection

