@extends('layouts.app')
<?php
    use App\Models\Partner; $incident = array();
    $request = request();
    $posturl = url("partner/process");
    $successurl = url("partner/index");
    $successurlnxt = url('partner/index');
    $gotosuccess = true;
    $id = "";  $successmessage = $failureurl = $name = $contactperson = $contact =  $category = $location = "";
    if(!empty($request->id)){
        $id = base64_decode($request->id);
        $posturl = url("partner/update");
        $successurl = url("partner/index");
        $successurlnxt = url('partner/index');
        $gotosuccess = true;
        $partners = Partner::where('id', $id)->get();
        foreach ($partners as $partner) {
            $name = $partner['name'];
            $contactperson = $partner['contact_person'];
            $contact = $partner['contact'];
            $category = $partner['category'];
            $location = $partner['location'];
            $districtsv = explode(",", $partner['districts']);
        }
    }
?>
@section('content')
<div class="pcoded-content">
    <div class="pcoded-inner-content">
        <div class="main-body">
            <div class="page-wrapper">
                <!-- Page-header start -->
                <div class="page-header card page-body">
                    <div class="row align-items-end">
                        <div class="col-lg-8">
                            <div class="page-header-title">
                                <i class="icofont icofont icofont icofont-file-document bg-c-pink"></i>
                                <div class="d-inline">
                                    <h4>Partners</h4>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4">
                            <div class="page-header-breadcrumb">
                                <ul class="breadcrumb-title">
                                    <li class="breadcrumb-item">
                                        <a href="index.html">
                                            <i class="icofont icofont-home"></i>
                                        </a>
                                    </li>
                                    <li class="breadcrumb-item"><a href="#!">Partners</a>
                                    </li>
                                    <li class="breadcrumb-item"><a href="#!">Partner Registration</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                        <hr>
                        <div class="row">
                            <div class="col-sm-12">
                                <form id="indexform" class="form-horizontal" method="POST" action="<?php echo $posturl; ?>">
                                    @csrf
                                    <input name="entityname" id="entityname" type="hidden" value="Partner" />
                                    <input type="hidden" id="action" name="action"value="" />
                                    <input type="hidden" id="id" name="id" value="<?php echo $id; ?>" />
                                    <input name="successmessage" id="successmessage" type="hidden" value="<?php echo $successmessage; ?>" />
                                    <input type="hidden" id="<?php echo "SUCCESS_MESSAGE"; ?>" name="<?php echo "SUCCESS_MESSAGE"; ?>" value="<?php echo $successmessage; ?>" />
                                    <input type="hidden" id="<?php echo "URL_SUCCESS"; ?>" name="successurl" value="<?php echo base64_encode($successurl); ?>" />
                                    <input type="hidden" id="<?php echo "URL_FAILURE"; ?>" name="failureurl" value="<?php echo base64_encode($failureurl); ?>" />

                                    <div class="form-group row">
                                        <label class="col-sm-2 col-form-label">Partner Name</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="name" placeholder="Partner Name" required="required" value="<?php echo $name; ?>">
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-sm-2 col-form-label">Contact Person</label>
                                        <div class="col-sm-4">
                                            <input type="text" class="form-control"
                                            placeholder="Contact Person" name="contactperson" value="<?php echo $contactperson; ?>">
                                        </div>
                                        <label class="col-sm-2 col-form-label">Contact</label>
                                        <div class="col-sm-4">
                                            <input type="text" class="form-control"
                                            placeholder="Contact" name="contact" value="<?php echo $contact; ?>">
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-sm-2 col-form-label">Districts</label>
                                        <div class="col-sm-4">
                                            <select id="district" multiple class="form-control search-select" name="districtids[]" required>
                                                <option value="">Choose One</option>
                                                @foreach($districts as $district)
                                                    <option value="{{$district->id}}" @if(in_array($district->id, $districtsv)) selected="selected" @endif>
                                                        {{$district->name}}
                                                    </option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-sm-2 col-form-label">Address</label>
                                        <div class="col-sm-10">
                                            <textarea rows="5" cols="5" class="form-control" name="location"
                                            placeholder="Locations"><?php echo $location; ?></textarea>
                                        </div>
                                    </div>

                                    <div class="form-group row">
                                        <label class="col-sm-10 col-form-label"></label>
                                        <button type="submit" class="col-sm-2 btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                        </div>

                </div>
                <!-- Page-header end -->
            </div>
        </div>
        <div id="styleSelector">

        </div>
    </div>
</div>
@endsection
