import Index$1 from './Index-0d7ad3de.js';
import { T as Textbox } from './Textbox-1cbc4f9a.js';
import { a as Button, B as Block } from './Button-723db480.js';
import { $ as $format } from './Index-f62c49f9.js';
/* empty css                                                */import Index from './Index-24a33ce1.js';
import './BlockTitle-082b4bca.js';
import './Info-a7917974.js';
import './Copy-e5864b80.js';
import './index-b5b16a51.js';
import './svelte/svelte.js';

const Login_svelte_svelte_type_style_lang = '';

/* src/Login.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent,
	add_flush_callback,
	append,
	attr,
	bind,
	binding_callbacks,
	component_subscribe,
	create_component,
	destroy_component,
	detach,
	element,
	init,
	insert,
	mount_component,
	safe_not_equal,
	set_data,
	space,
	text,
	toggle_class,
	transition_in,
	transition_out
} = window.__gradio__svelte__internal;
function create_if_block_2(ctx) {
	let p;
	let t;

	return {
		c() {
			p = element("p");
			t = text(/*auth_message*/ ctx[0]);
			attr(p, "class", "auth svelte-1ogxbi0");
		},
		m(target, anchor) {
			insert(target, p, anchor);
			append(p, t);
		},
		p(ctx, dirty) {
			if (dirty & /*auth_message*/ 1) set_data(t, /*auth_message*/ ctx[0]);
		},
		d(detaching) {
			if (detaching) {
				detach(p);
			}
		}
	};
}

// (39:2) {#if space_id}
function create_if_block_1(ctx) {
	let p;
	let t_value = /*$_*/ ctx[6]("login.enable_cookies") + "";
	let t;

	return {
		c() {
			p = element("p");
			t = text(t_value);
			attr(p, "class", "auth svelte-1ogxbi0");
		},
		m(target, anchor) {
			insert(target, p, anchor);
			append(p, t);
		},
		p(ctx, dirty) {
			if (dirty & /*$_*/ 64 && t_value !== (t_value = /*$_*/ ctx[6]("login.enable_cookies") + "")) set_data(t, t_value);
		},
		d(detaching) {
			if (detaching) {
				detach(p);
			}
		}
	};
}

// (44:2) {#if incorrect_credentials}
function create_if_block(ctx) {
	let p;
	let t_value = /*$_*/ ctx[6]("login.incorrect_credentials") + "";
	let t;

	return {
		c() {
			p = element("p");
			t = text(t_value);
			attr(p, "class", "creds svelte-1ogxbi0");
		},
		m(target, anchor) {
			insert(target, p, anchor);
			append(p, t);
		},
		p(ctx, dirty) {
			if (dirty & /*$_*/ 64 && t_value !== (t_value = /*$_*/ ctx[6]("login.incorrect_credentials") + "")) set_data(t, t_value);
		},
		d(detaching) {
			if (detaching) {
				detach(p);
			}
		}
	};
}

