<?php   
    $validations = [];

    if (isset($field['validations'])) {
        array_push($validations, $field['validations']);
    }

    $validations = implode('|', array_filter($validations));

    $key = explode(".", $item['key']);

    $firstField = current($key);

    $secondField = next($key);

    $name = $item['key'] . '.' . $field['name'];

    if (isset($field['data_source'])) {
        $temp = explode("@", $field['data_source']);

        $value = app(current($temp))->{end($temp)}();
    }

    $fieldName = $firstField . "[" . $secondField . "][" . $field['name'] . "]";
?>

<?php if($field['type'] == 'depends'): ?>
    <?php        
        $depends = explode(":", $field['depend']);

        $dependField = current($depends);

        $dependValue = end($depends);

        if (isset($value) && $value) {
            $i = 0;

            foreach ($value as $key => $result) {
                $data['title'] = $result;

                $data['value'] = $key;

                $options[$i] = $data;

                $i++;
            }

            $field['options'] = $options;
        }

        if (! isset($field['options'])) {
            $field['options'] = '';
        }

        $selectedOption = core()->getConfigData($name) ?? '';
    ?>

    <depends
        :name="'<?php echo e($fieldName); ?>'"
        :value="'<?php echo e($dependValue); ?>'"
        :result="'<?php echo e($selectedOption); ?>'"
        :options='<?php echo json_encode($field['options'], 15, 512) ?>'
        :validations="'<?php echo e($validations); ?>'"
        :field_name="'<?php echo e(trans($field['title'])); ?>'"
        :depend="'<?php echo e($firstField); ?>[<?php echo e($secondField); ?>][<?php echo e($dependField); ?>]'"
    ></depends>

