@use 'sass:math';
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/global.variables' as globalVariables;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/spacing.variables' as spacing;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/colours.variables' as colours;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/breakpoints.variables' as breakpoints;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/fonts.variables' as fonts;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/placeholder/focus.placeholders' as placeholders;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/font-weights.variables' as fontWeights;
@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/functions/global.functions' as globalFunctions;

$ontario-button-bg-primary: colours.$ontario-colour-link;
$ontario-button-bg-primary--hover: colours.$ontario-colour-link--hover;
$ontario-button-bg-primary--active: colours.$ontario-colour-link--active;
$ontario-button-bg-secondary: colours.$ontario-colour-white;
$ontario-focus-transition: box-shadow 0.1s ease-in-out;

.ontario-button {
	border: none;
	border-radius: globalVariables.$global-radius;
	box-sizing: border-box;
	box-shadow: none;
	display: inline-block;
	font-size: 1.125rem;
	font-family: fonts.$ontario-font-open-sans;
	font-weight: fontWeights.$ontario-font-weights-semi-bold;
	line-height: calc(14 / 9);
	margin: spacing.$spacing-0 calc(#{spacing.$spacing-4} + #{spacing.$spacing-3}) spacing.$spacing-5 spacing.$spacing-0;
	min-width: 10rem;
	padding: math.div(spacing.$spacing-4 + spacing.$spacing-1, 2) spacing.$spacing-5;
	text-align: center;
	text-decoration: none;
	cursor: pointer;

	&:focus,
	&:active {
		@extend %ontario-focus;
	}

	@media screen and (max-width: breakpoints.$small-breakpoint) {
		margin-right: spacing.$spacing-0;
		display: block;
		width: globalVariables.$full-width;
	}

	.ontario-icon {
		margin-right: spacing.$spacing-1;
	}
}

.ontario-button--primary {
	background-color: $ontario-button-bg-primary;
	color: colours.$ontario-colour-white;

	&:hover {
		background-color: $ontario-button-bg-primary--hover;
		color: colours.$ontario-colour-white;
	}

	&:focus {
		background-color: $ontario-button-bg-primary--hover;
		color: colours.$ontario-colour-white;
		transition: background-color 0.2s ease-out, $ontario-focus-transition;
	}

	&:active {
		background-color: $ontario-button-bg-primary--active;
		color: colours.$ontario-colour-white;
		transition: background-color 0s, $ontario-focus-transition;
	}

	&:visited {
		color: colours.$ontario-colour-white;
	}
}

.ontario-button--secondary {
	background-color: $ontario-button-bg-secondary;
	border: globalFunctions.px-to-rem(2) solid colours.$ontario-colour-link;
	color: colours.$ontario-colour-link;
	padding-top: spacing.$spacing-2;
	padding-bottom: spacing.$spacing-2;

	&:hover {
		background-color: colours.$ontario-colour-button-secondary--hover;
		border-color: colours.$ontario-colour-link--hover;
		color: colours.$ontario-colour-link--hover;
	}

	&:focus {
		background-color: colours.$ontario-colour-button-secondary--hover;
		border-color: colours.$ontario-colour-link--hover;
		color: colours.$ontario-colour-link--hover;
		transition: background-color 0.2s ease-out, $ontario-focus-transition;
	}

	&:active {
		background-color: colours.$ontario-colour-button-secondary--active;
		border-color: colours.$ontario-colour-link--active;
		color: colours.$ontario-colour-link--active;
		transition: background-color 0s, $ontario-focus-transition;
	}

	&:visited {
		color: colours.$ontario-colour-link;
	}
}

.ontario-button--tertiary {
	background-color: transparent;
	color: colours.$ontario-colour-link;
	text-decoration: underline;

	&:hover {
		background-color: colours.$ontario-colour-button-tertiary--hover;
		color: $ontario-button-bg-primary--hover;
		text-decoration: underline;
	}

	&:focus {
		background-color: colours.$ontario-colour-button-tertiary--hover;
		color: colours.$ontario-colour-link--hover;
		text-decoration: underline;
		transition: background-color 0.2s ease-out, $ontario-focus-transition;
	}

	&:active {
		background-color: colours.$ontario-colour-button-tertiary--active;
		color: colours.$ontario-colour-link--active;
		text-decoration: underline;
		transition: background-color 0s, $ontario-focus-transition;
	}

	&:visited {
		color: colours.$ontario-colour-link;
	}
}
