import { B as Block } from './Button-723db480.js';
import './Index-f62c49f9.js';
import { g as get_fetchable_url_or_file } from './index-b5b16a51.js';
import './svelte/svelte.js';

const Index_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/dataset/Index.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent,
	append,
	assign,
	attr,
	check_outros,
	construct_svelte_component,
	create_component,
	destroy_component,
	destroy_each,
	detach,
	element,
	empty,
	ensure_array_like,
	get_spread_object,
	get_spread_update,
	group_outros,
	init,
	insert,
	listen,
	mount_component,
	noop,
	null_to_empty,
	run_all,
	safe_not_equal,
	set_data,
	set_style,
	space,
	svg_element,
	text,
	toggle_class,
	transition_in,
	transition_out
} = window.__gradio__svelte__internal;
function get_each_context(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[35] = list[i];
	return child_ctx;
}

function get_each_context_2(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[38] = list[i];
	child_ctx[40] = i;
	return child_ctx;
}

function get_each_context_3(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[0] = list[i].value;
	child_ctx[42] = list[i].component;
	child_ctx[45] = i;
	const constants_0 = /*components*/ child_ctx[1][/*j*/ child_ctx[45]];
	child_ctx[43] = constants_0;
	return child_ctx;
}

function get_each_context_4(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[46] = list[i];
	return child_ctx;
}

function get_each_context_1(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[38] = list[i];
	child_ctx[40] = i;
	return child_ctx;
}

// (122:1) {:else}
function create_else_block_1(ctx) {
	let div;
	let table;
	let thead;
	let tr;
	let t;
	let tbody;
	let current;
	let each_value_4 = ensure_array_like(/*headers*/ ctx[5]);
	let each_blocks_1 = [];

	for (let i = 0; i < each_value_4.length; i += 1) {
		each_blocks_1[i] = create_each_block_4(get_each_context_4(ctx, each_value_4, i));
	}

	let each_value_2 = ensure_array_like(/*component_meta*/ ctx[17]);
	let each_blocks = [];

	for (let i = 0; i < each_value_2.length; i += 1) {
		each_blocks[i] = create_each_block_2(get_each_context_2(ctx, each_value_2, i));
	}

	const out = i => transition_out(each_blocks[i], 1, 1, () => {
		each_blocks[i] = null;
	});

	return {
		c() {
			div = element("div");
			table = element("table");
			thead = element("thead");
			tr = element("tr");

			for (let i = 0; i < each_blocks_1.length; i += 1) {
				each_blocks_1[i].c();
			}

			t = space();
			tbody = element("tbody");

			for (let i = 0; i < each_blocks.length; i += 1) {
				each_blocks[i].c();
			}

			attr(tr, "class", "tr-head svelte-13hsdno");
			attr(table, "tabindex", "0");
			attr(table, "role", "grid");
			attr(table, "class", "svelte-13hsdno");
			attr(div, "class", "table-wrap svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, div, anchor);
			append(div, table);
			append(table, thead);
			append(thead, tr);

			for (let i = 0; i < each_blocks_1.length; i += 1) {
				if (each_blocks_1[i]) {
					each_blocks_1[i].m(tr, null);
				}
			}

			append(table, t);
			append(table, tbody);

			for (let i = 0; i < each_blocks.length; i += 1) {
				if (each_blocks[i]) {
					each_blocks[i].m(tbody, null);
				}
			}

			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*headers*/ 32) {
				each_value_4 = ensure_array_like(/*headers*/ ctx[5]);
				let i;

				for (i = 0; i < each_value_4.length; i += 1) {
					const child_ctx = get_each_context_4(ctx, each_value_4, i);

					if (each_blocks_1[i]) {
						each_blocks_1[i].p(child_ctx, dirty);
					} else {
						each_blocks_1[i] = create_each_block_4(child_ctx);
						each_blocks_1[i].c();
						each_blocks_1[i].m(tr, null);
					}
				}

				for (; i < each_blocks_1.length; i += 1) {
					each_blocks_1[i].d(1);
				}

				each_blocks_1.length = each_value_4.length;
			}

			if (dirty[0] & /*value, page, samples_per_page, gradio, handle_mouseenter, handle_mouseleave, component_meta, components, component_props, samples_dir, current_hover, component_map*/ 7025167) {
				each_value_2 = ensure_array_like(/*component_meta*/ ctx[17]);
				let i;

				for (i = 0; i < each_value_2.length; i += 1) {
					const child_ctx = get_each_context_2(ctx, each_value_2, i);

					if (each_blocks[i]) {
						each_blocks[i].p(child_ctx, dirty);
						transition_in(each_blocks[i], 1);
					} else {
						each_blocks[i] = create_each_block_2(child_ctx);
						each_blocks[i].c();
						transition_in(each_blocks[i], 1);
						each_blocks[i].m(tbody, null);
					}
				}

				group_outros();

				for (i = each_value_2.length; i < each_blocks.length; i += 1) {
					out(i);
				}

				check_outros();
			}
		},
		i(local) {
			if (current) return;

			for (let i = 0; i < each_value_2.length; i += 1) {
				transition_in(each_blocks[i]);
			}

			current = true;
		},
		o(local) {
			each_blocks = each_blocks.filter(Boolean);

			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out(each_blocks[i]);
			}

			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(div);
			}

			destroy_each(each_blocks_1, detaching);
			destroy_each(each_blocks, detaching);
		}
	};
}

