<?php
$script = '$("#Queue_tier_rule_no_agent_no_wait").trigger("change");';
Yii::app()->clientScript->registerScript('checkTierRuleNoAgentSettings', $script);

echo $form->textFieldRow($model, 'max_subscriber', array(
    'class' => 'span1',
    'data-translation-id' => 'QUEUE_MODEL_MAX_SUBSCRIBER',
    'labelOptions' => array('class' => 'contextHelp-control-label')
        )
);

echo $form->textFieldRow($model, 'max_wait_time', array(
    'class' => 'span1',
    'value' => $model->getDefaultValue($model),
    'data-translation-target' => 'QUEUE_MODEL_MAX_WAITING_TIME_TRANSLATION',
    'append' => __('QUEUE_MODEL_WAITING_TIME_SECONDS'),
    'labelOptions' => array('class' => 'contextHelp-control-label')
        )
);

echo $form->textFieldRow($model, 'max_wait_time_with_no_agent_time_reached', array(
    'class' => 'span1',
    'value' => $model->getDefaultValue($model),
    'data-translation-target' => 'QUEUE_MODEL_MAX_WAITING_TIME_NO_AGENT_REACHED_TRANSLATION',
    'append' => __('QUEUE_MODEL_WAITING_TIME_SECONDS'),
    'labelOptions' => array('class' => 'contextHelp-control-label')
        )
);

echo '<p>';
echo $form->label($model, 'tier_rule_no_agent_no_wait', array('class' => 'newCheckbox span1'));
echo $form->checkBox($model, 'tier_rule_no_agent_no_wait', array(
    'data-translation-id' => 'QUEUE_MODEL_TIER_RULE_NO_AGENT_NO_WAIT',
        )
);
echo $form->error($model, 'tier_rule_no_agent_no_wait');
echo '</p>' . '<br>';

echo $form->textFieldRow($model, 'max_wait_time_with_no_agent', array(
    'class' => 'span1',
    'data-translation-target' => 'QUEUE_MODEL_MAX_WAITING_TIME_NO_AGENT_TRANSLATION',
    'append' => __('QUEUE_MODEL_WAITING_TIME_SECONDS'),
    'labelOptions' => array('class' => 'contextHelp-control-label')
        )
);

if ($model->getVisibilityByLicense()) {
    echo '<p>';
    echo $form->labelEx($model, 'tier_rules_apply', array('class' => 'newCheckbox span1'));
    echo $form->checkBox($model, 'tier_rules_apply', array(
        'data-translation-id' => 'QUEUE_MODEL_TIER_RULES_APPLY',
            )
    );
    echo $form->error($model, 'tier_rules_apply');
    echo '</p>' . '<br>';

    echo '<p>';
    echo $form->label($model, 'tier_rule_wait_multiply_level', array('class' => 'newCheckbox span1'));
    echo $form->checkBox($model, 'tier_rule_wait_multiply_level', array(
        'data-translation-id' => 'QUEUE_MODEL_TIER_RULE_WAIT_MULTIPLY_LEVEL',
            )
    );
    echo $form->error($model, 'tier_rule_wait_multiply_level');
    echo '</p>' . '<br>';

    echo $form->textFieldRow($model, 'tier_rule_wait_second', array(
        'class' => 'span1',
        'data-translation-target' => 'QUEUE_MODEL_WAITING_TIME_TRANSLATION',
        'append' => __('QUEUE_MODEL_WAITING_TIME_SECONDS'),
        'labelOptions' => array('class' => 'contextHelp-control-label')
            )
    );

    echo '<p>';
    echo $form->label($model, 'abandoned_resume_allowed', array('class' => 'newCheckbox span1'));
    echo $form->checkBox($model, 'abandoned_resume_allowed', array(
        'data-translation-id' => 'QUEUE_MODEL_ABANDONED_RESUME_ALLOWED',
            )
    );
    echo $form->error($model, 'abandoned_resume_allowed');
    echo '</p>' . '<br>';

    echo $form->textFieldRow($model, 'discard_abandoned_after', array(
        'class' => 'span1',
        'data-translation-target' => 'QUEUE_MODEL_DISCARD_ABBANDONED_AFTER_TRANSLATION',
        'append' => __('QUEUE_MODEL_WAITING_TIME_SECONDS'),
        'labelOptions' => array('class' => 'contextHelp-control-label')
            )
    );


    echo '<p>';
    echo $form->dropDownListRow($model, 'time_base_score', $model->getTimeBaseScoreList(), array(
        'class' => 'contextHelp-span2',
        'data-translation-id' => 'QUEUE_MODEL_TIME_BASE_SCORE',
        'labelOptions' => array('class' => 'contextHelp-control-label')
            )
    );
    echo $form->error($model, 'time_base_score');
    echo '</p>';
}
if (PhonalisaLicenseManager::routingScriptExtensionMax() !== 0) {
    echo $form->dropDownListRow(
            $model, 'scriptExtension', ScriptExtension::model()->listData, array(
        'class' => 'contextHelp-span2',
        'data-translation-id' => 'USER_MODEL_SCRIPT_EXTENSION',
        'labelOptions' => array('class' => 'contextHelp-control-label')
            )
    );
}


