@extends('admin.layouts.app')

@section('page-title', 'Add Customer')

@section('content')

<style>
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --glass-bg: #ffffff;
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 12px 48px rgba(0, 0, 0, 0.15);
    --shadow-strong: 0 20px 60px rgba(0, 0, 0, 0.2);
}

/* Enhanced Card - No Blur - Original Width */
.card {
    background: var(--glass-bg);
    border-radius: 24px;
    box-shadow: var(--shadow-strong);
    border: 1px solid #e4e6ef;
    animation: cardEntrance 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
    /* Maintaining original width */
    width: 100%;
    max-width: none;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, 
        rgba(102, 126, 234, 0.03) 0%, 
        rgba(118, 75, 162, 0.03) 50%, 
        rgba(16, 185, 129, 0.03) 100%);
    pointer-events: none;
}

@keyframes cardEntrance {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Premium Card Header */
.card-header {
    background: var(--primary-gradient);
    color: white;
    border-bottom: none;
    padding: 25px 30px;
    position: relative;
    overflow: hidden;
}

.card-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, 
        transparent 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        transparent 100%);
    animation: headerShimmer 6s infinite linear;
    transform: rotate(45deg);
}

@keyframes headerShimmer {
    0% { transform: translateX(-100%) rotate(45deg); }
    100% { transform: translateX(100%) rotate(45deg); }
}

