@extends('layouts.app')

@section('content')
<div class="header bg-gradient-primary pb-8 pt-5 pt-md-8"></div>

<div class="container-fluid mt--7">
    @if ($errors->any())
    <div class="alert alert-danger">
        <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
         @endforeach
        </ul>
    </div>
    <br /> 
    @endif

    @if(auth()->user()->hasRole('super_admin', 'admin'))
        <div class="row">
            <div class="col">
                <div class="card bg-secondary shadow">
                    <div class="card-header border-0">
                        <div class="row align-items-center">
                            <div class="col-12">
                                <h2 class="mb-0">Update a Campaign - {{ $campaign->name }}</h2>
                                <p class="text-sm mb-0"></p>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <form method="post" action="{{ route('campaigns.update', $campaign->id) }}" enctype="multipart/form-data">
                            @method('PATCH') 
                            @csrf
                            <div class="form-group">
                                <label class="form-control-label" for="name">Name</label>
                                <input type="text" name="name" class="form-control form-control-alternative" id="name" value="{{ $campaign->name }}" >
                            </div>
                            <div class="form-group">
                                <label class="form-control-label" for="description">Description</label>
                                <textarea class="form-control form-control-alternative" name="description" id="description" rows="5">{{ $campaign->description }}</textarea>
                            </div> 

                            <div class="form-group">
                                <label class="form-control-label" for="agency_id">Agency</label>
                                <select class="form-control form-control-alternative js-example-basic-multiple" id="agency_id" name="agency_id">
                                    <option value="">Choose a option</option>
                                    @foreach($agencies as $agency)
                                        <option value="{{$agency->id}}" {{ ($agency->id == $selectedAgency) ? 'selected' : '' }}>{{$agency->name}}</option>
                                    @endforeach
                                </select>
                            </div>

                            <div class="form-group">
                                <label class="form-control-label" for="enabled">Status</label>
                                <select class="form-control form-control-alternative" id="enabled" name="enabled">
                                    <option value="0" {{ ( $campaign->enabled == "0") ? 'selected' : '' }}>INACTIVE</option>
                                    <option value="1" {{ ( $campaign->enabled == "1") ? 'selected' : '' }}>ACTIVE</option>
                                </select>
                            </div>  

                            
                            <div class="text-right">
                                <button type="submit" class="btn btn-success mt-4">Update Campaign</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    @endif
</div>
@endsection