import { S as SvelteComponent, i as init, s as safe_not_equal, e as element, t as text, f as insert, g as append, h as set_data, n as detach, c as create_component, a as space, b as attr, aa as add_render_callback, m as mount_component, ab as select_option, l as listen, j as transition_in, k as transition_out, o as destroy_component, B as destroy_each, E as createEventDispatcher, ac as select_value, P as assign, Q as StatusTracker, H as binding_callbacks, N as bind, R as get_spread_update, T as get_spread_object, K as add_flush_callback, J as bubble } from './index.4872dbae.js';
import { B as Block } from './Block.29585093.js';
import { g as get_styles } from './styles.c72835fa.js';
import { B as BlockTitle } from './BlockTitle.95b1a751.js';

/* home/runner/work/gradio/gradio/ui/packages/form/src/Dropdown.svelte generated by Svelte v3.49.0 */

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

// (16:1) <BlockTitle {show_label}>
function create_default_slot$1(ctx) {
	let t;

	return {
		c() {
			t = text(/*label*/ ctx[1]);
		},
		m(target, anchor) {
			insert(target, t, anchor);
		},
		p(ctx, dirty) {
			if (dirty & /*label*/ 2) set_data(t, /*label*/ ctx[1]);
		},
		d(detaching) {
			if (detaching) detach(t);
		}
	};
}

// (22:2) {#each choices as choice}
function create_each_block(ctx) {
	let option;
	let t_value = /*choice*/ ctx[10] + "";
	let t;
	let option_value_value;

	return {
		c() {
			option = element("option");
			t = text(t_value);
			option.__value = option_value_value = /*choice*/ ctx[10];
			option.value = option.__value;
		},
		m(target, anchor) {
			insert(target, option, anchor);
			append(option, t);
		},
		p(ctx, dirty) {
			if (dirty & /*choices*/ 4 && t_value !== (t_value = /*choice*/ ctx[10] + "")) set_data(t, t_value);

			if (dirty & /*choices*/ 4 && option_value_value !== (option_value_value = /*choice*/ ctx[10])) {
				option.__value = option_value_value;
				option.value = option.__value;
			}
		},
		d(detaching) {
			if (detaching) detach(option);
		}
	};
}

function create_fragment$1(ctx) {
	let label_1;
	let blocktitle;
	let t;
	let select;
	let select_class_value;
	let current;
	let mounted;
	let dispose;

	blocktitle = new BlockTitle({
			props: {
				show_label: /*show_label*/ ctx[4],
				$$slots: { default: [create_default_slot$1] },
				$$scope: { ctx }
			}
		});

	let each_value = /*choices*/ ctx[2];
	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() {
			label_1 = element("label");
			create_component(blocktitle.$$.fragment);
			t = space();
			select = element("select");

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

			attr(select, "class", select_class_value = "gr-box gr-input w-full disabled:cursor-not-allowed " + /*rounded*/ ctx[6] + " " + /*border*/ ctx[5]);
			select.disabled = /*disabled*/ ctx[3];
			if (/*value*/ ctx[0] === void 0) add_render_callback(() => /*select_change_handler*/ ctx[8].call(select));
		},
		m(target, anchor) {
			insert(target, label_1, anchor);
			mount_component(blocktitle, label_1, null);
			append(label_1, t);
			append(label_1, select);

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

			select_option(select, /*value*/ ctx[0]);
			current = true;

			if (!mounted) {
				dispose = listen(select, "change", /*select_change_handler*/ ctx[8]);
				mounted = true;
			}
		},
		p(ctx, [dirty]) {
			const blocktitle_changes = {};
			if (dirty & /*show_label*/ 16) blocktitle_changes.show_label = /*show_label*/ ctx[4];

			if (dirty & /*$$scope, label*/ 8194) {
				blocktitle_changes.$$scope = { dirty, ctx };
			}

			blocktitle.$set(blocktitle_changes);

			if (dirty & /*choices*/ 4) {
				each_value = /*choices*/ ctx[2];
				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(select, null);
					}
				}

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

				each_blocks.length = each_value.length;
			}

			if (!current || dirty & /*rounded, border*/ 96 && select_class_value !== (select_class_value = "gr-box gr-input w-full disabled:cursor-not-allowed " + /*rounded*/ ctx[6] + " " + /*border*/ ctx[5])) {
				attr(select, "class", select_class_value);
			}

			if (!current || dirty & /*disabled*/ 8) {
				select.disabled = /*disabled*/ ctx[3];
			}

			if (dirty & /*value, choices*/ 5) {
				select_option(select, /*value*/ ctx[0]);
			}
		},
		i(local) {
			if (current) return;
			transition_in(blocktitle.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(blocktitle.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			if (detaching) detach(label_1);
			destroy_component(blocktitle);
			destroy_each(each_blocks, detaching);
			mounted = false;
			dispose();
		}
	};
}