.card-header h4 {
    margin: 0;
    font-weight: 800;
    font-size: 1.5rem;
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card-header h4::before {
    content: '✨';
    font-size: 1.3rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.card-body {
    padding: 30px;
    background: #f8fafc;
    position: relative;
}

/* World-Class Form Elements - No Blur */
.form-label {
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-label::before {
    content: '';
    width: 3px;
    height: 14px;
    background: var(--primary-gradient);
    border-radius: 2px;
    display: inline-block;
}

.form-control, .form-select {
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    position: relative;
}

.form-control:focus, .form-select:focus {
    border-color: #667eea;
    box-shadow: 
        0 0 0 3px rgba(102, 126, 234, 0.15),
        0 6px 20px rgba(102, 126, 234, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    background: #ffffff;
    transform: translateY(-2px);
}

.form-control:hover, .form-select:hover {
    border-color: #cbd5e1;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* Enhanced Grid System - Original Layout */
.row.g-3 {
    margin: -12px;
}

.row.g-3 > [class*="col-"] {
    padding: 12px;
    animation: formElementEntrance 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

@keyframes formElementEntrance {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Staggered Animation Delays */
.row.g-3 > [class*="col-"]:nth-child(1) { animation-delay: 0.1s; }
.row.g-3 > [class*="col-"]:nth-child(2) { animation-delay: 0.15s; }
.row.g-3 > [class*="col-"]:nth-child(3) { animation-delay: 0.2s; }
.row.g-3 > [class*="col-"]:nth-child(4) { animation-delay: 0.25s; }
.row.g-3 > [class*="col-"]:nth-child(5) { animation-delay: 0.3s; }
.row.g-3 > [class*="col-"]:nth-child(6) { animation-delay: 0.35s; }

/* Premium Textarea */
textarea.form-control {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
    background: #ffffff;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

textarea.form-control:focus {
    transform: translateY(-2px);
    box-shadow: 
        0 0 0 3px rgba(102, 126, 234, 0.15),
        0 8px 24px rgba(102, 126, 234, 0.15);
}

/* World-Class Button Design */
.btn-success {
    background: var(--success-gradient);
    border: none;
    padding: 14px 35px;
    border-radius: 12px;
    color: white;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-medium);
    position: relative;
    overflow: hidden;
}

.btn-success::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.3), 
        transparent);
    transition: left 0.5s ease;
}

.btn-success:hover::before {
    left: 100%;
}

.btn-success:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 12px 30px rgba(16, 185, 129, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.1);
}

.btn-success:active {
    transform: translateY(-1px);
    transition: all 0.1s ease;
}

/* Enhanced Select Styling */
.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23667eea' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 16px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 45px;
    cursor: pointer;
    appearance: none;
}

/* Loading Animation */
.btn-success.loading {
    pointer-events: none;
    padding-right: 50px;
}

.btn-success.loading::after {
    content: '';
    position: absolute;
    right: 16px;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Micro-interactions for Enhanced UX */
.form-control:valid {
    border-left: 2px solid #10b981;
}

.form-control:invalid:not(:focus):not(:placeholder-shown) {
    border-left: 2px solid #ef4444;
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* Secondary Button */
.btn-secondary {
    background: #64748b;
    border: none;
    padding: 14px 30px;
    border-radius: 12px;
    color: white;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-soft);
}

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

/* Required Field Indicator */
.required-field::after {
    content: '*';
    color: #ef4444;
    margin-left: 4px;
    font-weight: 800;
}

/* Success Animation */
@keyframes successPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

.success-animation {
    animation: successPulse 0.5s ease-in-out;
}

/* Input Hints */
.input-hint {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.input-hint::before {
    content: '💡';
    font-size: 0.7rem;
}

/* Performance optimized animations */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
</style>

<div class="container py-4">
    <!-- Maintaining original container structure -->
    <div class="card shadow-sm" style="border: none; background: transparent; box-shadow: none !important;">
        <div class="card" style="margin: 0;">
            <!-- Premium Card Header -->
            <div class="card-header">
                <h4>
                    <i class="bi bi-person-plus-fill me-2"></i>
                    Add New Customer
                </h4>
            </div>

            <!-- Card Body - Original Structure -->
            <div class="card-body">
                <form action="{{ route('admin.customers.store') }}" method="POST" id="customerForm">
                    @csrf

                    <div class="row g-3">
                        <!-- Customer Name -->
                        <div class="col-md-6">
                            <label class="form-label required-field">Customer Name</label>
                            <input type="text" 
                                   name="customer_name" 
                                   class="form-control" 
                                   placeholder="Enter full name"
                                   required
                                   pattern="[A-Za-z\s]{2,}">
                            <div class="input-hint">Minimum 2 characters, letters only</div>
                        </div>

                        <!-- Company Name -->
                        <div class="col-md-6">
                            <label class="form-label">Company Name</label>
                            <input type="text" 
                                   name="company_name" 
                                   class="form-control" 
                                   placeholder="Enter company name">
                        </div>

                        <!-- Designation -->
                        <div class="col-md-6">
                            <label class="form-label">Designation</label>
                            <input type="text" 
                                   name="designation" 
                                   class="form-control" 
                                   placeholder="Enter job title">
                        </div>

                        <!-- Email -->
                        <div class="col-md-6">
                            <label class="form-label required-field">Email Address</label>
                            <input type="email" 
                                   name="email" 
                                   class="form-control" 
                                   placeholder="Enter email address"
                                   required
                                   pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
                            <div class="input-hint">Valid email format required</div>
                        </div>

                        <!-- Mobile -->
                        <div class="col-md-6">
                            <label class="form-label required-field">Mobile Number</label>
                            <input type="tel" 
                                   name="mobile_no" 
                                   class="form-control" 
                                   placeholder="Enter mobile number"
                                   required
                                   pattern="[0-9]{10}">
                            <div class="input-hint">10 digits without spaces</div>
                        </div>

                        <!-- Pincode -->
                        <div class="col-md-6">
                            <label class="form-label">Pincode</label>
                            <input type="text" 
                                   name="pincode" 
                                   class="form-control" 
                                   placeholder="Enter pincode"
                                   pattern="[0-9]{6}">
                            <div class="input-hint">6-digit pincode</div>
                        </div>

                        <!-- Address -->
                        <div class="col-12">
                            <label class="form-label">Address</label>
                            <textarea name="address" 
                                      class="form-control" 
                                      rows="3" 
                                      placeholder="Enter complete address"></textarea>
                        </div>

                        <!-- Customer Type -->
                        <div class="col-md-6">
                            <label class="form-label required-field">Customer Type</label>
                            <select name="customer_type" class="form-select" required>
                                <option value="regular">Regular</option>
                                <option value="premium">Premium</option>
                            </select>
                            <div class="input-hint">Premium customers get special benefits</div>
                        </div>

                        <!-- Status -->
                        <div class="col-md-6">
                            <label class="form-label required-field">Status</label>
                            <select name="status" class="form-select" required>
                                <option value="active">Active</option>
                                <option value="inactive">Inactive</option>
                            </select>
                            <div class="input-hint">Active customers can place orders</div>
                        </div>
                    </div>

                    <!-- Form Actions - Original Layout -->
                    <div class="text-end mt-4">
                        <a href="{{ route('admin.customers.index') }}" class="btn btn-secondary me-3">
                            <i class="bi bi-arrow-left me-2"></i>
                            Cancel
                        </a>
                        <button type="submit" class="btn-success" id="submitBtn">
                            <i class="bi bi-person-plus me-2"></i>
                            Create Customer
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const form = document.getElementById('customerForm');
    const submitBtn = document.getElementById('submitBtn');

    form.addEventListener('submit', function(e) {
        // Add loading state
        submitBtn.classList.add('loading');
        submitBtn.innerHTML = '<i class="bi bi-hourglass-split me-2"></i>Creating...';
        
        // Simulate form processing
        setTimeout(() => {
            submitBtn.classList.remove('loading');
            submitBtn.classList.add('success-animation');
            submitBtn.innerHTML = '<i class="bi bi-check-circle me-2"></i>Customer Created!';
            
            setTimeout(() => {
                submitBtn.classList.remove('success-animation');
                submitBtn.innerHTML = '<i class="bi bi-person-plus me-2"></i>Create Customer';
            }, 1500);
        }, 1000);
    });

    // Real-time validation
    const inputs = form.querySelectorAll('input[required]');
    inputs.forEach(input => {
        input.addEventListener('blur', function() {
            if (this.value && this.checkValidity()) {
                this.style.borderLeft = '2px solid #10b981';
            } else if (this.value && !this.checkValidity()) {
                this.style.borderLeft = '2px solid #ef4444';
            } else {
                this.style.borderLeft = '';
            }
        });
    });

    // Enhanced input interactions
    const formControls = form.querySelectorAll('.form-control, .form-select');
    formControls.forEach(control => {
        control.addEventListener('focus', function() {
            this.style.transform = 'translateY(-2px)';
        });
        
        control.addEventListener('blur', function() {
            this.style.transform = 'translateY(0)';
        });
    });
});
</script>

@endsection