<div class="content-header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6">
                <h2>{{::vm.translate.get('Cart Price Rules')}}</h2>
            </div>
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="card">
            <div class="card-header">
                <h2 class="card-title ng-binding ng-scope" ng-if="!vm.isEditMode">{{::vm.translate.get('Create Cart Price Rule')}}</h2>
                <h2 class="card-title ng-binding ng-scope" ng-if="vm.isEditMode">{{::vm.translate.get('Edit Cart Price Rule')}}</h2>
            </div>
            <div class="card-body">
                <form name="cartRuleForm" class="form-horizontal">
                    <div class="col-sm-offset-2 bg-danger" ng-show="vm.validationErrors">
                        <ul>
                            <li ng-repeat="error in vm.validationErrors">{{error}}</li>
                        </ul>
                    </div>
                    <uib-tabset>
                        <uib-tab index="0" heading="{{::vm.translate.get('General Information')}}">
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Name')}} *</label>
                                <div>
                                    <input name="name" ng-model="vm.cartRule.name" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Description')}}</label>
                                <div>
                                    <textarea name="description" ng-model="vm.cartRule.description" rows="3" class="form-control" />
                                </div>
                            </div>
                            <div ng-show="false" class="form-group">
                                <div>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" ng-model="vm.cartRule.isCouponRequired">{{::vm.translate.get('Require coupon code')}}
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div ng-show="vm.cartRule.isCouponRequired" class="form-group">
                                <label class="control-label">{{::vm.translate.get('Coupon code')}} *</label>
                                <div>
                                    <input name="couponCode" ng-model="vm.cartRule.couponCode" class="form-control" />
                                </div>
                            </div>
                            <div ng-show="vm.cartRule.isCouponRequired" class="form-group">
                                <label class="control-label">{{::vm.translate.get('Usage limit per coupon')}}</label>
                                <div>
                                    <input name="usageLimitPerCoupon" ng-model="vm.cartRule.usageLimitPerCoupon" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Usage limit per customer')}}</label>
                                <div>
                                    <input name="usageLimitPerCustomer" ng-model="vm.cartRule.usageLimitPerCustomer" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Start')}}</label>
                                <div>
                                    <p class="input-group simpl-datetime-picker">
                                        <input type="text" class="form-control" datetime-picker="dd MMM yyyy HH:mm" ng-model="vm.cartRule.startOn" is-open="vm.datePickerStartOn.open" datepicker-options="vm.datePickerStartOn.datepickerOptions" />
                                        <span class="input-group-append">
                                            <button type="button" class="btn btn-default" ng-click="vm.openCalendar($event, 'datePickerStartOn')"><i class="fa fa-calendar"></i></button>
                                        </span>
                                    </p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('End')}}</label>
                                <div>
                                    <p class="input-group simpl-datetime-picker">
                                        <input type="text" class="form-control" datetime-picker="dd MMM yyyy HH:mm" ng-model="vm.cartRule.endOn" is-open="vm.datePickerEndOn.open" datepicker-options="vm.datePickerEndOn.datepickerOptions" />
                                        <span class="input-group-append">
                                            <button type="button" class="btn btn-default" ng-click="vm.openCalendar($event, 'datePickerEndOn')"><i class="fa fa-calendar"></i></button>
                                        </span>
                                    </p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Apply')}} *</label>
                                <div>
                                    <select class="form-control" ng-model="vm.cartRule.ruleToApply">
                                        <option value="cart_fixed">{{::vm.translate.get('Fixed amount discount for whole cart')}}</option>
                                        <option value="by_percent">{{::vm.translate.get('Percent of product price discount')}}</option>
                                        <!--<option value="buy_x_get_y">Buy X Get Y Free (discount amount is Y)</option>-->
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Discount Amount')}} *</label>
                                <div>
                                    <input name="discountAmount" ng-model="vm.cartRule.discountAmount" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">{{::vm.translate.get('Max Discount Amount')}}</label>
                                <div>
                                    <input name="maxDiscountAmount" ng-model="vm.cartRule.maxDiscountAmount" class="form-control" />
                                </div>
                            </div>
                            <div ng-show="vm.cartRule.ruleToApply == 'buy_x_get_y'" class="form-group">
                                <label class="control-label">{{::vm.translate.get('Discount Step (Buy X)')}}</label>
                                <div>
                                    <input name="discountStep" ng-model="vm.cartRule.discountStep" class="form-control" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" ng-model="vm.cartRule.isActive">{{::vm.translate.get('Is Active')}}
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </uib-tab>
                        <uib-tab index="1" heading="{{::vm.translate.get('Products Selection')}}">
                            <p>{{::vm.translate.get('Select products to apply or leave blank for all products')}}</p>
                            <product-selection-directive model-id="productsSelector" title="{{::vm.translate.get('Add products')}}" selected-products="vm.cartRule.products"></product-selection-directive>
                            <p><button type="button" class="btn btn-default" data-toggle="modal" data-target="#productsSelector">{{::vm.translate.get('Manage Products Selection')}}</button></p>
                            <table class="table table-striped">
                                <tr>
                                    <th>{{::vm.translate.get('Name')}}</th>
                                    <th class="text-center">{{::vm.translate.get('Is Published')}}</th>
                                </tr>
                                <tr ng-repeat="product in vm.cartRule.products">
                                    <td>{{product.name}}</td>
                                    <td class="text-center"><i ng-attr-class="{{product.isPublished && 'fa fa-circle' || 'fa fa-circle-o'}}"></i></td>
                                </tr>
                            </table>
                        </uib-tab>
                    </uib-tabset>
                    <div class="form-group">
                        <div class="">
                            <button class="btn btn-success float-right" ng-click="vm.save()"><span class="fa fa-save"></span> {{::vm.translate.get('Save')}}</button>
                            <button ui-sref="cart-rules" class="btn btn-default">{{::vm.translate.get('Cancel')}}</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>