<div class="ys-package-template-wrapper" id="package-template-[{$iKey}]">
    <div class="ys-package-template-header">[{oxmultilang ident="YS_PACKAGE_TEMPLATE" suffix="COLON"}] [{$aPackageTemplate.name}]
        <button class="btn ys-package-template-delete" data-fieldid="[{$iKey}]">
            <i class="fa fa-trash-alt"></i>
        </button>
        <button class="btn ys-package-template-really-delete" data-fieldid="[{$iKey}]">[{oxmultilang ident="YS_REALLY_DELETE"}]</button>
    </div>
    <div class="ys-package-template-body">
        <div class="row">
            <div class="form-group col-lg-6">
                <label>[{oxmultilang ident="YS_NAME"}]</label>
                <input class="form-control" type="text" name="ysedit[package_templates][[{$iKey}]][name]" value="[{$aPackageTemplate.name}]">
            </div>
            <div class="form-group col-lg-6">
                <label>[{oxmultilang ident="YS_WIDTH_IN_CM"}]</label>
                <input class="form-control" type="number" step="0.01" name="ysedit[package_templates][[{$iKey}]][width]" value="[{$aPackageTemplate.width}]">
            </div>
            <div class="form-group col-lg-6">
                <label>[{oxmultilang ident="YS_LENGTH_IN_CM"}]</label>
                <input class="form-control" type="number" step="0.01" name="ysedit[package_templates][[{$iKey}]][length]" value="[{$aPackageTemplate.length}]">
            </div>
            <div class="form-group col-lg-6">
                <label>[{oxmultilang ident="YS_HEIGHT_IN_CM"}]</label>
                <input class="form-control" type="number" step="0.01" name="ysedit[package_templates][[{$iKey}]][height]" value="[{$aPackageTemplate.height}]">
            </div>
            <div class="form-group col-lg-6">
                <label>[{oxmultilang ident="YS_PACKAGE_TYPE"}]</label>
                <select class="form-control" name="ysedit[package_templates][[{$iKey}]][type]">
                    <option value="standard" [{if $aPackageTemplate.type == "standard"}]selected[{/if}]>[{oxmultilang ident="ys_package_standard"}]</option>
                    <option value="bulk" [{if $aPackageTemplate.type == "bulk"}]selected[{/if}]>[{oxmultilang ident="ys_package_bulk"}]</option>
                    <option value="books" [{if $aPackageTemplate.type == "books"}]selected[{/if}]>[{oxmultilang ident="ys_package_books"}]</option>
                    <option value="parcel_letter" [{if $aPackageTemplate.type == "parcel_letter"}]selected[{/if}]>[{oxmultilang ident="ys_package_parcel_letter"}]</option>
                    <option value="parcel" [{if $aPackageTemplate.type == "parcel"}]selected[{/if}]>[{oxmultilang ident="ys_package_parcel"}]</option>
                    <option value="letter" [{if $aPackageTemplate.type == "letter"}]selected[{/if}]>[{oxmultilang ident="ys_package_letter"}]</option>
                </select>
            </div>
            <div class="form-group col-lg-6">
                <input class="form-control" type="checkbox" name="ysedit[package_templates][[{$iKey}]][send_order_mail]" id="ysedit_send_order"[{if $aPackageTemplate.send_order_mail}] checked[{/if}]>
                <label for="ysedit_send_order">[{oxmultilang ident="YS_SEND_ORDER_MAIL"}]</label>
            </div>
            <div class="form-group col-lg-6">
                <label>[{oxmultilang ident="YS_DEFAULT_ADDITIONAL_WEIGHT"}]</label>
                <input class="form-control" type="number" step="0.01" name="ysedit[package_templates][[{$iKey}]][additional_weight]" value="[{$aPackageTemplate.additional_weight}]">
            </div>
        </div>

        <div class="row">
            <div class="col-12">
                <h2>[{oxmultilang ident="YS_CARRIER_MAPPING"}]</h2>
                <div class="row">
                    [{assign var="delvsets" value=$oView->getDeliverySet()}]
                    [{assign var="aCarriers" value=$oView->getActiveCarriers()}]

                    [{foreach from=$delvsets item="delvset" name="delvset_loop"}]
                        <div class="col-12">
                            <h3>[{$delvset->oxdeliveryset__oxtitle->value}]</h3>
                        </div>
                        <div class="col-12 col-md-6 form-group">
                            [{assign var="delvId" value=$delvset->oxdeliveryset__oxid->value}]
                            <label class="control-label">[{oxmultilang ident="YS_CARRIER"}]</label>
                            [{assign var="custKey" value="[package_templates]["|cat:$iKey|cat:"][delvset]["|cat:$delvset->oxdeliveryset__oxid->value|cat:"][carrier]"}]

                            <select class="form-control" name="ysedit[{$custKey}]" [{$ys_disabled}]>
                                <option value="" [{if !$aPackageTemplate.delvset.$delvId.carrier}]SELECTED[{/if}]>---</option>
                                [{foreach from=$aCarriers item="oCarrier" key="iCarrier" name="carrier_loop"}]
                                    <option value="[{$oCarrier.name}]" [{if $oCarrier.name == $aPackageTemplate.delvset.$delvId.carrier}]selected[{/if}]>[{$oCarrier.display_name}]</option>
                                [{/foreach}]
                            </select>
                        </div>
                        <div class="col-12 col-md-6 form-group">
                            [{assign var="delvId" value=$delvset->oxdeliveryset__oxid->value}]
                            <label class="control-label">[{oxmultilang ident="YS_CARRIER_SERVICE"}]</label>
                            [{assign var="carrierName" value=$aPackageTemplate.delvset.$delvId.carrier}]
                            [{assign var="custSerKey" value="[package_templates]["|cat:$iKey|cat:"][delvset]["|cat:$delvset->oxdeliveryset__oxid->value|cat:"][service]"}]
                            <select class="form-control" name="ysedit[{$custSerKey}]" [{$ys_disabled}]>
                                <option value="" [{if !$aPackageTemplate.delvset.$delvId.carrier}]SELECTED[{/if}]>---</option>
                                [{foreach from=$aCarriers item="oCarrier" key="iCarrier" name="scarrier_loop"}]
                                    [{foreach from=$oCarrier.services item="oService" key="iService" name="carrier_service_loop"}]
                                        <option value="[{$iService}]" class="[{if $carrierName != $iCarrier}]d-none [{/if}]cl-carrier-[{$iCarrier}]" [{if $aPackageTemplate.delvset.$delvId.service == $iService}]selected[{/if}]>[{"ys_service_"|cat:$iService|oxmultilangassign}]</option>
                                    [{/foreach}]
                                [{/foreach}]
                            </select>
                            <script>
                                $(document).ready(function () {
                                    $('select[name="ysedit[{$custKey}]"').on('change', function () {
                                        var value = ".cl-carrier-" + $(this)[0].value;
                                        $('select[name="ysedit[{$custSerKey}]"]').val("");
                                        $('select[name="ysedit[{$custSerKey}]"] option[class^="cl-carrier-"]').addClass('d-none');
                                        $('select[name="ysedit[{$custSerKey}]"] option' + value).removeClass('d-none');
                                    });
                                });
                            </script>
                        </div>
                    [{/foreach}]
                </div>
                [{*foreach from=$aCarriers item="oCarrier" key="iCarrier" name="carrier_loop"}]
                    [{if !$smarty.foreach.carrier_loop.first}]
                        <hr>
                    [{/if}]
                    <h3>[{$oCarrier.display_name}]</h3>
                    [{foreach from=$delvsets item="delvset" name="delvset_loop"}]
                        <div class="form-group">
                            [{assign var="custKey" value="[package_templates]["|cat:$iKey|cat:"][delvset]["|cat:$iCarrier|cat:"]["|cat:$delvset->oxdeliveryset__oxid->value|cat:"]"}]
                            [{assign var="delvId" value=$delvset->oxdeliveryset__oxid->value}]
                            <input type=checkbox class="form-control editinput" id="[{$custKey}]" name="ysedit[{$custKey}]" [{if $aPackageTemplate.delvset.$iCarrier.$delvId}]checked[{/if}]>
                            <label class="control-label" for="[{$custKey}]">[{$delvset->oxdeliveryset__oxtitle->value}]</label>
                        </div>
                    [{/foreach}]
                [{/foreach*}]
            </div>
        </div>
    </div>
    <div class="new-package-template-connection"><span></span></div>
</div>
