@extends('layouts.admin')

@section('page_title', 'Create Announcement')

@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.announcements.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 Announcement
                    </h3>
                    <p class="text-secondary opacity-75 mb-0" style="font-size: 0.8125rem;">Broadcast a message to all
                        employees.</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.announcements.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;">Announcement Title</label>
                                <input type="text" name="title"
                                    class="form-control border-0 bg-light py-2.5 rounded-3 fw-medium text-dark @error('title') is-invalid @enderror"
                                    value="{{ old('title') }}" placeholder="Enter an engaging title..." required>
                                @error('title')
                                    <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;">Type</label>
                                <select name="type" class="form-select border-0 bg-light py-2.5 rounded-3 fw-medium"
                                    required>
                                    <option value="general" {{ old('type') == 'general' ? 'selected' : '' }}>General
                                    </option>
                                    <option value="policy" {{ old('type') == 'policy' ? 'selected' : '' }}>Policy Update
                                    </option>
                                    <option value="event" {{ old('type') == 'event' ? 'selected' : '' }}>Company Event
                                    </option>
                                    <option value="holiday" {{ old('type') == 'holiday' ? 'selected' : '' }}>Holiday
                                    </option>
                                </select>
                            </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;">Message Content</label>
                            <textarea name="content" class="form-control border-0 bg-light py-3 rounded-3 @error('content') is-invalid @enderror"
                                rows="6" placeholder="Write the details of your announcement here..." required>{{ old('content') }}</textarea>
                            @error('content')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="row g-4 mb-5">
                            <div class="col-md-6">
                                <label class="text-uppercase fw-bold text-secondary mb-2 d-block"
                                    style="font-size: 0.65rem; letter-spacing: 0.05rem;">Expiry 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;">calendar_today</span></span>
                                    <input type="date" name="expires_at"
                                        class="form-control border-0 bg-light py-2.5 rounded-end-3"
                                        value="{{ old('expires_at') }}">
                                </div>
                                <p class="text-secondary opacity-75 mt-2 mb-0" style="font-size: 0.75rem;">Leave empty if
                                    message should remain indefinitely.</p>
                            </div>
                            <div class="col-md-6 d-flex flex-column justify-content-center">
                                <div
                                    class="form-check form-switch ps-0 m-0 p-4 border rounded-3 bg-light bg-opacity-50 d-flex align-items-center justify-content-between">
                                    <div>
                                        <label class="form-check-label fw-bold text-dark d-block mb-1" for="isActive"
                                            style="font-size: 0.875rem;">Publish Immediately</label>
                                        <span class="text-secondary" style="font-size: 0.75rem;">Make this visible to all
                                            employees right away.</span>
                                    </div>
                                    <input class="form-check-input flex-shrink-0 m-0 ms-3 shadow-none" type="checkbox"
                                        name="is_active" id="isActive" value="1"
                                        {{ old('is_active', true) ? 'checked' : '' }}
                                        style="width: 2.5em; height: 1.25em; cursor: pointer;">
                                </div>
                            </div>
                        </div>

                        <div class="d-flex justify-content-end gap-3 pt-4 border-top">
                            <a href="{{ route('admin.announcements.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">send</span> Publish Announcement
                            </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;
        }

        .form-check-input:checked {
            background-color: #059669;
            border-color: #059669;
        }
    </style>
@endpush
