client_id = document.getElementById("helper").getAttribute("data-clientID");
location_id = document.getElementById("helper").getAttribute("data-LocationID");
inv_widget = document.getElementById("helper").getAttribute("data-invWidget");
chat_widget = document.getElementById("helper").getAttribute("data-chatWidget");

html = `<html><head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Oswald:wght@400&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css">
  </head>
  
  <body>

  	<style>
	  	
	  body {
	    font-family: 'Oswald', sans-serif !important; 
	    background-color: transparent; 
	    background-image: none;
	  }
	
	  #widgetContainer {
	    z-index:5000;
	  }
	
	  #inventoryWidget {
	    position:absolute !important;
	    left: 50% !important;
	    bottom:0px;
	    margin-left:-150px;
	  }
	
	  #chatWidget {
	    position:absolute !important;
	    right:20px;
	    bottom:10px;
	    max-width:50px;
	  }
	
	  .modal-header  {
	    color:#fff !important;
	    background:#000;
	  }
	
	  .modal-sm	{
	    max-width: 400px !important;
	  }
	
	  .modal.bottom .modal-dialog {
	  	  /* width:20%; */
	      position:fixed;
	      bottom:80px;
	      right:10px;
	      margin:0;
	  }
	
	  .btn-dark {
	    background:#000 !important;
	  }
	
	    .has-error {
	    border:solid 1px red;
	  }
	
	  .error {
	      color: #721c24;
	      background-color: #f8d7da;
	      border-color: #f5c6cb;
	      position: relative;
	      padding: 0.75rem 1.25rem;
	      margin-bottom: 1rem;
	      border: 1px solid transparent;
	      border-radius: 0.25rem;
	  }
	
	  @media (max-width: 800px) {
	    #inventoryWidget {
	      left:0px !important;
	      margin-left:0px;
	    }
	    
	    #chatWidget {
	    position:absolute !important;
	    right:5px;
	    bottom:10px;
	    max-width:50px;
		}
		.modal-title {
		
		 	font-size:18px !important;
			
		}
		.trigger {
		
		 	font-size:17px !important;
			
		}
		
  </style>

    <div id="widgetContainer" class="fixed-bottom">

		<button id="inventoryWidget" data-bs-toggle="modal" data-bs-target="#inventoryModal" type="button" class="fs-5 btn btn-dark btn-lg rounded-0 rounded-top trigger">View our Inventory Clearance List <i class="fa-solid fa-cart-shopping"></i></button>

		<img id="chatWidget" role="button" data-bs-toggle="modal" data-bs-target="#chatModal" src="https://pi-company-assets.s3.amazonaws.com/Inventory+Clearance+Widget/chat.png" class="trigger" />

	</div>
	
	<!-- Inventory Modal -->
    <div class="modal fade" data-bs-backdrop="false" id="inventoryModal" tabindex="-1" aria-labelledby="inventoryModalLabel" aria-hidden="true">
    
    	<div class="modal-dialog modal-sm modal-dialog-centered">
    	
			<div class="modal-content">
			
				<div class="modal-header">
					<h5 style="padding-left: 20px;" class="modal-title fs-5" id="inventoryModalLabel">INVENTORY CLEARANCE LIST REQUEST <i class="fa-solid fa-cart-shopping"></i></h5>
					<button id="close_inv" type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
			    </div>
			    
				<div class="modal-body pt-1 pb-4">
			
					<div class="my-3 input-group-lg locationSelectContainerInv">
						<p class="fs-5 text-center mb-3 mt-3">Please select the location nearest you.</p>
						<select class="form-select form-select-lg locationSelectInv"></select>
						<div class="d-grid gap-2 mt-4">
							<button type="button" class="btn btn-primary btn-lg locationSelectBtnInv">Next <i class="fas fa-arrow-right"></i></button>
						</div>
					</div>
					
					<div class="inventoryClearanceConfirmation">
						<p class="fs-5 text-center mb-3 mt-2">
							We've just sent you an email!<br>
							<small>Remember to check spam folder as well!</small>
						</p>
						<img class="w-100" src="https://pi-company-assets.s3.amazonaws.com/email.jpg" /></div>
				
				    <form id="inventoryClearanceForm" method="post">

						<p class="fs-5 text-center mb-3 mt-2">To be emailed an updated Inventory Clearance List please complete the form below.</p>
	
						<div class="form-text text-center mb-3"><small>NOTICE: We\'ll never share your contact information with anyone else.</small></div>
	
			            <div class="inv_message"></div>
			
			            <div class="mb-3 input-group-lg">
			              <input name="name" type="text" class="form-control" placeholder="Name">
			            </div>
			            <div class="mb-3 input-group-lg">
			              <input name="LeadEmail" type="text" class="form-control" placeholder="Email" required>
			            </div>
			            <div class="mb-3 input-group-lg">
			              <input name="LeadPhone" type="text" class="form-control phone" placeholder="Phone">
			            </div>
			            <div class="mb-3 form-check input-group-lg">
			              <input name="appoointment_request" type="checkbox" class="form-check-input">
			              <label class="form-check-label">Request an appointment</label>
			            </div>
			            <div class="mb-3 input-group-lg">
			              <textarea name="Note" class="form-control" placeholder="What are you searching for?" id="floatingTextarea2" style="height: 100px"></textarea>
			            </div>
			            <div class="d-grid gap-2">
			              <button type="button" class="btn btn-success btn-lg SubmitButton">SEND <i class="fa fa-paper-plane" aria-hidden="true"></i></button>
			            </div>
		              
			        </form>

			    </div>
        
	        </div>
      
        </div>
        
    </div>
    
    <!-- Chat Modal -->
    <div class="modal bottom fade" data-bs-backdrop="false" id="chatModal" tabindex="-1" aria-labelledby="chatModalLabel" aria-hidden="true">
    
	    <div class="modal-dialog modal-sm">
	    
	        <div class="modal-content">
	        
		        <div class="modal-header">
		          <h5 class="modal-title fs-5" id="chatModalLabel">Let\'s Chat <i class="fa-solid fa-mobile-screen-button"></i></h5>
		          <button id="close_chat" type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
		        </div>
	        
		        <div class="modal-body pt-1">
		        
		        <div class="my-3 input-group-lg locationSelectContainerChat">
						<p class="fs-5 text-center mb-3 mt-3">Please select the location nearest you.</p>
						<select class="form-select form-select-lg locationSelectChat"></select>
						<div class="d-grid gap-2 mt-4">
							<button type="button" class="btn btn-primary btn-lg locationSelectBtnChat">Next <i class="fas fa-arrow-right"></i></button>
						</div>
					</div>
					
					<form id="chatForm" method="post">
		
			        <p class="fs-4 text-center mb-2 mt-2">Leave us a message and a team member will text you shortly.</p>
			
			        <div class="form-text text-center mb-4"><small>NOTICE: We\'ll never share your contact information with anyone else.</small></div>
				
				            <div class="chat_message"></div>
				
				              <div class="mb-3 input-group-lg">
				                <input name="name" type="text" class="form-control" placeholder="Name">
				              </div>
				              <div class="mb-3 input-group-lg">
				                <input name="phone" type="text" class="form-control phone" placeholder="Phone">
				              </div>
				              <div class="mb-3 input-group-lg">
				                <textarea name="message" class="form-control" placeholder="Message" id="floatingTextarea2" style="height: 100px"></textarea>
				              </div>
				              <div class="d-grid gap-2">
				                <button type="submit" class="btn btn-success btn-lg SubmitButton">SEND <i class="fa fa-paper-plane" aria-hidden="true"></i></button>
				              </div>
				
				            </div>
				              
				        </form>
			        
		            </div>
	        
	            </div>
	        
            </div>
            
        </div>
              
    </div>

  </body>
  
  <script>
  	client_id = `+client_id+`;
  	location_id = `+location_id+`;
  	inv_widget = `+inv_widget+`
  	chat_widget = `+chat_widget+`
  </script>
  
  <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.4/jquery.validate.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.maskedinput/1.4.1/jquery.maskedinput.min.js"></script>
  <script src="https://widgets.bridgewidgets.com/js/bw.js"></script>
  
</html>`;

