@extends('layouts.master')

@section('title')
{{__('Add service')}}
@endsection

@section('breadcrumb')
<div class="row page-title">
    <div class="col-md-12">
        <h3 class="mb-1 mt-0">{{__('Add service')}}</h3>
        <nav aria-label="breadcrumb" class="float-left mt-1">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{{route('dashboard')}}">{{__('Home')}}</a></li>
                <li class="breadcrumb-item"><a href="{{route('service-list')}}">{{__('Services list')}}</a></li>
                <li class="breadcrumb-item active" aria-current="page">{{__('Add service')}}</li>
            </ol>
        </nav>
    </div>
</div>
@endsection

@section('content')
<!-- select -->
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-body">
                <h4 class="header-title mt-0 mb-1">{{__('Create service')}}</h4>
                <p class="sub-header">
                    {{__('Please fill all given fields')}}.
                </p>
                <form action="" method="get">
                    <div class="row">
                        <div class="col-lg-6 col-sm-4">
                            <label class="col-form-label" for="">{{__('Service name ')}}<span class="text-danger">*</span></label>
                            <input type="text" class="form-control" required id="service_name" name="first_name"
                                placeholder="{{__('Enter service name')}}">

                        </div>

                        <div class="col-lg-6 col-sm-4">
                            <div class="form-group mt-3 mt-sm-0">
                                <label class="col-form-label">{{__('Parent')}} <span class="text-danger">*</span></label>
                                <select class="custom-select" required>
                                    <option selected disabled>{{__('Select parent service')}}</option>
                                    <option value="0">Plumber</option>
                                    <option value="2">Carpanter</option>
                                    <option value="1">Electrician</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-lg-6 col-sm-4">
                            <label class="col-form-label" for="">{{__('Code')}} <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" required id="service_code" name="service_code"
                                placeholder="E.g. Elektra (code E100, E101...)">

                        </div>
                        <div class="col-lg-6 col-sm-4">
                            <label class="col-form-label" for="">{{__('Price')}} <span class="text-danger">*</span></label>
                            <input type="text" class="form-control" required id="service_price" name="service_price"
                                placeholder="{{__('Enter service price')}}">
                        </div>
                        <div class="col-lg-12 col-sm-4 pt-2">

                            <input type="submit" class="btn custom-button d-flex btnSubmit mr-0" value="{{__('Add service')}}"
                                id="btnSubmit">
                        </div>
                    </div>
                </form>


            </div> <!-- end card-body -->
        </div> <!-- end card-->
    </div> <!-- end col -->
</div>
<!-- end row -->


<!-- end row -->
@endsection

@section('script-bottom')
<script>
    $(document).ready(function (e) {
        $(document).on('change', '.imageChange', function (e) {
            photoError = 0;
            if (e.target.files && e.target.files[0]) {
                // console.log(e.target.files[0].name.strtolower())
                if (e.target.files[0].name.match(/\.(jpg|jpeg|JPG|png|gif|PNG)$/)) {
                    $("#photo-error").empty();
                    photoError = 0;
                    var reader = new FileReader();

                    reader.onload = function (e) {
                        $('#user_photo_selected').attr('src', e.target.result);
                    }
                    reader.readAsDataURL(e.target.files[0]);

                } else {
                    photoError = 1;
                    $("#photo-error").empty();
                    $(".btnSubmit").prop('disabled', true);

                    $("#photo-error").append(
                        '<p class="text-danger">Please upload only jpg, png format!</p>');
                }
            } else {
                $('#user_photo_selected').attr('src', '');
            }

            if (photoError == 0) {
                $(".btn-change-photo").prop('disabled', false);
                $("#btnSubmit").attr('disabled', false);
            } else {
                $(".btn-change-photo").prop('disabled', true);
            }
        });
    });

</script>

@endsection
