@extends('layouts.admin')

@section('title', 'Add New Shipping Method')

@section('content')
<div class="max-w-[1200px] mx-auto">
    <!-- Header -->
    <div class="flex flex-col md:flex-row md:items-center justify-between gap-8 mb-12">
        <div>
            <div class="flex items-center gap-3 mb-2">
                <span class="px-3 py-1 bg-brand/10 text-brand text-[10px] font-bold uppercase tracking-wider rounded-full">Logistics</span>
                <span class="w-1 h-1 rounded-full bg-gray-300"></span>
                <span class="text-[10px] font-bold text-gray-400 uppercase tracking-wider">Shipping Method</span>
            </div>
            <h1 class="text-3xl font-black text-gray-900 tracking-tight">Add New <span class="text-brand">Method</span></h1>
            <p class="text-gray-500 text-sm font-medium mt-1">Create a new shipping option for your customers.</p>
        </div>
        <div class="flex items-center gap-4">
            <a href="{{ route('admin.delivery-types.index') }}" class="px-6 py-3 bg-white border border-gray-200 rounded-xl text-xs font-bold text-gray-500 hover:text-gray-900 hover:border-gray-300 transition-all flex items-center gap-2">
                <i class="fas fa-chevron-left text-[10px]"></i>
                Back to List
            </a>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-10">
        <!-- Form Section -->
        <div class="lg:col-span-2 space-y-8">
            <form action="{{ route('admin.delivery-types.store') }}" method="POST" id="delivery-form" class="space-y-8">
                @csrf
                
                <!-- Main Configuration -->
                <div class="bg-white rounded-2xl p-6 border border-gray-200 shadow-sm">

                    <div class="relative">
                        <div class="mb-6">
                            <h3 class="text-lg font-semibold text-gray-900">Method details</h3>
                            <p class="text-sm text-gray-500">Configure name, cost and time</p>
                        </div>

                        <div class="space-y-8">
                            <!-- Name -->
                            <div class="space-y-3">
                                <label for="name" class="text-sm font-medium text-gray-700">Method name</label>
                                <div class="relative">
                                    <input type="text" name="name" id="name" value="{{ old('name') }}" required
                                        class="w-full bg-white border border-gray-200 rounded-lg px-4 py-2.5 text-gray-900 placeholder:text-gray-400 focus:border-brand focus:ring-2 focus:ring-brand/20 transition"
                                        placeholder="e.g. Standard Delivery">
                                </div>
                                @error('name') <p class="text-xs text-red-600 ml-1">{{ $message }}</p> @enderror
                            </div>

                            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                                <!-- Cost -->
                                <div class="space-y-3">
                                    <label for="cost" class="text-sm font-medium text-gray-700">Shipping cost</label>
                                    <div class="relative">
                                        <input type="number" name="cost" id="cost" step="0.01" min="0" value="{{ old('cost') }}" required
                                            class="w-full bg-white border border-gray-200 rounded-lg px-4 py-2.5 text-gray-900 placeholder:text-gray-400 focus:border-brand focus:ring-2 focus:ring-brand/20 transition"
                                            placeholder="0.00">
                                    </div>
                                    @error('cost') <p class="text-xs text-red-600 ml-1">{{ $message }}</p> @enderror
                                </div>

                                <!-- Time -->
                                <div class="space-y-3">
                                    <label for="estimated_time" class="text-sm font-medium text-gray-700">Estimated time</label>
                                    <div class="relative">
                                        <input type="text" name="estimated_time" id="estimated_time" value="{{ old('estimated_time') }}"
                                            class="w-full bg-white border border-gray-200 rounded-lg px-4 py-2.5 text-gray-900 placeholder:text-gray-400 focus:border-brand focus:ring-2 focus:ring-brand/20 transition"
                                            placeholder="e.g. 3-5 business days">
                                    </div>
                                    @error('estimated_time') <p class="text-xs text-red-600 ml-1">{{ $message }}</p> @enderror
                                </div>
                            </div>

                            <!-- Description -->
                            <div class="space-y-3">
                                <label for="description" class="text-sm font-medium text-gray-700">Description</label>
                                <div class="relative">
                                    <textarea name="description" id="description" rows="4"
                                        class="w-full bg-white border border-gray-200 rounded-lg px-4 py-2.5 text-gray-900 placeholder:text-gray-400 focus:border-brand focus:ring-2 focus:ring-brand/20 transition resize-none"
                                        placeholder="Add more details about this shipping method...">{{ old('description') }}</textarea>
                                </div>
                                @error('description') <p class="text-xs text-red-600 ml-1">{{ $message }}</p> @enderror
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Status Card -->
                <div class="p-4 bg-gray-50 rounded-xl border border-gray-200 flex items-center justify-between">
                    <div>
                        <p class="text-sm font-medium text-gray-900">Status</p>
                        <p class="text-xs text-gray-500">Show at checkout</p>
                    </div>
                    <label class="relative inline-flex items-center cursor-pointer">
                        <input type="checkbox" name="is_active" value="1" class="sr-only peer" checked>
                        <div class="w-12 h-7 bg-gray-200 rounded-full peer peer-checked:after:translate-x-5 after:content-[''] after:absolute after:top-[3px] after:left-[3px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-brand shadow-inner"></div>
                    </label>
                </div>

                <!-- Actions -->
                <div class="flex items-center justify-end gap-4 pt-2">
                    <a href="{{ route('admin.delivery-types.index') }}" class="inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-gray-200 text-gray-700 hover:bg-gray-50 transition">
                        Discard
                    </a>
                    <button type="submit" class="inline-flex items-center gap-2 btn-brand text-white px-6 py-3 rounded-lg font-medium">
                        Save method
                    </button>
                </div>
            </form>
        </div>

        <!-- Sidebar Info -->
        <div class="space-y-8">
            <div class="bg-white rounded-2xl p-6 border border-gray-200 shadow-sm">
                <h3 class="text-sm font-semibold text-gray-900 mb-4">Quick tips</h3>
                <div class="space-y-6">
                    <div class="flex gap-4">
                        <div class="w-10 h-10 bg-brand/10 rounded-xl flex items-center justify-center text-brand flex-shrink-0">
                            <i class="fas fa-lightbulb text-sm"></i>
                        </div>
                        <p class="text-xs text-gray-600 leading-relaxed">Use clear names like "Standard" or "Express" so customers know what they're choosing.</p>
                    </div>
                    <div class="flex gap-4">
                        <div class="w-10 h-10 bg-blue-50 rounded-xl flex items-center justify-center text-blue-500 flex-shrink-0">
                            <i class="fas fa-clock text-sm"></i>
                        </div>
                        <p class="text-xs text-gray-600 leading-relaxed">Setting accurate delivery times helps manage customer expectations.</p>
                    </div>
                </div>
            </div>

            <div class="bg-gray-50 rounded-2xl p-6 border border-gray-200">
                <h3 class="text-sm font-semibold text-gray-900 mb-4">Active methods</h3>
                <div class="space-y-4">
                    @php
                        $activeMethods = \App\Models\DeliveryType::where('is_active', true)->limit(5)->get();
                    @endphp
                    @forelse($activeMethods as $method)
                    <div class="flex items-center justify-between p-4 bg-white rounded-xl border border-gray-200 shadow-sm">
                        <div>
                            <p class="text-sm font-medium text-gray-900">{{ $method->name }}</p>
                            <p class="text-xs text-gray-500 mt-0.5">{{ number_format($method->cost, 2) }} {{ $currencySymbol ?? '$' }}</p>
                        </div>
                        <span class="w-2 h-2 rounded-full bg-brand"></span>
                    </div>
                    @empty
                    <p class="text-xs text-gray-500 text-center py-4">No active methods</p>
                    @endforelse
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
