import { B as Block } from './Button-723db480.js';
import { B as BlockTitle } from './BlockTitle-082b4bca.js';
import { S as Static } from './Index-f62c49f9.js';
export { default as BaseExample } from './Example-0b753ad4.js';
import './index-b5b16a51.js';
import './svelte/svelte.js';
import './Info-a7917974.js';

const Radio_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/radio/shared/Radio.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent: SvelteComponent$1,
	append,
	attr: attr$1,
	detach: detach$1,
	element: element$1,
	init: init$1,
	init_binding_group,
	insert: insert$1,
	listen,
	noop,
	safe_not_equal: safe_not_equal$1,
	set_data: set_data$1,
	set_input_value,
	space: space$1,
	text: text$1,
	toggle_class
} = window.__gradio__svelte__internal;
const { createEventDispatcher } = window.__gradio__svelte__internal;
function create_fragment$1(ctx) {
	let label;
	let input;
	let value_has_changed = false;
	let t0;
	let span;
	let t1;
	let label_data_testid_value;
	let binding_group;
	let mounted;
	let dispose;
	binding_group = init_binding_group(/*$$binding_groups*/ ctx[6][0]);

	return {
		c() {
			label = element$1("label");
			input = element$1("input");
			t0 = space$1();
			span = element$1("span");
			t1 = text$1(/*display_value*/ ctx[1]);
			input.disabled = /*disabled*/ ctx[3];
			attr$1(input, "type", "radio");
			attr$1(input, "name", "radio-" + ++id);
			input.__value = /*internal_value*/ ctx[2];
			set_input_value(input, input.__value);
			attr$1(input, "class", "svelte-1mhtq7j");
			attr$1(span, "class", "ml-2 svelte-1mhtq7j");
			attr$1(label, "data-testid", label_data_testid_value = "" + (/*display_value*/ ctx[1] + "-radio-label"));
			attr$1(label, "class", "svelte-1mhtq7j");
			toggle_class(label, "disabled", /*disabled*/ ctx[3]);
			toggle_class(label, "selected", /*is_selected*/ ctx[4]);
			binding_group.p(input);
		},
		m(target, anchor) {
			insert$1(target, label, anchor);
			append(label, input);
			input.checked = input.__value === /*selected*/ ctx[0];
			append(label, t0);
			append(label, span);
			append(span, t1);

			if (!mounted) {
				dispose = listen(input, "change", /*input_change_handler*/ ctx[5]);
				mounted = true;
			}
		},
		p(ctx, [dirty]) {
			if (dirty & /*disabled*/ 8) {
				input.disabled = /*disabled*/ ctx[3];
			}

			if (dirty & /*internal_value*/ 4) {
				input.__value = /*internal_value*/ ctx[2];
				set_input_value(input, input.__value);
				value_has_changed = true;
			}

			if (value_has_changed || dirty & /*selected*/ 1) {
				input.checked = input.__value === /*selected*/ ctx[0];
			}

			if (dirty & /*display_value*/ 2) set_data$1(t1, /*display_value*/ ctx[1]);

			if (dirty & /*display_value*/ 2 && label_data_testid_value !== (label_data_testid_value = "" + (/*display_value*/ ctx[1] + "-radio-label"))) {
				attr$1(label, "data-testid", label_data_testid_value);
			}

			if (dirty & /*disabled*/ 8) {
				toggle_class(label, "disabled", /*disabled*/ ctx[3]);
			}

			if (dirty & /*is_selected*/ 16) {
				toggle_class(label, "selected", /*is_selected*/ ctx[4]);
			}
		},
		i: noop,
		o: noop,
		d(detaching) {
			if (detaching) {
				detach$1(label);
			}

			binding_group.r();
			mounted = false;
			dispose();
		}
	};
}

let id = 0;

function instance$1($$self, $$props, $$invalidate) {
	let { display_value } = $$props;
	let { internal_value } = $$props;
	let { disabled = false } = $$props;
	let { selected = null } = $$props;
	const dispatch = createEventDispatcher();
	let is_selected = false;

	async function handle_input(selected, internal_value) {
		$$invalidate(4, is_selected = selected === internal_value);

		if (is_selected) {
			dispatch("input", internal_value);
		}
	}

	const $$binding_groups = [[]];

	function input_change_handler() {
		selected = this.__value;
		$$invalidate(0, selected);
	}

	$$self.$$set = $$props => {
		if ('display_value' in $$props) $$invalidate(1, display_value = $$props.display_value);
		if ('internal_value' in $$props) $$invalidate(2, internal_value = $$props.internal_value);
		if ('disabled' in $$props) $$invalidate(3, disabled = $$props.disabled);
		if ('selected' in $$props) $$invalidate(0, selected = $$props.selected);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty & /*selected, internal_value*/ 5) {
			handle_input(selected, internal_value);
		}
	};

	return [
		selected,
		display_value,
		internal_value,
		disabled,
		is_selected,
		input_change_handler,
		$$binding_groups
	];
}

