import { S as SvelteComponent, i as init, s as safe_not_equal, f as element, m as space, h as text, b as attr, t as toggle_class, c as insert, d as append, l as listen, j as set_data, e as detach, q as create_component, u as mount_component, a7 as update_keyed_each, ak as destroy_block, v as transition_in, w as transition_out, x as destroy_component, A as createEventDispatcher, L as assign, M as StatusTracker, D as binding_callbacks, J as bind, N as get_spread_update, O as get_spread_object, G as add_flush_callback, F as bubble } from './index.20bd6624.js';
import { B as Block } from './Block.a79664d5.js';
import { g as get_styles } from './styles.db46e346.js';
import { B as BlockTitle } from './BlockTitle.4f6dc51f.js';

/* Users/aliabid/projects/gradio/ui/packages/form/src/Radio.svelte generated by Svelte v3.49.0 */

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

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

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

// (23:1) {#each choices as choice, i (i)}
function create_each_block(key_1, ctx) {
	let label_1;
	let input;
	let input_name_value;
	let input_class_value;
	let input_value_value;
	let t0;
	let span;
	let t1_value = /*choice*/ ctx[13] + "";
	let t1;
	let label_1_class_value;
	let mounted;
	let dispose;

	return {
		key: key_1,
		first: null,
		c() {
			label_1 = element("label");
			input = element("input");
			t0 = space();
			span = element("span");
			t1 = text(t1_value);
			input.disabled = /*disabled*/ ctx[2];
			attr(input, "type", "radio");
			attr(input, "name", input_name_value = "radio-" + /*elem_id*/ ctx[5]);
			attr(input, "class", input_class_value = "gr-check-radio gr-radio " + /*border*/ ctx[7] + " " + /*rounded*/ ctx[8]);
			input.__value = input_value_value = /*choice*/ ctx[13];
			input.value = input.__value;
			/*$$binding_groups*/ ctx[11][0].push(input);
			attr(span, "class", "ml-2");
			attr(label_1, "class", label_1_class_value = "gr-input-label flex items-center text-gray-700 text-sm space-x-2 border py-1.5 px-3 rounded-lg cursor-pointer bg-white shadow-sm checked:shadow-inner " + /*item_container*/ ctx[6]);
			toggle_class(label_1, "!cursor-not-allowed", /*disabled*/ ctx[2]);
			this.first = label_1;
		},
		m(target, anchor) {
			insert(target, label_1, anchor);
			append(label_1, input);
			input.checked = input.__value === /*value*/ ctx[0];
			append(label_1, t0);
			append(label_1, span);
			append(span, t1);

			if (!mounted) {
				dispose = listen(input, "change", /*input_change_handler*/ ctx[10]);
				mounted = true;
			}
		},
		p(new_ctx, dirty) {
			ctx = new_ctx;

			if (dirty & /*disabled*/ 4) {
				input.disabled = /*disabled*/ ctx[2];
			}

			if (dirty & /*elem_id*/ 32 && input_name_value !== (input_name_value = "radio-" + /*elem_id*/ ctx[5])) {
				attr(input, "name", input_name_value);
			}

			if (dirty & /*border, rounded*/ 384 && input_class_value !== (input_class_value = "gr-check-radio gr-radio " + /*border*/ ctx[7] + " " + /*rounded*/ ctx[8])) {
				attr(input, "class", input_class_value);
			}

			if (dirty & /*choices*/ 2 && input_value_value !== (input_value_value = /*choice*/ ctx[13])) {
				input.__value = input_value_value;
				input.value = input.__value;
			}

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

			if (dirty & /*choices*/ 2 && t1_value !== (t1_value = /*choice*/ ctx[13] + "")) set_data(t1, t1_value);

			if (dirty & /*item_container*/ 64 && label_1_class_value !== (label_1_class_value = "gr-input-label flex items-center text-gray-700 text-sm space-x-2 border py-1.5 px-3 rounded-lg cursor-pointer bg-white shadow-sm checked:shadow-inner " + /*item_container*/ ctx[6])) {
				attr(label_1, "class", label_1_class_value);
			}

			if (dirty & /*item_container, disabled*/ 68) {
				toggle_class(label_1, "!cursor-not-allowed", /*disabled*/ ctx[2]);
			}
		},
		d(detaching) {
			if (detaching) detach(label_1);
			/*$$binding_groups*/ ctx[11][0].splice(/*$$binding_groups*/ ctx[11][0].indexOf(input), 1);
			mounted = false;
			dispose();
		}
	};
}

function create_fragment$1(ctx) {
	let blocktitle;
	let t;
	let div;
	let each_blocks = [];
	let each_1_lookup = new Map();
	let current;

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

	let each_value = /*choices*/ ctx[1];
	const get_key = ctx => /*i*/ ctx[15];

	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(blocktitle.$$.fragment);
			t = space();
			div = element("div");

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

			attr(div, "class", "flex flex-wrap gap-2");
		},
		m(target, anchor) {
			mount_component(blocktitle, target, anchor);
			insert(target, t, anchor);
			insert(target, div, anchor);

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

			current = true;
		},
		p(ctx, [dirty]) {
			const blocktitle_changes = {};
			if (dirty & /*show_label*/ 16) blocktitle_changes.show_label = /*show_label*/ ctx[4];

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

			blocktitle.$set(blocktitle_changes);

			if (dirty & /*item_container, disabled, choices, elem_id, border, rounded, value*/ 487) {
				each_value = /*choices*/ ctx[1];
				each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value, each_1_lookup, div, destroy_block, create_each_block, null, get_each_context);
			}
		},
		i(local) {
			if (current) return;
			transition_in(blocktitle.$$.fragment, local);
			current = true;
		},
		o(local) {
			transition_out(blocktitle.$$.fragment, local);
			current = false;
		},
		d(detaching) {
			destroy_component(blocktitle, detaching);
			if (detaching) detach(t);
			if (detaching) detach(div);

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

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

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

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

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

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

	return [
		value,
		choices,
		disabled,
		label,
		show_label,
		elem_id,
		item_container,
		border,
		rounded,
		style,
		input_change_handler,
		$$binding_groups
	];
}

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

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

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

function create_default_slot(ctx) {
	let statustracker;
	let t;
	let radio;
	let updating_value;
	let current;
	const statustracker_spread_levels = [/*loading_status*/ ctx[9]];
	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 radio_value_binding(value) {
		/*radio_value_binding*/ ctx[10](value);
	}

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

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

	radio = new Radio({ props: radio_props });
	binding_callbacks.push(() => bind(radio, 'value', radio_value_binding));
	radio.$on("change", /*change_handler*/ ctx[11]);

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

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

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

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

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

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

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

	function radio_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 ('mode' in $$props) $$invalidate(5, mode = $$props.mode);
		if ('form_position' in $$props) $$invalidate(6, form_position = $$props.form_position);
		if ('show_label' in $$props) $$invalidate(7, show_label = $$props.show_label);
		if ('style' in $$props) $$invalidate(8, style = $$props.style);
		if ('loading_status' in $$props) $$invalidate(9, loading_status = $$props.loading_status);
	};

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

class Radio_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,
			mode: 5,
			form_position: 6,
			show_label: 7,
			style: 8,
			loading_status: 9
		});
	}
}

var Radio_1$1 = Radio_1;

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

export { Radio_1$1 as Component, modes };
