{% extends "base.html" %}
{% block content %}
<div>
  {{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
  {{ macros.m_row_start('5') }}
  {{ macros.m_row_end() }}

  <nav>  
    {{ macros.m_tab_head_start() }}
      {{ macros.m_tab_head('basic', 'Basic', true) }}
      {{ macros.m_tab_head('advanced', 'Advanced', false) }}
    {{ macros.m_tab_head_end() }}
  </nav>  
  <form id='setting' name='setting'>
    <div class="tab-content" id="nav-tabContent">
    {{ macros.m_tab_content_start('basic', true) }}
      {{ macros.setting_checkbox('notify_telegram_use', '텔레그램 사용', value=arg['notify_telegram_use']) }}
      <div id="notify_telegram_use_div" class="collapse">
      {{ macros.setting_input_text('notify_telegram_token', 'Bot Token', value=arg['notify_telegram_token']) }}
      {{ macros.setting_input_text('notify_telegram_chat_id', 'My Chat ID', value=arg['notify_telegram_chat_id'], col='3') }}
      {{ macros.setting_checkbox('notify_telegram_disable_notification', '알람 Disable', value=arg['notify_telegram_disable_notification'], desc='On : 알람 소리 없이 메시지를 수신합니다.') }}
      {{ macros.setting_input_text_and_buttons('tmp_text_telegram', 'Test', [['tmp_telegram_test_btn', '전송']], value='테스트 메시지입니다.', col='9', desc=['사용자가 먼저 봇과 대화를 시작하여 대화창이 생성된 상태여야 합니다.', '(대화창이 있을 경우에만 알림 수신)']) }}
      </div>

      {{ macros.m_hr() }}

      {{ macros.setting_checkbox('notify_discord_use', '디스코드 사용', value=arg['notify_discord_use']) }}
      <div id="notify_discord_use_div" class="collapse">
      {{ macros.setting_input_text('notify_discord_webhook', '웹훅', value=arg['notify_discord_webhook']) }}
      {{ macros.setting_input_text_and_buttons('tmp_text_discord', 'Test', [['tmp_discord_test_btn', '전송']], value='테스트 메시지입니다.', col='9') }}
      </div>
      
      {{ macros.m_hr() }}

      {{ macros.setting_checkbox('notify_slack_use', '슬랙 사용', value=arg['notify_slack_use']) }}
      <div id="notify_slack_use_div" class="collapse">
      {{ macros.setting_input_text('notify_slack_webhook', '웹훅', value=arg['notify_slack_webhook']) }}
      {{ macros.setting_input_text_and_buttons('tmp_text_slack', 'Test', [['tmp_slack_test_btn', '전송']], value='테스트 메시지입니다.', col='9') }}
      </div>
    {{ macros.m_tab_content_end() }} 

    {{ macros.m_tab_content_start('advanced', false) }}
      {{ macros.setting_checkbox('notify_advaned_use', '사용', value=arg['notify_advaned_use'], desc=['사용시 기본설정은 무시됩니다.']) }}
      <div id="notify_advaned_use_div" class="collapse">
      {{ macros.info_text_and_buttons('notify_yaml_filepath', '파일 위치', [['globalEditBtn', '편집기에서 열기', [('file',arg['notify_yaml_filepath'])]]], value=arg['notify_yaml_filepath']) }}
      {{ macros.setting_input_textarea('notify.yaml', '정책', value=arg['notify.yaml'], row='20') }}
      {{ macros.setting_input_text('tmp_message_id', 'Test Message ID', value='DEFAULT') }}
      {{ macros.setting_input_text_and_buttons('tmp_text_advanced', 'Test', [['tmp_advanced_test_btn', '전송']], value='테스트 메시지입니다.', col='9', desc=['저장 후 적용됩니다.']) }}
      
      </div>
    {{ macros.m_tab_content_end() }} 

    </div><!--tab-content-->
  </form>
</div> <!--전체-->



<script type="text/javascript">

$(document).ready(function(){
  use_collapse("notify_telegram_use");
  use_collapse("notify_discord_use");
  use_collapse("notify_slack_use");
  use_collapse("notify_advaned_use");
});

$('#notify_telegram_use').change(function() {
  use_collapse('notify_telegram_use');
});

$('#notify_discord_use').change(function() {
  use_collapse('notify_discord_use');
});

$('#notify_slack_use').change(function() {
  use_collapse('notify_slack_use');
});

$('#notify_advaned_use').change(function() {
  use_collapse('notify_advaned_use');
});


$("body").on('click', '#tmp_telegram_test_btn', function(e){
  e.preventDefault();
  param = $('#notify_telegram_token').val() + '||' + $('#notify_telegram_chat_id').val() + '||' + $('#notify_telegram_disable_notification').is(":checked") + '||' + $('#tmp_text_telegram').val();
  globalSendCommand('notify_test', 'telegram', param);
});

$("body").on('click', '#tmp_discord_test_btn', function(e){
  e.preventDefault();
  globalSendCommand('notify_test', 'discord', $('#notify_discord_webhook').val(), $('#tmp_text_discord').val());
});

$("body").on('click', '#tmp_slack_test_btn', function(e){
  e.preventDefault();
  globalSendCommand('notify_test', 'slack', $('#notify_slack_webhook').val(), $('#tmp_text_slack').val());
});

$("body").on('click', '#tmp_advanced_test_btn', function(e){
  e.preventDefault();
  globalSendCommand('notify_test', 'advanced', $('#tmp_message_id').val(), $('#tmp_text_advanced').val());
});

</script>    
{% endblock %}
