@extends('layouts.admin')

@section('page_title', 'Create New Project')

@section('content')
    <div class="row mb-4">
        <div class="col-lg-10 mx-auto">
            <div class="d-flex align-items-center gap-3 mb-4">
                <a href="{{ route('admin.projects.index') }}"
                    class="btn btn-light rounded-circle p-2 d-flex align-items-center justify-content-center border"
                    style="width: 40px; height: 40px;">
                    <span class="material-symbols-outlined fs-5 text-secondary">arrow_back</span>
                </a>
                <div>
                    <h3 class="fw-extrabold tracking-tight mb-0" style="font-weight: 800; font-size: 1.5rem;">New Project</h3>
                    <p class="text-secondary opacity-75 mb-0" style="font-size: 0.8125rem;">Set up a new workspace for your
                        team.</p>
                </div>
            </div>

            <div class="card border-0 shadow-sm"
                style="border-radius: 1rem; border: 1px solid rgba(0,0,0,0.05) !important;">
                <div class="card-body p-4 p-md-5">
                    <form action="{{ route('admin.projects.store') }}" method="POST">
                        @csrf

                        <div class="row g-4 mb-4">
                            <div class="col-md-8">
                                <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                    style="font-size: 0.65rem; letter-spacing: 0.05rem;">Project Name</label>
                                <input type="text" name="name"
                                    class="form-control border-0 bg-light py-2.5 rounded-3 fw-medium text-dark @error('name') is-invalid @enderror"
                                    value="{{ old('name') }}" placeholder="Enter project title" required>
                                @error('name')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="col-md-4">
                                <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                    style="font-size: 0.65rem; letter-spacing: 0.05rem;">Department</label>
                                <select name="department_id"
                                    class="form-select border-0 bg-light py-2.5 rounded-3 fw-medium @error('department_id') is-invalid @enderror"
                                    required>
                                    <option value="" disabled selected>Select Department</option>
                                    @foreach ($departments as $dept)
                                        <option value="{{ $dept->id }}"
                                            {{ old('department_id') == $dept->id ? 'selected' : '' }}>{{ $dept->name }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('department_id')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <div class="mb-4">
                            <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                style="font-size: 0.65rem; letter-spacing: 0.05rem;">Description / Guidelines</label>
                            <textarea name="description"
                                class="form-control border-0 bg-light py-3 rounded-3 @error('description') is-invalid @enderror" rows="5"
                                placeholder="Brief project overview...">{{ old('description') }}</textarea>
                            @error('description')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="row g-4 mb-5">
                            <div class="col-md-4">
                                <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                    style="font-size: 0.65rem; letter-spacing: 0.05rem;">Start Date</label>
                                <div class="input-group">
                                    <span class="input-group-text bg-light border-0 ps-3 pe-2"><span
                                            class="material-symbols-outlined text-secondary"
                                            style="font-size: 1.1rem;">calendar_month</span></span>
                                    <input type="date" name="start_date"
                                        class="form-control border-0 bg-light py-2.5 rounded-end-3"
                                        value="{{ old('start_date') }}" required>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                    style="font-size: 0.65rem; letter-spacing: 0.05rem;">Due Date (Optional)</label>
                                <div class="input-group">
                                    <span class="input-group-text bg-light border-0 ps-3 pe-2"><span
                                            class="material-symbols-outlined text-secondary"
                                            style="font-size: 1.1rem;">event</span></span>
                                    <input type="date" name="end_date"
                                        class="form-control border-0 bg-light py-2.5 rounded-end-3"
                                        value="{{ old('end_date') }}">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                    style="font-size: 0.65rem; letter-spacing: 0.05rem;">Initial Status</label>
                                <select name="status" class="form-select border-0 bg-light py-2.5 rounded-3 fw-medium"
                                    required>
                                    <option value="active" {{ old('status') == 'active' ? 'selected' : '' }}>Active - In
                                        Progress</option>
                                    <option value="on_hold" {{ old('status') == 'on_hold' ? 'selected' : '' }}>On Hold
                                    </option>
                                    <option value="completed" {{ old('status') == 'completed' ? 'selected' : '' }}>
                                        Completed</option>
                                    <option value="cancelled" {{ old('status') == 'cancelled' ? 'selected' : '' }}>
                                        Cancelled</option>
                                </select>
                            </div>
                        </div>

                        <div class="d-flex justify-content-end gap-3 pt-4 border-top">
                            <a href="{{ route('admin.projects.index') }}"
                                class="btn btn-light px-4 py-2.5 fw-bold border text-secondary rounded-3">Cancel</a>
                            <button type="submit"
                                class="btn btn-primary px-4 py-2.5 fw-bold rounded-3 shadow-sm d-flex align-items-center gap-2">
                                <span class="material-symbols-outlined fs-5">rocket_launch</span> Launch Project
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('styles')
    <style>
        .tracking-tight {
            letter-spacing: -0.015rem;
        }

        .form-control:focus,
        .form-select:focus {
            background-color: #f8fafc !important;
            box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.1) !important;
        }
    </style>
@endpush