// (95:1) {#if gallery}
function create_if_block_2(ctx) {
	let div;
	let current;
	let each_value_1 = ensure_array_like(/*selected_samples*/ ctx[14]);
	let each_blocks = [];

	for (let i = 0; i < each_value_1.length; i += 1) {
		each_blocks[i] = create_each_block_1(get_each_context_1(ctx, each_value_1, i));
	}

	const out = i => transition_out(each_blocks[i], 1, 1, () => {
		each_blocks[i] = null;
	});

	return {
		c() {
			div = element("div");

			for (let i = 0; i < each_blocks.length; i += 1) {
				each_blocks[i].c();
			}

			attr(div, "class", "gallery svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, div, anchor);

			for (let i = 0; i < each_blocks.length; i += 1) {
				if (each_blocks[i]) {
					each_blocks[i].m(div, null);
				}
			}

			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*value, page, samples_per_page, gradio, selected_samples, handle_mouseenter, handle_mouseleave, component_meta, component_props, samples_dir, current_hover, component_map, components*/ 7041551) {
				each_value_1 = ensure_array_like(/*selected_samples*/ ctx[14]);
				let i;

				for (i = 0; i < each_value_1.length; i += 1) {
					const child_ctx = get_each_context_1(ctx, each_value_1, i);

					if (each_blocks[i]) {
						each_blocks[i].p(child_ctx, dirty);
						transition_in(each_blocks[i], 1);
					} else {
						each_blocks[i] = create_each_block_1(child_ctx);
						each_blocks[i].c();
						transition_in(each_blocks[i], 1);
						each_blocks[i].m(div, null);
					}
				}

				group_outros();

				for (i = each_value_1.length; i < each_blocks.length; i += 1) {
					out(i);
				}

				check_outros();
			}
		},
		i(local) {
			if (current) return;

			for (let i = 0; i < each_value_1.length; i += 1) {
				transition_in(each_blocks[i]);
			}

			current = true;
		},
		o(local) {
			each_blocks = each_blocks.filter(Boolean);

			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out(each_blocks[i]);
			}

			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(div);
			}

			destroy_each(each_blocks, detaching);
		}
	};
}

