<template>
  <ion-page>
    <Header 
      title="设置"
      :onBack="handleBackPress"
    />
    
    <ion-content class="settings-content">
      <div class="settings-section">
        <div class="section-header">
          账户
        </div>
        <div button @click="handleLogin" class="settings-item settings-item-clickable">
          <div class="item-text-primary">登录云同步</div>
          <div class="item-text-tertiary">未登录</div>
        </div>
      </div>
      
      <div class="settings-section">
        <div class="section-header">
          偏好设置
        </div>
        <div class="settings-item settings-item-border">
          <div class="item-text-primary">云同步</div>
          <ion-toggle 
            slot="end" 
            :checked="settings.cloudSync" 
            @ion-change="toggleCloudSync"
          ></ion-toggle>
        </div>
        <div class="settings-item">
          <div class="item-text-primary">深色模式</div>
          <ion-toggle 
            slot="end" 
            :checked="settings.darkMode" 
            @ion-change="toggleDarkMode"
          ></ion-toggle>
        </div>
      </div>
      
      <div class="settings-section">
        <div class="section-header">
          数据管理
        </div>
        <div button @click="handleBackup" class="settings-item settings-item-clickable settings-item-border">
          <img :src="'/assets/icons/drawable-xxhdpi/btn_save_pic.png'" class="item-icon" />
          <div class="item-text-primary">备份便签</div>
        </div>
        <div button @click="handleRestore" class="settings-item settings-item-clickable settings-item-border">
          <img :src="'/assets/icons/drawable-xxhdpi/btn_restore.png'" class="item-icon" />
          <div class="item-text-primary">恢复便签</div>
        </div>
        <div button @click="handleExport" class="settings-item settings-item-clickable settings-item-border">
          <img :src="'/assets/icons/drawable-xxhdpi/btn_share.png'" class="item-icon" />
          <div class="item-text-primary">导出便签</div>
        </div>
        <div button @click="handleImport" class="settings-item settings-item-clickable">
          <img :src="'/assets/icons/drawable-xxhdpi/btn_load_error.png'" class="item-icon" />
          <div class="item-text-primary">导入便签</div>
        </div>
      </div>
      
      <div class="settings-section">
        <div class="section-header">
          关于
        </div>
        <div class="settings-item settings-item-border">
          <div class="item-text-primary">版本</div>
          <div class="item-text-tertiary">1.0.0</div>
        </div>
        <div button @click="handlePrivacyPolicy" class="settings-item settings-item-clickable settings-item-border">
          <div class="item-text-primary">隐私政策</div>
        </div>
        <div button @click="handleTermsOfService" class="settings-item settings-item-clickable">
          <div class="item-text-primary">服务条款</div>
        </div>
      </div>
    </ion-content>
  </ion-page>
</template>

<script setup>
import { computed, onMounted } from 'vue';
import { useAppStore } from '../stores/useAppStore';
import Header from '../components/Header.vue';

const store = useAppStore();

// 加载初始数据
onMounted(() => {
  store.loadData();
});

const toggleCloudSync = () => {
  store.toggleCloudSync();
};

const toggleDarkMode = () => {
  store.toggleDarkMode();
};

const handleLogin = () => {
  // In a full implementation, this would open a login screen
  console.log('Login to cloud');
};

const handlePrivacyPolicy = () => {
  // In a full implementation, this would show the privacy policy
  console.log('Privacy policy');
};

const handleTermsOfService = () => {
  // In a full implementation, this would show the terms of service
  console.log('Terms of service');
};

const handleBackup = () => {
  // In a full implementation, this would backup notes
  console.log('Backup notes');
};

const handleRestore = () => {
  // In a full implementation, this would restore notes
  console.log('Restore notes');
};

const handleExport = () => {
  // In a full implementation, this would export notes
  console.log('Export notes');
};

const handleImport = () => {
  // In a full implementation, this would import notes
  console.log('Import notes');
};

const handleBackPress = () => {
  window.history.back();
};

const settings = computed(() => store.settings);
</script>

<style scoped>
.settings-content {
  background-color: var(--background);
}

.settings-section {
  margin-bottom: 12px;
  background-color: var(--background-card);
}

.section-header {
  background-color: var(--background-secondary);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 10px 16px;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--background-card);
  padding: 14px 16px;
}

.settings-item-border {
  border-bottom: 1px solid var(--border);
}

.settings-item-clickable {
  cursor: pointer;
}

.item-text-primary {
  font-size: 16px;
  color: var(--text-primary);
}

.item-text-tertiary {
  font-size: 15px;
  color: var(--text-tertiary);
}

.item-icon {
  width: 20px;
  height: 20px;
  color: var(--text-primary);
  margin-right: 12px;
}

.settings-item-clickable .item-text-primary {
  flex: 1;
}

.settings-item-clickable {
  display: flex;
  align-items: center;
}
</style>