@extends('backEnd.layouts.master')
@section('title','Add Landing Review')

@section('css')
<style>
    .card {
        border: none;
        box-shadow: 0 0 20px rgba(18, 38, 63, 0.03);
        border-radius: 12px;
        background: #fff;
        margin-bottom: 24px;
    }
    .card-header {
        background: #fff;
        border-bottom: 1px solid #f1f5f7;
        padding: 18px 22px;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    .card-title {
        font-size: 16px;
        font-weight: 700;
        color: #2d3436;
        margin: 0;
    }
    .header-icon {
        width: 32px;
        height: 32px;
        background: rgba(24, 119, 242, 0.08);
        color: #1877f2;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
    }
    .form-label {
        font-weight: 600;
        font-size: 13px;
        color: #636e72;
        margin-bottom: 6px;
    }
    .form-control, .form-select {
        background-color: #fbfcff;
        border: 1px solid #eef2f7;
        padding: 10px 12px;
        border-radius: 8px;
        font-size: 14px;
        color: #2d3436;
    }
    .form-control:focus, .form-select:focus {
        background-color: #fff;
        border-color: #1877f2;
        box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.18);
    }
    .image-upload-box {
        border: 2px dashed #eef2f7;
        border-radius: 10px;
        padding: 18px;
        text-align: center;
        cursor: pointer;
        background: #f9fbfd;
        min-height: 160px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    .image-upload-box:hover {
        border-color: #1877f2;
        background: #fff;
    }
    .preview-img {
        max-width: 100%;
        max-height: 150px;
        border-radius: 6px;
        display: none;
        object-fit: cover;
    }
    .switch { position: relative; display: inline-block; width: 44px; height: 22px; }
    .switch input { opacity: 0; width: 0; height: 0; }
    .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #eef2f7; transition: .4s; border-radius: 34px; border: 1px solid #dee2e6; }
    .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 2px; bottom: 1px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
    input:checked + .slider { background-color: #0acf97; border-color: #0acf97; }
    input:checked + .slider:before { transform: translateX(20px); }
    .btn-submit {
        background: linear-gradient(45deg, #0acf97, #06b6d4);
        border: none;
        color: white;
        padding: 10px 16px;
        font-weight: 600;
        letter-spacing: 0.3px;
        box-shadow: 0 4px 12px rgba(10, 207, 151, 0.3);
        border-radius: 999px;
    }
</style>
@endsection

@section('content')
<div class="container-fluid">
    <div class="row mb-3 mt-3">
        <div class="col-12 d-flex justify-content-between align-items-center">
            <div>
                <h4 class="page-title mb-1 text-dark fw-bold">Add Landing Page Review</h4>
                <p class="text-muted small mb-0">These reviews will be shown on the Sukkari landing page.</p>
            </div>
            <a href="{{ route('landing-reviews.index') }}" class="btn btn-light rounded-pill border shadow-sm px-4">
                <i class="fe-arrow-left me-1"></i> Back to List
            </a>
        </div>
    </div>

    <form action="{{ route('landing-reviews.store') }}" method="POST" enctype="multipart/form-data">
        @csrf
        <div class="row">
            <div class="col-lg-8">
                <div class="card">
                    <div class="card-header">
                        <div class="header-icon"><i class="fe-message-circle"></i></div>
                        <h5 class="card-title">Review Content</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">Reviewer Name <span class="text-danger">*</span></label>
                            <input type="text" name="name" value="{{ old('name') }}" class="form-control @error('name') is-invalid @enderror" required>
                            @error('name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Email (optional)</label>
                            <input type="email" name="email" value="{{ old('email') }}" class="form-control @error('email') is-invalid @enderror">
                            @error('email')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Rating (1–5, optional)</label>
                            <select name="rating" class="form-select @error('rating') is-invalid @enderror">
                                <option value="">Select Rating</option>
                                @for($i = 1; $i <= 5; $i++)
                                    <option value="{{ $i }}" {{ old('rating') == $i ? 'selected' : '' }}>{{ $i }} Star{{ $i > 1 ? 's' : '' }}</option>
                                @endfor
                            </select>
                            @error('rating')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-0">
                            <label class="form-label">Review Text <span class="text-danger">*</span></label>
                            <textarea name="review" rows="4" class="form-control @error('review') is-invalid @enderror" required>{{ old('review') }}</textarea>
                            @error('review')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-lg-4">
                <div class="card mb-3">
                    <div class="card-header">
                        <div class="header-icon"><i class="fe-settings"></i></div>
                        <h5 class="card-title">Settings</h5>
                    </div>
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-center mb-3 p-2 bg-light rounded border border-light">
                            <div>
                                <h6 class="mb-1 text-dark fw-bold">Active Status</h6>
                                <p class="text-muted font-size-12 mb-0">Show this review on landing page?</p>
                            </div>
                            <label class="switch mb-0">
                                <input type="checkbox" name="status" value="1" {{ old('status', 1) ? 'checked' : '' }}>
                                <span class="slider round"></span>
                            </label>
                        </div>

                        <button type="submit" class="btn btn-submit w-100">
                            <i class="fe-save me-1"></i> Save Review
                        </button>
                    </div>
                </div>

                <div class="card">
                    <div class="card-header">
                        <div class="header-icon"><i class="fe-user"></i></div>
                        <h5 class="card-title">Reviewer Image</h5>
                    </div>
                    <div class="card-body">
                        <div class="image-upload-box" onclick="document.getElementById('image').click()">
                            <input type="file" name="image" id="image" class="d-none" accept="image/*" onchange="readPreview(this)">
                            <div id="upload_placeholder">
                                <i class="fe-upload-cloud text-muted mb-2" style="font-size: 26px;"></i>
                                <p class="mb-0 small text-muted">Click to upload avatar</p>
                                <small class="text-muted d-block mt-1">JPG, PNG, WEBP (Max 2MB)</small>
                            </div>
                            <img id="preview_image" class="preview-img" src="#" alt="Preview">
                        </div>
                        @error('image')
                            <div class="text-danger small mt-2 text-center">{{ $message }}</div>
                        @enderror
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
@endsection

@section('script')
<script>
    function readPreview(input) {
        if (input.files && input.files[0]) {
            const reader = new FileReader();
            reader.onload = function (e) {
                document.getElementById('preview_image').src = e.target.result;
                document.getElementById('preview_image').style.display = 'block';
                const placeholder = document.getElementById('upload_placeholder');
                if (placeholder) placeholder.style.display = 'none';
            };
            reader.readAsDataURL(input.files[0]);
        }
    }
</script>
@endsection