function instance$1($$self, $$props, $$invalidate) {
	let rounded;
	let border;
	let { label } = $$props;
	let { value = undefined } = $$props;
	let { style = {} } = $$props;
	let { choices } = $$props;
	let { disabled = false } = $$props;
	let { show_label } = $$props;
	const dispatch = createEventDispatcher();

	function select_change_handler() {
		value = select_value(this);
		$$invalidate(0, value);
		$$invalidate(2, choices);
	}

	$$self.$$set = $$props => {
		if ('label' in $$props) $$invalidate(1, label = $$props.label);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('style' in $$props) $$invalidate(7, style = $$props.style);
		if ('choices' in $$props) $$invalidate(2, choices = $$props.choices);
		if ('disabled' in $$props) $$invalidate(3, disabled = $$props.disabled);
		if ('show_label' in $$props) $$invalidate(4, show_label = $$props.show_label);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty & /*value*/ 1) {
			dispatch("change", value);
		}

		if ($$self.$$.dirty & /*style*/ 128) {
			$$invalidate(6, { rounded, border } = get_styles(style, ["rounded", "border"]), rounded, ($$invalidate(5, border), $$invalidate(7, style)));
		}
	};

	return [
		value,
		label,
		choices,
		disabled,
		show_label,
		border,
		rounded,
		style,
		select_change_handler
	];
}

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

		init(this, options, instance$1, create_fragment$1, safe_not_equal, {
			label: 1,
			value: 0,
			style: 7,
			choices: 2,
			disabled: 3,
			show_label: 4
		});
	}
}

/* src/components/Dropdown/Dropdown.svelte generated by Svelte v3.49.0 */

