@extends('template.app')

@section('meta')
@endsection

@section('title')
Offers & Discounts 
@endsection

@section('styles')
<link href="{{ asset('assets/css/dropify.min.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/sweetalert2.bundle.css') }}" rel="stylesheet">
@endsection

@section('content')
<div class="page-breadcrumb">
    <div class="row">
        <div class="col-7 align-self-center">
            <h4 class="page-title text-truncate text-dark font-weight-medium mb-1">Offers & Discounts Master</h4>
            <div class="d-flex align-items-center">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb m-0 p-0">
                        <li class="breadcrumb-item"><a href="{{ route('offer') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('offer') }}" class="text-muted">Offers & Discounts </a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">View</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <form action="{{ route('offer.view') }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('GET')

                        
                        <div class="row">
                            <div class="form-group col-sm-4">
                                <label for="tittle"> Tittle</label>
                                <input type="text" name="title" id="tittle" class="form-control" placeholder="Enter Tittle" value="{{ $data->title ??'' }}" disabled>
                                <span class="kt-form__help error tittle"></span>
                            </div>
                            
                            <div class="form-group col-sm-4">
                                <label for="start_date">Start date</label>
                                <input type="date" name="start_date" id="start_date" class="form-control" placeholder="Enter Start date" value="{{ $data->start_date ??'' }}" disabled>
                                <span class="kt-form__help error start_date"></span>
                            </div>
                            <div class="form-group col-sm-4">
                                <label for="end_date">End date</label>
                                <input type="date" name="end_date" id="end_date" class="form-control" placeholder="Enter End date" value="{{ $data->end_date ??'' }}" disabled>
                                <span class="kt-form__help error end_date"></span>
                            </div>
                            <div class="form-group col-sm-4">
                                <label for="offer_type">Offer type</label>
                                <input type="text" name="offer_type" id="offer_type" class="form-control" placeholder="Enter Offer type" value="{{ $data->offer_type ??'' }}" disabled>
                                <span class="kt-form__help error offer_type"></span>
                            </div>
                            <div class="form-group col-sm-4">
                                <label for="offer_type">Amount</label>
                                <input type="text" name="amount" id="offer_type" class="form-control" placeholder="Enter Amount" value="{{ $data->amount ??'' }}" disabled>
                                <span class="kt-form__help error offer_type"></span>
                            </div>
                            <div class="form-group col-sm-4 custom-form-spacing">
                                <label for="offer_type">KIA Share / Company Contribution </label>
                                <input type="text" name="company_contribution" id="company_contribution" class="form-control" placeholder="Enter Amount" value="{{ $data->company_contribution ?? '' }}" disabled>
                                <span class="kt-form__help error company_contribution"></span>
                            </div>
                            <div class="form-group col-sm-4">
                                 <label for="car_name">Branch</label>
                                 <select class="form-control" name="branch_id" id="branch_id" disabled>
                                    <option value="{{$data->branch_id}}">{{$data->branch_name}}</option>
                                 </select>
                                        
                                 <span class="kt-form__help error car_name"></span>
                             </div>
                             
                            <div class="form-group col-sm-4">
                                 <label for="car_name">Car Model</label>
                                 <select class="form-control" name="car_name" id="car_name" disabled>
                                    <option value="{{ $data->mid }}"> {{ $data->name }}</option>
                                 
                                 </select>
                                        
                                 <span class="kt-form__help error car_name"></span>
                             </div>

                             <div class="form-group col-sm-4" id="fule_type">
                                <label for="fule_type">Fuel Type</label>  
                                <select class="form-control" name="fuel_type" id="fuel_type" disabled>
                                    <option value="{{ $data->fid }}"> {{ $data->ftitle }}</option>              
                                 </select>
                                <span class="kt-form__help error fule_type"></span>
                            </div>

                             <div class="form-group col-sm-4">
                                 <label for="car_name">Car Variant</label>  
                                 <select class="form-control" name="veriant" id="veriant" disabled>
                                    <option value="{{ $data->vid }}"> {{ $data->vname }}</option>
                                   
                                 </select>                                        
                                 <span class="kt-form__help error car_name"></span>
                             </div>

                             <div class="form-group col-sm-4">
                                 <label for="vin">Car VIN Number</label>  
                                 <select class="form-control" name="vin" id="vin" disabled>
                                    <option value="{{ $data->vin_number }}"> {{ $data->vin_number }}</option>
                                 </select>                                        
                                 <span class="kt-form__help error vin"></span>
                             </div>

                            <div class="form-group col-sm-4" id="price">
                                <label for="price">Ex Showroom Price</label>
                                <input type="text" name="ex_showroom_price"  readonly="readonly" class="form-control" value="{{$data->ex_showroom_price}}">
                            </div>

                            <div class="form-group col-sm-4">
                                <label for="description">Description</label>
                                <textarea name="description" row="3" id="description"  class="form-control" disabled> {{ $data->description ??'' }} </textarea>
                                <span class="kt-form__help error description"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <a href="{{ route('offer') }}" class="btn waves-effect waves-light btn-rounded btn-outline-secondary">Back</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script src="{{ asset('assets/js/promise.min.js') }}"></script>
<script src="{{ asset('assets/js/sweetalert2.bundle.js') }}"></script>

<script>
    $(document).ready(function() {
        var form = $('#form');
        $('.kt-form__help').html('');
        form.submit(function(e) {
            $('.help-block').html('');
            $('.m-form__help').html('');
            $.ajax({
                url: form.attr('action'),
                type: form.attr('method'),
                data: new FormData($(this)[0]),
                dataType: 'json',
                async: false,
                processData: false,
                contentType: false,
                success: function(json) {
                    return true;
                },
                error: function(json) {
                    if (json.code === 422) {
                        e.preventDefault();
                        var errors_ = json.responseJSON;
                        $('.kt-form__help').html('');
                        $.each(errors_.errors, function(key, value) {
                            $('.' + key).html(value);
                        });
                    }
                }
            });
        });
    });
</script>
@endsection