var iframe = document.createElement('iframe');
iframe.id = 'iframe';
iframe.setAttribute('style', 'position:fixed; bottom:0px; width:100%; height:60px; z-index:4324321');
iframe.setAttribute('frameBorder', '0');

document.documentElement.appendChild(iframe);

var doc = document.getElementById('iframe').contentWindow.document;
doc.open();
doc.write(html);
doc.close();

var iframe = document.getElementById("iframe");

var pi_inv_btn = iframe.contentWindow.document.getElementById("inventoryWidget");
var pi_chat_btn = iframe.contentWindow.document.getElementById("chatWidget");
var pi_close_inv = iframe.contentWindow.document.getElementById("close_inv");
var pi_close_chat = iframe.contentWindow.document.getElementById("close_chat");


pi_inv_btn.onclick = function() {  
	iframe.setAttribute('style', 'position:fixed; bottom:0px; width:100%; height:100%; z-index:4324321');
}

pi_chat_btn.onclick = function() {  
	iframe.setAttribute('style', 'position:fixed; bottom:0px; width:100%; height:100%; z-index:4324321');
}

pi_close_inv.onclick = function() { 
	iframe.setAttribute('style', 'position:fixed; bottom:0px; width:100%; height:60px; z-index:4324321');
}

pi_close_chat.onclick = function() { 
	iframe.setAttribute('style', 'position:fixed; bottom:0px; width:100%; height:60px; z-index:4324321');
}
