<?php
Route::isJs(function () {
    ob_start();
?>
    <div>
        <div ng-show="loading" style="min-height: 150px;display: flex;align-items: center;justify-content: center;">
            <md-progress-circular md-mode="indeterminate" md-diameter="48"></md-progress-circular>
        </div>
        <div ng-hide="loading">
            <table class="table table-striped table-bordered" ng-repeat="item in data.data.array">
                    <tr><th>Marque</th><td>{{item.vehicleDetails.manuName}}</td></tr>
                    <tr><th>Model</th><td>{{item.vehicleDetails.modelName}}</td></tr>
                    <tr><th>TypeName</th><td>{{item.vehicleDetails.typeName}}</td></tr>
                    <tr><th>Codes moteur</th><td>{{item.motorCodes.array}}</td></tr>
                    <tr><th>Année</th><td>{{(item.vehicleDetails.yearOfConstrFrom?(item.vehicleDetails.yearOfConstrFrom/100).toFixed(2):'')}}-{{(item.vehicleDetails.yearOfConstrTo?(item.vehicleDetails.yearOfConstrTo/100).toFixed(2):'')}}</td></tr>
                    <tr><th>Type de carrosserie</th><td>{{item.vehicleDetails.constructionType}}</td></tr>
                    <tr><th>Type de motricité</th><td>{{item.vehicleDetails.impulsionType}}</td></tr>
                    <tr><th>Type moteur</th><td>{{item.vehicleDetails.motorType}}</td></tr>
                    <tr><th>Cylindres</th><td>{{item.vehicleDetails.cylinder}}</td></tr>
                    <tr><th>Soupapes</th><td>{{item.vehicleDetails.valves}}</td></tr>
                    <tr><th>Cylindrée</th><td>{{item.vehicleDetails.cylinderCapacityCcm}}</td></tr>
                    <tr><th>Type de carburant</th><td>{{item.vehicleDetails.fuelType}}</td></tr>
                    <tr><th>Système de carburation</th><td>{{item.vehicleDetails.fuelTypeProcess}}</td></tr>
                    <tr><th>CH</th><td>{{item.vehicleDetails.powerHpFrom}}-{{item.vehicleDetails.powerHpTo}}</td></tr>
                    <tr><th>KW</th><td>{{item.vehicleDetails.powerKwFrom}}-{{item.vehicleDetails.powerKwTo}}</td></tr>
                    <tr><th>rmiTypeId</th><td>{{item.vehicleDetails.rmiTypeId}}</td></tr>
            </table>
        </div>
    </div>
    <?php $code = ob_get_clean(); ?>
    <script>
        app.directive('listcar', [function() {
            return {
                restrict: 'EA',
                transclude: false,
                replace: false,
                template: <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope: {
                    carId: "@",
                    country: "@"
                },
                controller: function($scope) {
                    $scope.loading = false;
                    $scope.data = [];
                    $scope.$watch("carId", function() {
                        $scope.data = [];
                        if ($scope.carId) {
                            $scope.loading = true;
                            api("getCarx", {
                                carId: $scope.carId,
                                country: $scope.country
                            }, function(data) {
                                $scope.data = data || [];
                                $scope.loading = false;
                                $scope.$apply();
                            });
                        }
                    });
                },
                link: function(scope, iElement, iAttrs) {}
            };
        }]);
    </script>
<?php
});
Route::isJs(function () {
    ob_start();
?>
    <div>
        <div ng-show="loading" style="min-height: 150px;display: flex;align-items: center;justify-content: center;">
            <md-progress-circular md-mode="indeterminate" md-diameter="48"></md-progress-circular>
        </div>
        <div ng-hide="loading">
            <table class="table table-striped">
                <tr ng-repeat="oe in data">
                    <th>{{oe.manuName}}</th>
                    <td>
                        <button class="btn btn-xs" ng-click="dilog.mfrName=oe.manuName;dilog.mfrId = oe.manuId;dilog.articleId = articleId;dilog.show()">
                            <span class="glyphicon glyphicon-eye-open"></span>
                        </button>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <?php $code = ob_get_clean(); ?>
    <script>
        app.directive('manuslist', [function() {
            return {
                restrict: 'EA',
                transclude: false,
                replace: false,
                template: <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope: {
                    articleId: "@",
                    dilog: "=?"
                },
                controller: function($scope) {
                    $scope.loading = false;
                    $scope.data = [];
                    $scope.$watch("articleId", function() {
                        $scope.data = [];
                        if ($scope.articleId) {
                            $scope.loading = true;
                            api("getMarqueCars", {
                                articleId: $scope.articleId,
                            }, function(data) {
                                $scope.data = data || [];
                                $scope.loading = false;
                                $scope.$apply();
                            });
                        }
                    });
                },
                link: function(scope, iElement, iAttrs) {}
            };
        }]);
    </script>
<?php
});
Route::isJs(function () {
    ob_start();
?>
    <div style="padding: 15px;background: #fff;">
    <div ng-show="!redonly" ng-cloak>
                <w-form api="getpiece2" on-reset="" on-success="" on-end="" ng-model="ctrl.form">
                        <div  style="display: flex;align-items: flex-end;flex:1">
                            <div class="form-group avs" style="margin-right:5px">
                                <label style="display:block" class="control-label">PIECE</label>
                                <input type="text" class="form-control avs" required name="piece" ng-model="ctrl.form.data.piece" placeholder="PIECE">
                            </div>
                            <div class="form-group avs" style="margin-right:5px">
                                <label style="display:block" class="control-label">RECHERCHE PAR</label>
                                <select class="form-control avs" ng-model="ctrl.form.data.search">
                                    <option value="">Tout</option>
                                    <option value="0">Référence</option>
                                    <option value="1">OE Number</option>
                                    <option value="6">Code-barres</option>
                                    <option value="Id">legacyArticleId</option>
                                </select>
                            </div>
                            <div class="form-group avs" style="margin-right:5px">
                                <label style="display:block" class="control-label">MARQUE</label>
                                <select class="form-control avs" ng-model="ctrl.form.data.marque">
                                    <option value="">Tout</option>
                                    <option ng-repeat="elm in ctrl.form.res.tecall2.dataSupplierFacets.counts | orderBy:'mfrName'" value="{{elm.dataSupplierId}}¤{{elm.mfrName}}">{{elm.mfrName}} ({{elm.count}})</option>
                                </select>
                            </div>
                            <div class="form-group avs" style="margin-right:5px">
                                <label style="display:block" class="control-label">GROUPE</label>
                                <select class="form-control avs" ng-model="ctrl.form.data.groupe">
                                    <option value="">Tout</option>
                                    <option ng-repeat="elm in ctrl.form.res.tecall2.genericArticleFacets.counts | orderBy:'genericArticleDescription'" value="{{elm.genericArticleId}}¤{{elm.genericArticleDescription}}">{{elm.genericArticleDescription}} ({{elm.count}})</option>
                                </select>
                            </div>
                            <span style="flex:1"></span>
                            <div class="form-group">
                                <button class="btn btn-primary" type="submit">Search</button>
                            </div>
                    </div>
                </w-form>
            </div>
        <div ng-show="loading" style="min-height: 150px;display: flex;align-items: center;justify-content: center;">
            <md-progress-circular md-mode="indeterminate" md-diameter="48"></md-progress-circular>
        </div>
        <div ng-hide="loading">
                            <table class="table table-striped table-bordered" style="background: #fff;">
                                <tr>
                                    <th>Ref</th>
                                    <th>legacyId</th>
                                    <th>Code-barres</th>
                                    <th>Marque</th>
                                    <th>Groupe</th>
                                    <th>Images</th>
                                    <th>Criteria</th>
                                    <th>rplcArt</th>
                                    <th>rplcByArt</th>
                                    <th>R.O</th>
                                    <th>A.V</th>
                                </tr>
                                <tr ng-if="ctrl.form.res" ng-repeat="item in ctrl.form.res.tecall2.articles">
                                    <td>{{item.articleNumber}}</td>
                                    <td>{{item.genericArticles[0].legacyArticleId}}</td>
                                    <td>{{item.gtins.join(' | ')}}</td>
                                    <td>{{item.mfrName}}</td>
                                    <td>{{item.genericArticles[0].genericArticleDescription}}</td>
                                    <td>
                                        <div style="display: grid;grid-auto-flow: row;row-gap: 8px">
                                            <img ng-repeat="img in item.images" ng-if="img.headerKey!=16" ng-click="imgxDialog.img=img;imgxDialog.show();" src="{{img.imageURL100}}">
                                        </div>
                                    </td>
                                    <td>
                                        <button class="btn btn-xs" ng-if="item.articleCriteria.length>0" ng-click="criteriDialog.articleNumber = item.articleNumber;criteriDialog.articleCriteria=item.articleCriteria;criteriDialog.show()">
                                            <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                    <td>
                                        <button class="btn btn-xs" ng-if="item.replacesArticles.length>0" ng-click="replacedDialog.titre = 'replacesArticles: '+item.articleNumber;replacedDialog.data=item.replacesArticles;replacedDialog.show()">
                                            <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                    <td>
                                        <button class="btn btn-xs" ng-if="item.replacedByArticles.length>0" ng-click="replacedDialog.titre = 'replacedByArticles: '+item.articleNumber;replacedDialog.data=item.replacedByArticles;replacedDialog.show()">
                                            <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                    <td>
                                        <button class="btn btn-xs" ng-if="item.oemNumbers.length>0" ng-click="oemDialog.articleNumber = item.articleNumber;oemDialog.oemNumbers = item.oemNumbers;oemDialog.show()">
                                            <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                    <td>
                                        <button class="btn btn-xs" ng-click="icarDialog.articleNumber = item.articleNumber;icarDialog.idarticle = item.genericArticles[0].legacyArticleId;icarDialog.show()">
                                            <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                </tr>
                            </table>
        </div>
        <dialog ng-model="imgxDialog" titre="Image : {{imgxDialog.img.fileName}}" btn-fermer="true" width="fit-content">
			<img ng-src="{{imgxDialog.img.imageURL800+''}}">
		</dialog>
        <dialog ng-model="criteriDialog" titre="Caractéristiques : {{criteriDialog.articleNumber}} " btn-fermer="true" width="fit-content">
            <table class="table table-striped">
                <tr ng-repeat="cr in criteriDialog.articleCriteria">
                    <th>{{cr.criteriaAbbrDescription || cr.criteriaDescription}}</th>
                    <td>{{cr.formattedValue}} {{cr.criteriaUnitDescription}}</td>
                </tr>
            </table>
        </dialog>
        <dialog ng-model="replacedDialog" titre="{{replacedDialog.titre}} " btn-fermer="true" width="fit-content">
            <table class="table table-striped">
                <tr ng-repeat="dt in replacedDialog.data">
                    <th>{{dt.mfrName}}</th>
                    <td>{{dt.articleNumber}}</td>
                    <td>
                    <button class="btn btn-xs" ng-click="ijkx(dt.articleNumber,dt.dataSupplierId)">
                        <span class="glyphicon glyphicon-eye-open"></span>
                    </button>
                    </td>
                </tr>
            </table>
        </dialog>
        <dialog ng-model="oemDialog" titre="References d'origine : {{oemDialog.articleNumber}} " btn-fermer="true" width="fit-content">
            <table class="table table-striped">
                <tr ng-repeat="oem in oemDialog.oemNumbers">
                    <th>{{oem.mfrName}}</th>
                    <td>{{oem.articleNumber}}</td>
                </tr>
            </table>
        </dialog>
        <dialog ng-model="icarDialog" titre="Affectation véhicule : {{icarDialog.articleNumber}} " btn-fermer="true" width="fit-content">
            <manuslist article-id="{{icarDialog.idarticle}}" dilog="carDialog"></manuslist>
        </dialog>
        <dialog ng-model="carDialog" titre="Véhicules : {{carDialog.mfrName}}" btn-fermer="true" width="fit-content">
            <carslist article-id="{{carDialog.articleId}}" mfr-id="{{carDialog.mfrId}}"></carslist>
        </dialog>
    </div>
    <?php $code = ob_get_clean(); ?>
    <script>
        app.directive('piecelist', [function() {
            return {
                restrict: 'EA',
                transclude: false,
                replace: false,
                template: <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope: {
                    pieceId: "@",
                    redonly: "@",
                    dil : "=?",
                },
                controller: function($scope) {
                    $scope.loading = false;
                    $scope.ijkx = (x,y) => {
                        $scope.dil.articleNumber = x;
                        $scope.dil.dataSupplierId = y;
                        $scope.dil.show();
                        angular.element(document.getElementsByTagName('piecelist')).scope().$$childTail.wwc(x+"¤"+y);
                    };
                    $scope.wwc = (i) =>{
                        api("getpiece1", {
                                id: i
                            }, function(data) {
                                $scope.ctrl.form.res= {};
                                $scope.ctrl.form.data.piece="";
                                $scope.ctrl.form.data.marque="";
                                $scope.ctrl.form.data.groupe="";
                                $scope.ctrl.form.res = data.res || {};
                                $scope.loading = false;
                                $scope.$apply();
                            });
                    };
                    $scope.$watch("pieceId", function() {
                        if ($scope.pieceId&&$scope.pieceId!="¤") {
                            $scope.loading = true;
                            $scope.wwc($scope.pieceId.replace(/¤\s*$/, ""));
                        }
                    });
                },
                link: function(scope, iElement, iAttrs) {}
            };
        }]);
    </script>
<?php
});
Route::isJs(function () {
    ob_start();
?>
    <div>
        <div ng-show="loading" style="min-height: 150px;display: flex;align-items: center;justify-content: center;">
            <md-progress-circular md-mode="indeterminate" md-diameter="48"></md-progress-circular>
        </div>
        <div ng-hide="loading">
            <table class="table table-striped table-bordered">
                <tr>
                    <th>id</th>
                    <th>Manu</th>
                    <th>Model</th>
                    <th>Description</th>
                    <th>Date Construction</th>
                    <th>HP</th>
                    <th>KW</th>
                </tr>
                <tr ng-repeat="item in data">
                    <td><a style="cursor: pointer" ng-click="detailDialog.itemx = item;detailDialog.show()">{{item.carId}}</a></td>
                    <td>{{item.manuDesc}}</td>
                    <td>{{item.modelDesc}}</td>
                    <td>{{item.carDesc}}</td>
                    <td>de {{item.yearOfConstructionFrom/100}} à {{item.yearOfConstructionTo/100}}</td>
                    <td>de {{item.powerHpFrom}} à {{item.powerHpTo}}</td>
                    <td>de {{item.powerKwFrom}} à {{item.powerKwTo}}</td>
                </tr>
            </table>
        </div>
        <dialog ng-model="detailDialog" titre="Détail : {{detailDialog.itemx.manuDesc}} {{detailDialog.itemx.modelDesc}} {{detailDialog.itemx.carDesc}} " btn-fermer="true" width="fit-content">
            <listcar car-id="{{detailDialog.itemx.carId}}"></listcar>
        </dialog>
    </div>
    <?php $code = ob_get_clean(); ?>
    <script>
        app.directive('carslist', [function() {
            return {
                restrict: 'EA',
                transclude: false,
                replace: false,
                template: <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope: {
                    articleId: "@",
                    mfrId: "@"
                },
                controller: function($scope) {
                    $scope.loading = false;
                    $scope.data = [];
                    $scope.$watch("[articleId,mfrId]", function() {
                        $scope.data = [];
                        if ($scope.articleId && $scope.mfrId) {
                            $scope.loading = true;
                            api("getCars", {
                                articleId: $scope.articleId,
                                mfrId: $scope.mfrId
                            }, function(data) {
                                $scope.data = data || [];
                                $scope.loading = false;
                                $scope.$apply();
                            });
                        }
                    });
                },
                link: function(scope, iElement, iAttrs) {}
            };
        }]);
    </script>
<?php
});
Route::isJs(function () {
    ob_start();
?>
    <div style="width:1000px;background: #fff;">
        <div style="padding: 15px;flex:1;display: flex;">
            <div ng-cloak style="display: flex;width: 100%;align-items: flex-start;flex:1;justify-content: flex-start;flex-direction: column;">
                <div ng-show="loading" style="display: flex;align-items: center;justify-content: center;flex:1;width: 100%;">
                    <b>Recherche en cours, veuillez patienter ...</b>
                </div>
                <div ng-hide="loading" style="width: 100%;">
                    <md-tabs md-dynamic-height md-border-bottom>
                        <md-tab ng-if="res.tecall2.matchingModels.array[0]" label="TecAlliance">
                            <div ng-repeat="model in res.tecall2.matchingModels.array">
                                <h2>{{model.modelName}}</h2>
                                <table class="table table-striped table-bordered" style="background: #fff;">
                                    <tr>
                                        <th>Model</th>
                                        <th>Vehicle</th>
                                        <th>Details</th>
                                    </tr>
                                    <tr ng-repeat="item in res.tecall2.matchingVehicles.array | filter : {modelId : model.modelId}">
                                        <td>{{model.modelName}}</td>
                                        <td>{{item.carName}}</td>
                                        <td>
                                            <button class="btn btn-xs" ng-click="detailDialog.item = item;detailDialog.show()">
                                                {{item.carId}}
                                                <span class="glyphicon glyphicon-list"></span>
                                            </button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </md-tab>
                        <md-tab ng-if="res.vinx[0]" label="ServiceBox">
                            <h2>{{res.vinx[0].brandName}}</h2>
                            <table class="table table-striped table-bordered" style="background: #fff;">
                                <tr>
                                    <th>Véhicule</th>
                                    <th>Détails</th>
                                </tr>
                                <tr ng-repeat="item in res.vinx">
                                    <td>{{item.fullName}}</td>
                                    <td style="width:1px">
                                        <button class="btn btn-xs" ng-click="tabDialog.item = item;tabDialog.show()">
                                            <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                </tr>
                            </table>
                        </md-tab>
                        <md-tab ng-if="res.partsouq.data[0]" label="Partsouq">
                            <h2>{{res.partsouq.data[0].brand}}</h2>
                            <table class="table table-striped table-bordered" ng-repeat="item in res.partsouq.data">
                                <tr ng-repeat="(key, value) in item"><th style="width:1px">{{key}}</th><td ng-bind-html="value"></td></tr>
                            </table>
                        </md-tab>
                        <md-tab ng-if="res.vindv" label="VinDV">
                            <table class="table table-striped table-bordered">
                                <tr ng-repeat="(key, value) in res.vindv">
                                    <th style="width:1px">{{key}}</th>
                                    <td ng-if="key=='carId'">
                                        <button class="btn btn-xs" ng-click="detailDialog.item.carName = res.vindv.vehicleModelSeriesName;detailDialog.item.carId=value;detailDialog.show();">
                                            {{value}} <span class="glyphicon glyphicon-list"></span>
                                        </button>
                                    </td>
                                    <td ng-if="key!='carId'">{{value}}</td>
                                </tr>
                            </table>
                        </md-tab>
                    </md-tabs>
                </div>
            </div>
        </div>
        <dialog ng-model="detailDialog" titre="Détail : {{detailDialog.item.carName}} " btn-fermer="true" width="fit-content">
            <listcar car-id="{{detailDialog.item.carId}}"></listcar>
        </dialog>
        <dialog ng-model="tabDialog" titre="Véhicule : {{tabDialog.item.fullName}} " btn-fermer="true" width="fit-content">
            <table class="table table-striped table-bordered" style="background: #fff;">
                <tr ng-repeat="(key, value) in tabDialog.item"><th style="width:1px">{{key}}</th><td ng-if="key=='id'"><a style="cursor: pointer" ng-click="detailDialog.item.carName = tabDialog.item.fullName;detailDialog.item.carId=value;detailDialog.show();">{{value}}</a></td><td ng-if="key!='id'">{{value}}</td></tr>
            </table>
        </dialog>
    </div>
    <?php $code = ob_get_clean(); ?>
    <script>
        app.directive('vinlist', [function() {
            return {
                restrict: 'EA',
                transclude: false,
                replace: false,
                template: <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope: {
                    vinId: "@"
                },
                controller: function($scope) {
                    $scope.wwc = (i) =>{
                        $scope.loading = true;
                        $scope.res = {};
                        api("getvin", {
                                vin: i
                            }, function(data) {
                                $scope.loading = false;
                                $scope.res = {};
                                $scope.res = data.res || {};
                                $scope.$apply();
                            });
                    };
                    $scope.$watch("vinId", function() {
                        if ($scope.vinId) {
                            $scope.wwc($scope.vinId);
                        }
                    });
                },
                link: function(scope, iElement, iAttrs) {}
            };
        }]);
    </script>
<?php
});
Route::isJs(function () {
    ob_start();
?>
    <div style="width:1000px;background: #fff;">
        <div style="padding: 15px;flex:1;display: flex;">
            <div ng-cloak style="display: flex;width: 100%;align-items: flex-start;flex:1;justify-content: flex-start;flex-direction: column;">
                <div ng-show="loading" style="display: flex;align-items: center;justify-content: center;flex:1;width: 100%;">
                    <b>Recherche en cours, veuillez patienter ...</b>
                </div>
                <div ng-hide="loading" style="width: 100%;">
                        <div>
                            <div ng-if="res.fad[0].TYPE">
                                <table class="table table-striped table-bordered" style="background: #fff;">
                                    <tr>
                                        <th>TYPE</th>
                                        <th>MARQUE</th>
                                        <th>MODELE_NAME</th>
                                        <th>LIB_TYPE</th>
                                        <th>CAR_NAME</th>
                                        <th>Année</th>
                                        <th>CARROSSERIE</th>
                                        <th>CCM</th>
                                        <th>KW</th>
                                        <th>CH</th>
                                        <th>Carburant</th>
                                    </tr>
                                    <tr ng-repeat="item in res.fad">
                                        <td><a style="cursor: pointer" ng-click="detailDialog.item.carName = item.CAR_NAME;detailDialog.item.carId=item.TYPE;detailDialog.show();">{{item.TYPE}}</a></td>
                                        <td>{{item.MARQUE}}</td>
                                        <td>{{item.MODELE_NAME}}</td>
                                        <td>{{item.LIB_TYPE}}</td>
                                        <td>{{item.CAR_NAME}}</td>
                                        <td>{{item.Annee}}</td>
                                        <td>{{item.CARROSSERIE}}</td>
                                        <td>{{item.CCM}}</td>
                                        <td>{{item.KW}}</td>
                                        <td>{{item.CH}}</td>
                                        <td>{{item.Carburant}}</td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                </div>
            </div>
        </div>
        <dialog ng-model="detailDialog" titre="Détail : {{detailDialog.item.carName}} " btn-fermer="true" width="fit-content">
            <listcar car-id="{{detailDialog.item.carId}}"></listcar>
        </dialog>

    </div>
    <?php $code = ob_get_clean(); ?>
    <script>
        app.directive('immlist', [function() {
            return {
                restrict: 'EA',
                transclude: false,
                replace: false,
                template: <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope: {
                    imm: "@"
                },
                controller: function($scope) {
                    $scope.wwc = (i) =>{
                        $scope.loading = true;
                        $scope.res = {};
                        api("getimma", {
                                imm: i
                            }, function(data) {
                                $scope.loading = false;
                                $scope.res = {};
                                $scope.res = data.res || {};
                                $scope.$apply();
                            });
                    };
                    $scope.$watch("imm", function() {
                        if ($scope.imm) {
                            $scope.wwc($scope.imm);
                        }
                    });
                },
                link: function(scope, iElement, iAttrs) {}
            };
        }]);
    </script>
<?php
});
Route::isJs(function(){
    ob_start();
    ?>
      <div class="form-group avs" style="margin: 0;">
          <select class="form-control avs" required ng-model="ngModel" ng-options="elm.id as elm.name for elm in list">
            <option value="" style="display: none"></option>
          </select>
      </div>
    <?php
    $code=ob_get_clean();
    ?>
    <script>
        app.directive('selectmanu', [function () {
            return {
                restrict: 'EA',
                transclude : false,
                replace : false,
                template : <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope : {
                    ngModel : "=?",
                    lst:"=?",
                    country: "@"
                },
                controller : function($scope){
                    $scope.loading = false;
                    $scope.list = [];
                    $scope.loadData = function(){
                        $scope.loading = true;
                        api("getManux",{lst:$scope.lst,country: $scope.country},function(list){
                            if(!list) list=[];
                            $scope.list = list;
                            if(list.length==1) $scope.ngModel=list[0].id;
                            $scope.loading = false;
                            $scope.$apply();
                        });
                    }
                    window.resetselectmanu = function(){
                        $scope.lst = [];
                        $scope.loadData();
                    }
                    $scope.$watch("lst",function(){
                        $scope.loadData();
                    });
                    $scope.$watch("country",function(){
                        $scope.loadData();
                        $scope.ngModel=null;
                    });
                    $scope.loadData();
                },
                link: function (scope, iElement, iAttrs) {
                    
                }
            };
        }]);
    </script>
    <?php
});
Route::isJs(function(){
    ob_start();
    ?>
      <div class="form-group avs" style="margin: 0;">
          <select class="form-control avs" required ng-model="ngModel" ng-options="elm.titre as elm.titre for elm in list">
            <option value="" style="display: none"></option>
          </select>
      </div>
    <?php
    $code=ob_get_clean();
    ?>
    <script>
        app.directive('selectdb', [function () {
            return {
                restrict: 'EA',
                transclude : false,
                replace : false,
                template : <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope : {
                    ngModel : "=?"
                },
                controller : function($scope){
                    $scope.loading = false;
                    $scope.list = [];
                    $scope.loadData = function(){
                        api("getDBS",{},function(list){
                            $scope.list = list;
                            if(list.length==1) $scope.ngModel=list[0].id;
                            $scope.$apply();
                        });
                    }
                    $scope.loadData();
                },
                link: function (scope, iElement, iAttrs) {
                    
                }
            };
        }]);
    </script>
    <?php
});
Route::isJs(function(){
    ob_start();
    ?>
      <div class="form-group avs" style="margin: 0;">
        <select class="form-control avs" required ng-model="ngModel" ng-options="elm.id as elm.name for elm in list">
            <option value="" style="display: none"></option>
          </select>
      </div>
    <?php
    $code=ob_get_clean();
    ?>
    <script>
        app.directive('selectmod', [function () {
            return {
                restrict: 'EA',
                transclude : false,
                replace : false,
                template : <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope : {
                    ngModel : "=?",
                    manuid: "=?",
                    lst:"=?",
                    country: "@"
                },
                controller : function($scope){
                    $scope.loading = false;
                    $scope.list = [];
                    $scope.loadData = function(){
                        if(($scope.manuid??0)>0){
                            $scope.loading = true;
                            api("getModx",{manuid : ($scope.manuid??0),lst:$scope.lst,country: $scope.country},function(list){
                                if(!list) list=[];
                                $scope.list = list;
                                if(list.length==1) $scope.ngModel=list[0].id;
                                $scope.loading = false;
                                $scope.$apply();
                            });
                        }
                        else{
                            $scope.list = [];
                        }
                    }
                    window.resetselectmod = function(){
                        $scope.lst = [];
                        $scope.loadData();
                    }
                    $scope.$watch("manuid",function(){
                        $scope.loadData();
                    });
                },
                link: function (scope, iElement, iAttrs) {
                    
                }
            };
        }]);
    </script>
    <?php
});