// (127:6) {#each headers as header}
function create_each_block_4(ctx) {
	let th;
	let t0_value = /*header*/ ctx[46] + "";
	let t0;
	let t1;

	return {
		c() {
			th = element("th");
			t0 = text(t0_value);
			t1 = space();
			attr(th, "class", "svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, th, anchor);
			append(th, t0);
			append(th, t1);
		},
		p(ctx, dirty) {
			if (dirty[0] & /*headers*/ 32 && t0_value !== (t0_value = /*header*/ ctx[46] + "")) set_data(t0, t0_value);
		},
		d(detaching) {
			if (detaching) {
				detach(th);
			}
		}
	};
}

// (147:8) {#if component_name !== undefined && component_map.get(component_name) !== undefined}
function create_if_block_4(ctx) {
	let td;
	let switch_instance;
	let td_class_value;
	let current;

	const switch_instance_spread_levels = [
		/*component_props*/ ctx[2][/*j*/ ctx[45]],
		{ value: /*value*/ ctx[0] },
		{ samples_dir: /*samples_dir*/ ctx[19] },
		{ type: "table" },
		{
			selected: /*current_hover*/ ctx[16] === /*i*/ ctx[40]
		},
		{ index: /*i*/ ctx[40] }
	];

	var switch_value = /*component*/ ctx[42];

	function switch_props(ctx, dirty) {
		let switch_instance_props = {};

		if (dirty !== undefined && dirty[0] & /*component_props, component_meta, samples_dir, current_hover*/ 720900) {
			switch_instance_props = get_spread_update(switch_instance_spread_levels, [
				dirty[0] & /*component_props*/ 4 && get_spread_object(/*component_props*/ ctx[2][/*j*/ ctx[45]]),
				dirty[0] & /*component_meta*/ 131072 && { value: /*value*/ ctx[0] },
				dirty[0] & /*samples_dir*/ 524288 && { samples_dir: /*samples_dir*/ ctx[19] },
				switch_instance_spread_levels[3],
				dirty[0] & /*current_hover*/ 65536 && {
					selected: /*current_hover*/ ctx[16] === /*i*/ ctx[40]
				},
				switch_instance_spread_levels[5]
			]);
		} else {
			for (let i = 0; i < switch_instance_spread_levels.length; i += 1) {
				switch_instance_props = assign(switch_instance_props, switch_instance_spread_levels[i]);
			}
		}

		return { props: switch_instance_props };
	}

	if (switch_value) {
		switch_instance = construct_svelte_component(switch_value, switch_props(ctx));
	}

	return {
		c() {
			td = element("td");
			if (switch_instance) create_component(switch_instance.$$.fragment);

			set_style(td, "max-width", /*component_name*/ ctx[43] === 'textbox'
			? '35ch'
			: 'auto');

			attr(td, "class", td_class_value = "" + (null_to_empty(/*component_name*/ ctx[43]) + " svelte-13hsdno"));
		},
		m(target, anchor) {
			insert(target, td, anchor);
			if (switch_instance) mount_component(switch_instance, td, null);
			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*component_meta*/ 131072 && switch_value !== (switch_value = /*component*/ ctx[42])) {
				if (switch_instance) {
					group_outros();
					const old_component = switch_instance;

					transition_out(old_component.$$.fragment, 1, 0, () => {
						destroy_component(old_component, 1);
					});

					check_outros();
				}

				if (switch_value) {
					switch_instance = construct_svelte_component(switch_value, switch_props(ctx, dirty));
					create_component(switch_instance.$$.fragment);
					transition_in(switch_instance.$$.fragment, 1);
					mount_component(switch_instance, td, null);
				} else {
					switch_instance = null;
				}
			} else if (switch_value) {
				const switch_instance_changes = (dirty[0] & /*component_props, component_meta, samples_dir, current_hover*/ 720900)
				? get_spread_update(switch_instance_spread_levels, [
						dirty[0] & /*component_props*/ 4 && get_spread_object(/*component_props*/ ctx[2][/*j*/ ctx[45]]),
						dirty[0] & /*component_meta*/ 131072 && { value: /*value*/ ctx[0] },
						dirty[0] & /*samples_dir*/ 524288 && { samples_dir: /*samples_dir*/ ctx[19] },
						switch_instance_spread_levels[3],
						dirty[0] & /*current_hover*/ 65536 && {
							selected: /*current_hover*/ ctx[16] === /*i*/ ctx[40]
						},
						switch_instance_spread_levels[5]
					])
				: {};

				switch_instance.$set(switch_instance_changes);
			}

			if (!current || dirty[0] & /*components*/ 2) {
				set_style(td, "max-width", /*component_name*/ ctx[43] === 'textbox'
				? '35ch'
				: 'auto');
			}

			if (!current || dirty[0] & /*components*/ 2 && td_class_value !== (td_class_value = "" + (null_to_empty(/*component_name*/ ctx[43]) + " svelte-13hsdno"))) {
				attr(td, "class", td_class_value);
			}
		},
		i(local) {
			if (current) return;
			if (switch_instance) transition_in(switch_instance.$$.fragment, local);
			current = true;
		},
		o(local) {
			if (switch_instance) transition_out(switch_instance.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(td);
			}

			if (switch_instance) destroy_component(switch_instance);
		}
	};
}

// (145:7) {#each sample_row as { value, component }
function create_each_block_3(ctx) {
	let show_if = /*component_name*/ ctx[43] !== undefined && /*component_map*/ ctx[3].get(/*component_name*/ ctx[43]) !== undefined;
	let if_block_anchor;
	let current;
	let if_block = show_if && create_if_block_4(ctx);

	return {
		c() {
			if (if_block) if_block.c();
			if_block_anchor = empty();
		},
		m(target, anchor) {
			if (if_block) if_block.m(target, anchor);
			insert(target, if_block_anchor, anchor);
			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*components, component_map*/ 10) show_if = /*component_name*/ ctx[43] !== undefined && /*component_map*/ ctx[3].get(/*component_name*/ ctx[43]) !== undefined;

			if (show_if) {
				if (if_block) {
					if_block.p(ctx, dirty);

					if (dirty[0] & /*components, component_map*/ 10) {
						transition_in(if_block, 1);
					}
				} else {
					if_block = create_if_block_4(ctx);
					if_block.c();
					transition_in(if_block, 1);
					if_block.m(if_block_anchor.parentNode, if_block_anchor);
				}
			} else if (if_block) {
				group_outros();

				transition_out(if_block, 1, 1, () => {
					if_block = null;
				});

				check_outros();
			}
		},
		i(local) {
			if (current) return;
			transition_in(if_block);
			current = true;
		},
		o(local) {
			transition_out(if_block);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(if_block_anchor);
			}

			if (if_block) if_block.d(detaching);
		}
	};
}

