import{c as e}from"./content-8Jpot79T.js";import{env as t}from"cloudflare:workers";function n(){return t.DB}async function r(){let t=n();return await t.batch([t.prepare(`CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY AUTOINCREMENT, slug TEXT NOT NULL UNIQUE, title TEXT NOT NULL, excerpt TEXT NOT NULL, content TEXT NOT NULL, image TEXT, tag TEXT NOT NULL DEFAULT 'خبر', date TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'published', created_at TEXT NOT NULL)`),t.prepare(`CREATE TABLE IF NOT EXISTS requests (id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT NOT NULL, name TEXT NOT NULL, company TEXT NOT NULL, phone TEXT NOT NULL, email TEXT NOT NULL, size TEXT, message TEXT, status TEXT NOT NULL DEFAULT 'new', created_at TEXT NOT NULL)`),t.prepare(`CREATE INDEX IF NOT EXISTS idx_posts_status_date ON posts(status, date)`),t.prepare(`CREATE INDEX IF NOT EXISTS idx_requests_status_created ON requests(status, created_at)`)]),(await t.prepare(`PRAGMA table_info(posts)`).all()).results.some(e=>e.name===`image`)||await t.prepare(`ALTER TABLE posts ADD COLUMN image TEXT`).run(),await t.batch([...e].reverse().map((e,n)=>t.prepare(`INSERT OR IGNORE INTO posts (slug,title,excerpt,content,image,tag,date,status,created_at) VALUES (?,?,?,?,?,?,?,?,?)`).bind(e.slug,e.title,e.excerpt,e.content,e.image,e.tag,e.date,`published`,new Date(Date.UTC(2026,7,29,0,0,n)).toISOString()))),t}async function i(e=!1){return(await(await r()).prepare(`SELECT * FROM posts ${e?``:`WHERE status = 'published'`} ORDER BY id DESC`).all()).results}async function a(e){return await(await r()).prepare(`SELECT * FROM posts WHERE slug = ? AND status = 'published'`).bind(e).first()}async function o(){return(await(await r()).prepare(`SELECT * FROM requests ORDER BY id DESC`).all()).results}async function s(e){return(await r()).prepare(`INSERT INTO requests (type,name,company,phone,email,size,message,status,created_at) VALUES (?,?,?,?,?,?,?,?,?)`).bind(e.type,e.name,e.company,e.phone,e.email,e.size||null,e.message||null,`new`,new Date().toISOString()).run()}async function c(e){return(await r()).prepare(`INSERT INTO posts (slug,title,excerpt,content,image,tag,date,status,created_at) VALUES (?,?,?,?,?,?,?,?,?)`).bind(e.slug,e.title,e.excerpt,e.content,e.image||null,e.tag,e.date,e.status||`published`,new Date().toISOString()).run()}async function l(e,t){return(await r()).prepare(`UPDATE requests SET status = ? WHERE id = ?`).bind(t,e).run()}async function u(e,t){return(await r()).prepare(`UPDATE posts SET slug = ?, title = ?, excerpt = ?, content = ?, image = ?, tag = ?, date = ?, status = ? WHERE id = ?`).bind(t.slug,t.title,t.excerpt,t.content,t.image||null,t.tag,t.date,t.status||`published`,e).run()}async function d(e){return(await r()).prepare(`DELETE FROM posts WHERE id = ?`).bind(e).run()}export{a,u as c,r as i,l,s as n,i as o,d as r,o as s,c as t};