class Radio extends SvelteComponent$1 {
	constructor(options) {
		super();

		init$1(this, options, instance$1, create_fragment$1, safe_not_equal$1, {
			display_value: 1,
			internal_value: 2,
			disabled: 3,
			selected: 0
		});
	}
}

const BaseRadio = Radio;

const Index_svelte_svelte_type_style_lang = '';

/* home/runner/work/gradio/gradio/js/radio/Index.svelte generated by Svelte v4.2.2 */
const {
	SvelteComponent,
	add_flush_callback,
	assign,
	attr,
	bind,
	binding_callbacks,
	check_outros,
	create_component,
	destroy_component,
	detach,
	element,
	empty,
	ensure_array_like,
	get_spread_object,
	get_spread_update,
	group_outros,
	init,
	insert,
	mount_component,
	outro_and_destroy_block,
	safe_not_equal,
	set_data,
	space,
	text,
	transition_in,
	transition_out,
	update_keyed_each
} = window.__gradio__svelte__internal;
const { afterUpdate } = window.__gradio__svelte__internal;
function get_each_context(ctx, list, i) {
	const child_ctx = ctx.slice();
	child_ctx[19] = list[i][0];
	child_ctx[20] = list[i][1];
	child_ctx[22] = i;
	return child_ctx;
}

