[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]

<link rel="stylesheet" href="[{$oViewConf->getModuleUrl('ys_shipcloud', 'out/css/ys_shipcloud.min.css')}]">

<script type="text/javascript" src="[{$oViewConf->getModuleUrl('ys_shipcloud', 'out/js/ys_shipcloud.min.js')}]"></script>

[{assign var="readonly" value=""}]
[{if $readonly}]
    [{assign var="readonly" value="readonly disabled"}]
[{/if}]

<form name="transfer" id="transfer" action="[{$oViewConf->getSelfLink()}]" method="post">
    [{$oViewConf->getHiddenSid()}]
    <input type="hidden" name="oxid" value="[{$oxid}]">
    <input type="hidden" name="cl" value="ShipcloudAdmin">
    <input type="hidden" name="fnc" value="">
    <input type="hidden" name="actshop" value="[{$oViewConf->getActiveShopId()}]">
    <input type="hidden" name="updatenav" value="">
    <input type="hidden" name="editlanguage" value="[{$editlanguage}]">
</form>
<div class="shipcloud">
    <form name="myedit" id="myedit" action="[{$oViewConf->getSelfLink()}]" method="post" onSubmit="">
        [{$oViewConf->getHiddenSid()}]
        <input type="hidden" name="cl" value="ShipcloudAdmin">
        <input type="hidden" name="fnc" value="save">
        <input type="hidden" name="actshop" value="[{$oViewConf->getActiveShopId()}]">
        <input type="hidden" name="oxid" value="[{$oxid}]">
        <input type="hidden" name="editval[oxshops__oxid]" value="[{$oxid}]">

        <div class="fullwidth-container">
            <div class="row">
                [{* Start of left page *}]
                <div class="col-md-6">
                    <fieldset id="dlfLayout">
                        <LEGEND>
                            [{oxmultilang ident="YS_SETTINGS"}]
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-12 form-group">
                                <label class="control-label" data-toggle="tooltip" title="[{oxinputhelp ident="API_KEY"}]">[{oxmultilang ident="YS_API_KEY"}]</label>
                                <input type=text class="form-control editinput" name="ysedit[API_KEY]" value="[{$settings.API_KEY}]">
                            </div>
                            <div class="col-12 col-md-6 form-group">
                                <input type=checkbox class="form-control editinput" id="enable_sandbox_mode" name="ysedit[ENABLE_SANDBOX_MODUS]" [{if $settings.ENABLE_SANDBOX_MODUS}]checked[{/if}]>
                                <label class="control-label" for="enable_sandbox_mode">[{oxmultilang ident="YS_ENABLE_SANDBOX_MODUS"}]</label>
                            </div>
                            <div class="col-12 col-md-6 form-group">
                                <label class="control-label" data-toggle="tooltip" title="[{oxinputhelp ident="API_KEY"}]">[{oxmultilang ident="YS_SANDBOX_API_KEY"}]</label>
                                <input type=text class="form-control editinput" name="ysedit[SANDBOX_API_KEY]" value="[{$settings.SANDBOX_API_KEY}]">
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-12">
                                <input type="submit" value="[{oxmultilang ident="GENERAL_SAVE"}]">
                            </div>
                        </div>
                    </fieldset>
                    <fieldset id="dlfLayout">
                        <LEGEND>
                            [{oxmultilang ident="YS_ADVANCED_SETTINGS"}]
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-12 col-md-6 form-group">
                                <div class="custom-control custom-checkbox">
                                    <input type=checkbox class="custom-control-input" id="show_all_available_packages" name="ysedit[SHOW_ALL_AVAILABLE_PACKAGES]" [{if $settings.SHOW_ALL_AVAILABLE_PACKAGES}]checked[{/if}]>
                                    <label class="custom-control-label" for="show_all_available_packages">[{oxmultilang ident="YS_SHOW_ALL_AVAILABLE_PACKAGES"}]</label>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-12">
                                <input type="submit" value="[{oxmultilang ident="GENERAL_SAVE"}]">
                            </div>
                        </div>
                    </fieldset>
                    <FIELDSET id="fldLayout">
                        <LEGEND id="lgdLayout">
                            [{oxmultilang ident="YS_ADDRESS_DATA"}]
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_FIRST_NAME"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][fname]" value="[{$settings.from.fname}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_LAST_NAME"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][lname]" value="[{$settings.from.lname}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_ADDITIONAL_INFO"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][addinfo]" value="[{$settings.from.addinfo}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_COMPANY"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][company]" value="[{$settings.from.company}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_EMAIL"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][mail]" value="[{$settings.from.mail}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_FON"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][fon]" value="[{$settings.from.fon}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_STREET"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][street]" value="[{$settings.from.street}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-2 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_STREET_NUMBER"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][streetnr]" value="[{$settings.from.streetnr}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-2 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_ZIP_CODE"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][zip]" value="[{$settings.from.zip}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-4 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_CITY"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][city]" value="[{$settings.from.city}]" [{$ys_readonly}]>
                            </div>
                            <div class="col-md-6 form-group">
                                <label class="control-label">[{oxmultilang ident="GENERAL_COUNTRY"}]</label>
                                <input type="text" class="form-control editinput" size="10" name="ysedit[from][country]" value="[{$settings.from.country}]" [{$ys_readonly}]>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-12">
                                <input type="submit" value="[{oxmultilang ident="GENERAL_SAVE"}]">
                            </div>
                        </div>
                    </FIELDSET>
                    <FIELDSET id="fldLayout">
                        <LEGEND id="lgdLayout">
                            [{oxmultilang ident="YS_CARRIER_MAPPING"}]
                        </LEGEND>
                        <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="[delvset]["|cat:$delvset->oxdeliveryset__oxid->value|cat:"][carrier]"}]

                                    <select class="form-control" name="ysedit[{$custKey}]" [{$ys_disabled}]>
                                        <option value="" [{if !$settings.delvset.$delvId.carrier}]SELECTED[{/if}]>---</option>
                                        [{foreach from=$aCarriers item="oCarrier" key="iCarrier" name="carrier_loop"}]
                                            <option value="[{$oCarrier.name}]" [{if $oCarrier.name == $settings.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=$settings.delvset.$delvId.carrier}]
                                    [{assign var="custSerKey" value="[delvset]["|cat:$delvset->oxdeliveryset__oxid->value|cat:"][service]"}]
                                    <select class="form-control" name="ysedit[{$custSerKey}]" [{$ys_disabled}]>
                                        <option value="" [{if !$settings.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 $settings.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>
                        <div class="row">
                            <div class="col-12">
                                <input type="submit" value="[{oxmultilang ident="GENERAL_SAVE"}]">
                            </div>
                        </div>
                    </FIELDSET>
                </div>
                [{* Start of right page *}]
                <div class="col-md-6">
                    <fieldset id="dlfLayout">
                        <LEGEND>
                            [{oxmultilang ident="YS_ACCOUNT_DATA"}]
                        </LEGEND>
                        <div class="ys--row row">
                            <div class="col-12 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_ACCOUNT_OWNER"}]</label>
                                <input type="text" class="editinput form-control" name="ysedit[ACCOUNT_OWNER]" value="[{$settings.ACCOUNT_OWNER}]">
                            </div>
                            <div class="col-12 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_BANK_NAME"}]</label>
                                <input type="text" class="editinput form-control" name="ysedit[BANK_NAME]" value="[{$settings.BANK_NAME}]">
                            </div>
                            <div class="col-12 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_IBAN"}]</label>
                                <input type="text" class="editinput form-control" name="ysedit[IBAN]" value="[{$settings.IBAN}]">
                            </div>
                            <div class="col-12 form-group">
                                <label class="control-label">[{oxmultilang ident="YS_BIC"}]</label>
                                <input type="text" class="editinput form-control" name="ysedit[BIC]" value="[{$settings.BIC}]">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-12">
                                <input type="submit" value="[{oxmultilang ident="GENERAL_SAVE"}]">
                            </div>
                        </div>
                    </fieldset>

                    <FIELDSET id=fldLayout style="padding: 5px;">
                        <LEGEND id=lgdLayout>
                            [{oxmultilang ident="YS_CARRIER_FILTER"}]
                        </LEGEND>
                        <table border="0" width="98%">
                            <tr>
                                [{* Start of left page *}]
                                <td valign="top" class="edittext">
                                    <table cellspacing="0" cellpadding="0" border="0">
                                        <tr>
                                            [{if $settings.API_KEY}]
                                                [{assign var="carriers" value=$oView->getCarriers($settings.API_KEY)}]
                                            [{elseif $settings.SANDBOX_API_KEY}]
                                                [{assign var="carriers" value=$oView->getCarriers($settings.SANDBOX_API_KEY)}]
                                            [{/if}]
                                            [{if $carriers}]
                                                <td colspan="2">
                                                    <table cellspacing="0" cellpadding="5" border="0">
                                                        <thead>
                                                        <tr>
                                                            <th>[{oxmultilang ident="YS_CARRIER"}]</th>
                                                            <th>[{oxmultilang ident="YS_CARRIER_SERVICE"}]</th>
                                                            <th>[{oxmultilang ident="YS_CARRIER_PACKAGE_TYPE"}]</th>
                                                        </tr>
                                                        </thead>
                                                        [{foreach from=$carriers item="carrier"}]
                                                            <tr style="vertical-align: top">
                                                                <td style="border-bottom: 1px solid black;">
                                                                    <table cellspacing="0" cellpadding="1" border="0">
                                                                        <tr>
                                                                            <td class="edittext" style="vertical-align: top">
                                                                                <input type="checkbox" class="editinput" name="ysedit[carriers][[{$carrier.name}]][active]" [{if $settings.carriers[$carrier.name].active}]checked[{/if}]>
                                                                                <input type="hidden" name="ysedit[carriers][[{$carrier.name}]][display_name]" value="[{$carrier.display_name}]">
                                                                                <input type="hidden" name="ysedit[carriers][[{$carrier.name}]][name]" value="[{$carrier.name}]">
                                                                            </td>
                                                                            <td class="edittext" style="vertical-align: top">
                                                                                [{$carrier.display_name}]
                                                                            </td>
                                                                        </tr>
                                                                    </table>
                                                                </td>
                                                                <td style="vertical-align: top; border-bottom: 1px solid black">
                                                                    <table cellspacing="0" cellpadding="1" border="0">
                                                                        [{foreach from=$carrier.services item="service"}]
                                                                            <tr>
                                                                                <td class="edittext">
                                                                                    <input type="checkbox" class="editinput" name="ysedit[carriers][[{$carrier.name}]][services][[{$service}]]" [{if $settings.carriers[$carrier.name].services[$service]}]checked[{/if}] >
                                                                                </td>
                                                                                <td class="edittext">
                                                                                    [{"ys_service_"|cat:$service|oxmultilangassign}]
                                                                                </td>
                                                                            </tr>
                                                                        [{/foreach}]
                                                                    </table>
                                                                </td>
                                                                <td style="vertical-align: top; border-bottom: 1px solid black">
                                                                    <table cellspacing="0" cellpadding="1" border="0">
                                                                        [{foreach from=$carrier.package_types item="package"}]
                                                                            <tr>
                                                                                <td class="edittext">
                                                                                    <input type="checkbox" class="editinput" name="ysedit[carriers][[{$carrier.name}]][packages][[{$package}]]" [{if $settings.carriers[$carrier.name].packages[$package]}]checked[{/if}] >
                                                                                </td>
                                                                                <td class="edittext">
                                                                                    [{"ys_package_"|cat:$package|oxmultilangassign}]
                                                                                </td>
                                                                            </tr>
                                                                        [{/foreach}]
                                                                    </table>
                                                                </td>
                                                            </tr>
                                                        [{/foreach}]
                                                    </table>
                                                </td>
                                            [{/if}]
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>

                        <div class="row">
                            <div class="col-12">
                                <input type="submit" value="[{oxmultilang ident="GENERAL_SAVE"}]">
                            </div>
                        </div>
                    </FIELDSET>
                </div>
            </div>
        </div>
    </form>
</div>
[{include file="bottomnaviitem.tpl"}]
[{include file="bottomitem.tpl"}]
