const setMember = function () {
  let form = document.forms['meminfo'];
  let data = new FormData(form);
  data.append("mode", "setMember");

  ajax_form({
    url: "./member_set.ajax.php",
    data: data,
    success: function (data) {
      if (data.code) {
        form.member_pwo.value = "";
        form.member_pw.value = "";
        form.member_pwf.value = "";
      }
      kuls_alert(data.mesg);
    },
    error: function (request, status, error) {
      kuls_alert(error.message);
    },
    complete: function () {
    }
  });
};

const chkPw = function () {
  let pw = document.getElementById("member_pw").value;
  let pwf = document.getElementById("member_pwf").value;
  let rst = true;

  if (pw || pwf) {
    if (pw != pwf) {
      document.getElementById("pw_info1").classList.add("d-block");
      document.getElementById("pw_info2").classList.remove("d-block");
      rst = false;
    } else if (!/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{6,}$/is.test(pw)) {
      document.getElementById("pw_info1").classList.remove("d-block");
      document.getElementById("pw_info2").classList.add("d-block");
      rst = false;
    } else {
      document.getElementById("pw_info1").classList.remove("d-block");
      document.getElementById("pw_info2").classList.remove("d-block");
    }
  }

  return rst;
};

['keyup', 'keydown', 'change'].forEach(evt => {
  document.getElementById("member_pw").addEventListener(evt, chkPw);
  document.getElementById("member_pwf").addEventListener(evt, chkPw);
});


const labels = [];
Object.keys(chart_log_data).forEach(key => labels.push(key));

let divnum = 3;
if (today >= luxon.DateTime.now().toFormat("yyyy-MM-dd")) {
  divnum = 2;
}

let options_log = {
  series: [{
    name: "페이지뷰",
    color: "#D06356",
    type: 'column',
    data: Object.values(chart_log_data),
  }, {
    name: "방문수",
    color: "#52AFAE",
    type: 'column',
    data: Object.values(chart_sess_data),
  }],
  chart: {
    height: 300,
    zoom: {
      enabled: false
    },
    animations: {
      enabled: false,
      easing: 'linear',
      speed: 800,
      animateGradually: {
        enabled: false,
        delay: 50
      },
      dynamicAnimation: {
        enabled: false,
        speed: 200
      }
    },
  },
  dataLabels: {
    enabled: false
  },
  stroke: {
    curve: 'smooth'
  },
  title: {
    text: `${startday} ~ ${today} 방문 / 페이지뷰`,
    align: 'center'
  },
  grid: {
    show: true,
    borderColor: '#ccc',
    strokeDashArray: 1,
    xaxis: {
      lines: {
        show: true
      }
    },
    yaxis: {
      lines: {
        show: true
      }
    },
  },
  xaxis: {
    categories: labels,
  },
};

let chart_log = new ApexCharts(document.querySelector("#day_chart"), options_log);
chart_log.render();

var options_week_log = {
  series: Object.values(chart_week_data),
  chart: {
    width: '95%',
    type: 'pie',
  },
  /*
  title: {
    text: '<?=$startday?> ~ <?=$today?> 요일별 평균',
    align: 'center'
  },*/
  labels: ['일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일'],
  colors: ['#008FFB', '#00E396', '#FEB019', '#FF4560', '#775DD0', '#BF5B16', '#DAAADB'],
  responsive: [{
    breakpoint: 480,
    options: {
      chart: {
        width: 200
      },
      legend: {
        position: 'bottom'
      }
    }
  }]
};

let chart_week_log = new ApexCharts(document.querySelector("#week_chart"), options_week_log);
chart_week_log.render();

const mvselect = (tgt)=>{
  document.querySelectorAll("#member_mail_sign, #member_mail_tkor, #member_mail_teng").forEach( t => t.classList.add('d-none') );
  document.getElementById(tgt).classList.remove('d-none');
};