<?php
// login form

	function logingpower_loginform() {
	$form_bgcolor=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_background_color'] ??'#ffffff');
	$form_fontweight=absint(get_option('logingpower_settings')['logingpower_loginform_fontweight'] ??400);
	$form_borderwidth=absint(get_option('logingpower_settings')['logingpower_loginform_border_width'] ??1);
	$form_borderstyle=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_border_style'] ??'solid');
	$form_bordercolor=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_border_color'] ??'#c3c4c7');
	$form_border_radius_topleft=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_border_radius_topleft'] ??'none');
	$form_border_radius_topright=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_border_radius_topright'] ??'none');
	$form_border_radis_bottomright=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_border_radius_bottomright'] ??'none');
	$form_border_radis_bottomleft=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_border_radius_bottomleft'] ??'none');
	// form input 

	// form label
	$label_fontsize=absint(get_option('logingpower_settings')['logingpower_loginform_label_fontsize'] ??14);
	$label_cursor=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_label_cursor'] ??'pointer');
	$label_color=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_label_color'] ??'#3c434a');

	$form_background_img='none';
	$form_background_repeat='no-repeat';
	$form_background_imgsize_style='auto';

	if ( !empty(get_option('logingpower_settings')['logingpowerloginform_background_show'] ) )
	$form_background_img=sanitize_url(get_option('logingpower_settings')['logingpower_loginform_background_img'] ??plugins_url( 'imgs/loginform_bglaptop.jpg', __FILE__ ));
	$form_background_repeat=sanitize_text_field(get_option('logingpower_settings')[ 'logingpower_loginform_background_repeat' ]??'no-repeat');
	
	$form_background_imgsize=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_background_imgsize']??'auto');
	switch ($form_background_imgsize) {
			case 'auto':
			 	$form_background_imgsize_style='auto';
				break;
			case 'width':
			 $form_background_imgsize_style='100%  auto';
				break;
			case 'height':
				$form_background_imgsize_style='auto 100%';
				break;
			case 'both':
			 $form_background_imgsize_style='100%  100%';
				break;
			default:
				$form_background_imgsize_style='auto';
				break;
		}
		
	// form input 
	$form_input_border_width=absint(get_option('logingpower_settings')['logingpower_loginform_input_border_width'] ??1);
	$form_input_border_style=sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_input_style'] ??'solid');
	$form_input_border_color=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_input_border_color'] ??'#c3c4c7');
	$form_input_radius_topleft=absint(get_option('logingpower_settings')['logingpower_loginform_input_radius_topleft'] ??0);
	$form_input_border_radius_topright=absint(get_option('logingpower_settings')['logingpower_loginform_input_radius_topright'] ??0);
	$form_input_border_radis_bottomright=absint(get_option('logingpower_settings')['logingpower_loginform_input_radius_bottomright'] ??0);
	$form_input_border_radis_bottomleft=absint(get_option('logingpower_settings')['logingpower_loginform_input_radius_bottomleft'] ??0);
	$form_input_height=absint(get_option('logingpower_settings')['logingpower_loginform_input_height'] ??50);
	$form_input_color=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_input_color'] ??'#ffffff');
	// submit button 
	
	$form_submit_width=absint(get_option('logingpower_settings')['logingpower_loginform_submit_width']??25);
	$form_submit_height=absint(get_option('logingpower_settings')['logingpower_loginform_submit_height']??32);
	$form_submit_bgcolor=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_submit_bgcolor'] ??'#2271b1');
	$form_submit_lbcolor=sanitize_hex_color(get_option('logingpower_settings')['logingpower_loginform_submit_lbcolor'] ??'#ffffff');
	$form_submit_fontsize=absint(get_option('logingpower_settings')['logingpower_loginform_submit_fontsize'] ??13);
	// submit button radius 
	$form_submit_radius_topleft=absint(get_option('logingpower_settings')['logingpower_loginform_submit_radius_topleft'] ??0);
	$form_submit_radius_topright=absint(get_option('logingpower_settings')['logingpower_loginform_submit_radius_topright'] ??0);
	$form_submit_radius_bottomright=absint(get_option('logingpower_settings')['logingpower_loginform_submit_radius_bottomright'] ??0);
	$form_submit_radius_bottomleft=absint(get_option('logingpower_settings')['logingpower_loginform_submit_radius_bottomleft'] ??0);
		
	$logingpower_style="body.login div#login form#loginform {
		margin-top: 20px;
		margin-left: 0;
		padding: 26px 24px 34px;
		font-weight: ". esc_attr($form_fontweight)."!important;
		overflow: hidden;
		background: ". esc_attr($form_bgcolor).";
		border: ". esc_attr($form_borderwidth)."px ". esc_attr($form_borderstyle ). esc_attr($form_bordercolor) ." ;
		border-radius:". esc_attr($form_border_radius_topleft)."px ". esc_attr($form_border_radius_topright )."px ".  esc_attr($form_border_radis_bottomright )."px ". esc_attr($form_border_radis_bottomleft)."px ;
		box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
		background-image:url(". esc_url($form_background_img).");
		background-size:". esc_attr( $form_background_imgsize_style)."!important;
		background-repeat: " .esc_attr($form_background_repeat)."!important;
	}";
	wp_add_inline_style('login',stripslashes($logingpower_style)); 	
	$logingpower_style="body.login div#login form#loginform p {
		font-weight: ". esc_attr($form_fontweight)."!important;}";
	wp_add_inline_style('login',stripslashes($logingpower_style));
	$logingpower_style="body.login div#login form#loginform  label {
		color:". esc_attr($label_color)."!important;
		font-size: ". esc_attr($label_fontsize)."px !important;
		cursor: ". esc_attr($label_cursor)."!important;}";
	wp_add_inline_style('login',stripslashes($logingpower_style));			
	$logingpower_style="body.login div#login form#loginform input#user_login,
					body.login div#login form#loginform input#user_pass{
			border: ". esc_attr($form_input_border_width)."px ". esc_attr($form_input_border_style) .esc_attr( $form_input_border_color) ." ;
			border-radius:". esc_attr($form_input_radius_topleft)."px ". esc_attr($form_input_border_radius_topright)."px ".  esc_attr($form_input_border_radis_bottomright)."px ". esc_attr($form_input_border_radis_bottomleft)."px !important ;
			background-color:". esc_attr($form_input_color)." !important;
			height:". esc_attr($form_input_height)."px !important;}";
	wp_add_inline_style('login',stripslashes($logingpower_style));
	$logingpower_style="body.login div#login form#loginform p.submit input#wp-submit {
			width:". esc_attr($form_submit_width)."% !important;
			height:". esc_attr($form_submit_height)."px !important;
			background:". esc_attr($form_submit_bgcolor)." !important;
			color:". esc_attr($form_submit_lbcolor)." !important;
			font-size:". esc_attr($form_submit_fontsize)."px !important;
			border-radius:". esc_attr($form_submit_radius_topleft)."px ". esc_attr($form_submit_radius_topright) ."px ".  esc_attr($form_submit_radius_bottomright )."px ". esc_attr($form_submit_radius_bottomleft)."px ;}";
			 
	wp_add_inline_style('login',stripslashes($logingpower_style));	   
			
	  add_filter( 'gettext', 'logingpower_form_labels_change', 20, 3 );
    function logingpower_form_labels_change( $translated_text, $text, $domain ) {
         if ($text === 'Username or Email Address') {
    	$translated_text= sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_username'] ??'Username or Email Address');
         }elseif($text === 'Password'){
         	$translated_text= sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_password'] ??'Password');
         }elseif($text === 'Remember Me'){
         	$translated_text= sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_rememberme'] ??'Remember Me');
         }elseif($text === 'Lost your password?'){
         	$translated_text= sanitize_text_field('Lost your password?');
         }elseif($text === 'Log In'){
         	$translated_text= sanitize_text_field(get_option('logingpower_settings')['logingpower_loginform_submit_label'] ??'Log In');
         }
        return $translated_text;
    }

	}add_action( 'login_enqueue_scripts', 'logingpower_loginform') ;
	// add_action( 'login_head', 'logingpower_loginform') ;
	