@extends('admin.master')

@section('title')
    News
@endsection

@section('content')
    <!--begin::Card-->
    <div class="card card-custom gutter-b example example-compact card-collapsed" data-card="true" id="kt_card_4">
        <div class="card-header">
            <h3 class="card-title">
                Add New News
            </h3>
            <div class="card-toolbar">
                <a href="#" class="btn btn-icon btn-sm btn-light-primary mr-1" data-card-tool="toggle">
                    <i class="ki ki-arrow-down icon-nm"></i>
                </a>
            </div>
        </div>

        <form class="form" action="{{ route('pressreleases.store') }}" method="POST" enctype="multipart/form-data">
            @csrf
            <div class="card-body">
                <div class="form-group row">
                    <div class="col-lg-12">
                        <label>News Title: <span class="text-danger">*</span></label>
                        <input type="text" name="title" class="form-control mb-2" placeholder="Enter news title here" value="{{ old('title') }}" required />
                        @error('title')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>
                </div>
                <div class="form-group row">
                    <div class="col-lg-6">
                        <label>News Image: <span class="text-danger">*</span></label>
                        <div class="custom-file">
                            <input type="file" class="custom-file-input" id="customFile" name="main_image" required />
                            <label class="custom-file-label" for="customFile">Choose file</label>
                        </div>
                        @error('main_image')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>

                    <div class="col-lg-6">
                        <label>News Image Alt Text:</label>
                        <input type="text" name="main_image_alt" class="form-control mb-2" placeholder="Enter news image alt text here" value="{{ old('main_image_alt') }}" />
                        @error('main_image_alt')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>
                </div>

                <div class="form-group row">
                    <div class="col-lg-12">
                        <label>Newspaper Name: <span class="text-danger">*</span></label>
                        <input type="text" name="news_name" class="form-control mb-2" placeholder="Enter newspaper name here" value="{{ old('news_name') }}" required />
                        @error('news_name')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>
                </div>

                <div class="form-group row">
                    <div class="col-lg-12">
                        <label>News Url: <span class="text-danger">*</span></label>
                        <input type="text" name="news_url" class="form-control mb-2" placeholder="Enter news url here" value="{{ old('news_url') }}" required />
                        @error('news_url')
                            <span class="text-danger">{{ $message }}</span>
                        @enderror
                    </div>
                </div>



            </div>
            <div class="card-footer">
                <div class="row">
                    <div class="col-lg-12 text-center">
                        <button type="submit" class="btn btn-success mr-2">Add New News</button>
                    </div>
                </div>
            </div>
        </form>

    </div>
    <!--end::Card-->

    <!--begin::Card-->
    <div class="card card-custom">
        <div class="card-header flex-wrap py-5">
            <div class="card-title">
                <h3 class="card-label">
                    News Lists
                </h3>
            </div>
        </div>

        <div class="card-body">
            <!--begin: Datatable-->
            @if ($pressReleases->isEmpty())
                <p>No News found.</p>
            @else
                <table class="table table-separate table-head-custom table-checkable" id="kt_datatable1">
                    <thead>
                        <tr>
                            <th></th>
                            <th>ID</th>
                            <th>News Title</th>
                            <th>Newspaper Name</th>
                            <th>Actions</th>
                        </tr>
                    </thead>

                    <tbody>
                        @foreach ($pressReleases as $item)
                            <tr>
                                <td></td>
                                <td>{{ $item->id }}</td>
                                <td>{{ $item->title }}</td>
                                <td>{{ $item->news_name }}</td>
                                <td>
                                    <span style="display: inline-block;">
                                        <a href="{{ route('pressreleases.show', $item->id) }}" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Show"><i class="la la-eye"></i></a>
                                    </span>

                                    <span style="display: inline-block;">
                                        <a href="{{ route('pressreleases.edit', $item->id) }}" class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Edit"><i class="la la-edit"></i></a>
                                    </span>

                                    <span style="display: inline-block;">
                                        <form action="{{ route('pressreleases.destroy', $item->id) }}" method="POST" onsubmit="return confirm('Are you sure want to delete?')">
                                            @csrf
                                            @method('DELETE')
                                            <button class="btn btn-sm btn-clean btn-icon btn-icon-md" title="Delete"><i class="la la-trash"></i></button>
                                        </form>
                                    </span>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>

                </table>
            @endif
            <!--end: Datatable-->
        </div>
    </div>
@endsection