// (135:5) {#each component_meta as sample_row, i}
function create_each_block_2(ctx) {
	let tr;
	let t;
	let current;
	let mounted;
	let dispose;
	let each_value_3 = ensure_array_like(/*sample_row*/ ctx[38]);
	let each_blocks = [];

	for (let i = 0; i < each_value_3.length; i += 1) {
		each_blocks[i] = create_each_block_3(get_each_context_3(ctx, each_value_3, i));
	}

	const out = i => transition_out(each_blocks[i], 1, 1, () => {
		each_blocks[i] = null;
	});

	function click_handler_1() {
		return /*click_handler_1*/ ctx[30](/*i*/ ctx[40]);
	}

	function mouseenter_handler_1() {
		return /*mouseenter_handler_1*/ ctx[31](/*i*/ ctx[40]);
	}

	return {
		c() {
			tr = element("tr");

			for (let i = 0; i < each_blocks.length; i += 1) {
				each_blocks[i].c();
			}

			t = space();
			attr(tr, "class", "tr-body svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, tr, anchor);

			for (let i = 0; i < each_blocks.length; i += 1) {
				if (each_blocks[i]) {
					each_blocks[i].m(tr, null);
				}
			}

			append(tr, t);
			current = true;

			if (!mounted) {
				dispose = [
					listen(tr, "click", click_handler_1),
					listen(tr, "mouseenter", mouseenter_handler_1),
					listen(tr, "mouseleave", /*mouseleave_handler_1*/ ctx[32])
				];

				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;

			if (dirty[0] & /*components, component_meta, component_props, samples_dir, current_hover, component_map*/ 720910) {
				each_value_3 = ensure_array_like(/*sample_row*/ ctx[38]);
				let i;

				for (i = 0; i < each_value_3.length; i += 1) {
					const child_ctx = get_each_context_3(ctx, each_value_3, i);

					if (each_blocks[i]) {
						each_blocks[i].p(child_ctx, dirty);
						transition_in(each_blocks[i], 1);
					} else {
						each_blocks[i] = create_each_block_3(child_ctx);
						each_blocks[i].c();
						transition_in(each_blocks[i], 1);
						each_blocks[i].m(tr, t);
					}
				}

				group_outros();

				for (i = each_value_3.length; i < each_blocks.length; i += 1) {
					out(i);
				}

				check_outros();
			}
		},
		i(local) {
			if (current) return;

			for (let i = 0; i < each_value_3.length; i += 1) {
				transition_in(each_blocks[i]);
			}

			current = true;
		},
		o(local) {
			each_blocks = each_blocks.filter(Boolean);

			for (let i = 0; i < each_blocks.length; i += 1) {
				transition_out(each_blocks[i]);
			}

			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(tr);
			}

			destroy_each(each_blocks, detaching);
			mounted = false;
			run_all(dispose);
		}
	};
}

// (108:5) {#if component_meta.length && component_map.get(components[0])}
function create_if_block_3(ctx) {
	let switch_instance;
	let switch_instance_anchor;
	let current;

	const switch_instance_spread_levels = [
		/*component_props*/ ctx[2][0],
		{ value: /*sample_row*/ ctx[38][0] },
		{ samples_dir: /*samples_dir*/ ctx[19] },
		{ type: "gallery" },
		{
			selected: /*current_hover*/ ctx[16] === /*i*/ ctx[40]
		},
		{ index: /*i*/ ctx[40] }
	];

	var switch_value = /*component_meta*/ ctx[17][0][0].component;

	function switch_props(ctx, dirty) {
		let switch_instance_props = {};

		if (dirty !== undefined && dirty[0] & /*component_props, selected_samples, samples_dir, current_hover*/ 606212) {
			switch_instance_props = get_spread_update(switch_instance_spread_levels, [
				dirty[0] & /*component_props*/ 4 && get_spread_object(/*component_props*/ ctx[2][0]),
				dirty[0] & /*selected_samples*/ 16384 && { value: /*sample_row*/ ctx[38][0] },
				dirty[0] & /*samples_dir*/ 524288 && { samples_dir: /*samples_dir*/ ctx[19] },
				switch_instance_spread_levels[3],
				dirty[0] & /*current_hover*/ 65536 && {
					selected: /*current_hover*/ ctx[16] === /*i*/ ctx[40]
				},
				switch_instance_spread_levels[5]
			]);
		} else {
			for (let i = 0; i < switch_instance_spread_levels.length; i += 1) {
				switch_instance_props = assign(switch_instance_props, switch_instance_spread_levels[i]);
			}
		}

		return { props: switch_instance_props };
	}

	if (switch_value) {
		switch_instance = construct_svelte_component(switch_value, switch_props(ctx));
	}

	return {
		c() {
			if (switch_instance) create_component(switch_instance.$$.fragment);
			switch_instance_anchor = empty();
		},
		m(target, anchor) {
			if (switch_instance) mount_component(switch_instance, target, anchor);
			insert(target, switch_instance_anchor, anchor);
			current = true;
		},
		p(ctx, dirty) {
			if (dirty[0] & /*component_meta*/ 131072 && switch_value !== (switch_value = /*component_meta*/ ctx[17][0][0].component)) {
				if (switch_instance) {
					group_outros();
					const old_component = switch_instance;

					transition_out(old_component.$$.fragment, 1, 0, () => {
						destroy_component(old_component, 1);
					});

					check_outros();
				}

				if (switch_value) {
					switch_instance = construct_svelte_component(switch_value, switch_props(ctx, dirty));
					create_component(switch_instance.$$.fragment);
					transition_in(switch_instance.$$.fragment, 1);
					mount_component(switch_instance, switch_instance_anchor.parentNode, switch_instance_anchor);
				} else {
					switch_instance = null;
				}
			} else if (switch_value) {
				const switch_instance_changes = (dirty[0] & /*component_props, selected_samples, samples_dir, current_hover*/ 606212)
				? get_spread_update(switch_instance_spread_levels, [
						dirty[0] & /*component_props*/ 4 && get_spread_object(/*component_props*/ ctx[2][0]),
						dirty[0] & /*selected_samples*/ 16384 && { value: /*sample_row*/ ctx[38][0] },
						dirty[0] & /*samples_dir*/ 524288 && { samples_dir: /*samples_dir*/ ctx[19] },
						switch_instance_spread_levels[3],
						dirty[0] & /*current_hover*/ 65536 && {
							selected: /*current_hover*/ ctx[16] === /*i*/ ctx[40]
						},
						switch_instance_spread_levels[5]
					])
				: {};

				switch_instance.$set(switch_instance_changes);
			}
		},
		i(local) {
			if (current) return;
			if (switch_instance) transition_in(switch_instance.$$.fragment, local);
			current = true;
		},
		o(local) {
			if (switch_instance) transition_out(switch_instance.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(switch_instance_anchor);
			}

			if (switch_instance) destroy_component(switch_instance, detaching);
		}
	};
}

// (97:3) {#each selected_samples as sample_row, i}
function create_each_block_1(ctx) {
	let button;
	let show_if = /*component_meta*/ ctx[17].length && /*component_map*/ ctx[3].get(/*components*/ ctx[1][0]);
	let t;
	let current;
	let mounted;
	let dispose;
	let if_block = show_if && create_if_block_3(ctx);

	function click_handler() {
		return /*click_handler*/ ctx[27](/*i*/ ctx[40], /*sample_row*/ ctx[38]);
	}

	function mouseenter_handler() {
		return /*mouseenter_handler*/ ctx[28](/*i*/ ctx[40]);
	}

	return {
		c() {
			button = element("button");
			if (if_block) if_block.c();
			t = space();
			attr(button, "class", "gallery-item svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, button, anchor);
			if (if_block) if_block.m(button, null);
			append(button, t);
			current = true;

			if (!mounted) {
				dispose = [
					listen(button, "click", click_handler),
					listen(button, "mouseenter", mouseenter_handler),
					listen(button, "mouseleave", /*mouseleave_handler*/ ctx[29])
				];

				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			if (dirty[0] & /*component_meta, component_map, components*/ 131082) show_if = /*component_meta*/ ctx[17].length && /*component_map*/ ctx[3].get(/*components*/ ctx[1][0]);

			if (show_if) {
				if (if_block) {
					if_block.p(ctx, dirty);

					if (dirty[0] & /*component_meta, component_map, components*/ 131082) {
						transition_in(if_block, 1);
					}
				} else {
					if_block = create_if_block_3(ctx);
					if_block.c();
					transition_in(if_block, 1);
					if_block.m(button, t);
				}
			} else if (if_block) {
				group_outros();

				transition_out(if_block, 1, 1, () => {
					if_block = null;
				});

				check_outros();
			}
		},
		i(local) {
			if (current) return;
			transition_in(if_block);
			current = true;
		},
		o(local) {
			transition_out(if_block);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(button);
			}

			if (if_block) if_block.d();
			mounted = false;
			run_all(dispose);
		}
	};
}

// (172:1) {#if paginate}
function create_if_block(ctx) {
	let div;
	let t;
	let each_value = ensure_array_like(/*visible_pages*/ ctx[15]);
	let each_blocks = [];

	for (let i = 0; i < each_value.length; i += 1) {
		each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i));
	}

	return {
		c() {
			div = element("div");
			t = text("Pages:\n\t\t\t");

			for (let i = 0; i < each_blocks.length; i += 1) {
				each_blocks[i].c();
			}

			attr(div, "class", "paginate svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, div, anchor);
			append(div, t);

			for (let i = 0; i < each_blocks.length; i += 1) {
				if (each_blocks[i]) {
					each_blocks[i].m(div, null);
				}
			}
		},
		p(ctx, dirty) {
			if (dirty[0] & /*visible_pages, page*/ 40960) {
				each_value = ensure_array_like(/*visible_pages*/ ctx[15]);
				let i;

				for (i = 0; i < each_value.length; i += 1) {
					const child_ctx = get_each_context(ctx, each_value, i);

					if (each_blocks[i]) {
						each_blocks[i].p(child_ctx, dirty);
					} else {
						each_blocks[i] = create_each_block(child_ctx);
						each_blocks[i].c();
						each_blocks[i].m(div, null);
					}
				}

				for (; i < each_blocks.length; i += 1) {
					each_blocks[i].d(1);
				}

				each_blocks.length = each_value.length;
			}
		},
		d(detaching) {
			if (detaching) {
				detach(div);
			}

			destroy_each(each_blocks, detaching);
		}
	};
}

// (178:4) {:else}
function create_else_block(ctx) {
	let button;
	let t0_value = /*visible_page*/ ctx[35] + 1 + "";
	let t0;
	let t1;
	let mounted;
	let dispose;

	function click_handler_2() {
		return /*click_handler_2*/ ctx[33](/*visible_page*/ ctx[35]);
	}

	return {
		c() {
			button = element("button");
			t0 = text(t0_value);
			t1 = space();
			attr(button, "class", "svelte-13hsdno");
			toggle_class(button, "current-page", /*page*/ ctx[13] === /*visible_page*/ ctx[35]);
		},
		m(target, anchor) {
			insert(target, button, anchor);
			append(button, t0);
			append(button, t1);

			if (!mounted) {
				dispose = listen(button, "click", click_handler_2);
				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			if (dirty[0] & /*visible_pages*/ 32768 && t0_value !== (t0_value = /*visible_page*/ ctx[35] + 1 + "")) set_data(t0, t0_value);

			if (dirty[0] & /*page, visible_pages*/ 40960) {
				toggle_class(button, "current-page", /*page*/ ctx[13] === /*visible_page*/ ctx[35]);
			}
		},
		d(detaching) {
			if (detaching) {
				detach(button);
			}

			mounted = false;
			dispose();
		}
	};
}

// (176:4) {#if visible_page === -1}
function create_if_block_1(ctx) {
	let div;

	return {
		c() {
			div = element("div");
			div.textContent = "...";
		},
		m(target, anchor) {
			insert(target, div, anchor);
		},
		p: noop,
		d(detaching) {
			if (detaching) {
				detach(div);
			}
		}
	};
}

// (175:3) {#each visible_pages as visible_page}
function create_each_block(ctx) {
	let if_block_anchor;

	function select_block_type_1(ctx, dirty) {
		if (/*visible_page*/ ctx[35] === -1) return create_if_block_1;
		return create_else_block;
	}

	let current_block_type = select_block_type_1(ctx);
	let if_block = current_block_type(ctx);

	return {
		c() {
			if_block.c();
			if_block_anchor = empty();
		},
		m(target, anchor) {
			if_block.m(target, anchor);
			insert(target, if_block_anchor, anchor);
		},
		p(ctx, dirty) {
			if (current_block_type === (current_block_type = select_block_type_1(ctx)) && if_block) {
				if_block.p(ctx, dirty);
			} else {
				if_block.d(1);
				if_block = current_block_type(ctx);

				if (if_block) {
					if_block.c();
					if_block.m(if_block_anchor.parentNode, if_block_anchor);
				}
			}
		},
		d(detaching) {
			if (detaching) {
				detach(if_block_anchor);
			}

			if_block.d(detaching);
		}
	};
}

// (67:0) <Block  {visible}  padding={false}  {elem_id}  {elem_classes}  {scale}  {min_width}  allow_overflow={false}  container={false} >
function create_default_slot(ctx) {
	let div;
	let svg;
	let path;
	let t0;
	let t1;
	let t2;
	let current_block_type_index;
	let if_block0;
	let t3;
	let if_block1_anchor;
	let current;
	const if_block_creators = [create_if_block_2, create_else_block_1];
	const if_blocks = [];

	function select_block_type(ctx, dirty) {
		if (/*gallery*/ ctx[18]) return 0;
		return 1;
	}

	current_block_type_index = select_block_type(ctx);
	if_block0 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
	let if_block1 = /*paginate*/ ctx[20] && create_if_block(ctx);

	return {
		c() {
			div = element("div");
			svg = svg_element("svg");
			path = svg_element("path");
			t0 = space();
			t1 = text(/*label*/ ctx[4]);
			t2 = space();
			if_block0.c();
			t3 = space();
			if (if_block1) if_block1.c();
			if_block1_anchor = empty();
			attr(path, "fill", "currentColor");
			attr(path, "d", "M10 6h18v2H10zm0 18h18v2H10zm0-9h18v2H10zm-6 0h2v2H4zm0-9h2v2H4zm0 18h2v2H4z");
			attr(svg, "xmlns", "http://www.w3.org/2000/svg");
			attr(svg, "xmlns:xlink", "http://www.w3.org/1999/xlink");
			attr(svg, "aria-hidden", "true");
			attr(svg, "role", "img");
			attr(svg, "width", "1em");
			attr(svg, "height", "1em");
			attr(svg, "preserveAspectRatio", "xMidYMid meet");
			attr(svg, "viewBox", "0 0 32 32");
			attr(svg, "class", "svelte-13hsdno");
			attr(div, "class", "label svelte-13hsdno");
		},
		m(target, anchor) {
			insert(target, div, anchor);
			append(div, svg);
			append(svg, path);
			append(div, t0);
			append(div, t1);
			insert(target, t2, anchor);
			if_blocks[current_block_type_index].m(target, anchor);
			insert(target, t3, anchor);
			if (if_block1) if_block1.m(target, anchor);
			insert(target, if_block1_anchor, anchor);
			current = true;
		},
		p(ctx, dirty) {
			if (!current || dirty[0] & /*label*/ 16) set_data(t1, /*label*/ ctx[4]);
			let previous_block_index = current_block_type_index;
			current_block_type_index = select_block_type(ctx);

			if (current_block_type_index === previous_block_index) {
				if_blocks[current_block_type_index].p(ctx, dirty);
			} else {
				group_outros();

				transition_out(if_blocks[previous_block_index], 1, 1, () => {
					if_blocks[previous_block_index] = null;
				});

				check_outros();
				if_block0 = if_blocks[current_block_type_index];

				if (!if_block0) {
					if_block0 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
					if_block0.c();
				} else {
					if_block0.p(ctx, dirty);
				}

				transition_in(if_block0, 1);
				if_block0.m(t3.parentNode, t3);
			}

			if (/*paginate*/ ctx[20]) if_block1.p(ctx, dirty);
		},
		i(local) {
			if (current) return;
			transition_in(if_block0);
			current = true;
		},
		o(local) {
			transition_out(if_block0);
			current = false;
		},
		d(detaching) {
			if (detaching) {
				detach(div);
				detach(t2);
				detach(t3);
				detach(if_block1_anchor);
			}

			if_blocks[current_block_type_index].d(detaching);
			if (if_block1) if_block1.d(detaching);
		}
	};
}

function create_fragment(ctx) {
	let block;
	let current;

	block = new Block({
			props: {
				visible: /*visible*/ ctx[8],
				padding: false,
				elem_id: /*elem_id*/ ctx[6],
				elem_classes: /*elem_classes*/ ctx[7],
				scale: /*scale*/ ctx[10],
				min_width: /*min_width*/ ctx[11],
				allow_overflow: false,
				container: false,
				$$slots: { default: [create_default_slot] },
				$$scope: { ctx }
			}
		});

	return {
		c() {
			create_component(block.$$.fragment);
		},
		m(target, anchor) {
			mount_component(block, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const block_changes = {};
			if (dirty[0] & /*visible*/ 256) block_changes.visible = /*visible*/ ctx[8];
			if (dirty[0] & /*elem_id*/ 64) block_changes.elem_id = /*elem_id*/ ctx[6];
			if (dirty[0] & /*elem_classes*/ 128) block_changes.elem_classes = /*elem_classes*/ ctx[7];
			if (dirty[0] & /*scale*/ 1024) block_changes.scale = /*scale*/ ctx[10];
			if (dirty[0] & /*min_width*/ 2048) block_changes.min_width = /*min_width*/ ctx[11];

			if (dirty[0] & /*visible_pages, page, selected_samples, value, samples_per_page, gradio, component_meta, component_props, current_hover, component_map, components, gallery, headers, label*/ 520767 | dirty[1] & /*$$scope*/ 262144) {
				block_changes.$$scope = { dirty, ctx };
			}

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

function instance($$self, $$props, $$invalidate) {
	let gallery;
	let { components } = $$props;
	let { component_props } = $$props;
	let { component_map } = $$props;
	let { label = "Examples" } = $$props;
	let { headers } = $$props;
	let { samples } = $$props;
	let { elem_id = "" } = $$props;
	let { elem_classes = [] } = $$props;
	let { visible = true } = $$props;
	let { value = null } = $$props;
	let { root } = $$props;
	let { proxy_url } = $$props;
	let { samples_per_page = 10 } = $$props;
	let { scale = null } = $$props;
	let { min_width = undefined } = $$props;
	let { gradio } = $$props;
	let samples_dir = get_fetchable_url_or_file(null, root, proxy_url);
	let page = 0;
	let paginate = samples.length > samples_per_page;
	let selected_samples;
	let page_count;
	let visible_pages = [];
	let current_hover = -1;

	function handle_mouseenter(i) {
		$$invalidate(16, current_hover = i);
	}

	function handle_mouseleave() {
		$$invalidate(16, current_hover = -1);
	}

	let component_meta = [];

	async function get_component_meta(selected_samples) {
		$$invalidate(17, component_meta = await Promise.all(selected_samples.map(async sample_row => await Promise.all(sample_row.map(async (sample_cell, j) => {
			return {
				value: sample_cell,
				component: (await component_map.get(components[j]))?.component?.default
			};
		})))));
	}

	const click_handler = (i, sample_row) => {
		$$invalidate(0, value = i + page * samples_per_page);
		gradio.dispatch("click", value);
		gradio.dispatch("select", { index: value, value: sample_row });
	};

	const mouseenter_handler = i => handle_mouseenter(i);
	const mouseleave_handler = () => handle_mouseleave();

	const click_handler_1 = i => {
		$$invalidate(0, value = i + page * samples_per_page);
		gradio.dispatch("click", value);
	};

	const mouseenter_handler_1 = i => handle_mouseenter(i);
	const mouseleave_handler_1 = () => handle_mouseleave();
	const click_handler_2 = visible_page => $$invalidate(13, page = visible_page);

	$$self.$$set = $$props => {
		if ('components' in $$props) $$invalidate(1, components = $$props.components);
		if ('component_props' in $$props) $$invalidate(2, component_props = $$props.component_props);
		if ('component_map' in $$props) $$invalidate(3, component_map = $$props.component_map);
		if ('label' in $$props) $$invalidate(4, label = $$props.label);
		if ('headers' in $$props) $$invalidate(5, headers = $$props.headers);
		if ('samples' in $$props) $$invalidate(23, samples = $$props.samples);
		if ('elem_id' in $$props) $$invalidate(6, elem_id = $$props.elem_id);
		if ('elem_classes' in $$props) $$invalidate(7, elem_classes = $$props.elem_classes);
		if ('visible' in $$props) $$invalidate(8, visible = $$props.visible);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('root' in $$props) $$invalidate(24, root = $$props.root);
		if ('proxy_url' in $$props) $$invalidate(25, proxy_url = $$props.proxy_url);
		if ('samples_per_page' in $$props) $$invalidate(9, samples_per_page = $$props.samples_per_page);
		if ('scale' in $$props) $$invalidate(10, scale = $$props.scale);
		if ('min_width' in $$props) $$invalidate(11, min_width = $$props.min_width);
		if ('gradio' in $$props) $$invalidate(12, gradio = $$props.gradio);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty[0] & /*components*/ 2) {
			$$invalidate(18, gallery = components.length < 2);
		}

		if ($$self.$$.dirty[0] & /*samples, page, samples_per_page, page_count, visible_pages*/ 75538944) {
			{
				if (paginate) {
					$$invalidate(15, visible_pages = []);
					$$invalidate(14, selected_samples = samples.slice(page * samples_per_page, (page + 1) * samples_per_page));
					$$invalidate(26, page_count = Math.ceil(samples.length / samples_per_page));

					[0, page, page_count - 1].forEach(anchor => {
						for (let i = anchor - 2; i <= anchor + 2; i++) {
							if (i >= 0 && i < page_count && !visible_pages.includes(i)) {
								if (visible_pages.length > 0 && i - visible_pages[visible_pages.length - 1] > 1) {
									visible_pages.push(-1);
								}

								visible_pages.push(i);
							}
						}
					});
				} else {
					$$invalidate(14, selected_samples = samples.slice());
				}
			}
		}

		if ($$self.$$.dirty[0] & /*selected_samples*/ 16384) {
			get_component_meta(selected_samples);
		}
	};

	return [
		value,
		components,
		component_props,
		component_map,
		label,
		headers,
		elem_id,
		elem_classes,
		visible,
		samples_per_page,
		scale,
		min_width,
		gradio,
		page,
		selected_samples,
		visible_pages,
		current_hover,
		component_meta,
		gallery,
		samples_dir,
		paginate,
		handle_mouseenter,
		handle_mouseleave,
		samples,
		root,
		proxy_url,
		page_count,
		click_handler,
		mouseenter_handler,
		mouseleave_handler,
		click_handler_1,
		mouseenter_handler_1,
		mouseleave_handler_1,
		click_handler_2
	];
}

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

		init(
			this,
			options,
			instance,
			create_fragment,
			safe_not_equal,
			{
				components: 1,
				component_props: 2,
				component_map: 3,
				label: 4,
				headers: 5,
				samples: 23,
				elem_id: 6,
				elem_classes: 7,
				visible: 8,
				value: 0,
				root: 24,
				proxy_url: 25,
				samples_per_page: 9,
				scale: 10,
				min_width: 11,
				gradio: 12
			},
			null,
			[-1, -1]
		);
	}
}

export { Index as default };
//# sourceMappingURL=Index-226940e6.js.map
