<template>
	<view class="demo-block">
		<text class="demo-block__title-text ultra">DateTimePicker 时间选择器</text>
		<text class="demo-block__desc-text">用于选择时间，支持日期、时分等时间维度。</text>
		<view class="demo-block__body">
			<view class="demo-block card">
				<text class="demo-block__title-text">基础用法</text>
				<view class="demo-block__body">
					<l-date-time-picker></l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">年月</text>
				<view class="demo-block__body">
					<l-date-time-picker confirm-btn="确认" cancel-btn="取消" title="选择日期" :mode="1|2"></l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">时分秒{{time}}</text>
				<view class="demo-block__body">
					<l-date-time-picker v-model="time" confirm-btn="确认" cancel-btn="取消" title="选择时间" :mode="8|16|32"></l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">完整的时间</text>
				<view class="demo-block__body">
					<l-date-time-picker confirm-btn="确认" cancel-btn="取消" title="选择日期" mode="1|2|4|8|16"></l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">自定义范围{{value}}</text>
				<view class="demo-block__body">
					<l-date-time-picker 
						title="选择日期"
						v-model="value"
						:mode="1|2|4"  
						confirm-btn="确认"
						cancel-btn="取消"
						start="2020-6-30"
						end="2025-6-30"
						format="YYYY-MM-DD"
						@confirm="onConfirm"
						@change="onChange">
					</l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">自定义label</text>
				<view class="demo-block__body">
					<l-date-time-picker 
						title="选择日期"
						:mode="1|2|4"  
						confirm-btn="确认"
						cancel-btn="取消"
						start="2020-6-30"
						end="2025-6-30"
						format="YYYY-MM-DD"
						:renderLabel="renderLabel"
						@confirm="onConfirm"
						@change="onChange">
					</l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">过滤项</text>
				<view class="demo-block__body">
					<l-date-time-picker 
						title="选择日期"
						:mode="1|2|4"  
						confirm-btn="确认"
						cancel-btn="取消"
						start="2020-6-30"
						end="2025-6-30"
						format="YYYY-MM-DD"
						:customFilter="filter"
						@confirm="onConfirm"
						@change="onChange">
					</l-date-time-picker>
				</view>
			</view>
			<view class="demo-block card">
				<text class="demo-block__title-text">配合弹窗</text>
				<view class="demo-block__body">
					<button type="primary" @click="showTime = true">打开</button>
					<l-popup position="bottom" v-model="showTime">
						<l-date-time-picker v-model="value" cancel-btn="取消" confirm-btn="确认" :confirmStyle="confirmStyle" :mode="7" :end="endTime" :show-unit="false"></l-date-time-picker>
					</l-popup>
				</view>
			</view>
			
			
		</view>
	</view>
</template>

<script lang="uts" setup>
	import { DateTimePickerColumnItem, DateTimePickerColumn, TimeModeValues } from '@/uni_modules/lime-date-time-picker'
	
	
	const confirmStyle = 'padding: 2px 40px;text-align:center;'
	const endTime = new Date().getTime();
	
	const showTime = ref<boolean>(false);
	
	
	const time = ref('')
	const value = ref('2024-05-02')

	
	const onConfirm = (value: string) => {
		console.log('onConfirm', value)
	}
	const onChange = (value: string) => {
		console.log('onChange', value)
	}
	const renderLabel = (type: TimeModeValues, value: string): string => {
		if(type == 'year') {
			return `${value}年`
		}
		return value
	}
	const filter = (type: TimeModeValues, columns: DateTimePickerColumn):DateTimePickerColumn => {
		if (type == 'month') {
		    return columns.filter((option) => parseInt(option.value) % 6 == 0);
		}
		return columns
	}
</script>

<style lang="scss">
	$card-bg-color: var(--doc-card-bg-color, white);
	// $page-bg-color: var(--doc-page-bg-color, #f5f5f5);
	$title-color: var(--doc-title-color, #000000E6);
	$summary-color: var(--doc-summary-color, #00000099);
	.btn {
		margin-bottom: 20rpx;
		margin-right: 20rpx;
		align-self: center;
	}

	.demo-block {
		margin: 32px 0 0;

		// overflow: visible;
		&.card {
			// background-color: white;
			padding: 30rpx;
			margin-bottom: 20rpx;
		}

		&__title {
			margin: 0;
			margin-top: 8px;

			&-text {
				color: $summary-color;
				font-weight: 400;
				font-size: 14px;
				line-height: 16px;
				display: flex;
				margin-left: 5px;

				&.large {
					color: $title-color;
					font-size: 18px;
					font-weight: 700;
					line-height: 26px;
					margin-left: 20px;
				}

				&.ultra {
					color: $title-color;
					font-size: 24px;
					font-weight: 700;
					line-height: 32px;
					padding-left: 15px ;
				}
			}
		}

		&__desc-text {
			color: $summary-color;
			margin: 8px 16px 0 0;
			font-size: 14px;
			line-height: 22px;
			margin-left: 20px;
		}

		&__body {
			margin: 16px 0;
			overflow: visible;

			.demo-block {
				// margin-top: 0px;
				margin: 0;
				overflow: visible;
			}
		}
	}
</style>