// (52:1) <BlockTitle {show_label} {info}>
function create_default_slot_1(ctx) {
	let t;

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

// (55:2) {#each choices as [display_value, internal_value], i (i)}
function create_each_block(key_1, ctx) {
	let first;
	let baseradio;
	let updating_selected;
	let current;

	function baseradio_selected_binding(value) {
		/*baseradio_selected_binding*/ ctx[16](value);
	}

	function input_handler() {
		return /*input_handler*/ ctx[17](/*internal_value*/ ctx[20], /*i*/ ctx[22]);
	}

	let baseradio_props = {
		display_value: /*display_value*/ ctx[19],
		internal_value: /*internal_value*/ ctx[20],
		disabled: /*disabled*/ ctx[13]
	};

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

	baseradio = new BaseRadio({ props: baseradio_props });
	binding_callbacks.push(() => bind(baseradio, 'selected', baseradio_selected_binding));
	baseradio.$on("input", input_handler);

	return {
		key: key_1,
		first: null,
		c() {
			first = empty();
			create_component(baseradio.$$.fragment);
			this.first = first;
		},
		m(target, anchor) {
			insert(target, first, anchor);
			mount_component(baseradio, target, anchor);
			current = true;
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;
			const baseradio_changes = {};
			if (dirty & /*choices*/ 128) baseradio_changes.display_value = /*display_value*/ ctx[19];
			if (dirty & /*choices*/ 128) baseradio_changes.internal_value = /*internal_value*/ ctx[20];
			if (dirty & /*disabled*/ 8192) baseradio_changes.disabled = /*disabled*/ ctx[13];

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

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

			destroy_component(baseradio, detaching);
		}
	};
}

// (37:0) <Block  {visible}  type="fieldset"  {elem_id}  {elem_classes}  {container}  {scale}  {min_width} >
function create_default_slot(ctx) {
	let statustracker;
	let t0;
	let blocktitle;
	let t1;
	let div;
	let each_blocks = [];
	let each_1_lookup = new Map();
	let current;

	const statustracker_spread_levels = [
		{ autoscroll: /*gradio*/ ctx[1].autoscroll },
		{ i18n: /*gradio*/ ctx[1].i18n },
		/*loading_status*/ ctx[12]
	];

	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 Static({ props: statustracker_props });

	blocktitle = new BlockTitle({
			props: {
				show_label: /*show_label*/ ctx[8],
				info: /*info*/ ctx[3],
				$$slots: { default: [create_default_slot_1] },
				$$scope: { ctx }
			}
		});

	let each_value = ensure_array_like(/*choices*/ ctx[7]);
	const get_key = ctx => /*i*/ ctx[22];

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

	return {
		c() {
			create_component(statustracker.$$.fragment);
			t0 = space();
			create_component(blocktitle.$$.fragment);
			t1 = space();
			div = element("div");

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

			attr(div, "class", "wrap svelte-1kzox3m");
		},
		m(target, anchor) {
			mount_component(statustracker, target, anchor);
			insert(target, t0, anchor);
			mount_component(blocktitle, target, anchor);
			insert(target, t1, 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) {
			const statustracker_changes = (dirty & /*gradio, loading_status*/ 4098)
			? get_spread_update(statustracker_spread_levels, [
					dirty & /*gradio*/ 2 && { autoscroll: /*gradio*/ ctx[1].autoscroll },
					dirty & /*gradio*/ 2 && { i18n: /*gradio*/ ctx[1].i18n },
					dirty & /*loading_status*/ 4096 && get_spread_object(/*loading_status*/ ctx[12])
				])
			: {};

			statustracker.$set(statustracker_changes);
			const blocktitle_changes = {};
			if (dirty & /*show_label*/ 256) blocktitle_changes.show_label = /*show_label*/ ctx[8];
			if (dirty & /*info*/ 8) blocktitle_changes.info = /*info*/ ctx[3];

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

			blocktitle.$set(blocktitle_changes);

			if (dirty & /*choices, disabled, value, gradio*/ 8323) {
				each_value = ensure_array_like(/*choices*/ ctx[7]);
				group_outros();
				each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, div, outro_and_destroy_block, create_each_block, null, get_each_context);
				check_outros();
			}
		},
		i(local) {
			if (current) return;
			transition_in(statustracker.$$.fragment, local);
			transition_in(blocktitle.$$.fragment, local);

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

			current = true;
		},
		o(local) {
			transition_out(statustracker.$$.fragment, local);
			transition_out(blocktitle.$$.fragment, local);

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

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

			destroy_component(statustracker, detaching);
			destroy_component(blocktitle, detaching);

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

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

	block = new Block({
			props: {
				visible: /*visible*/ ctx[6],
				type: "fieldset",
				elem_id: /*elem_id*/ ctx[4],
				elem_classes: /*elem_classes*/ ctx[5],
				container: /*container*/ ctx[9],
				scale: /*scale*/ ctx[10],
				min_width: /*min_width*/ ctx[11],
				$$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*/ 64) block_changes.visible = /*visible*/ ctx[6];
			if (dirty & /*elem_id*/ 16) block_changes.elem_id = /*elem_id*/ ctx[4];
			if (dirty & /*elem_classes*/ 32) block_changes.elem_classes = /*elem_classes*/ ctx[5];
			if (dirty & /*container*/ 512) block_changes.container = /*container*/ ctx[9];
			if (dirty & /*scale*/ 1024) block_changes.scale = /*scale*/ ctx[10];
			if (dirty & /*min_width*/ 2048) block_changes.min_width = /*min_width*/ ctx[11];

			if (dirty & /*$$scope, choices, disabled, value, gradio, show_label, info, label, loading_status*/ 8401295) {
				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 disabled;
	let { gradio } = $$props;
	let { label = gradio.i18n("radio.radio") } = $$props;
	let { info = undefined } = $$props;
	let { elem_id = "" } = $$props;
	let { elem_classes = [] } = $$props;
	let { visible = true } = $$props;
	let { value = null } = $$props;
	let { value_is_output = false } = $$props;
	let { choices = [] } = $$props;
	let { show_label = true } = $$props;
	let { container = false } = $$props;
	let { scale = null } = $$props;
	let { min_width = undefined } = $$props;
	let { loading_status } = $$props;
	let { interactive = true } = $$props;

	function handle_change() {
		gradio.dispatch("change");

		if (!value_is_output) {
			gradio.dispatch("input");
		}
	}

	afterUpdate(() => {
		$$invalidate(14, value_is_output = false);
	});

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

	const input_handler = (internal_value, i) => gradio.dispatch("select", { value: internal_value, index: i });

	$$self.$$set = $$props => {
		if ('gradio' in $$props) $$invalidate(1, gradio = $$props.gradio);
		if ('label' in $$props) $$invalidate(2, label = $$props.label);
		if ('info' in $$props) $$invalidate(3, info = $$props.info);
		if ('elem_id' in $$props) $$invalidate(4, elem_id = $$props.elem_id);
		if ('elem_classes' in $$props) $$invalidate(5, elem_classes = $$props.elem_classes);
		if ('visible' in $$props) $$invalidate(6, visible = $$props.visible);
		if ('value' in $$props) $$invalidate(0, value = $$props.value);
		if ('value_is_output' in $$props) $$invalidate(14, value_is_output = $$props.value_is_output);
		if ('choices' in $$props) $$invalidate(7, choices = $$props.choices);
		if ('show_label' in $$props) $$invalidate(8, show_label = $$props.show_label);
		if ('container' in $$props) $$invalidate(9, container = $$props.container);
		if ('scale' in $$props) $$invalidate(10, scale = $$props.scale);
		if ('min_width' in $$props) $$invalidate(11, min_width = $$props.min_width);
		if ('loading_status' in $$props) $$invalidate(12, loading_status = $$props.loading_status);
		if ('interactive' in $$props) $$invalidate(15, interactive = $$props.interactive);
	};

	$$self.$$.update = () => {
		if ($$self.$$.dirty & /*value*/ 1) {
			(handle_change());
		}

		if ($$self.$$.dirty & /*interactive*/ 32768) {
			$$invalidate(13, disabled = !interactive);
		}
	};

	return [
		value,
		gradio,
		label,
		info,
		elem_id,
		elem_classes,
		visible,
		choices,
		show_label,
		container,
		scale,
		min_width,
		loading_status,
		disabled,
		value_is_output,
		interactive,
		baseradio_selected_binding,
		input_handler
	];
}

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

		init(this, options, instance, create_fragment, safe_not_equal, {
			gradio: 1,
			label: 2,
			info: 3,
			elem_id: 4,
			elem_classes: 5,
			visible: 6,
			value: 0,
			value_is_output: 14,
			choices: 7,
			show_label: 8,
			container: 9,
			scale: 10,
			min_width: 11,
			loading_status: 12,
			interactive: 15
		});
	}
}

export { BaseRadio, Index as default };
//# sourceMappingURL=Index-d96be787.js.map
