<!--
  ~ Copyright 2021 Apollo Authors
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  ~
-->
<!doctype html>
<html ng-app="namespace">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="icon" href="./img/config.png">
    <!-- styles -->
    <link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/angular/angular-toastr-1.4.1.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
    <link rel="stylesheet" type="text/css" media='all' href="vendor/angular/loading-bar.min.css">
    <link rel="stylesheet" type="text/css" href="styles/common-style.css">
    <title>{{'Namespace.Title' | translate }}</title>
</head>

<body>

    <apollonav></apollonav>

    <div class="container-fluid apollo-container hidden" ng-controller="LinkNamespaceController">

        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="panel">
                    <header class="panel-heading">
                        <div class="row">
                            <div class="col-md-6">{{'Namespace.Title' | translate }}
                                <small><a target="_blank"
                                        href="https://www.apolloconfig.com/#/zh/design/apollo-core-concept-namespace">
                                        {{'Namespace.UnderstandMore' | translate }}
                                    </a> </small>
                            </div>
                            <div class="col-md-6 text-right">
                                <button type="button" class="btn btn-info"
                                    ng-click="back()">{{'Common.ReturnToIndex' | translate }} </button>
                            </div>
                        </div>

                    </header>

                    <div class="panel-body">

                        <div class="alert alert-info no-radius">
                            <strong>Tips:</strong>
                            <ul ng-show="type == 'link'">
                                <li>{{'Namespace.Link.Tips1' | translate }}</li>
                                <li>{{'Namespace.Link.Tips2' | translate }}</li>
                            </ul>
                            <ul ng-show="type == 'create' && appNamespace.isPublic">
                                <li>{{'Namespace.CreatePublic.Tips1' | translate }}</li>
                                <li>{{'Namespace.CreatePublic.Tips2' | translate }}</li>
                                <li>{{'Namespace.CreatePublic.Tips3' | translate }}</li>
                                <li>{{'Namespace.CreatePublic.Tips4' | translate }}</li>
                            </ul>
                            <ul ng-show="type == 'create' && !appNamespace.isPublic">
                                <li>{{'Namespace.CreatePrivate.Tips1' | translate }}</li>
                                <li>{{'Namespace.CreatePrivate.Tips2' | translate }}</li>
                                <li>{{'Namespace.CreatePrivate.Tips3' | translate }}</li>
                                <li>{{'Namespace.CreatePrivate.Tips4' | translate }}</li>
                            </ul>
                        </div>
                        <div class="row text-right" style="padding-right: 20px;">
                            <div class="btn-group btn-group-sm" role="group" aria-label="...">
                                <button type="button" class="btn btn-default" ng-class="{active:type=='link'}"
                                    ng-click="switchType('link')">{{'Namespace.AssociationPublicNamespace' | translate }}
                                </button>
                                <button type="button" class="btn btn-default" ng-class="{active:type=='create'}"
                                    ng-click="switchType('create')">{{'Namespace.CreateNamespace' | translate }}
                                </button>
                            </div>
                        </div>


                        <form class="form-horizontal" name="namespaceForm" valdr-type="AppNamespace"
                            style="margin-top: 30px;" ng-show="step == 1" ng-submit="createNamespace()">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">{{'Common.AppId' | translate }}</label>
                                <div class="col-sm-6" valdr-form-group>
                                    <label class="form-control-static" ng-bind="appId"></label>
                                </div>
                            </div>
                            <div class="form-horizontal" ng-show="type == 'link'">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">
                                        <apollorequiredfield></apollorequiredfield>
                                        {{'Namespace.ChooseCluster' | translate }}
                                    </label>
                                    <div class="col-sm-6" valdr-form-group>
                                        <apolloclusterselector apollo-app-id="appId" apollo-default-all-checked="true"
                                            apollo-select="collectSelectedClusters"></apolloclusterselector>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" ng-show="type == 'create'">
                                <label class="col-sm-3 control-label">
                                    <apollorequiredfield></apollorequiredfield>
                                    {{'Namespace.NamespaceName' | translate }}
                                </label>
                                <div class="col-sm-5" valdr-form-group>
                                    <div ng-class="{'input-group':appNamespace.isPublic && appendNamespacePrefix}">
                                        <span class="input-group-addon"
                                            ng-show="appNamespace.isPublic && appendNamespacePrefix"
                                            ng-bind="appBaseInfo.namespacePrefix"></span>
                                        <input type="text" name="namespaceName" class="form-control"
                                            ng-model="appNamespace.name">
                                    </div>
                                </div>

                                <div class="col-sm-2">
                                    <select class="form-control" name="format" ng-model="appNamespace.format">
                                        <option value="properties">properties</option>
                                        <option value="xml">xml</option>
                                        <option value="json">json</option>
                                        <option value="yml">yml</option>
                                        <option value="yaml">yaml</option>
                                        <option value="txt">txt</option>
                                    </select>
                                </div>

                                &nbsp;&nbsp;
                                <span ng-show="appNamespace.isPublic && appendNamespacePrefix"
                                    ng-bind="concatNamespace()" style="line-height: 34px;"></span>
                            </div>

                            <div class="form-group" ng-show="type == 'create' && appNamespace.isPublic">
                                <label class="col-sm-3 control-label">
                                    {{'Namespace.AutoAddDepartmentPrefix' | translate }}
                                </label>
                                <div class="col-sm-6" valdr-form-group>
                                    <div>
                                        <label class="checkbox-inline">
                                            <input type="checkbox" ng-model="appendNamespacePrefix" />
                                            {{appBaseInfo.namespacePrefix}}
                                        </label>
                                    </div>
                                    <small>{{'Namespace.AutoAddDepartmentPrefixTips' | translate }}</small>
                                </div>
                            </div>

                            <div class="form-group"
                                ng-show="type == 'create' && (pageSetting.canAppAdminCreatePrivateNamespace || hasRootPermission)">
                                <label class="col-sm-3 control-label">
                                    <apollorequiredfield></apollorequiredfield>
                                    {{'Namespace.NamespaceType' | translate }}
                                </label>
                                <div class="col-sm-4" valdr-form-group>
                                    <label class="radio-inline">
                                        <input type="radio" name="namespaceType" value="true" ng-value="true"
                                            ng-model="appNamespace.isPublic"> {{'Namespace.NamespaceType.Public' | translate }}
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="namespaceType" value="false" ng-value="false"
                                            ng-model="appNamespace.isPublic"> {{'Namespace.NamespaceType.Private' | translate }}
                                    </label>
                                </div>
                            </div>
                            <div class="form-group" ng-show="type == 'create'" valdr-form-group>
                                <label class="col-sm-3 control-label">{{'Namespace.Remark' | translate }}</label>
                                <div class="col-sm-7" valdr-form-group>
                                    <textarea class="form-control" rows="3" name="comment"
                                        ng-model="appNamespace.comment"></textarea>
                                </div>
                            </div>
                            <div class="form-group" ng-show="type == 'link'">
                                <label class="col-sm-3 control-label">
                                    <apollorequiredfield></apollorequiredfield>
                                    {{'Namespace.Namespace' | translate }}
                                </label>
                                <div class="col-sm-4" valdr-form-group>
                                    <select id="namespaces">
                                        <option></option>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-offset-3 col-sm-10">
                                    <button type="submit" class="btn btn-primary"
                                        ng-disabled="(type == 'create' && namespaceForm.$invalid) || submitBtnDisabled">
                                        {{'Common.Submit' | translate }}
                                    </button>
                                </div>
                            </div>
                        </form>

                        <div class="row text-center" ng-show="step == 2">
                            <img src="img/sync-succ.png" style="height: 100px; width: 100px">
                            <h3>{{'Common.Created' | translate }}</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <div ng-include="'views/common/footer.html'"></div>

    <!--angular-->
    <script src="vendor/angular/angular.min.js"></script>
    <script src="vendor/angular/angular-resource.min.js"></script>
    <script src="vendor/angular/angular-toastr-1.4.1.tpls.min.js"></script>
    <script src="vendor/angular/loading-bar.min.js"></script>
    <script src="vendor/angular/angular-cookies.min.js"></script>

    <script src="vendor/angular/angular-translate.2.18.1/angular-translate.min.js"></script>
    <script src="vendor/angular/angular-translate.2.18.1/angular-translate-loader-static-files.min.js"></script>
    <script src="vendor/angular/angular-translate.2.18.1/angular-translate-storage-cookie.min.js"></script>

    <!-- jquery.js -->
    <script src="vendor/jquery.min.js" type="text/javascript"></script>

    <script src="vendor/select2/select2.min.js" type="text/javascript"></script>


    <!-- bootstrap.js -->
    <script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>

    <script src="vendor/valdr/valdr.min.js" type="text/javascript"></script>
    <script src="vendor/valdr/valdr-message.min.js" type="text/javascript"></script>

    <script type="application/javascript" src="scripts/app.js"></script>
    <script type="application/javascript" src="scripts/services/AppService.js"></script>
    <script type="application/javascript" src="scripts/services/EnvService.js"></script>
    <script type="application/javascript" src="scripts/services/UserService.js"></script>
    <script type="application/javascript" src="scripts/services/CommonService.js"></script>
    <script type="application/javascript" src="scripts/services/NamespaceService.js"></script>
    <script type="application/javascript" src="scripts/services/PermissionService.js"></script>
    <script type="application/javascript" src="scripts/AppUtils.js"></script>

    <!--directive-->
    <script type="application/javascript" src="scripts/directive/directive.js"></script>

    <script type="application/javascript" src="scripts/controller/NamespaceController.js"></script>

    <script src="scripts/valdr.js" type="text/javascript"></script>

</body>

</html>