<?php else: ?>
    <div
        class="form-group <?php echo e($field['type']); ?>"
        <?php if($field['type'] == 'multiselect'): ?>
            :class="[errors.has('<?php echo e($fieldName); ?>[]') ? 'has-error' : '']"
        <?php else: ?>
            :class="[errors.has('<?php echo e($fieldName); ?>') ? 'has-error' : '']"
        <?php endif; ?>
    >

        <label
            for="<?php echo e($name); ?>"
            <?php echo e(!isset($field['validations']) || preg_match('/\brequired\b/', $field['validations']) == false ? '' : 'class=required'); ?>

        >
            <?php echo e(__($field['title'])); ?>


        </label>

        <?php if($field['type'] == "password" || $field['type'] == "color"): ?>
            <?php echo $__env->make('admin::configuration.fields.input', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php else: ?>
            <?php echo $__env->make('admin::configuration.fields.' . $field['type'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php endif; ?>

        <?php if(isset($field['info'])): ?>
            <span class="control-info mt-10"><?php echo e(trans($field['info'])); ?></span>
        <?php endif; ?>

        <span
            class="control-error"
            <?php if($field['type'] == 'multiselect'): ?>
                v-if="errors.has('<?php echo e($fieldName); ?>[]')"
            <?php else: ?>
                v-if="errors.has('<?php echo e($fieldName); ?>')"
            <?php endif; ?>
        >
            <?php if($field['type'] == 'multiselect'): ?>
                {{ errors.first('<?php echo $firstField; ?>[<?php echo $secondField; ?>][<?php echo $field['name']; ?>][]') }}
            <?php else: ?>
                {{ errors.first('<?php echo $firstField; ?>[<?php echo $secondField; ?>][<?php echo $field['name']; ?>]') }}
            <?php endif; ?>
        </span>

    </div>

<?php endif; ?>

<?php $__env->startPush('scripts'); ?>
    <?php if($field['type'] == 'country'): ?>
        <script type="text/x-template" id="country-template">

            <div>
                <select
                    type="text"
                    :name="name"
                    class="control"
                    :id="name"
                    v-model="country"
                    v-validate="validations"
                    data-vv-as="&quot;<?php echo e(__('admin::app.customers.customers.country')); ?>&quot;"
                    @change="sendCountryCode"
                >
                    <option value=""></option>

                    <?php $__currentLoopData = core()->countries(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $country): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                        <option value="<?php echo e($country->code); ?>"><?php echo e($country->name); ?></option>

                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

        </script>

        <script type="text/x-template" id="state-template">

            <div>
                <input
                    type="text"
                    :name="name"
                    class="control"
                    :id="name"
                    v-model="state"
                    v-validate="'required'"
                    data-vv-as="&quot;<?php echo e(__('admin::app.customers.customers.state')); ?>&quot;"
                    v-if="! haveStates()"
                />

                <select
                    :name="name"
                    class="control"
                    :id="name"
                    v-model="state"
                    v-validate="'required'"
                    data-vv-as="&quot;<?php echo e(__('admin::app.customers.customers.state')); ?>&quot;"
                    v-if="haveStates()"
                >

                    <option value=""><?php echo e(__('admin::app.customers.customers.select-state')); ?></option>

                    <option v-for='(state, index) in countryStates[country]' :value="state.code">
                        {{ state.default_name }}
                    </option>

                </select>

            </div>

        </script>

        <script>
            Vue.component('country', {

                template: '#country-template',

                inject: ['$validator'],

                props: ['country_code', 'name', 'validations'],

                data: function () {
                    return {
                        country: "",
                    }
                },

                mounted: function () {
                    this.country = this.country_code;
                    this.sendCountryCode()
                },

                methods: {
                    sendCountryCode: function () {
                        this.$root.$emit('countryCode', this.country)
                    },
                }
            });

            Vue.component('state', {

                template: '#state-template',

                inject: ['$validator'],

                props: ['state_code', 'name', 'validations'],

                data: function () {
                    return {
                        state: "",

                        country: "",

                        countryStates: <?php echo json_encode(core()->groupedStatesByCountries(), 15, 512) ?>
                    }
                },

                mounted: function () {
                    this.state = this.state_code
                },

                methods: {
                    haveStates: function () {
                        var this_this = this;

                        this_this.$root.$on('countryCode', function (country) {
                            this_this.country = country;
                        });

                        if (this.countryStates[this.country] && this.countryStates[this.country].length)
                            return true;

                        return false;
                    },
                }
            });
        </script>
    <?php endif; ?>

    <script type="text/x-template" id="depends-template">

        <div class="form-group"  :class="[errors.has(name) ? 'has-error' : '']" v-if="this.isVisible">
            <label :for="name" :class="[ isRequire ? 'required' : '']">
                {{ field_name }}
            </label>

            <select
                :id="name"
                :name="name"
                class="control"
                v-model="savedValue"
                v-validate="validations"
                :data-vv-as="field_name"
                v-if="this.options.length"
            >
                <option v-for='(option, index) in this.options' :value="option.value">
                    {{ option.title }}
                </option>
            </select>

            <input
                :id="name"
                :name="name"
                class="control"
                v-else type="text"
                v-model="savedValue"
                v-validate="validations"
                :data-vv-as="field_name"
            >

            <span class="control-error" v-if="errors.has(name)">
                {{ errors.first(name) }}
            </span>
        </div>

    </script>

    <script>
        Vue.component('depends', {

            template: '#depends-template',

            inject: ['$validator'],

            props: [
                'name',
                'depend',
                'value',
                'result',
                'options',
                'data_source',
                'field_name',
                'validations',
            ],

            data: function() {
                return {
                    isRequire: false,
                    isVisible: false,
                    savedValue: "",
                }
            },

            mounted: function () {
                var this_this = this;

                this_this.savedValue = this_this.result;

                if (this_this.validations || (this_this.validations.indexOf("required") != -1)) {
                    this_this.isRequire = true;
                }

                $(document).ready(function(){
                    var dependentElement = document.getElementById(this_this.depend);
                    var dependValue = this_this.value;

                    if (dependValue == 'true') {
                        dependValue = 1;
                    } else if (dependValue == 'false') {
                        dependValue = 0;
                    }

                    $(document).on("change", "select.control", function() {
                        if (this_this.depend == this.name) {
                            if (this_this.value == this.value) {
                                this_this.isVisible = true;
                            } else {
                                this_this.isVisible = false;
                            }
                        }
                    })

                    if (dependentElement && dependentElement.value == dependValue) {
                        this_this.isVisible = true;
                    } else {
                        this_this.isVisible = false;
                    }

                    if (this_this.result) {
                        if (dependentElement.value == this_this.value) {
                            this_this.isVisible = true;
                        } else {
                            this_this.isVisible = false;
                        }
                    }
                });
            }
        });
    </script>

<?php $__env->stopPush(); ?><?php /**PATH C:\xampp\htdocs\laravel-crm\packages\Webkul\Admin\src/resources/views/configuration/field-type.blade.php ENDPATH**/ ?>