// (48:3) <Block>
function create_default_slot_4(ctx) {
	let textbox;
	let updating_value;
	let current;

	function textbox_value_binding(value) {
		/*textbox_value_binding*/ ctx[9](value);
	}

	let textbox_props = {
		label: "username",
		lines: 1,
		show_label: true,
		max_lines: 1
	};

	if (/*username*/ ctx[3] !== void 0) {
		textbox_props.value = /*username*/ ctx[3];
	}

	textbox = new Textbox({ props: textbox_props });
	binding_callbacks.push(() => bind(textbox, 'value', textbox_value_binding));
	textbox.$on("submit", /*submit*/ ctx[7]);

	return {
		c() {
			create_component(textbox.$$.fragment);
		},
		m(target, anchor) {
			mount_component(textbox, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const textbox_changes = {};

			if (!updating_value && dirty & /*username*/ 8) {
				updating_value = true;
				textbox_changes.value = /*username*/ ctx[3];
				add_flush_callback(() => updating_value = false);
			}

			textbox.$set(textbox_changes);
		},
		i(local) {
			if (current) return;
			transition_in(textbox.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(textbox.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component(textbox, detaching);
		}
	};
}

// (59:3) <Block>
function create_default_slot_3(ctx) {
	let textbox;
	let updating_value;
	let current;

	function textbox_value_binding_1(value) {
		/*textbox_value_binding_1*/ ctx[10](value);
	}

	let textbox_props = {
		label: "password",
		lines: 1,
		show_label: true,
		max_lines: 1,
		type: "password"
	};

	if (/*password*/ ctx[4] !== void 0) {
		textbox_props.value = /*password*/ ctx[4];
	}

	textbox = new Textbox({ props: textbox_props });
	binding_callbacks.push(() => bind(textbox, 'value', textbox_value_binding_1));
	textbox.$on("submit", /*submit*/ ctx[7]);

	return {
		c() {
			create_component(textbox.$$.fragment);
		},
		m(target, anchor) {
			mount_component(textbox, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const textbox_changes = {};

			if (!updating_value && dirty & /*password*/ 16) {
				updating_value = true;
				textbox_changes.value = /*password*/ ctx[4];
				add_flush_callback(() => updating_value = false);
			}

			textbox.$set(textbox_changes);
		},
		i(local) {
			if (current) return;
			transition_in(textbox.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(textbox.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component(textbox, detaching);
		}
	};
}

// (47:2) <Form>
function create_default_slot_2(ctx) {
	let block0;
	let t;
	let block1;
	let current;

	block0 = new Block({
			props: {
				$$slots: { default: [create_default_slot_4] },
				$$scope: { ctx }
			}
		});

	block1 = new Block({
			props: {
				$$slots: { default: [create_default_slot_3] },
				$$scope: { ctx }
			}
		});

	return {
		c() {
			create_component(block0.$$.fragment);
			t = space();
			create_component(block1.$$.fragment);
		},
		m(target, anchor) {
			mount_component(block0, target, anchor);
			insert(target, t, anchor);
			mount_component(block1, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const block0_changes = {};

			if (dirty & /*$$scope, username*/ 2056) {
				block0_changes.$$scope = { dirty, ctx };
			}

			block0.$set(block0_changes);
			const block1_changes = {};

			if (dirty & /*$$scope, password*/ 2064) {
				block1_changes.$$scope = { dirty, ctx };
			}

			block1.$set(block1_changes);
		},
		i(local) {
			if (current) return;
			transition_in(block0.$$.fragment, local);
			transition_in(block1.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(block0.$$.fragment, local);
			transition_out(block1.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(t);
			}

			destroy_component(block0, detaching);
			destroy_component(block1, detaching);
		}
	};
}

// (72:2) <BaseButton size="lg" variant="primary" on:click={submit}    >
function create_default_slot_1(ctx) {
	let t_value = /*$_*/ ctx[6]("login.login") + "";
	let t;

	return {
		c() {
			t = text(t_value);
		},
		m(target, anchor) {
			insert(target, t, anchor);
		},
		p(ctx, dirty) {
			if (dirty & /*$_*/ 64 && t_value !== (t_value = /*$_*/ ctx[6]("login.login") + "")) set_data(t, t_value);
		},
		d(detaching) {
			if (detaching) {
				detach(t);
			}
		}
	};
}

// (34:1) <Column variant="panel" min_width={480}>
function create_default_slot(ctx) {
	let h2;
	let t0_value = /*$_*/ ctx[6]("login.login") + "";
	let t0;
	let t1;
	let t2;
	let t3;
	let t4;
	let form;
	let t5;
	let basebutton;
	let current;
	let if_block0 = /*auth_message*/ ctx[0] && create_if_block_2(ctx);
	let if_block1 = /*space_id*/ ctx[2] && create_if_block_1(ctx);
	let if_block2 = /*incorrect_credentials*/ ctx[5] && create_if_block(ctx);

	form = new Index$1({
			props: {
				$$slots: { default: [create_default_slot_2] },
				$$scope: { ctx }
			}
		});

	basebutton = new Button({
			props: {
				size: "lg",
				variant: "primary",
				$$slots: { default: [create_default_slot_1] },
				$$scope: { ctx }
			}
		});

	basebutton.$on("click", /*submit*/ ctx[7]);

	return {
		c() {
			h2 = element("h2");
			t0 = text(t0_value);
			t1 = space();
			if (if_block0) if_block0.c();
			t2 = space();
			if (if_block1) if_block1.c();
			t3 = space();
			if (if_block2) if_block2.c();
			t4 = space();
			create_component(form.$$.fragment);
			t5 = space();
			create_component(basebutton.$$.fragment);
			attr(h2, "class", "svelte-1ogxbi0");
		},
		m(target, anchor) {
			insert(target, h2, anchor);
			append(h2, t0);
			insert(target, t1, anchor);
			if (if_block0) if_block0.m(target, anchor);
			insert(target, t2, anchor);
			if (if_block1) if_block1.m(target, anchor);
			insert(target, t3, anchor);
			if (if_block2) if_block2.m(target, anchor);
			insert(target, t4, anchor);
			mount_component(form, target, anchor);
			insert(target, t5, anchor);
			mount_component(basebutton, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			if ((!current || dirty & /*$_*/ 64) && t0_value !== (t0_value = /*$_*/ ctx[6]("login.login") + "")) set_data(t0, t0_value);

			if (/*auth_message*/ ctx[0]) {
				if (if_block0) {
					if_block0.p(ctx, dirty);
				} else {
					if_block0 = create_if_block_2(ctx);
					if_block0.c();
					if_block0.m(t2.parentNode, t2);
				}
			} else if (if_block0) {
				if_block0.d(1);
				if_block0 = null;
			}

			if (/*space_id*/ ctx[2]) {
				if (if_block1) {
					if_block1.p(ctx, dirty);
				} else {
					if_block1 = create_if_block_1(ctx);
					if_block1.c();
					if_block1.m(t3.parentNode, t3);
				}
			} else if (if_block1) {
				if_block1.d(1);
				if_block1 = null;
			}

			if (/*incorrect_credentials*/ ctx[5]) {
				if (if_block2) {
					if_block2.p(ctx, dirty);
				} else {
					if_block2 = create_if_block(ctx);
					if_block2.c();
					if_block2.m(t4.parentNode, t4);
				}
			} else if (if_block2) {
				if_block2.d(1);
				if_block2 = null;
			}

			const form_changes = {};

			if (dirty & /*$$scope, password, username*/ 2072) {
				form_changes.$$scope = { dirty, ctx };
			}

			form.$set(form_changes);
			const basebutton_changes = {};

			if (dirty & /*$$scope, $_*/ 2112) {
				basebutton_changes.$$scope = { dirty, ctx };
			}

			basebutton.$set(basebutton_changes);
		},
		i(local) {
			if (current) return;
			transition_in(form.$$.fragment, local);
			transition_in(basebutton.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(form.$$.fragment, local);
			transition_out(basebutton.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(h2);
				detach(t1);
				detach(t2);
				detach(t3);
				detach(t4);
				detach(t5);
			}

			if (if_block0) if_block0.d(detaching);
			if (if_block1) if_block1.d(detaching);
			if (if_block2) if_block2.d(detaching);
			destroy_component(form, detaching);
			destroy_component(basebutton, detaching);
		}
	};
}

function create_fragment(ctx) {
	let div;
	let column;
	let current;

	column = new Index({
			props: {
				variant: "panel",
				min_width: 480,
				$$slots: { default: [create_default_slot] },
				$$scope: { ctx }
			}
		});

	return {
		c() {
			div = element("div");
			create_component(column.$$.fragment);
			attr(div, "class", "wrap svelte-1ogxbi0");
			toggle_class(div, "min-h-screen", /*app_mode*/ ctx[1]);
		},
		m(target, anchor) {
			insert(target, div, anchor);
			mount_component(column, div, null);
			current = true;
		},
		p(ctx, [dirty]) {
			const column_changes = {};

			if (dirty & /*$$scope, $_, password, username, incorrect_credentials, space_id, auth_message*/ 2173) {
				column_changes.$$scope = { dirty, ctx };
			}

			column.$set(column_changes);

			if (!current || dirty & /*app_mode*/ 2) {
				toggle_class(div, "min-h-screen", /*app_mode*/ ctx[1]);
			}
		},
		i(local) {
			if (current) return;
			transition_in(column.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(column.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(div);
			}

			destroy_component(column);
		}
	};
}

function instance($$self, $$props, $$invalidate) {
	let $_;
	component_subscribe($$self, $format, $$value => $$invalidate(6, $_ = $$value));
	let { root } = $$props;
	let { auth_message } = $$props;
	let { app_mode } = $$props;
	let { space_id } = $$props;
	let username = "";
	let password = "";
	let incorrect_credentials = false;

	const submit = async () => {
		const formData = new FormData();
		formData.append("username", username);
		formData.append("password", password);
		let response = await fetch(root + "/login", { method: "POST", body: formData });

		if (response.status === 400) {
			$$invalidate(5, incorrect_credentials = true);
			$$invalidate(3, username = "");
			$$invalidate(4, password = "");
		} else if (response.status == 200) {
			location.reload();
		}
	};

	function textbox_value_binding(value) {
		username = value;
		$$invalidate(3, username);
	}

	function textbox_value_binding_1(value) {
		password = value;
		$$invalidate(4, password);
	}

	$$self.$$set = $$props => {
		if ('root' in $$props) $$invalidate(8, root = $$props.root);
		if ('auth_message' in $$props) $$invalidate(0, auth_message = $$props.auth_message);
		if ('app_mode' in $$props) $$invalidate(1, app_mode = $$props.app_mode);
		if ('space_id' in $$props) $$invalidate(2, space_id = $$props.space_id);
	};

	return [
		auth_message,
		app_mode,
		space_id,
		username,
		password,
		incorrect_credentials,
		$_,
		submit,
		root,
		textbox_value_binding,
		textbox_value_binding_1
	];
}

class Login extends SvelteComponent {
	constructor(options) {
		super();

		init(this, options, instance, create_fragment, safe_not_equal, {
			root: 8,
			auth_message: 0,
			app_mode: 1,
			space_id: 2
		});
	}
}

export { Login as default };
//# sourceMappingURL=Login-954d74ef.js.map
