@extends('layouts.app')

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

@section('content')
    <div class="mb-4 d-flex align-items-center gap-3">
        <a href="{{ route('companies.index') }}" class="btn btn-light btn-sm rounded-circle"><i class="bi bi-arrow-left"></i></a>
        <div>
            <h4 class="mb-0 fw-bold">Update Profile: {{ $company->name }}</h4>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-0">
                    <li class="breadcrumb-item"><a href="{{ url('/') }}">Dashboard</a></li>
                    <li class="breadcrumb-item"><a href="{{ route('companies.index') }}">Companies</a></li>
                    <li class="breadcrumb-item active">Edit Entity</li>
                </ol>
            </nav>
        </div>
    </div>

    <div class="row justify-content-center">
        <div class="col-lg-7">
            <div class="card border-0 shadow-sm overflow-hidden">
                <div class="card-header bg-dark text-white py-3 px-4 border-0">
                    <h5 class="mb-0 fw-bold">Administrative Settings</h5>
                    <p class="mb-0 small opacity-75">Modify the core details of this organization.</p>
                </div>
                <div class="card-body p-4 p-xl-5">
                    <form action="{{ route('companies.update', $company->id) }}" method="POST">
                        @csrf
                        @method('PUT')

                        <div class="mb-5 text-center">
                            <div class="mx-auto position-relative mb-3" style="width: 100px;">
                                <div class="avatar bg-primary-subtle border border-primary-subtle rounded-circle d-flex align-items-center justify-content-center overflow-hidden"
                                    style="width: 100px; height: 100px;">
                                    <span class="h1 mb-0 text-primary fw-bold">{{ substr($company->name, 0, 1) }}</span>
                                </div>
                                <button type="button" class="btn btn-primary btn-sm rounded-circle position-absolute bottom-0 end-0 shadow-sm" style="width: 32px; height: 32px; padding: 0;">
                                    <i class="bi bi-pencil-square"></i>
                                </button>
                            </div>
                            <h6 class="fw-bold mb-0">Entity Branding</h6>
                        </div>

                        <div class="row g-4">
                            <div class="col-12">
                                <label class="form-label fw-bold small text-muted text-uppercase ls-1">Legal Company Name <span class="text-danger">*</span></label>
                                <input type="text" name="name" class="form-control form-control-lg @error('name') is-invalid @enderror"
                                    value="{{ old('name', $company->name) }}" required>
                                @error('name')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-6">
                                <label class="form-label fw-bold small text-muted text-uppercase ls-1">Registered VAT Number</label>
                                <div class="input-group">
                                    <span class="input-group-text bg-light"><i class="bi bi-hash"></i></span>
                                    <input type="text" name="vat_number" class="form-control"
                                        value="{{ old('vat_number', $company->vat_number) }}">
                                </div>
                            </div>

                            <div class="col-md-6">
                                <label class="form-label fw-bold small text-muted text-uppercase ls-1">Enterprise Status <span class="text-danger">*</span></label>
                                <select name="status" class="form-select @error('status') is-invalid @enderror" required>
                                    <option value="active" {{ old('status', $company->status) == 'active' ? 'selected' : '' }}>Active Operational</option>
                                    <option value="inactive" {{ old('status', $company->status) == 'inactive' ? 'selected' : '' }}>Inactive / Suspended</option>
                                </select>
                                @error('status')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-12">
                                <label class="form-label fw-bold small text-muted text-uppercase ls-1">Headquarters Address</label>
                                <textarea name="address" class="form-control"
                                    rows="4">{{ old('address', $company->address) }}</textarea>
                            </div>
                        </div>

                        <div class="mt-5 d-flex gap-3">
                            <button type="submit" class="btn btn-primary btn-lg flex-grow-1 fw-bold shadow-sm">
                                <i class="bi bi-save me-2"></i> Save Changes
                            </button>
                            <a href="{{ route('companies.index') }}" class="btn btn-light btn-lg px-4 border">Cancel</a>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Danger Zone -->
            <div class="card border-danger border-opacity-25 bg-danger bg-opacity-10 mt-4">
                <div class="card-body d-flex justify-content-between align-items-center">
                    <div>
                        <h6 class="mb-0 fw-bold">Delete this Entity</h6>
                        <small class="text-muted">This will permanently remove the company and all its data.</small>
                    </div>
                    <form action="{{ route('companies.destroy', $company->id) }}" method="POST" onsubmit="return confirm('CRITICAL: This action cannot be undone. Are you sure?')">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn btn-outline-danger btn-sm px-3">Proceed to Delete</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <style>
        .ls-1 { letter-spacing: 0.05rem; }
    </style>
@endsection