Route::isJs(function(){
    ob_start();
    ?>
      <div class="form-group avs" style="margin: 0;">
          <select class="form-control avs" required ng-model="ngModel" ng-options="elm.id as elm.name for elm in list">
            <option value="" style="display: none"></option>
          </select>
      </div>
    <?php
    $code=ob_get_clean();
    ?>
    <script>
        app.directive('selecttype', [function () {
            return {
                restrict: 'EA',
                transclude : false,
                replace : false,
                template : <?= json_encode(preg_replace("/\t|\n|\r/i", "", $code)) ?>,
                scope : {
                    ngModel : "=?",
                    modid: "=?",
                    lst:"=?",
                    country: "@"
                },
                controller : function($scope){
                    $scope.loading = false;
                    $scope.list = [];
                    $scope.loadData = function(){
                        
                        if(($scope.modid??0)>0){
                            $scope.loading = true;
                            api("getTypex",{modid : ($scope.modid??0),lst:$scope.lst,country: $scope.country},function(list){
                                if(!list) list=[];
                                $scope.list = list;
                                if(list.length==1) {$scope.ngModel=list[0].id;}
                                $scope.loading = false;
                                $scope.$apply();
                                if(list.length==1) setTimeout(() => {
                                    angular.element(document.getElementsByTagName('form')[2]).scope().submit();
                                }, 100);
                            });
                        }else{
                            $scope.list = [];
                        }
                    }
                    window.resetselecttype = function(){
                        $scope.lst = [];
                        $scope.loadData();
                    }
                    $scope.$watch("modid",function(){
                        $scope.loadData();
                    });
                },
                link: function (scope, iElement, iAttrs) {
                    
                }
            };
        }]);
    </script>
    <?php
});