/*
 * Event Filters (Core Features plugin: matchbox/event-filters)
 *
 * The plugin renders a GET form inside an events Query Loop; this file is
 * the Discover O'Fallon presentation:
 *
 *   __bar     one bordered row: keyword search, location, the Find Activities
 *             button and the List View / Photo View switch. Stacks on phones.
 *   __chips   pill-shaped menus for category, day and time; a chosen one
 *             (is-active) is solid Navy. Clear filters follows when any is set.
 *
 * Enqueued only on pages that use the block (see enqueue_block_styles()).
 *
 * @package Kindling
 * @since Kindling 4.1.0
 */

.wp-block-matchbox-event-filters {
	--event-filters-border: var(--wp--custom--color--separator);
	--event-filters-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='m1 1 4 4 4-4' fill='none' stroke='%23022D58' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--30);

	:is(input, select, button) {
		font-family: inherit;
	}

	:is(input, select):focus-visible {
		outline: 2px solid var(--wp--custom--color--focus, currentColor);
		outline-offset: 2px;
	}

	.wp-block-matchbox-event-filters__error {
		margin: 0;
		color: var(--wp--custom--color--error);
		font-weight: 600;

		&[hidden] {
			display: none;
		}
	}
}

/* Bar --------------------------------------------------------------------- */

.wp-block-matchbox-event-filters__bar {
	display: flex;
	align-items: center;
	gap: var(--wp--custom--spacing--8);
	padding: var(--wp--custom--spacing--8);
	background-color: var(--wp--custom--color--surface--background);
	border: 1px solid var(--wp--custom--color--surface--border);
}

.wp-block-matchbox-event-filters__field {
	position: relative;
	display: flex;
	flex: 1 1 0;
	align-items: center;
	min-width: 0;
	color: var(--wp--custom--color--text--heading);

	/* A rule between the search and location fields. */
	& + & {
		border-inline-start: 1px solid var(--event-filters-border);
	}
}

.wp-block-matchbox-event-filters__icon {
	position: absolute;
	inset-inline-start: var(--wp--custom--spacing--12);
	flex: none;
	pointer-events: none;
}

.wp-block-matchbox-event-filters__input {
	width: 100%;
	min-height: 2.75rem;
	padding: var(--wp--custom--spacing--8) var(--wp--custom--spacing--12) var(--wp--custom--spacing--8) calc(var(--wp--custom--spacing--12) * 2 + 1rem);
	color: var(--wp--custom--color--text--heading);
	background: transparent;
	border: 0;
	border-radius: 0;
	font-size: var(--wp--preset--font-size--body-small);
	line-height: 1.4;

	&::placeholder {
		color: var(--wp--custom--color--text--body);
		opacity: 1;
	}

	&::-webkit-search-cancel-button {
		cursor: pointer;
	}
}

.wp-block-matchbox-event-filters__submit.wp-element-button {
	flex: none;
	padding: var(--wp--custom--spacing--12) var(--wp--custom--spacing--20);
	font-size: var(--wp--preset--font-size--body-small);
	cursor: pointer;
}

.wp-block-matchbox-event-filters__view select {
	field-sizing: content;
	min-height: 2.75rem;
	padding: var(--wp--custom--spacing--8) calc(var(--wp--custom--spacing--12) * 2 + 0.625rem) var(--wp--custom--spacing--8) var(--wp--custom--spacing--12);
	color: var(--wp--custom--color--text--heading);
	background: var(--event-filters-chevron) no-repeat right var(--wp--custom--spacing--12) center;
	border: 0;
	border-radius: 0;
	font-size: var(--wp--preset--font-size--body-small);
	font-weight: 600;
	appearance: none;
	cursor: pointer;
}

/* Phones: each field on its own row, the button full width. */
@media (max-width: 781px) {
	.wp-block-matchbox-event-filters__bar {
		flex-wrap: wrap;
	}

	.wp-block-matchbox-event-filters__field {
		flex-basis: 100%;

		& + & {
			border-inline-start: 0;
			border-block-start: 1px solid var(--event-filters-border);
		}
	}

	.wp-block-matchbox-event-filters__submit.wp-element-button {
		flex: 1 1 auto;
		justify-content: center;
	}
}

/* Chips ------------------------------------------------------------------- */

.wp-block-matchbox-event-filters__chips {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--wp--custom--spacing--8);
}

.wp-block-matchbox-event-filters__chip select {
	/* As wide as the chosen option, where supported, rather than the longest. */
	field-sizing: content;
	min-height: 2.5rem;
	padding: var(--wp--custom--spacing--8) var(--wp--custom--spacing--16);
	color: var(--wp--custom--color--text--heading);
	background-color: transparent;
	border: 1px solid var(--wp--custom--color--surface--border);
	border-radius: 999px;
	font-size: var(--wp--preset--font-size--body-small);
	font-weight: 600;
	line-height: 1.3;
	appearance: none;
	cursor: pointer;
	transition:
		background-color 0.2s ease-out,
		border-color 0.2s ease-out,
		color 0.2s ease-out;

	&:hover {
		border-color: var(--wp--custom--color--text--heading);
	}

	@media (prefers-reduced-motion: reduce) {
		transition: none;
	}
}

/* A chosen filter. Options keep the menu's own colors. */
.wp-block-matchbox-event-filters__chip.is-active select {
	color: var(--wp--preset--color--theme-01);
	background-color: var(--wp--custom--color--text--heading);
	border-color: var(--wp--custom--color--text--heading);

	option {
		color: initial;
		background-color: initial;
	}
}

.wp-block-matchbox-event-filters__clear {
	margin-inline-start: var(--wp--custom--spacing--8);
	font-size: var(--wp--preset--font-size--body-small);
	font-weight: 600;

	&[hidden] {
		display: none;
	}
}

/* Editor preview: the controls are placeholders. */
.editor-styles-wrapper .wp-block-matchbox-event-filters :is(input, select):disabled {
	opacity: 1;
	cursor: default;
}
