@extends('layouts.main') 
@section('title', 'ART Center Master')
@section('content')

<?php 
    $getstatecodedata = DB::table('state_master')->get();
    $getdistrictcodedata = DB::table('district_master')->get();
?>
    <div class="container-fluid">
        <div class="page-header">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">
                        <i class="ik ik-edit bg-blue"></i>
                        <div class="d-inline">
                            <h5>{{ __('ART Center Master')}}</h5>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="{{route('dashboard')}}"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item"><a href="#">{{ __('Forms')}}</a></li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-7 mx-auto">
                <div class="card">
                    <div class="card-header"><h3>{{ __('ART Center Master Form')}}</h3></div>
                    <div class="card-body">
                        <form class="forms-sample" method='POST' @if(!empty($showdata)) action='{{ url('updateartcenter') }}' @else action='{{ url('artcenterinsert') }}' @endif name='artcenteremaster'>
                            @csrf
                            
                            @if(!empty($showdata))
                            <input type='hidden' name='artcenterid' value='{{$showdata[0]->id}}'>
                            @endif
                            
                            <div class="form-group">
                                <label for="emp_code">{{ __('Art Center Code')}}</label>
                                <input type="text" class="form-control" id="artcenter_code" name='artcenter_code' <?php if(!empty($showdata)){ ?> value='{{$showdata[0]->art_centre_code}}' <?php } ?> placeholder="Enter Art Center Code" required>
                            </div>
                            <div class="form-group">
                                <label for="artcenter_name">{{ __('ART Center Name')}}</label>
                                <input type="text" class="form-control" id="artcenter_name" name='artcenter_name' <?php if(!empty($showdata)){ ?> value='{{$showdata[0]->name_of_artc}}' <?php } ?> placeholder="Enter Art Center Name" required>
                            </div>
                            <div class="form-group">
                                <label for="dist_code">{{ __('District Code')}}</label>
                                <select name='dist_code'  class='form-control' value='Select Option' id="dist_code" required>
                                    <option value="">Select District Code</option>
                                    <?php foreach($getdistrictcodedata as $getdistrictcode){ ?>
                                     <option value='<?php echo $getdistrictcode->district_code; ?>' @if(!empty($showdata)){{ $showdata[0]->dist_code == $getdistrictcode->district_code ? 'selected' : '' }} @endif ><?php echo $getdistrictcode->district_code; ?></option>
                                     <?php } ?>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="state_code">{{ __('State Code')}}</label>
                                <input type="text" class="form-control" id="state_code" name='state_code' <?php if(!empty($showdata)){ ?> value='{{$showdata[0]->state_code}}' <?php } ?> placeholder="Enter State Code" readonly>
                            </div>
                            <div class="form-group">
                                <label for="status">{{ __('State Status')}}</label>
                                <select name='status'  class='form-control' value='Select Option'>
                                    <option>Select Status</option>
                                    <option value="Yes" @if(!empty($showdata)){{ $showdata[0]->status == "Yes" ? 'selected' : '' }} @endif >Yes</option>
                                    <option value="No" @if(!empty($showdata)){{ $showdata[0]->status == "No" ? 'selected' : '' }} @endif >No</option>
                                </select>
                            </div>
                            <br><br>
                            <button type="submit" class="btn btn-primary mr-2">{{ __('Submit')}}</button>
                            @if(empty($showdata))
                            <a href='{{'artcenter-master'}}' class="btn btn-light">{{ __('Cancel')}}</a>
                            @endif
                          </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- push external js -->
    @push('script')
        <script src="{{ asset('js/form-components.js') }}"></script>
        <script type="text/javascript">
            $( "#dist_code" ).change(function() { 
                var dist_code = $(this).val();
                $.ajax({
                    type: "POST",
                    url: "{{ url('getstatecode') }}",
                    data: {dist_code:dist_code, _token: '{{csrf_token()}}' },
                    dataType: "json",
                    success: function(res) { 
                        var state_code = res.showdata.state_code;
                        $('#state_code').val(state_code);
                    },
                    error: function (jqXHR, exception) {
        
                    }
                });
            });
        </script>
    @endpush
@endsection