@extends('layouts.seller')

@section('title', 'Company Profile')

@section('content')
@section('content')
<div class="page-header">
    <div>
        <h4 class="page-title">Company Profile</h4>
        <p class="text-muted mb-0">Manage your company details and documents</p>
    </div>
    @if($seller->slug)
        <a href="{{ route('seller.public.profile', $seller->slug) }}" target="_blank" class="btn btn-outline-primary shadow-sm">
            <i class="bi bi-box-arrow-up-right me-1"></i> View Public Profile
        </a>
    @endif
</div>

<div class="row g-4">
    <!-- Profile Form -->
    <div class="col-lg-8">
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-white py-3 border-bottom">
                <h6 class="fw-bold mb-0 text-primary"><i class="bi bi-building me-2"></i>Company Details</h6>
            </div>
            <div class="card-body p-4">
                <form action="{{ route('seller.profile.update') }}" method="POST" enctype="multipart/form-data">
                    @csrf
                    <div class="row g-4">
                        <div class="col-md-6">
                            <label class="form-label fw-bold">Company Name <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" name="company_name" 
                                   value="{{ old('company_name', $seller->company_name) }}" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">MOQ</label>
                            <div class="input-group">
                                <span class="input-group-text bg-light"><i class="bi bi-box-seam"></i></span>
                                <input type="text" class="form-control bg-light" readonly
                                       value="{{ $seller->moq_quantity }} {{ $seller->unit ? $seller->unit->code : '' }}">
                            </div>
                            <small class="text-muted"><i class="bi bi-lock-fill"></i> Contact Admin to change</small>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">GST Number</label>
                            <input type="text" class="form-control" name="gst" value="{{ old('gst', $seller->gst) }}">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">GST Document</label>
                            <div class="d-grid">
                                <a href="{{ route('seller.verification.index') }}" class="btn btn-outline-primary">
                                    <i class="bi bi-shield-check me-2"></i>Manage KYC Documents
                                </a>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">IEC Code</label>
                            <input type="text" class="form-control" name="iec" value="{{ old('iec', $seller->iec) }}">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold">IEC Document</label>
                            <div class="d-grid">
                                <a href="{{ route('seller.verification.index') }}" class="btn btn-outline-primary">
                                    <i class="bi bi-file-earmark-text me-2"></i>Manage KYC Documents
                                </a>
                            </div>
                        </div>
                        <div class="col-12">
                            <label class="form-label fw-bold">Company Logo</label>
                            <div class="p-4 border border-dashed rounded-3 bg-light text-center">
                                <input type="file" class="form-control mb-2" name="logo" accept="image/*">
                                <small class="text-muted">Recommended size: 500x500px. Max: 2MB</small>
                            </div>
                        </div>
                    </div>
                    <div class="mt-4 text-end">
                        <button type="submit" class="btn btn-primary-gradient px-5 py-2 fw-bold">
                            <i class="bi bi-check-lg me-1"></i> Update Profile
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Danger Zone -->
    <div class="col-lg-8">
        <div class="card border-danger shadow-sm">
            <div class="card-header bg-danger bg-opacity-10 py-3 border-bottom border-danger-subtle">
                <h6 class="fw-bold mb-0 text-danger"><i class="bi bi-exclamation-triangle me-2"></i>Danger Zone</h6>
            </div>
            <div class="card-body p-4">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h6 class="fw-bold mb-1">Delete Account</h6>
                        <p class="text-muted small mb-0">
                            Once you delete your account, there is no going back. Please be certain.
                        </p>
                    </div>
                    <button type="button" class="btn btn-outline-danger" data-bs-toggle="modal" data-bs-target="#deleteAccountModal">
                        Delete Account
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Delete Account Modal -->
    <div class="modal fade" id="deleteAccountModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header border-0 pb-0">
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body text-center pb-4">
                    <div class="text-danger mb-3">
                        <i class="bi bi-exclamation-circle" style="font-size: 3rem;"></i>
                    </div>
                    <h4 class="fw-bold mb-2">Are you sure?</h4>
                    <p class="text-muted mb-4">
                        Do you really want to delete your account? This process cannot be undone.
                    </p>
                    <div class="d-flex justify-content-center gap-2">
                        <button type="button" class="btn btn-light px-4" data-bs-dismiss="modal">Cancel</button>
                        <form action="{{ route('seller.profile.destroy') }}" method="POST">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="btn btn-danger px-4">Delete My Account</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Sidebar Info -->
    <div class="col-lg-4">
        <div class="card border-0 shadow-sm mb-4">
            <div class="card-body text-center py-5">
                @if($seller->logo)
                    <img src="{{ asset('storage/' . $seller->logo) }}" class="rounded-circle mb-3 shadow-sm border" 
                         style="width: 120px; height: 120px; object-fit: cover;">
                @else
                    <div class="bg-primary-subtle text-primary rounded-circle d-inline-flex align-items-center justify-content-center mb-3 shadow-sm" 
                         style="width: 120px; height: 120px; font-size: 3rem; font-weight: bold;">
                        {{ substr($seller->company_name, 0, 1) }}
                    </div>
                @endif
                <h4 class="fw-bold mb-1">{{ $seller->company_name }}</h4>
                <p class="text-muted mb-2">{{ $seller->category->name ?? 'Uncategorized' }}</p>

                <!-- Plan Badge -->
                @if($seller->subscription && $seller->subscription->plan)
                    <div class="mb-3">
                        @if(Str::contains(strtolower($seller->subscription->plan->name), 'silver'))
                            <span class="badge bg-secondary text-white border border-secondary px-3 py-1 rounded-pill">
                                <i class="bi bi-star-fill text-warning me-1"></i> Silver Member
                            </span>
                        @elseif(Str::contains(strtolower($seller->subscription->plan->name), 'basic'))
                            <span class="badge bg-primary text-white border border-primary px-3 py-1 rounded-pill">
                                Basic Member
                            </span>
                        @else
                             <span class="badge bg-dark text-white border border-dark px-3 py-1 rounded-pill">
                                Premium Member
                            </span>
                        @endif
                    </div>
                @else
                     <span class="badge bg-light text-muted border px-3 py-1 rounded-pill mb-3">Free Member</span>
                @endif
                
                <div class="d-flex justify-content-around border-top pt-4">
                    <div class="text-center px-3">
                        <h4 class="fw-bold mb-0 text-primary">{{ $seller->products->count() }}</h4>
                        <small class="text-muted text-uppercase" style="font-size: 0.75rem; letter-spacing: 1px;">Products</small>
                    </div>
                    <div class="vr"></div>
                    <div class="text-center px-3">
                        <h4 class="fw-bold mb-0 text-success">{{ $seller->inquiries->count() }}</h4>
                        <small class="text-muted text-uppercase" style="font-size: 0.75rem; letter-spacing: 1px;">Inquiries</small>
                    </div>
                </div>

                <!-- MOQ Info -->
                <div class="mt-4 text-start bg-light p-3 rounded small">
                    <div class="d-flex justify-content-between mb-2">
                        <span class="text-muted">Platform MOQ:</span>
                        <span class="fw-bold text-dark">10 - 150 Units</span>
                    </div>
                    <div class="d-flex justify-content-between">
                        <span class="text-muted">Product MOQ:</span>
                        <div class="text-end">
                             @if($seller->moq_quantity)
                                <span class="fw-bold text-dark">{{ $seller->moq_quantity }} (Custom)</span>
                             @else
                                <span class="text-muted fst-italic">Not Set</span>
                             @endif
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="card-header bg-white py-3 border-bottom">
                 <h6 class="fw-bold mb-0 text-dark">
                    <i class="bi bi-shield-check me-2 text-primary"></i>KYC Status
                </h6>
            </div>
            <div class="card-body p-0">
                <div class="list-group list-group-flush">
                    <div class="list-group-item d-flex justify-content-between align-items-center py-3">
                        <span class="fw-medium">Document Status</span>
                        @if($seller->kyc_status === 'verified')
                             <span class="badge bg-success-subtle text-success rounded-pill px-3">
                                <i class="bi bi-check-circle-fill me-1"></i> Verified
                            </span>
                        @elseif($seller->kyc_status === 'submitted')
                            <span class="badge bg-info-subtle text-info rounded-pill px-3">
                                <i class="bi bi-file-earmark-check me-1"></i> KYC Submitted
                            </span>
                        @else
                             <span class="badge bg-secondary-subtle text-secondary rounded-pill px-3">
                                <i class="bi bi-hourglass me-1"></i> Pending
                            </span>
                        @endif
                    </div>
                     <div class="list-group-item bg-light text-center py-2">
                        <small class="text-muted">
                            <i class="bi bi-info-circle me-1"></i>
                            KYC Verified status is awarded after document approval.
                        </small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
@endsection