if (Yii::app()->user->translateMode) {
    echo '<i data-translation-target="QUEUE_MODEL_WAITING_TIME_TRANSLATION" data-translation-id="QUEUE_MODEL_TIER_RULE_WAIT_SECOND"></i>';
    echo '<i data-translation-target="QUEUE_MODEL_WAITING_TIME_TRANSLATION" data-translation-id="QUEUE_MODEL_WAITING_TIME_SECONDS"></i>';

    echo '<i data-translation-target="QUEUE_MODEL_DISCARD_ABBANDONED_AFTER_TRANSLATION" data-translation-id="QUEUE_MODEL_DISCARD_ABANDONED_AFTER"></i>';
    echo '<i data-translation-target="QUEUE_MODEL_DISCARD_ABBANDONED_AFTER_TRANSLATION" data-translation-id="QUEUE_MODEL_WAITING_TIME_SECONDS"></i>';

    echo '<i data-translation-target="QUEUE_MODEL_MAX_WAITING_TIME_TRANSLATION" data-translation-id="QUEUE_MODEL_MAX_WAIT_TIME"></i>';
    echo '<i data-translation-target="QUEUE_MODEL_MAX_WAITING_TIME_TRANSLATION" data-translation-id="QUEUE_MODEL_WAITING_TIME_SECONDS"></i>';

    echo '<i data-translation-target="QUEUE_MODEL_MAX_WAITING_TIME_NO_AGENT_TRANSLATION" data-translation-id="QUEUE_MODEL_MAX_WAIT_TIME_NO_AGENT"></i>';
    echo '<i data-translation-target="QUEUE_MODEL_MAX_WAITING_TIME_NO_AGENT_TRANSLATION" data-translation-id="QUEUE_MODEL_WAITING_TIME_SECONDS"></i>';

    echo '<i data-translation-target="QUEUE_MODEL_MAX_WAITING_TIME_NO_AGENT_REACHED_TRANSLATION" data-translation-id="QUEUE_MODEL_MAX_WAIT_TIME_NO_AGENT_TIME_REACHED"></i>';
    echo '<i data-translation-target="QUEUE_MODEL_MAX_WAITING_TIME_NO_AGENT_REACHED_TRANSLATION" data-translation-id="QUEUE_MODEL_WAITING_TIME_SECONDS"></i>';
}
?>

<style>
    .newCheckbox {
        text-align: right;
        width: 250px;
        margin-right: 20px;
        margin-top: 2px;
    }
</style>

<script>
    var additionalDataIDs = [
        '#Queue_time_base_score',
        '#Queue_tier_rule_wait_second',
        '#Queue_tier_rule_wait_multiply_level',
        '#Queue_discard_abandoned_after',
        '#Queue_abandoned_resume_allowed'
    ];

    $('#Queue_tier_rules_apply').change(function () {
        if ($(this).is(':checked')) {
            $(additionalDataIDs).each(function (key, id) {
                $(id).removeAttr('disabled');
            });
        } else {
            $(additionalDataIDs).each(function (key, id) {
                $(id).val('');
                $(id).prop("checked", false);
                $(id).attr('disabled', 'disabled');
                if ($(id).prev().attr('type') === 'hidden') {
                    $(id).prev().attr('disabled', 'disabled');
                }
            });
        }
    });
    $('#Queue_tier_rules_apply').trigger("change");
    $('#Queue_tier_rule_no_agent_no_wait').trigger("change");

    $('#Queue_tier_rule_no_agent_no_wait').change(function () {
        if ($(this).is(':checked')) {
            $('#Queue_max_wait_time_with_no_agent').removeAttr('disabled');
        } else {
            $('#Queue_max_wait_time_with_no_agent').val('');
            $('#Queue_max_wait_time_with_no_agent').attr('disabled', 'disabled');
        }
    });
</script>