@extends('layouts.app')

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

@push('styles')
<style>
    /* Page header */
    .page-header {
        margin-bottom: 32px;
    }

    .page-title {
        display: flex;
        align-items: center;
        gap: 12px;
        color: #ffffff;
        font-size: 28px;
        font-weight: 600;
        margin-bottom: 8px;
    }

    .page-title svg {
        width: 32px;
        height: 32px;
    }

    .page-subtitle {
        color: rgba(255, 255, 255, 0.6);
        font-size: 15px;
    }

    /* Breadcrumb */
    .glass-breadcrumb {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 16px;
        flex-wrap: wrap;
    }

    .glass-breadcrumb a {
        color: rgba(255, 255, 255, 0.6);
        text-decoration: none;
        font-size: 14px;
        transition: color 0.2s ease;
    }

    .glass-breadcrumb a:hover {
        color: #5eead4;
    }

    .glass-breadcrumb .separator {
        color: rgba(255, 255, 255, 0.4);
        font-size: 12px;
    }

    .glass-breadcrumb .current {
        color: rgba(255, 255, 255, 0.9);
        font-size: 14px;
    }

    /* Glass card */
    .glass-card {
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 16px;
        padding: 32px;
    }

    .card-title {
        display: flex;
        align-items: center;
        gap: 10px;
        color: #ffffff;
        font-size: 18px;
        font-weight: 600;
        margin: 0 0 24px 0;
        padding-bottom: 16px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .card-title svg {
        width: 22px;
        height: 22px;
    }

    /* Form styles */
    .form-row {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
        margin-bottom: 24px;
    }

    .form-group {
        margin-bottom: 24px;
    }

    .form-group.full-width {
        grid-column: 1 / -1;
    }

    .form-label {
        display: block;
        color: rgba(255, 255, 255, 0.7);
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 8px;
    }

    .form-label .required {
        color: #f87171;
        margin-left: 4px;
    }

    .glass-input {
        width: 100%;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 10px;
        color: #ffffff;
        padding: 14px 16px;
        font-size: 15px;
        transition: all 0.3s ease;
    }

    .glass-input::placeholder {
        color: rgba(255, 255, 255, 0.4);
    }

    .glass-input:focus {
        outline: none;
        border-color: #14b8a6;
        background: rgba(255, 255, 255, 0.15);
        box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
    }

    .glass-input.is-invalid {
        border-color: #f87171;
        background: rgba(239, 68, 68, 0.1);
    }

    .glass-input.is-invalid:focus {
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
    }

    .invalid-feedback {
        display: block;
        color: #f87171;
        font-size: 13px;
        margin-top: 8px;
    }

    .form-hint {
        color: rgba(255, 255, 255, 0.5);
        font-size: 13px;
        margin-top: 6px;
    }

    /* Button styles */
    .form-actions {
        display: flex;
        gap: 12px;
        justify-content: flex-end;
        margin-top: 32px;
        padding-top: 24px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .btn-gradient {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: linear-gradient(90deg, #14b8a6, #06b6d4);
        color: #ffffff;
        text-decoration: none;
        padding: 14px 28px;
        border-radius: 10px;
        font-size: 15px;
        font-weight: 600;
        transition: all 0.3s ease;
        box-shadow: 0 4px 15px rgba(20, 184, 166, 0.3);
        border: none;
        cursor: pointer;
    }

    .btn-gradient:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(20, 184, 166, 0.4);
        color: #ffffff;
    }

    .btn-gradient svg {
        width: 18px;
        height: 18px;
    }

    .btn-ghost {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: transparent;
        color: rgba(255, 255, 255, 0.8);
        text-decoration: none;
        padding: 14px 28px;
        border-radius: 10px;
        font-size: 15px;
        font-weight: 500;
        border: 1px solid rgba(255, 255, 255, 0.3);
        transition: all 0.3s ease;
        cursor: pointer;
    }

    .btn-ghost:hover {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.5);
        color: #ffffff;
    }

    .btn-ghost svg {
        width: 18px;
        height: 18px;
    }

    /* Responsive */
    @media (max-width: 768px) {
        .form-row {
            grid-template-columns: 1fr;
            gap: 0;
        }

        .form-actions {
            flex-direction: column;
        }

        .btn-gradient, .btn-ghost {
            width: 100%;
            justify-content: center;
        }

        .glass-card {
            padding: 24px;
        }
    }
</style>
@endpush

@section('content')
<!-- Breadcrumb -->
<div class="glass-breadcrumb">
    <a href="{{ route('dashboard') }}">Dashboard</a>
    <span class="separator">/</span>
    <a href="{{ route('companies.index') }}">Companies</a>
    <span class="separator">/</span>
    <a href="{{ route('companies.show', $company) }}">{{ $company->company_name }}</a>
    <span class="separator">/</span>
    <span class="current">Edit</span>
</div>

<!-- Page Header -->
<div class="page-header">
    <h1 class="page-title">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
            <path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
        </svg>
        Edit Company
    </h1>
    <p class="page-subtitle">Update the company information and statutory records</p>
</div>

<!-- Form Card -->
<div class="glass-card" style="max-width: 800px;">
    <h2 class="card-title">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <path d="M19 21V5a2 2 0 0 0-2-2H7a2 2 0 0 0-2 2v16"></path>
            <path d="M1 21h22"></path>
            <path d="M9 7h1"></path>
            <path d="M9 11h1"></path>
            <path d="M9 15h1"></path>
            <path d="M14 7h1"></path>
            <path d="M14 11h1"></path>
            <path d="M14 15h1"></path>
        </svg>
        Company Details
    </h2>

    <form action="{{ route('companies.update', $company) }}" method="POST">
        @csrf
        @method('PUT')

        @if(auth()->user()->isSuperAdmin())
            <div class="form-group">
                <label for="audit_company_id" class="form-label">
                    Audit Company / 審計公司 <span class="required">*</span>
                </label>
                <select class="glass-input @error('audit_company_id') is-invalid @enderror"
                        id="audit_company_id"
                        name="audit_company_id"
                        style="max-width: 400px;"
                        required>
                    <option value="">Select an audit company</option>
                    @foreach($auditCompanies as $auditCompany)
                        <option value="{{ $auditCompany->id }}" {{ old('audit_company_id', $company->audit_company_id) == $auditCompany->id ? 'selected' : '' }}>
                            {{ $auditCompany->name }}
                        </option>
                    @endforeach
                </select>
                @error('audit_company_id')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>
        @endif

        <div class="form-row">
            <div class="form-group">
                <label for="company_name" class="form-label">
                    Company Name / 公司名稱 <span class="required">*</span>
                </label>
                <input type="text"
                       class="glass-input @error('company_name') is-invalid @enderror"
                       id="company_name"
                       name="company_name"
                       value="{{ old('company_name', $company->company_name) }}"
                       placeholder="Enter company name"
                       required>
                @error('company_name')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="form-group">
                <label for="ci_number" class="form-label">
                    CI Number / 公司註冊證號碼 <span class="required">*</span>
                </label>
                <input type="text"
                       class="glass-input @error('ci_number') is-invalid @enderror"
                       id="ci_number"
                       name="ci_number"
                       value="{{ old('ci_number', $company->ci_number) }}"
                       placeholder="e.g., 1234567"
                       required>
                @error('ci_number')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
                <p class="form-hint">Certificate of Incorporation number</p>
            </div>
        </div>

        <div class="form-group">
            <label for="date_of_incorporation" class="form-label">
                Date of Incorporation / 成立日期 <span class="required">*</span>
            </label>
            <input type="date"
                   class="glass-input @error('date_of_incorporation') is-invalid @enderror"
                   id="date_of_incorporation"
                   name="date_of_incorporation"
                   value="{{ old('date_of_incorporation', $company->date_of_incorporation->format('Y-m-d')) }}"
                   style="max-width: 300px;"
                   required>
            @error('date_of_incorporation')
                <div class="invalid-feedback">{{ $message }}</div>
            @enderror
        </div>

        <div class="form-actions">
            <a href="{{ route('companies.show', $company) }}" class="btn-ghost">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <line x1="18" y1="6" x2="6" y2="18"></line>
                    <line x1="6" y1="6" x2="18" y2="18"></line>
                </svg>
                Cancel
            </a>
            <button type="submit" class="btn-gradient">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <polyline points="20 6 9 17 4 12"></polyline>
                </svg>
                Update Company
            </button>
        </div>
    </form>
</div>
@endsection
