@extends('admin.partials.master')

@section('admin_content')
<section id="dashboard-ecommerce">
    <div class="row">
        <div class="col-md-10 offset-md-1">
            <div class="card">
                <div class="card-header pb-0">
                    <h4 class="card-title">Create New Official Post</h4>
                </div>
                <div class="card-body">
                    <form action="{{ route('admin.official.store') }}" method="POST">
                        @csrf

                        <div class="form-group mb-2">
                            <label for="title">Title <span class="text-danger">*</span></label>
                            <input type="text" id="title" name="title" class="form-control" required value="{{ old('title') }}">
                        </div>

                        <div class="form-group mb-2">
                            <label for="content">Content <span class="text-danger">*</span></label>
                            <textarea id="content" name="content" class="form-control" rows="5" required>{{ old('content') }}</textarea>
                        </div>

                        <div class="form-group mb-2">
                            <label>Images</label>
                            <div id="images-wrapper">
                                <input type="text" name="images[]" class="form-control mb-2" placeholder="https://example.com/img1.png">
                            </div>
                            <button type="button" class="btn btn-sm btn-primary" onclick="addImageField()">+ Add Image</button>
                        </div>

                        <div class="form-group mb-3">
                            <label for="link">External Link (optional)</label>
                            <input type="url" id="link" name="link" class="form-control" value="{{ old('link') }}">
                        </div>

                        <div class="d-flex justify-content-between mt-3">
                            <a href="{{ route('admin.official.index') }}" class="btn btn-secondary">Cancel</a>
                            <button type="submit" class="btn btn-success">Save Post</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    function addImageField() {
        let wrapper = document.getElementById('images-wrapper');
        let input = document.createElement('input');
        input.type = 'text';
        input.name = 'images[]';
        input.classList.add('form-control', 'mb-2');
        input.placeholder = 'https://example.com/img.png';
        wrapper.appendChild(input);
    }
</script>
@endsection