function create_default_slot(ctx) {
	let statustracker;
	let t;
	let dropdown;
	let updating_value;
	let current;
	const statustracker_spread_levels = [/*loading_status*/ ctx[7]];
	let statustracker_props = {};

	for (let i = 0; i < statustracker_spread_levels.length; i += 1) {
		statustracker_props = assign(statustracker_props, statustracker_spread_levels[i]);
	}

	statustracker = new StatusTracker({ props: statustracker_props });

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

	let dropdown_props = {
		choices: /*choices*/ ctx[4],
		label: /*label*/ ctx[1],
		show_label: /*show_label*/ ctx[5],
		style: /*style*/ ctx[6],
		disabled: /*mode*/ ctx[8] === "static"
	};

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

	dropdown = new Dropdown({ props: dropdown_props });
	binding_callbacks.push(() => bind(dropdown, 'value', dropdown_value_binding));
	dropdown.$on("change", /*change_handler*/ ctx[10]);

	return {
		c() {
			create_component(statustracker.$$.fragment);
			t = space();
			create_component(dropdown.$$.fragment);
		},
		m(target, anchor) {
			mount_component(statustracker, target, anchor);
			insert(target, t, anchor);
			mount_component(dropdown, target, anchor);
			current = true;
		},
		p(ctx, dirty) {
			const statustracker_changes = (dirty & /*loading_status*/ 128)
			? get_spread_update(statustracker_spread_levels, [get_spread_object(/*loading_status*/ ctx[7])])
			: {};

			statustracker.$set(statustracker_changes);
			const dropdown_changes = {};
			if (dirty & /*choices*/ 16) dropdown_changes.choices = /*choices*/ ctx[4];
			if (dirty & /*label*/ 2) dropdown_changes.label = /*label*/ ctx[1];
			if (dirty & /*show_label*/ 32) dropdown_changes.show_label = /*show_label*/ ctx[5];
			if (dirty & /*style*/ 64) dropdown_changes.style = /*style*/ ctx[6];
			if (dirty & /*mode*/ 256) dropdown_changes.disabled = /*mode*/ ctx[8] === "static";

			if (!updating_value && dirty & /*value*/ 1) {
				updating_value = true;
				dropdown_changes.value = /*value*/ ctx[0];
				add_flush_callback(() => updating_value = false);
			}

			dropdown.$set(dropdown_changes);
		},
		i(local) {
			if (current) return;
			transition_in(statustracker.$$.fragment, local);
			transition_in(dropdown.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(statustracker.$$.fragment, local);
			transition_out(dropdown.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component(statustracker, detaching);
			if (detaching) detach(t);
			destroy_component(dropdown, detaching);
		}
	};
}

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

	block = new Block({
			props: {
				visible: /*visible*/ ctx[3],
				elem_id: /*elem_id*/ ctx[2],
				disable: typeof /*style*/ ctx[6].container === "boolean" && !/*style*/ ctx[6].container,
				$$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 & /*visible*/ 8) block_changes.visible = /*visible*/ ctx[3];
			if (dirty & /*elem_id*/ 4) block_changes.elem_id = /*elem_id*/ ctx[2];
			if (dirty & /*style*/ 64) block_changes.disable = typeof /*style*/ ctx[6].container === "boolean" && !/*style*/ ctx[6].container;

			if (dirty & /*$$scope, choices, label, show_label, style, mode, value, loading_status*/ 2547) {
				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 { label = "Dropdown" } = $$props;
	let { elem_id = "" } = $$props;
	let { visible = true } = $$props;
	let { value = "" } = $$props;
	let { choices } = $$props;
	let { show_label } = $$props;
	let { style = {} } = $$props;
	let { loading_status } = $$props;
	let { mode } = $$props;

	function dropdown_value_binding(value$1) {
		value = value$1;
		$$invalidate(0, value);
	}

	function change_handler(event) {
		bubble.call(this, $$self, event);
	}

	$$self.$$set = $$props => {
		if ('label' in $$props) $$invalidate(1, label = $$props.label);
		if ('elem_id' in $$props) $$invalidate(2, elem_id = $$props.elem_id);
		if ('visible' in $$props) $$invalidate(3, visible = $$props.visible);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('choices' in $$props) $$invalidate(4, choices = $$props.choices);
		if ('show_label' in $$props) $$invalidate(5, show_label = $$props.show_label);
		if ('style' in $$props) $$invalidate(6, style = $$props.style);
		if ('loading_status' in $$props) $$invalidate(7, loading_status = $$props.loading_status);
		if ('mode' in $$props) $$invalidate(8, mode = $$props.mode);
	};

	return [
		value,
		label,
		elem_id,
		visible,
		choices,
		show_label,
		style,
		loading_status,
		mode,
		dropdown_value_binding,
		change_handler
	];
}

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

		init(this, options, instance, create_fragment, safe_not_equal, {
			label: 1,
			elem_id: 2,
			visible: 3,
			value: 0,
			choices: 4,
			show_label: 5,
			style: 6,
			loading_status: 7,
			mode: 8
		});
	}
}

var Dropdown_1$1 = Dropdown_1;

const modes = ["static", "dynamic"];

export { Dropdown_1$1 as Component, modes };
