<template>
	<view class="address-item">
		<view class="address-content" @click="$emit('click', address)">
			<!-- 地址信息 -->
			<view class="address-info">
				<view class="name-phone">
					<text class="name">{{ address.contactName }}</text>
					<text class="phone">{{ address.contactPhone }}</text>
				</view>
				<view class="address-detail">{{ address.provinceName }}{{ address.cityName }}{{ address.countyName }}{{ address.detailedAddress }}</view>
			</view>

			<!-- 操作区域 -->
			<view class="actions" v-if="isSowAction">
				<!-- 设为默认 -->
				<view class="set-default" @click.stop="$emit('set-default')">
					<view class="default-checkbox" :class="{ 'checked': address.defaultFlag == 1 }">
						<text v-if="address.defaultFlag == 1" class="checkmark">✓</text>
					</view>
					<text class="default-text" :class="{ 'checked': address.defaultFlag == 1 }">设为默认</text>
				</view>

				<!-- 删除和编辑按钮 -->
				<view class="edit-delete">
					<view class="action-text"  @click.stop="$emit('delete')">
						<image src="/static/img/address-delete.png" />
						<text class=" delete">删除</text>
					</view>
					<view class="action-text" @click.stop="$emit('edit')">
						<image src="/static/img/address-edit.png" />
						<text class=" edit" >编辑</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	defineProps({
		address: {
			type: Object,
			required: true
		},
		isDefault: {
			type: Boolean,
			default: false
		},
		isSowAction: {
			type: Boolean,
			default: true
		}
	})

	defineEmits(['set-default', 'edit', 'delete','click'])
</script>

<style scoped lang="less">
	.address-item {
		background-color: #fff;
		border-radius: 16rpx;
		padding: 16rpx;
		margin-bottom: 20rpx;
	}

	.address-content {
		display: flex;
		flex-direction: column;
	}

	.address-info {
		display: flex;
		flex-direction: column;
		margin-bottom: 16rpx;
		
		.name-phone {
			display: flex;
			align-items: center;
			margin-bottom: 16rpx;
		}
		
		.name {
			height: 48rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #333;
			margin-right: 30rpx;
			line-height: 48rpx;
		}
		
		.phone {
			height: 48rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #333;
			line-height: 48rpx;
		}
		
		.address-detail {
			font-size: 28rpx;
			color: #666;
			line-height: 44rpx;
		}
		
	}

	.actions {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.set-default {
		display: flex;
		align-items: center;
	}

	.default-checkbox {
		width: 36rpx;
		height: 36rpx;
		border: 2rpx solid #ccc;
		border-radius: 50%;
		margin-right: 16rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.default-checkbox.checked {
		background-color: #1B64F0;
		border-color: #1B64F0;
	}

	.default-text.checked {
		color: #1B64F0;
	}


	.checkmark {
		color: #fff;
		font-size: 24rpx;
	}

	.default-text {
		font-size: 28rpx;
		color: #666;
	}

	.edit-delete {
		display: flex;
		align-items: center;
	}

	.action-text {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		padding: 6rpx 20rpx;

		image {
			width: 32rpx;
			height: 32rpx;
			margin-right: 8rpx;
		}
	}

	.delete {
		color: #ff3b30;
	}

	.edit {
		color: #007aff;
	}

	.action-separator {
		color: #e0e0e0;
		font-size: 24rpx;
	}
</style>

