@extends('template.app')

@section('meta')
@endsection

@section('title')
    Insurance Create
@endsection

@section('styles')
<link href="{{ asset('assets/css/dropify.min.css') }}" rel="stylesheet">
<link href="{{ asset('assets/css/sweetalert2.bundle.css') }}" rel="stylesheet">
<style>
     .col-sm-3{
        font-size: 15px;
    }
    .form-control {
        height: 38px !important;
        width: 186px !important;
        font-size: 14px;
    }
    .custom-form-spacing {
      margin-bottom: -5px !important;
    }
</style>
@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">Insurance 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('dashboard') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('insurance') }}" class="text-muted">Insurance Master</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Create</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('insurance.insert') }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('POST')

                        <div class="row">
                            <div class="form-group col-md-3">
                                <label for="name">Company Name</label>
                                <input type="text" name="name" id="name" class="form-control" placeholder="Enter Company Name">
                                <span class="kt-form__help error name"></span>
                            </div>
                            <div class="form-group col-md-3">
                                <label for="years">Years</label>
                                <input type="number" name="years" id="years" class="form-control" placeholder="Enter Years">
                                <span class="kt-form__help error years"></span>
                            </div>
                            <div class="form-group col-md-3">
                                <label for="type">Insurance Type</label>
                                <input type="text" name="type" id="type" class="form-control" placeholder="Enter Type">
                                <span class="kt-form__help error type"></span>
                            </div>
                            <div class="form-group col-md-3">
                                <label for="name">MISP Payout (%)</label>
                                <input type="number" name="misp_payout_percentage" id="misp_payout_percentage" class="form-control" placeholder="Enter MISP Payout (%)" min="0" value="0">
                                <span class="kt-form__help error misp_payout_percentage"></span>
                            </div> 
                            <div class="form-group col-md-3">
                                <label for="name">Incentive Payout (%)</label>
                                <input type="number" name="incentive_payout_percentage" id="incentive_payout_percentage" class="form-control" placeholder="Enter Incentive Payout (%)" min="0" value="0">
                                <span class="kt-form__help error misp_payout_percentage"></span>
                            </div> 
                            <div class="form-group col-md-3">
                                <label for="amount">Amount</label>
                                <input type="number" name="amount" class="form-control" placeholder="Enter Amount">
                                <span class="kt-form__help error amount"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn waves-effect waves-light btn-sm btn-rounded btn-outline-primary">Submit</button>
                            <a href="{{ route('insurance') }}" class="btn waves-effect waves-light btn-sm 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.status === 422) {
                        e.preventDefault();
                        var errors_ = json.responseJSON;
                        $('.kt-form__help').html('');
                        $.each(errors_.errors, function(key, value) {
                            $('.' + key).html(value);
                        });
                    }
                }
            });
        });
    });
</script>
@endsection