/* Minification failed. Returning unminified contents.
(1,1): run-time error CSS1019: Unexpected token, found '$'
(1,2): run-time error CSS1019: Unexpected token, found '('
(1,12): run-time error CSS1031: Expected selector, found '('
(1,12): run-time error CSS1025: Expected comma or open brace, found '('
(68,2): run-time error CSS1019: Unexpected token, found ')'
 */
$(function () {
	sis.checkParam();
	//sis.removeMsgParam();

	sis.vuemodel = new Vue({
		el: '#my-app',
		data: {
			companyId: '',
			userId: '',
			loginPassword: '',
			BID: ''
		},
		mounted: function () {
			sis.vuemodel = this;
			if ($.cookie('BID')) {
				this.BID = $.cookie('BID');
			} else {
				var dt = new Date();
				var y = dt.getFullYear();
				var m = ("00" + (dt.getMonth() + 1)).slice(-2);
				var d = ("00" + dt.getDate()).slice(-2);
				var h = ("00" + dt.getHours()).slice(-2);
				var mm = ("00" + dt.getMinutes()).slice(-2);
				var s = ("00" + dt.getSeconds()).slice(-2);
				this.BID = y  + m + d + h + mm + s;
				var expiryDate = new Date();
				expiryDate.setFullYear(9999); // 有効期限を9999年に設定
				$.cookie('BID', this.BID, { expires: expiryDate, path: "/", domain: $("#Domain").val()/*, secure: true */ });
            }
		},
		methods: {
			doSubmit: async function (event) {
				this.$validator.validateAll()
					.then((result) => {
						if (result) {
							// 二重クリック防止
							sis.loading(true);

							sis.post(sis.apiUrls.auth, sis.vuemodel.$data)
								.done(function (data) {
									console.log(data);
									$.cookie('accessToken', data.token, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('userId', data.id, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('userName', data.name, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('userLongName', data.longName, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('companyId', data.companyId, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('companyName', data.companyName, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('roleId', data.roleId, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('role', data.role, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('address1', data.address1, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('address2', data.address2, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									$.cookie('categoryId', data.categoryId, { expires: 45, path: "/", domain: $("#Domain").val()/*, secure: true */ });
									
									//console.log($.cookie('accessToken'));
									sis.redirect(sis.urls.deviceLogin);
								})
								.fail(function (error) {
									console.log(error);
									// sis.handleErrorで、sis.loading(false);
									// をしている
									sis.handleError(error);
								});
						}
					});
			}
		}
	});
});
